Go to the documentation of this file.
68 "toserver TCP packet",
69 "toclient TCP packet",
70 "toserver TCP stream",
71 "toclient TCP stream",
72 "toserver UDP packet",
73 "toclient UDP packet",
90 static void RegisterInternal(
const char *
name,
int direction,
int priority,
94 uint8_t tx_min_progress)
96 SCLogDebug(
"registering %s/%d/%d/%p/%p/%u/%d",
name, direction, priority,
97 PrefilterRegister, GetData, alproto, tx_min_progress);
125 am->
sm_list = (int16_t)sm_list;
131 if (GetData != NULL) {
132 am->
app_v2.GetData = GetData;
133 }
else if (GetDataSingle != NULL) {
134 am->
app_v2.GetDataSingle = GetDataSingle;
135 }
else if (GetMultiData != NULL) {
136 am->
app_v2.GetMultiData = GetMultiData;
138 am->
app_v2.alproto = alproto;
139 am->
app_v2.tx_min_progress = tx_min_progress;
140 am->
app_v2.sub_state = sub_state;
146 while (t->
next != NULL) {
161 AppProto alproto, uint8_t tx_min_progress)
163 RegisterInternal(
name, direction, priority, PrefilterRegister, GetData, NULL, NULL, alproto, 0,
169 AppProto alproto, uint8_t sub_state, uint8_t tx_min_progress)
172 RegisterInternal(
name, direction, priority, PrefilterRegister, GetData, NULL, NULL, alproto,
173 sub_state, tx_min_progress);
178 AppProto alproto, uint8_t tx_min_progress)
180 RegisterInternal(
name, direction, priority, PrefilterRegister, NULL, GetData, NULL, alproto, 0,
186 AppProto alproto, uint8_t tx_min_progress)
188 RegisterInternal(
name, direction, priority, PrefilterRegister, NULL, NULL, GetData, alproto, 0,
194 AppProto alproto, uint8_t sub_state, uint8_t tx_min_progress)
196 RegisterInternal(
name, direction, priority, PrefilterRegister, NULL, NULL, GetData, alproto,
197 sub_state, tx_min_progress);
203 static void BuildBasicPname(
char *out,
const size_t out_size,
const char *
name,
const uint16_t
id)
216 size_t name_space = out_size - (id_space + 1);
217 char pname[name_space];
218 if (strlen(
name) >= name_space) {
223 snprintf(out, out_size,
"%s#%u", pname,
id);
231 static void AppendTransformsToPname(
234 if (transforms == NULL || transforms->
cnt == 0)
237 ssize_t left = (ssize_t)out_size - (ssize_t)strlen(out) - (ssize_t)4;
245 for (
int i = 0; i < transforms->
cnt; i++) {
247 (void)snprintf(ttstr,
sizeof(ttstr),
"%s,",
249 strlcat(xforms, ttstr,
sizeof(xforms));
251 if (strlen(xforms) == 0)
253 xforms[strlen(xforms) - 1] =
'\0';
254 SCLogDebug(
"left %d '%s' %d", (
int)left, xforms, (
int)strlen(xforms));
256 char xforms_print[out_size];
257 if ((
size_t)left >= strlen(xforms)) {
258 snprintf(xforms_print,
sizeof(xforms_print),
" (%s)", xforms);
260 char xforms_short[out_size];
262 snprintf(xforms_print,
sizeof(xforms_print),
" (%s)", xforms_short);
264 strlcat(out, xforms_print, out_size);
270 const int id,
const int parent_id,
273 SCLogDebug(
"registering %d/%d",
id, parent_id);
297 BuildBasicPname(am->
pname,
sizeof(am->
pname), am->
name, (uint16_t)
id);
299 memcpy(&am->
transforms, transforms,
sizeof(*transforms));
300 AppendTransformsToPname(am->
pname,
sizeof(am->
pname), transforms);
307 SCLogDebug(
"copied mpm registration for %s id %u "
308 "with parent %u and GetData %p",
320 while (list != NULL) {
340 char confstring[256] =
"detect.mpm.";
342 strlcat(confstring,
".shared",
sizeof(confstring));
376 if (mpm_ctx != NULL) {
396 SCLogDebug(
"registering %s/%d/%p/%s/%u",
name, priority, PrefilterRegister,
403 if (sm_list < 0 || sm_list > UINT16_MAX) {
411 am->
sm_list = (uint16_t)sm_list;
426 while (t->
next != NULL) {
442 SCLogDebug(
"registering %d/%d",
id, parent_id);
462 BuildBasicPname(am->
pname,
sizeof(am->
pname), am->
name, (uint16_t)
id);
464 memcpy(&am->
transforms, transforms,
sizeof(*transforms));
465 AppendTransformsToPname(am->
pname,
sizeof(am->
pname), transforms);
471 SCLogDebug(
"copied mpm registration for %s id %u "
473 t->
name,
id, parent_id);
486 SCLogDebug(
"registering %s/%d/%p/%s/%u",
name, priority, PrefilterRegister,
490 if (sm_list < 0 || sm_list > UINT16_MAX) {
502 am->
sm_list = (uint16_t)sm_list;
517 if (
SCConfGetBool(
"detect.mpm.frame.shared", &confshared) == 1)
531 while (t->
next != NULL) {
546 while (list != NULL) {
557 while (t->
next != NULL) {
569 char confstring[256] =
"detect.mpm.";
571 strlcat(confstring,
".shared",
sizeof(confstring));
607 if (mpm_ctx != NULL) {
629 PrefilterRegister, GetData);
646 am->
sm_list = (uint16_t)sm_list;
651 am->
pkt_v1.GetData = GetData;
657 while (t->
next != NULL) {
671 const int id,
const int parent_id,
674 SCLogDebug(
"registering %d/%d",
id, parent_id);
692 BuildBasicPname(am->
pname,
sizeof(am->
pname), am->
name, (uint16_t)
id);
694 memcpy(&am->
transforms, transforms,
sizeof(*transforms));
695 AppendTransformsToPname(am->
pname,
sizeof(am->
pname), transforms);
701 SCLogDebug(
"copied mpm registration for %s id %u "
702 "with parent %u and GetData %p",
713 while (list != NULL) {
724 while (t->
next != NULL) {
736 char confstring[256] =
"detect.mpm.";
738 strlcat(confstring,
".shared",
sizeof(confstring));
772 if (mpm_ctx != NULL) {
791 char confstring[256] =
"detect.mpm.";
793 strlcat(confstring,
".shared",
sizeof(confstring));
938 const char *mpm_algo;
942 if ((
SCConfGet(
"mpm-algo", &mpm_algo)) == 1) {
943 if (mpm_algo != NULL) {
944 #if __BYTE_ORDER == __BIG_ENDIAN
945 if (strcmp(mpm_algo,
"ac-ks") == 0) {
947 "not work on big endian systems at this time.");
950 if (strcmp(
"auto", mpm_algo) == 0) {
952 }
else if (strcmp(
"ac-bs", mpm_algo) == 0) {
953 SCLogWarning(
"mpm-algo \"ac-bs\" has been removed. See ticket #6586.");
966 #ifndef BUILD_HYPERSCAN
967 if ((strcmp(mpm_algo,
"hs") == 0)) {
968 FatalError(
"Hyperscan (hs) support for mpm-algo is "
969 "not compiled into Suricata.");
974 "in the yaml conf file: \"%s\"",
984 SCLogDebug(
"mpm_ctx %p, mpm_matcher %"PRIu16
"", mpm_ctx, mpm_matcher);
990 SCLogDebug(
"mpm_thread_ctx %p, mpm_matcher %"PRIu16
"", mpm_thread_ctx, mpm_matcher);
996 MpmCtx cum_mpm_ctx = { 0 };
1001 if (ms == NULL || ms->
mpm_ctx == NULL) {
1028 memset(&a, 0 ,
sizeof(a));
1032 for (u = 0; u < patlen; u++) {
1033 if (a[pat[u]] == 0) {
1034 if (isalpha(pat[u]))
1036 else if (isprint(pat[u]) || pat[u] == 0x00 || pat[u] == 0x01 || pat[u] == 0xFF)
1053 uint16_t pat_offset = cd->
offset;
1054 uint16_t pat_depth = cd->
depth;
1057 if (chop && (pat_depth || pat_offset)) {
1069 pat_depth = pat_offset = 0;
1091 #define SGH_PROTO(sgh, p) ((sgh)->init->protos[(p)] == 1)
1092 #define SGH_DIRECTION_TS(sgh) ((sgh)->init->direction & SIG_FLAG_TOSERVER)
1093 #define SGH_DIRECTION_TC(sgh) ((sgh)->init->direction & SIG_FLAG_TOCLIENT)
1097 if (s == NULL || mpm_sm == NULL)
1123 uint16_t max_len,
bool skip_negated_content)
1138 if (mpm_sm == NULL) {
1147 }
else if (ls == ss) {
1166 for (; app != NULL; app = app->
next) {
1169 if (app->
dir == 1) {
1191 int pos_sm_list[nlists];
1192 int neg_sm_list[nlists];
1193 memset(pos_sm_list, 0, nlists *
sizeof(
int));
1194 memset(neg_sm_list, 0, nlists *
sizeof(
int));
1195 int pos_sm_list_cnt = 0;
1196 int neg_sm_list_cnt = 0;
1245 SetMpm(s, sm, list_id);
1250 neg_sm_list[list_id] = 1;
1253 pos_sm_list[list_id] = 1;
1261 SCLogDebug(
"neg_sm_list_cnt %d pos_sm_list_cnt %d", neg_sm_list_cnt, pos_sm_list_cnt);
1264 int *curr_sm_list = NULL;
1265 int skip_negated_content = 1;
1266 if (pos_sm_list_cnt > 0) {
1267 curr_sm_list = pos_sm_list;
1268 }
else if (neg_sm_list_cnt > 0) {
1269 curr_sm_list = neg_sm_list;
1270 skip_negated_content = 0;
1275 int final_sm_list[nlists];
1276 memset(&final_sm_list, 0, (nlists *
sizeof(
int)));
1278 int count_final_sm_list = 0;
1279 int count_txbidir_toclient_sm_list = 0;
1283 while (tmp != NULL) {
1285 tmp != NULL && priority == tmp->
priority;
1291 if (curr_sm_list[tmp->
list_id] == 0)
1296 if (count_final_sm_list == 0) {
1298 final_sm_list[count_txbidir_toclient_sm_list++] = tmp->
list_id;
1304 final_sm_list[count_final_sm_list++] = tmp->
list_id;
1307 if (count_final_sm_list != 0)
1313 count_final_sm_list = count_txbidir_toclient_sm_list;
1315 BUG_ON(count_final_sm_list == 0);
1316 SCLogDebug(
"count_final_sm_list %d skip_negated_content %d", count_final_sm_list,
1317 skip_negated_content);
1319 uint16_t max_len = 0;
1320 for (
int i = 0; i < count_final_sm_list; i++) {
1321 SCLogDebug(
"i %d final_sm_list[i] %d", i, final_sm_list[i]);
1344 if (final_sm_list[i] == list_id) {
1365 int mpm_sm_list = -1;
1366 for (
int i = 0; i < count_final_sm_list; i++) {
1372 skip_negated_content);
1373 if (mpm_sm != prev_mpm_sm) {
1374 mpm_sm_list = final_sm_list[i];
1381 if (final_sm_list[i] == list_id) {
1387 skip_negated_content);
1389 if (mpm_sm != prev_mpm_sm) {
1390 mpm_sm_list = list_id;
1398 if (mpm_sm != NULL) {
1399 BUG_ON(mpm_sm_list == -1);
1401 BUG_ON(check_list != mpm_sm_list);
1405 SetMpm(s, mpm_sm, mpm_sm_list);
1417 static uint32_t MpmStoreHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
1439 static char MpmStoreCompareFunc(
void *data1, uint16_t len1,
void *data2,
1469 static void MpmStoreFreeFunc(
void *ptr)
1499 MpmStoreCompareFunc,
1544 while (am != NULL) {
1552 while (am != NULL) {
1564 uint32_t *appstats = NULL;
1565 uint32_t *pktstats = NULL;
1566 uint32_t *framestats = NULL;
1570 if (appstats == NULL) {
1574 if (pktstats == NULL) {
1578 if (framestats == NULL) {
1587 if (ms == NULL || ms->
mpm_ctx == NULL) {
1597 SCLogDebug(
"%s: %u patterns. Min %u, Max %u. Ctx %p",
1605 SCLogDebug(
"%s %s %s: %u patterns. Min %u, Max %u. Ctx %p",
1626 for (
int x = 0; x <
MPMB_MAX; x++) {
1630 while (am != NULL) {
1631 if (appstats[am->
sm_list] > 0) {
1634 SCLogPerf(
"AppLayer MPM \"%s %s (%s)\": %u", direction,
name,
1640 while (pm != NULL) {
1641 if (pktstats[pm->
sm_list] > 0) {
1648 while (um != NULL) {
1649 if (framestats[um->
sm_list] > 0) {
1725 const bool mpm_supports_endswith =
1730 if (ms->
sid_array[sig / 8] & (1 << (sig % 8))) {
1750 SCLogDebug(
"not adding negated mpm as it's not 'single'");
1787 int sgh_mpm_context = 0;
1789 uint8_t *sids_array =
SCCalloc(1, max_sid);
1790 if (sids_array == NULL) {
1855 sids_array[s->
iid / 8] |= 1 << (s->
iid % 8);
1863 sids_array[s->
iid / 8] |= 1 << (s->
iid % 8);
1869 sids_array[s->
iid / 8] |= 1 << (s->
iid % 8);
1873 sids_array[s->
iid / 8] |= 1 << (s->
iid % 8);
1886 MpmStore lookup = { sids_array, max_sid, direction, buf, sm_list, 0, 0, NULL };
1889 if (result == NULL) {
1893 uint8_t *sids =
SCCalloc(1, max_sid);
1900 memcpy(sids, sids_array, max_sid);
1908 MpmStoreSetup(
de_ctx, copy);
1909 MpmStoreAdd(
de_ctx, copy);
1938 0, am->
app_v2.alproto, NULL };
1943 if (result == NULL) {
1965 MpmStoreSetup(
de_ctx, copy);
1966 MpmStoreAdd(
de_ctx, copy);
1989 if (result == NULL) {
2009 MpmStoreSetup(
de_ctx, copy);
2010 MpmStoreAdd(
de_ctx, copy);
2032 if (result == NULL) {
2053 MpmStoreSetup(
de_ctx, copy);
2054 MpmStoreAdd(
de_ctx, copy);
2075 SCLogDebug(
"rule group %p has SIG_GROUP_HEAD_HAVERAWSTREAM set", sgh);
2079 SCLogDebug(
"rule group %p does NOT have SIG_GROUP_HEAD_HAVERAWSTREAM set", sgh);
2091 static uint32_t DetectBufferInstanceHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
2098 static char DetectBufferInstanceCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
2105 static void DetectBufferInstanceFreeFunc(
void *ptr)
2117 return HashListTableInit(4096, DetectBufferInstanceHashFunc, DetectBufferInstanceCompareFunc,
2118 DetectBufferInstanceFreeFunc);
2139 int *types =
SCCalloc(max_buffer_id,
sizeof(
int));
2144 types[a->sm_list] = a->type;
2148 if (instance == NULL) {
2149 instance =
SCCalloc(1,
sizeof(*instance));
2150 BUG_ON(instance == NULL);
2151 instance->
list = a->sm_list;
2161 if (add_ts || add_tc) {
2162 types[a->sm_list] = a->type;
2164 engines[a->sm_list].
array[engines[a->sm_list].
idx++] = a->frame_v1.alproto;
2168 if (instance == NULL) {
2169 instance =
SCCalloc(1,
sizeof(*instance));
2170 BUG_ON(instance == NULL);
2171 instance->
list = a->sm_list;
2172 instance->
alproto = a->frame_v1.alproto;
2182 if (add_ts || add_tc) {
2183 types[a->sm_list] = a->type;
2185 engines[a->sm_list].
array[engines[a->sm_list].
idx++] = a->app_v2.alproto;
2189 if (instance == NULL) {
2190 instance =
SCCalloc(1,
sizeof(*instance));
2191 BUG_ON(instance == NULL);
2192 instance->
list = a->sm_list;
2193 instance->
alproto = a->app_v2.alproto;
2201 for (uint32_t sig = 0; sig < sh->
init->
sig_cnt; sig++) {
2213 switch (types[list]) {
2217 for (
size_t e = 0; e < engines[list].
idx; e++) {
2221 if (!(AppProtoEqualsStrict(s->
alproto, alproto))) {
2232 if (instance == NULL)
2265 if (instance == NULL)
2295 if (instance == NULL) {
2302 MpmStore *mpm_store = MpmStorePrepareBufferPkt(
de_ctx, sh, a, sa);
2303 if (mpm_store != NULL) {
2306 SCLogDebug(
"a %p a->name %s a->reg->PrefilterRegisterWithListId %p "
2307 "mpm_store->mpm_ctx %p", a, a->name,
2308 a->PrefilterRegisterWithListId, mpm_store->
mpm_ctx);
2312 if (a->PrefilterRegisterWithListId && mpm_store->
mpm_ctx) {
2315 a, a->sm_list) != 0);
2316 SCLogDebug(
"mpm %s %d set up", a->name, a->sm_list);
2325 if (instance == NULL) {
2333 SCLogDebug(
"a %s direction %d PrefilterRegisterWithListId %p", a->name, a->direction,
2334 a->PrefilterRegisterWithListId);
2335 MpmStore *mpm_store = MpmStorePrepareBufferFrame(
de_ctx, sh, a, sa);
2336 if (mpm_store != NULL) {
2339 SCLogDebug(
"a %p a->name %s a->reg->PrefilterRegisterWithListId %p "
2340 "mpm_store->mpm_ctx %p",
2341 a, a->name, a->PrefilterRegisterWithListId, mpm_store->
mpm_ctx);
2346 if (a->PrefilterRegisterWithListId && mpm_store->
mpm_ctx) {
2347 BUG_ON(a->PrefilterRegisterWithListId(
2349 SCLogDebug(
"mpm %s %d set up", a->name, a->sm_list);
2360 if (instance == NULL) {
2368 MpmStore *mpm_store = MpmStorePrepareBufferAppLayer(
de_ctx, sh, a, sa);
2369 if (mpm_store != NULL) {
2372 SCLogDebug(
"a %p a->name %s a->PrefilterRegisterWithListId %p "
2373 "mpm_store->mpm_ctx %p",
2374 a, a->name, a->PrefilterRegisterWithListId, mpm_store->
mpm_ctx);
2378 if (a->PrefilterRegisterWithListId && mpm_store->
mpm_ctx) {
2379 BUG_ON(a->PrefilterRegisterWithListId(
2381 SCLogDebug(
"mpm %s %d set up", a->name, a->sm_list);
2400 if (mpm_store != NULL) {
2405 if (mpm_store != NULL) {
2409 SetRawReassemblyFlag(
de_ctx, sh);
2413 if (mpm_store != NULL) {
2418 if (mpm_store != NULL) {
2422 SetRawReassemblyFlag(
de_ctx, sh);
2424 }
else if (
SGH_PROTO(sh, IPPROTO_UDP)) {
2427 if (mpm_store != NULL) {
2433 if (mpm_store != NULL) {
2439 if (mpm_store != NULL) {
2463 static uint32_t PatternChopHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
2466 uint32_t hash =
p->sm_list + ContentFlagsForHash(
p->cd);
2467 uint16_t content_len =
p->cd->content_len;
2468 const uint8_t *content =
p->cd->content;
2470 content +=
p->cd->fp_chop_offset;
2471 content_len =
p->cd->fp_chop_len;
2486 static uint32_t PatternNoChopHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
2489 uint32_t hash =
p->sm_list + ContentFlagsForHash(
p->cd);
2505 static char PatternChopCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
2513 if (ContentFlagsForHash(p1->
cd) != ContentFlagsForHash(p2->
cd))
2529 if (p1_content_len != p2_content_len)
2532 if (memcmp(p1_content, p2_content, p1_content_len) != 0) {
2550 static char PatternNoChopCompareFunc(
void *data1, uint16_t len1,
void *data2, uint16_t len2)
2558 if (ContentFlagsForHash(p1->
cd) != ContentFlagsForHash(p2->
cd))
2571 static void PatternFreeFunc(
void *ptr)
2598 HashListTableInit(4096, PatternChopHashFunc, PatternChopCompareFunc, PatternFreeFunc);
2629 SCLogDebug(
"%u: add id %u cnt %u", s->
id, add->cd->id, add->cnt);
2646 4096, PatternNoChopHashFunc, PatternNoChopCompareFunc, PatternFreeFunc);
2652 switch (smd->
type) {
2682 for (; app != NULL; app = app->
next) {
2685 switch (smd->
type) {
2690 .
cd = cd, .sm_list = app->
sm_list, .cnt = 0, .mpm = 0
2715 for (; pkt != NULL; pkt = pkt->
next) {
2722 switch (smd->
type) {
2727 .
cd = cd, .sm_list = pkt->
sm_list, .cnt = 0, .mpm = 0
2752 for (; frame != NULL; frame = frame->
next) {
2759 switch (smd->
type) {
2764 .
cd = cd, .sm_list = frame->
sm_list, .cnt = 0, .mpm = 0
#define DETECT_CONTENT_NOCASE
int SignatureHasPacketContent(const Signature *s)
check if a signature has patterns that are to be inspected against a packets payload (as opposed to t...
uint32_t pkt_mpms_list_cnt
#define HashListTableGetListData(hb)
uint32_t frame_mpms_list_cnt
uint32_t max_content_list_id
int PrefilterGenericMpmPktRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
#define SGH_DIRECTION_TC(sgh)
#define DETECT_PROFILE_NAME_LEN
#define DETECT_CONTENT_FAST_PATTERN_CHOP
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
void PatternMatchDestroy(MpmCtx *mpm_ctx, uint16_t mpm_matcher)
SigTableElmt * sigmatch_table
int AppLayerParserIsEnabled(AppProto alproto)
simple way to globally test if a alproto is registered and fully enabled in the configuration.
int32_t sgh_mpm_context_proto_tcp_packet
int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
Prepare the pattern matcher ctx in a sig group head.
struct SCFPSupportSMList_ * next
struct DetectEngineAppInspectionEngine_ * next
void DetectAppLayerMpmRegisterSingle(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionSingleBufferGetDataPtr GetData, AppProto alproto, uint8_t tx_min_progress)
void MpmStoreFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->mpm_hash_table, allocated by MpmStoreInit() function.
void DetectFrameMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
Container for matching data for a signature group.
HashListTable * pattern_hash_table
void MpmFactoryReClaimMpmCtx(const DetectEngineCtx *de_ctx, MpmCtx *mpm_ctx)
void MpmStoreReportStats(const DetectEngineCtx *de_ctx)
void DetectPktMpmRegister(const char *name, int priority, int(*PrefilterRegister)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id), InspectionBufferGetPktDataPtr GetData)
register a MPM engine
void DetectBufferTypeSupportsFrames(const char *name)
struct DetectBufferMpmRegistry_::@90::@92 app_v2
void DetectMpmInitializeFrameMpms(DetectEngineCtx *de_ctx)
@ DETECT_SM_LIST_DYNAMIC_START
#define DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
uint32_t PatternStrength(uint8_t *pat, uint16_t patlen)
Predict a strength value for patterns.
DetectBufferMpmRegistry * pkt_mpms_list
@ DETECT_BUFFER_MPM_TYPE_FRAME
int DetectSetFastPatternAndItsId(DetectEngineCtx *de_ctx)
Figure out the FP and their respective content ids for all the sigs in the engine.
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
main detection engine ctx
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#define DETECT_CONTENT_MPM_IS_CONCLUSIVE(c)
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
#define DETECT_CONTENT_DEPTH_VAR
InspectionBuffer *(* InspectionBufferGetPktDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Packet *p, const int list_id)
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
void DetectMpmInitializeBuiltinMpms(DetectEngineCtx *de_ctx)
struct DetectBufferMpmRegistry_ * next
#define SIG_FLAG_REQUIRE_STREAM
#define SIG_FLAG_TXBOTHDIR
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
one time registration of keywords at start up
const struct DetectContentData_ * cd
#define SIG_GROUP_HEAD_HAVERAWSTREAM
uint8_t mpm_default_matcher
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
#define SIG_FLAG_TOCLIENT
int32_t sgh_mpm_context_proto_udp_packet
DetectEngineTransforms transforms
void ShortenString(const char *input, char *output, size_t output_size, char c)
void DetectEngineRegisterFastPatternForId(DetectEngineCtx *de_ctx, int list_id, int priority)
void DetectAppLayerMpmRegisterSubState(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, uint8_t sub_state, uint8_t tx_min_progress)
void EngineAnalysisAddAllRulePatterns(DetectEngineCtx *de_ctx, const Signature *s)
add all patterns on our stats hash Used to fill the hash later used by DumpPatterns()
DetectEngineFrameInspectionEngine * frame_inspect
const char * cache_dir_path
int DetectBufferTypeGetByName(const char *name)
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
struct DetectBufferMpmRegistry_::@90::@93 pkt_v1
size_t strlcpy(char *dst, const char *src, size_t siz)
void DetectAppLayerMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
struct MpmEngineList MpmEngineList
@ SIGNATURE_HOOK_TYPE_APP
void MpmInitCtx(MpmCtx *mpm_ctx, uint8_t matcher)
int32_t sgh_mpm_context_proto_other_packet
#define HashListTableGetListNext(hb)
#define SIG_FLAG_TOSERVER
HashListTable * HashListTableInit(uint32_t size, uint32_t(*Hash)(struct HashListTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
void MpmDestroyThreadCtx(MpmThreadCtx *mpm_thread_ctx, const uint16_t matcher)
char pname[DETECT_PROFILE_NAME_LEN]
struct DetectBufferMpmRegistry_::@90::@94 frame_v1
#define DETECT_CONTENT_ENDS_WITH
MpmCtx * MpmFactoryGetMpmCtxForProfile(const DetectEngineCtx *de_ctx, int32_t id, int direction)
void DetectMpmInitializePktMpms(DetectEngineCtx *de_ctx)
void DetectAppLayerMpmMultiRegisterSubState(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionMultiBufferGetDataPtr GetData, AppProto alproto, uint8_t sub_state, uint8_t tx_min_progress)
AppProto array[ALPROTO_MAX_STATIC]
#define MPM_PATTERN_CTX_OWNS_ID
size_t strlcat(char *, const char *src, size_t siz)
@ ENGINE_SGH_MPM_FACTORY_CONTEXT_SINGLE
#define DetectEngineGetMaxSigId(de_ctx)
int SCMpmAddPatternCI(MpmCtx *mpm_ctx, const uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
#define DETECT_CONTENT_DEPTH
DetectEnginePktInspectionEngine * pkt_inspect
bool(* InspectionSingleBufferGetDataPtr)(const void *txv, const uint8_t flow_flags, const uint8_t **buf, uint32_t *buf_len)
#define DETECT_CONTENT_IS_SINGLE(c)
#define DETECT_CONTENT_NEGATED
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
#define SCLogWarning(...)
Macro used to log WARNING messages.
int DetectEngineBufferTypeRegister(DetectEngineCtx *de_ctx, const char *name)
SigGroupHeadInitData * init
DetectEngineAppInspectionEngine * app_inspect
bool DetectBufferToClient(const DetectEngineCtx *de_ctx, int buf_id, AppProto alproto)
#define MPMCTX_FLAGS_GLOBAL
int(* PrefilterRegisterFunc)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
int32_t MpmFactoryRegisterMpmCtxProfile(DetectEngineCtx *de_ctx, const char *name, const int sm_list, const AppProto alproto)
Register a new Mpm Context.
int32_t sgh_mpm_context_stream
void PatternMatchThreadPrepare(MpmThreadCtx *mpm_thread_ctx, DetectEngineCtx *de_ctx)
void DetectEngineBufferTypeSupportsFrames(DetectEngineCtx *de_ctx, const char *name)
DetectBufferMpmRegistry * frame_mpms_list
int PrefilterPktPayloadRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx)
@ DETECT_BUFFER_MPM_TYPE_PKT
SignatureInitData * init_data
int FastPatternSupportEnabledForSigMatchList(const DetectEngineCtx *de_ctx, const int list_id)
Checks if a particular buffer is in the list of lists that need to be searched for a keyword that has...
enum DetectBufferMpmType type
int MpmAddPatternCS(struct MpmCtx_ *mpm_ctx, uint8_t *pat, uint16_t patlen, uint16_t offset, uint16_t depth, uint32_t pid, SigIntId sid, uint8_t flags)
void DetectEngineBufferTypeSupportsTransformations(DetectEngineCtx *de_ctx, const char *name)
bool(* InspectionMultiBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const void *txv, const uint8_t flow_flags, uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
#define SGH_DIRECTION_TS(sgh)
void DetectAppLayerMpmMultiRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionMultiBufferGetDataPtr GetData, AppProto alproto, uint8_t tx_min_progress)
#define MPM_FEATURE_FLAG_ENDSWITH
#define APP_LAYER_MAX_PROGRESS
MpmStore * MpmStorePrepareBuffer(DetectEngineCtx *de_ctx, SigGroupHead *sgh, enum MpmBuiltinBuffers buf)
Get MpmStore for a built-in buffer type.
int DetectMpmPrepareFrameMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
void DetectEngineFrameMpmRegister(DetectEngineCtx *de_ctx, const char *name, int direction, int priority, int(*PrefilterRegister)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id), AppProto alproto, uint8_t type)
int SignatureHasStreamContent(const Signature *s)
check if a signature has patterns that are to be inspected against the stream payload (as opposed to ...
enum DetectBufferMpmType type
int MpmStoreInit(DetectEngineCtx *de_ctx)
Initializes the MpmStore mpm hash table to be used by the detection engine context.
DetectBufferMpmRegistry * app_mpms_list
@ DETECT_BUFFER_MPM_TYPE_APP
void DetectBufferTypeSupportsMpm(const char *name)
void HashListTableFree(HashListTable *ht)
void SupportFastPatternForSigMatchList(int list_id, int priority)
Lets one add a sm list id to be searched for potential fp supported keywords later.
struct DetectEngineFrameInspectionEngine * next
enum SignatureHookType type
struct DetectEnginePktInspectionEngine * next
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, uint8_t tx_min_progress)
register an app layer keyword for mpm
uint8_t PatternMatchDefaultMatcher(void)
Function to return the multi pattern matcher algorithm to be used by the engine, based on the mpm-alg...
int DetectMpmPreparePktMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
void DetectEngineBufferTypeSupportsMpm(DetectEngineCtx *de_ctx, const char *name)
uint32_t app_mpms_list_cnt
void DetectBufferTypeSupportsTransformations(const char *name)
#define MPM_PATTERN_FLAG_ENDSWITH
const char * builtin_mpms[]
SignatureInitDataBuffer * buffers
DetectEngineAppInspectionEngine * app_inspect_engines
HashListTable * mpm_hash_table
int(* Prepare)(MpmConfig *, struct MpmCtx_ *)
void(* DestroyCtx)(struct MpmCtx_ *)
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
#define MPM_CTX_FACTORY_UNIQUE_CONTEXT
int DetectMpmPrepareBuiltinMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for builtin buffers that are in "single or "shared" mode.
#define DETECT_CONTENT_OFFSET
int(* PrefilterRegisterWithListId)(struct DetectEngineCtx_ *de_ctx, struct SigGroupHead_ *sgh, MpmCtx *mpm_ctx, const struct DetectBufferMpmRegistry_ *mpm_reg, int list_id)
#define DETECT_CONTENT_MPM
a single match condition for a signature
void MpmInitThreadCtx(MpmThreadCtx *mpm_thread_ctx, MpmCtx *mpm_ctx, uint16_t matcher)
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
void DetectMpmInitializeAppMpms(DetectEngineCtx *de_ctx)
InspectionBuffer *(* InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id)
@ DETECT_BUFFER_MPM_TYPE_SIZE
bool AppLayerParserSupportsSubStates(const AppProto alproto)
#define SGH_PROTO(sgh, p)
#define DETECT_CONTENT_REPLACE
void DetectPktMpmRegisterByParentId(DetectEngineCtx *de_ctx, const int id, const int parent_id, DetectEngineTransforms *transforms)
copy a mpm engine from parent_id, add in transforms
#define DETECT_CONTENT_FAST_PATTERN
#define MPMCTX_FLAGS_CACHE_TO_DISK
void DetectFrameMpmRegister(const char *name, int direction, int priority, int(*PrefilterRegister)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id), AppProto alproto, uint8_t type)
register a MPM engine
struct DetectBufferInstance DetectBufferInstance
#define SCMemcmp(a, b, c)
int DetectMpmPrepareAppMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
SCFPSupportSMList * fp_support_smlist_list
#define DEBUG_VALIDATE_BUG_ON(exp)
void PatternMatchThreadDestroy(MpmThreadCtx *mpm_thread_ctx, uint16_t mpm_matcher)
enum MpmBuiltinBuffers buffer
void RetrieveFPForSig(const DetectEngineCtx *de_ctx, Signature *s)
uint32_t StringHashDjb2(const uint8_t *data, uint32_t datalen)
int PrefilterPktStreamRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx)
#define DETECT_CONTENT_OFFSET_VAR
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto
#define SIG_FLAG_REQUIRE_PACKET