MpmInitCtx(ms->mpm_ctx, de_ctx->mpm_matcher);
+ const bool mpm_supports_endswith =
+ (mpm_table[de_ctx->mpm_matcher].feature_flags & MPM_FEATURE_FLAG_ENDSWITH) != 0;
+
/* add the patterns */
for (sig = 0; sig < (ms->sid_array_size * 8); sig++) {
if (ms->sid_array[sig / 8] & (1 << (sig % 8))) {
}
if (!skip) {
- PopulateMpmHelperAddPattern(ms->mpm_ctx,
- cd, s, 0, (cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP));
+ uint8_t flags = 0;
+ if ((cd->flags & DETECT_CONTENT_ENDS_WITH) && mpm_supports_endswith)
+ flags = MPM_PATTERN_FLAG_ENDSWITH;
+ PopulateMpmHelperAddPattern(
+ ms->mpm_ctx, cd, s, flags, (cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP));
}
}
}
}
ctx->pid_pat_list[ctx->parray[i]->id].offset = ctx->parray[i]->offset;
ctx->pid_pat_list[ctx->parray[i]->id].depth = ctx->parray[i]->depth;
+ ctx->pid_pat_list[ctx->parray[i]->id].endswith =
+ (ctx->parray[i]->flags & MPM_PATTERN_FLAG_ENDSWITH) != 0;
/* ACPatternList now owns this memory */
//SCLogInfo("ctx->parray[i]->sids_size %u", ctx->parray[i]->sids_size);
if (offset < (int)pat->offset || (pat->depth && i > pat->depth))
continue;
+ if (pat->endswith && (uint32_t)offset + pat->patlen != buflen)
+ continue;
if (SCMemcmp(pat->cs, buf + offset, pat->patlen) != 0) {
/* inside loop */
if (offset < (int)pat->offset || (pat->depth && i > pat->depth))
continue;
+ if (pat->endswith && (uint32_t)offset + pat->patlen != buflen)
+ continue;
if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
if (offset < (int)pat->offset || (pat->depth && i > pat->depth))
continue;
+ if (pat->endswith && (uint32_t)offset + pat->patlen != buflen)
+ continue;
if (SCMemcmp(pat->cs, buf + offset,
pat->patlen) != 0) {
if (offset < (int)pat->offset || (pat->depth && i > pat->depth))
continue;
+ if (pat->endswith && (uint32_t)offset + pat->patlen != buflen)
+ continue;
if (!(bitarray[pids[k] / 8] & (1 << (pids[k] % 8)))) {
bitarray[pids[k] / 8] |= (1 << (pids[k] % 8));
uint16_t offset;
uint16_t depth;
+ bool endswith;
+
/* sid(s) for this pattern */
uint32_t sids_size;
SigIntId *sids;
/** the ctx uses it's own internal id instead of
* what is passed through the API */
#define MPM_PATTERN_CTX_OWNS_ID 0x20
+#define MPM_PATTERN_FLAG_ENDSWITH 0x40
-#define MPM_FEATURE_FLAG_DEPTH BIT_U8(0)
-#define MPM_FEATURE_FLAG_OFFSET BIT_U8(1)
+#define MPM_FEATURE_FLAG_DEPTH BIT_U8(0)
+#define MPM_FEATURE_FLAG_OFFSET BIT_U8(1)
+#define MPM_FEATURE_FLAG_ENDSWITH BIT_U8(2)
typedef struct MpmTableElmt_ {
const char *name;