-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Backports/708/v2 #12265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backports/708/v2 #12265
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -725,6 +725,28 @@ static inline void DetectRunPrefilterPkt( | |
| #endif | ||
| } | ||
|
|
||
| static bool isOnlyTxInDirection(Flow *f, uint64_t txid, uint8_t dir) | ||
| { | ||
| uint64_t tx_cnt = AppLayerParserGetTxCnt(f, f->alstate); | ||
| if (tx_cnt == txid + 1) { | ||
| // only live tx | ||
| return true; | ||
| } | ||
| if (tx_cnt == txid + 2) { | ||
| // 2 live txs, one after us | ||
| void *tx = AppLayerParserGetTx(f->proto, f->alproto, f->alstate, txid + 1); | ||
| if (tx) { | ||
| AppLayerTxData *txd = AppLayerParserGetTxData(f->proto, f->alproto, tx); | ||
| // test if the other tx is unidirectional in the other way | ||
| if (txd && | ||
| (AppLayerParserGetTxDetectFlags(txd, dir) & APP_LAYER_TX_SKIP_INSPECT_FLAG)) { | ||
| return true; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we don't get a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it weird? Or would it be the same if we have more than 2 or more transactions open in flight for a non-unidirectional protocol, in which case we don't log any of them either, but we'd still have a tx_cnt.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jufajardini did you mean For txd, this should be impossible indeed, but it is the way to write code to make code analysis tools happy...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it was for tx. Ok, forgive my noise. |
||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static inline void DetectRulePacketRules( | ||
| ThreadVars * const tv, | ||
| DetectEngineCtx * const de_ctx, | ||
|
|
@@ -782,6 +804,10 @@ static inline void DetectRulePacketRules( | |
| goto next; // handle sig in DetectRunFrame | ||
| } | ||
|
|
||
| /* skip pkt sigs for flow end packets */ | ||
| if ((p->flags & PKT_PSEUDO_STREAM_END) != 0 && s->type == SIG_TYPE_PKT) | ||
| goto next; | ||
|
|
||
| /* don't run mask check for stateful rules. | ||
| * There we depend on prefilter */ | ||
| if ((s->mask & scratch->pkt_mask) != s->mask) { | ||
|
|
@@ -814,16 +840,18 @@ static inline void DetectRulePacketRules( | |
| DetectRunPostMatch(tv, det_ctx, p, s); | ||
|
|
||
| uint64_t txid = PACKET_ALERT_NOTX; | ||
| if ((alert_flags & PACKET_ALERT_FLAG_STREAM_MATCH) || | ||
| (s->alproto != ALPROTO_UNKNOWN && pflow->proto == IPPROTO_UDP)) { | ||
| // if there is a stream match (TCP), or | ||
| // a UDP specific app-layer signature, | ||
| // try to use the good tx for the packet direction | ||
| if (pflow->alstate) { | ||
| uint8_t dir = | ||
| (p->flowflags & FLOW_PKT_TOCLIENT) ? STREAM_TOCLIENT : STREAM_TOSERVER; | ||
| txid = AppLayerParserGetTransactionInspectId(pflow->alparser, dir); | ||
| if (pflow && pflow->alstate) { | ||
| uint8_t dir = (p->flowflags & FLOW_PKT_TOCLIENT) ? STREAM_TOCLIENT : STREAM_TOSERVER; | ||
| txid = AppLayerParserGetTransactionInspectId(pflow->alparser, dir); | ||
| if ((s->alproto != ALPROTO_UNKNOWN && pflow->proto == IPPROTO_UDP) || | ||
| (de_ctx->guess_applayer && isOnlyTxInDirection(pflow, txid, dir))) { | ||
| // if there is a UDP specific app-layer signature, | ||
| // or only one live transaction | ||
| // try to use the good tx for the packet direction | ||
| alert_flags |= PACKET_ALERT_FLAG_TX; | ||
| if (pflow->proto != IPPROTO_UDP) { | ||
| alert_flags |= PACKET_ALERT_FLAG_TX_GUESSED; | ||
| } | ||
| } | ||
| } | ||
| AlertQueueAppend(det_ctx, s, p, txid, alert_flags); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
IsOnly...