-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Detect tcp noupdatetotx 6299 v9 #10145
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -1296,6 +1296,46 @@ static inline void StoreDetectFlags(DetectTransaction *tx, const uint8_t flow_fl | |
| } | ||
| } | ||
|
|
||
| static inline RuleMatchCandidateMergeSorted(DetectEngineThreadCtx *det_ctx, uint32_t j, uint32_t k) | ||
|
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. I'm having trouble understanding this. When we get called we have have 0-N entries in
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. Is this a matter of where this has been called, together with the fact that we still have the qsort called later on, (and we're not taking
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.
The point is to avoid the call to qsort (in the case we do not have match candidates added after by stored flags) cf removal of
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.
Will put more comments. Quick and dirty answer : |
||
| { | ||
| for (uint32_t i = det_ctx->match_array_cnt; i > 0;) { | ||
| const Signature *s = det_ctx->match_array[i - 1]; | ||
| if (s->app_inspect != NULL) { | ||
| const SigIntId id = s->num; | ||
| if (j > 0) { | ||
| const RuleMatchCandidateTx *s0 = &det_ctx->tx_candidates[j - 1]; | ||
| if (s->id > s0->id) { | ||
|
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. Shouldn't this comparison be with
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.
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. Thinking about renaming
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. cf
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. Nice catch Juliana |
||
| det_ctx->tx_candidates[k - 1].s = s; | ||
| det_ctx->tx_candidates[k - 1].id = id; | ||
| det_ctx->tx_candidates[k - 1].flags = NULL; | ||
| det_ctx->tx_candidates[k - 1].stream_reset = 0; | ||
| i--; | ||
| } else { | ||
| // progress in the sorted list | ||
| det_ctx->tx_candidates[k - 1].s = det_ctx->tx_candidates[j - 1].s; | ||
| det_ctx->tx_candidates[k - 1].id = det_ctx->tx_candidates[j - 1].id; | ||
| det_ctx->tx_candidates[k - 1].flags = det_ctx->tx_candidates[j - 1].flags; | ||
| det_ctx->tx_candidates[k - 1].stream_reset = | ||
| det_ctx->tx_candidates[j - 1].stream_reset; | ||
| j--; | ||
| } | ||
| } else { | ||
| // simply append the end of sorted list | ||
| det_ctx->tx_candidates[k - 1].s = s; | ||
| det_ctx->tx_candidates[k - 1].id = id; | ||
| det_ctx->tx_candidates[k - 1].flags = NULL; | ||
| det_ctx->tx_candidates[k - 1].stream_reset = 0; | ||
| i--; | ||
| SCLogDebug("%p/%" PRIu64 " rule %u (%u) added from 'match' list", tx.tx_ptr, | ||
| tx.tx_id, s->id, id); | ||
| } | ||
| k--; | ||
| } else { | ||
| i--; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static void DetectRunTx(ThreadVars *tv, | ||
| DetectEngineCtx *de_ctx, | ||
| DetectEngineThreadCtx *det_ctx, | ||
|
|
@@ -1373,18 +1413,10 @@ static void DetectRunTx(ThreadVars *tv, | |
| for (uint32_t i = 0; i < det_ctx->match_array_cnt; i++) { | ||
| const Signature *s = det_ctx->match_array[i]; | ||
| if (s->app_inspect != NULL) { | ||
| const SigIntId id = s->num; | ||
| det_ctx->tx_candidates[array_idx].s = s; | ||
| det_ctx->tx_candidates[array_idx].id = id; | ||
| det_ctx->tx_candidates[array_idx].flags = NULL; | ||
| det_ctx->tx_candidates[array_idx].stream_reset = 0; | ||
| array_idx++; | ||
|
|
||
| SCLogDebug("%p/%"PRIu64" rule %u (%u) added from 'match' list", | ||
| tx.tx_ptr, tx.tx_id, s->id, id); | ||
| } | ||
| } | ||
| do_sort = (array_idx > x); // sort if match added anything | ||
| RuleMatchCandidateMergeSorted(det_ctx, x, array_idx); | ||
| SCLogDebug("%p/%" PRIu64 " rules added from 'match' list: %u", tx.tx_ptr, tx.tx_id, | ||
| array_idx - x); | ||
|
|
||
|
|
||
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.
If we merge this one, could we have a comment indicating what params j and k are?
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.
Good idea, will do. IIRC they are size of both sorted lists to merge into a big one