]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm: add depth/offset support
authorVictor Julien <victor@inliniac.net>
Sat, 4 Nov 2017 10:11:54 +0000 (11:11 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 11 Dec 2017 15:59:10 +0000 (16:59 +0100)
src/util-mpm.c
src/util-mpm.h

index 92fdedd52e46e790c7a82cecf32ece0e3700dd47..b8b68f26ddd82432c179ed64aa34a118eebf1446 100644 (file)
@@ -501,9 +501,10 @@ static inline uint32_t MpmInitHashRaw(uint8_t *pat, uint16_t patlen)
  *
  * \retval hash A 32 bit unsigned hash.
  */
-static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx, uint8_t *pat,
-                                                  uint16_t patlen, char flags,
-                                                  uint32_t pid)
+static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx,
+        uint8_t *pat, uint16_t patlen,
+        uint16_t offset, uint16_t depth,
+        uint8_t flags, uint32_t pid)
 {
     uint32_t hash = MpmInitHashRaw(pat, patlen);
 
@@ -517,7 +518,7 @@ static inline MpmPattern *MpmInitHashLookup(MpmCtx *ctx, uint8_t *pat,
             if (t->id == pid)
                 return t;
         } else {
-            if (t->len == patlen &&
+            if (t->len == patlen && t->offset == offset && t->depth == depth &&
                     memcmp(pat, t->original_pat, patlen) == 0 &&
                     t->flags == flags)
             {
@@ -652,7 +653,8 @@ int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
         pid = UINT_MAX;
 
     /* check if we have already inserted this pattern */
-    MpmPattern *p = MpmInitHashLookup(mpm_ctx, pat, patlen, flags, pid);
+    MpmPattern *p = MpmInitHashLookup(mpm_ctx, pat, patlen,
+            offset, depth, flags, pid);
     if (p == NULL) {
         SCLogDebug("Allocing new pattern");
 
@@ -661,6 +663,8 @@ int MpmAddPattern(MpmCtx *mpm_ctx, uint8_t *pat, uint16_t patlen,
 
         p->len = patlen;
         p->flags = flags;
+        p->offset = offset;
+        p->depth = depth;
         if (flags & MPM_PATTERN_CTX_OWNS_ID)
             p->id = mpm_ctx->max_pat_id++;
         else
index f20bf73774fd951d9af8f722a37f753b19e4b98d..3b7960a86d70e3c3aa1dfcd61bb1a16ff39e9a8e 100644 (file)
@@ -59,6 +59,13 @@ typedef struct MpmPattern_ {
     uint16_t len;
     /* flags decribing the pattern */
     uint8_t flags;
+
+    /* offset into the buffer where match may start */
+    uint16_t offset;
+
+    /* offset into the buffer before which match much complete */
+    uint16_t depth;
+
     /* holds the original pattern that was added */
     uint8_t *original_pat;
     /* case sensitive */