-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Detect rule types hooks/v18 #8906
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
Closed
victorjulien
wants to merge
3
commits into
OISF:master
from
victorjulien:detect-rule-types-hooks/v18
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -989,7 +989,7 @@ static int RulesGroupByProto(DetectEngineCtx *de_ctx) | |
| SigGroupHead *sgh_tc[256] = {NULL}; | ||
|
|
||
| for ( ; s != NULL; s = s->next) { | ||
| if (s->flags & SIG_FLAG_IPONLY) | ||
| if (s->type == SIG_TYPE_IPONLY) | ||
| continue; | ||
|
|
||
| int p; | ||
|
|
@@ -1168,7 +1168,7 @@ static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, uint8_t ipproto, u | |
| DetectPort *list = NULL; | ||
| while (s) { | ||
| /* IP Only rules are handled separately */ | ||
| if (s->flags & SIG_FLAG_IPONLY) | ||
| if (s->type == SIG_TYPE_IPONLY) | ||
| goto next; | ||
| if (!(s->proto.proto[ipproto / 8] & (1<<(ipproto % 8)) || (s->proto.flags & DETECT_PROTO_ANY))) | ||
| goto next; | ||
|
|
@@ -1300,21 +1300,65 @@ static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, uint8_t ipproto, u | |
|
|
||
| void SignatureSetType(DetectEngineCtx *de_ctx, Signature *s) | ||
| { | ||
| BUG_ON(s->type != SIG_TYPE_NOT_SET); | ||
| int iponly = 0; | ||
|
|
||
| /* see if the sig is dp only */ | ||
| if (SignatureIsPDOnly(de_ctx, s) == 1) { | ||
| s->flags |= SIG_FLAG_PDONLY; | ||
| s->type = SIG_TYPE_PDONLY; | ||
|
|
||
| /* see if the sig is ip only */ | ||
| /* see if the sig is ip only */ | ||
| } else if ((iponly = SignatureIsIPOnly(de_ctx, s)) > 0) { | ||
| if (iponly == 1) { | ||
| s->flags |= SIG_FLAG_IPONLY; | ||
| s->type = SIG_TYPE_IPONLY; | ||
| } else if (iponly == 2) { | ||
| s->flags |= SIG_FLAG_LIKE_IPONLY; | ||
| s->type = SIG_TYPE_LIKE_IPONLY; | ||
| } | ||
| } else if (SignatureIsDEOnly(de_ctx, s) == 1) { | ||
| s->init_data->init_flags |= SIG_FLAG_INIT_DEONLY; | ||
| s->type = SIG_TYPE_DEONLY; | ||
|
|
||
| } else { | ||
| const bool has_match = s->init_data->smlists[DETECT_SM_LIST_MATCH] != NULL; | ||
| const bool has_pmatch = s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL; | ||
| bool has_buffer_frame_engine = false; | ||
| bool has_buffer_packet_engine = false; | ||
| bool has_buffer_app_engine = false; | ||
|
|
||
| for (uint32_t x = 0; x < s->init_data->buffer_index; x++) { | ||
| const uint32_t id = s->init_data->buffers[x].id; | ||
|
|
||
| if (DetectEngineBufferTypeSupportsPacketGetById(de_ctx, id)) { | ||
| has_buffer_packet_engine = true; | ||
| } else if (DetectEngineBufferTypeSupportsFramesGetById(de_ctx, id)) { | ||
| has_buffer_frame_engine = true; | ||
| } else { | ||
| has_buffer_app_engine = true; | ||
| } | ||
| } | ||
|
|
||
| if (has_buffer_packet_engine) { | ||
| s->type = SIG_TYPE_PKT; | ||
| } else if (has_buffer_frame_engine || has_buffer_app_engine) { | ||
| s->type = SIG_TYPE_APP_TX; | ||
| } else if (has_pmatch) { | ||
| if ((s->flags & (SIG_FLAG_REQUIRE_PACKET | SIG_FLAG_REQUIRE_STREAM)) == | ||
| SIG_FLAG_REQUIRE_PACKET) { | ||
| s->type = SIG_TYPE_PKT; // TODO review | ||
|
Member
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. looks correct |
||
| } else if ((s->flags & (SIG_FLAG_REQUIRE_PACKET | SIG_FLAG_REQUIRE_STREAM)) == | ||
| SIG_FLAG_REQUIRE_STREAM) { | ||
| s->type = SIG_TYPE_STREAM; // TODO review | ||
|
Member
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. looks correct |
||
| } else { | ||
| s->type = SIG_TYPE_PKT_STREAM; | ||
| } | ||
| } else if (has_match) { | ||
| s->type = SIG_TYPE_PKT; | ||
|
|
||
| /* app-layer but no inspect engines */ | ||
| } else if (s->flags & SIG_FLAG_APPLAYER) { | ||
| s->type = SIG_TYPE_APPLAYER; | ||
| } else { | ||
| s->type = SIG_TYPE_PKT; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1354,15 +1398,15 @@ int SigAddressPrepareStage1(DetectEngineCtx *de_ctx) | |
|
|
||
| SCLogDebug("Signature %" PRIu32 ", internal id %" PRIu32 ", ptrs %p %p ", s->id, s->num, s, de_ctx->sig_array[s->num]); | ||
|
|
||
| if (s->flags & SIG_FLAG_PDONLY) { | ||
| if (s->type == SIG_TYPE_PDONLY) { | ||
| SCLogDebug("Signature %"PRIu32" is considered \"PD only\"", s->id); | ||
| } else if (s->flags & SIG_FLAG_IPONLY) { | ||
| } else if (s->type == SIG_TYPE_IPONLY) { | ||
| SCLogDebug("Signature %"PRIu32" is considered \"IP only\"", s->id); | ||
| cnt_iponly++; | ||
| } else if (SignatureIsInspectingPayload(de_ctx, s) == 1) { | ||
| SCLogDebug("Signature %"PRIu32" is considered \"Payload inspecting\"", s->id); | ||
| cnt_payload++; | ||
| } else if (s->init_data->init_flags & SIG_FLAG_INIT_DEONLY) { | ||
| } else if (s->type == SIG_TYPE_DEONLY) { | ||
| SCLogDebug("Signature %"PRIu32" is considered \"Decoder Event only\"", s->id); | ||
| cnt_deonly++; | ||
| } else if (s->flags & SIG_FLAG_APPLAYER) { | ||
|
|
@@ -1684,11 +1728,9 @@ int SigAddressPrepareStage2(DetectEngineCtx *de_ctx) | |
| /* now for every rule add the source group to our temp lists */ | ||
| for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) { | ||
| SCLogDebug("s->id %"PRIu32, s->id); | ||
| if (s->flags & SIG_FLAG_IPONLY) { | ||
| if (s->type == SIG_TYPE_IPONLY) { | ||
| IPOnlyAddSignature(de_ctx, &de_ctx->io_ctx, s); | ||
| } | ||
|
|
||
| if (s->init_data->init_flags & SIG_FLAG_INIT_DEONLY) { | ||
| } else if (s->type == SIG_TYPE_DEONLY) { | ||
| DetectEngineAddDecoderEventSig(de_ctx, s); | ||
| } | ||
| } | ||
|
|
@@ -1872,8 +1914,7 @@ static int SigMatchPrepare(DetectEngineCtx *de_ctx) | |
| DetectEngineAppInspectionEngine2Signature(de_ctx, s); | ||
|
|
||
| /* built-ins */ | ||
| int type; | ||
| for (type = 0; type < DETECT_SM_LIST_MAX; type++) { | ||
| for (int type = 0; type < DETECT_SM_LIST_MAX; type++) { | ||
| /* skip PMATCH if it is used in a stream 'app engine' instead */ | ||
| if (type == DETECT_SM_LIST_PMATCH && (s->init_data->init_flags & SIG_FLAG_INIT_STATE_MATCH)) | ||
| continue; | ||
|
|
@@ -1888,16 +1929,15 @@ static int SigMatchPrepare(DetectEngineCtx *de_ctx) | |
| EngineAnalysisRules2(de_ctx, s); | ||
| } | ||
| /* free lists. Ctx' are xferred to sm_arrays so won't get freed */ | ||
| uint32_t i; | ||
| for (i = 0; i < DETECT_SM_LIST_MAX; i++) { | ||
| for (uint32_t i = 0; i < DETECT_SM_LIST_MAX; i++) { | ||
| SigMatch *sm = s->init_data->smlists[i]; | ||
| while (sm != NULL) { | ||
| SigMatch *nsm = sm->next; | ||
| SigMatchFree(de_ctx, sm); | ||
| sm = nsm; | ||
| } | ||
| } | ||
| for (i = 0; i < (uint32_t)s->init_data->transforms.cnt; i++) { | ||
| for (uint32_t i = 0; i < (uint32_t)s->init_data->transforms.cnt; i++) { | ||
| if (s->init_data->transforms.transforms[i].options) { | ||
| int transform = s->init_data->transforms.transforms[i].transform; | ||
| sigmatch_table[transform].Free( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@jasonish @jufajardini we should probably consider this and the verdict output discussion we had. It would be good to make these things similar if not the same, and at least use one set of keywords.
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.
Given we brainstormed on this for a while, can you fit this new "policy" into #8596 (comment)?
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.
I'm sorry, this escaped me completely last week.
I noticed that this part seems to not have made it to the merged PR (#8928).
Well defining the keywords is one of the first steps, in my opinion, as at the moment 'policy', for instance, only echoes "exception policy" in my head xD
So in engine analysis mode, one would be able to see all actions that are available for rules, and what each of them means, if triggered (aka the 'verdict')?