]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
b2g cuda up, compiling and running
authorAnoop Saldanha <poonaatsoc@gmail.com>
Fri, 23 Mar 2012 03:18:10 +0000 (08:48 +0530)
committerVictor Julien <victor@inliniac.net>
Tue, 27 Mar 2012 09:46:06 +0000 (11:46 +0200)
src/cuda-packet-batcher.c
src/detect-engine-mpm.c
src/util-mpm-b2g-cuda.c
src/util-mpm-b2g-cuda.h
src/util-mpm.c

index cf3eb94e8cfeb5892c2f9d88dfcb1b63a496007c..d850c3bd262992270f659adbbcc7e6f2f3414832 100644 (file)
@@ -708,9 +708,15 @@ TmEcode SCCudaPBBatchPackets(ThreadVars *tv, Packet *p, void *data, PacketQueue
 
     MpmCtx *mpm_ctx = NULL;
     if (p->proto == IPPROTO_TCP) {
-        mpm_ctx = sgh->mpm_proto_tcp_ctx;
+        if (p->flowflags & FLOW_PKT_TOSERVER)
+            mpm_ctx = sgh->mpm_proto_tcp_ctx_ts;
+        else
+            mpm_ctx = sgh->mpm_proto_tcp_ctx_tc;
     } else if (p->proto == IPPROTO_UDP) {
-        mpm_ctx = sgh->mpm_proto_udp_ctx;
+        if (p->flowflags & FLOW_PKT_TOSERVER)
+            mpm_ctx = sgh->mpm_proto_udp_ctx_ts;
+        else
+            mpm_ctx = sgh->mpm_proto_udp_ctx_tc;
     } else {
         mpm_ctx = sgh->mpm_proto_other_ctx;
     }
index b08c6dd325638396787b5ae6b74ebf7a95d6d342..304d23fda928676e1e9d1e64a99acee860827c92 100644 (file)
@@ -2020,8 +2020,8 @@ int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
         MpmInitCtx(sh->mpm_hscd_ctx_ts, de_ctx->mpm_matcher, -1);
         MpmInitCtx(sh->mpm_hscd_ctx_tc, de_ctx->mpm_matcher, -1);
 #else
-        MpmInitCtx(sh->mpm_hscd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle, 0);
-        MpmInitCtx(sh->mpm_hscd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle, 1);
+        MpmInitCtx(sh->mpm_hscd_ctx_ts, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
+        MpmInitCtx(sh->mpm_hscd_ctx_tc, de_ctx->mpm_matcher, de_ctx->cuda_rc_mod_handle);
 #endif
     }
 
index 70e0857102f17050ebf72b8e4f73f2a1de02480e..b3a01bfd8556ae55fdeeffcd9225833d6dfe5edd 100644 (file)
@@ -191,9 +191,9 @@ static inline void memcpy_tolower(uint8_t *d, uint8_t *s, uint16_t len)
 
 static inline uint32_t B2gCudaInitHash(B2gCudaPattern *p)
 {
-    uint32_t hash = p->len * p->cs[0];
+    uint32_t hash = p->len * p->original_pat[0];
     if (p->len > 1)
-        hash += p->cs[1];
+        hash += p->original_pat[1];
 
     return (hash % INIT_HASH_SIZE);
 }
@@ -246,7 +246,8 @@ static inline int B2gCudaCmpPattern(B2gCudaPattern *p, uint8_t *pat,
 }
 
 static inline B2gCudaPattern *B2gCudaInitHashLookup(B2gCudaCtx *ctx, uint8_t *pat,
-                                                    uint16_t patlen, char flags)
+                                                    uint16_t patlen, char flags,
+                                                    uint32_t pid)
 {
     uint32_t hash = B2gCudaInitHashRaw(pat, patlen);
 
@@ -255,7 +256,8 @@ static inline B2gCudaPattern *B2gCudaInitHashLookup(B2gCudaCtx *ctx, uint8_t *pa
 
     B2gCudaPattern *t = ctx->init_hash[hash];
     for ( ; t != NULL; t = t->next) {
-        if (B2gCudaCmpPattern(t, pat, patlen, flags) == 1)
+        //if (B2gCudaCmpPattern(t, pat, patlen, flags) == 1)
+        if (t->flags == flags && t->id == pid)
             return t;
     }
 
@@ -298,7 +300,7 @@ static inline int B2gCudaAddPattern(MpmCtx *mpm_ctx, uint8_t *pat,
         return 0;
 
     /* get a memory piece */
-    B2gCudaPattern *p = B2gCudaInitHashLookup(ctx, pat, patlen, flags);
+    B2gCudaPattern *p = B2gCudaInitHashLookup(ctx, pat, patlen, flags, pid);
     if (p == NULL) {
         SCLogDebug("allocing new pattern");
 
@@ -310,6 +312,13 @@ static inline int B2gCudaAddPattern(MpmCtx *mpm_ctx, uint8_t *pat,
         p->flags = flags;
         p->id = pid;
 
+        p->original_pat = SCMalloc(patlen);
+        if (p->original_pat == NULL)
+            goto error;
+        mpm_ctx->memory_cnt++;
+        mpm_ctx->memory_size += patlen;
+        memcpy(p->original_pat, pat, patlen);
+
         /* setup the case insensitive part of the pattern */
         p->ci = SCMalloc(patlen);
         if (p->ci == NULL)
@@ -349,6 +358,7 @@ static inline int B2gCudaAddPattern(MpmCtx *mpm_ctx, uint8_t *pat,
             printf("Max search words reached\n");
             exit(1);
         }
+
         mpm_ctx->pattern_cnt++;
 
         if (mpm_ctx->maxlen < patlen) mpm_ctx->maxlen = patlen;
@@ -619,6 +629,11 @@ int B2gCudaPreparePatterns(MpmCtx *mpm_ctx)
 {
     B2gCudaCtx *ctx = (B2gCudaCtx *)mpm_ctx->ctx;
 
+    if (mpm_ctx->pattern_cnt == 0 || ctx->init_hash == NULL) {
+        SCLogDebug("no patterns supplied to this mpm_ctx");
+        return 0;
+    }
+
     /* alloc the pattern array */
     ctx->parray = (B2gCudaPattern **)SCMalloc(mpm_ctx->pattern_cnt *
                                               sizeof(B2gCudaPattern *));
@@ -794,9 +809,10 @@ static void B2gGetConfig()
 
 void B2gCudaInitCtx(MpmCtx *mpm_ctx, int module_handle)
 {
-    SCLogDebug("mpm_ctx %p, ctx %p", mpm_ctx, mpm_ctx->ctx);
+    if (mpm_ctx->ctx != NULL)
+        return;
 
-    BUG_ON(mpm_ctx->ctx != NULL);
+    SCLogDebug("mpm_ctx %p, ctx %p", mpm_ctx, mpm_ctx->ctx);
 
     mpm_ctx->ctx = SCMalloc(sizeof(B2gCudaCtx));
     if (mpm_ctx->ctx == NULL)
index d0191a24593c0995202d7efee4bc68706ea6b6f2..6281bfba2ee80fa09146793de2258a45f814ab0d 100644 (file)
@@ -53,6 +53,7 @@ typedef struct B2gCudaPattern_ {
     uint8_t *ci;
     struct B2gCudaPattern_ *next;
     uint32_t id;
+    uint8_t *original_pat;
 } B2gCudaPattern;
 
 typedef struct B2gCudaHashItem_ {
index 463745d5010ff396a1a18ee6c3b50753c28dec27..35934aa19b5991e6809581c2212a978d7f6e1d2f 100644 (file)
@@ -544,19 +544,19 @@ MpmCudaConf *MpmCudaConfParse(void)
     TAILQ_FOREACH(seq_node, &cuda_node->head, next) {
         if (strcasecmp(seq_node->val, "mpm") == 0) {
             packet_buffer_limit = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "packet_buffer_limit");
+                (seq_node->head.tqh_first, "packet-buffer-limit");
             packet_size_limit = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "packet_size_limit");
+                (seq_node->head.tqh_first, "packet-size-limit");
             packet_buffers = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "packet_buffers");
+                (seq_node->head.tqh_first, "packet-buffers");
             batching_timeout = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "batching_timeout");
+                (seq_node->head.tqh_first, "batching-timeout");
             page_locked = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "page_locked");
+                (seq_node->head.tqh_first, "page-locked");
             device_id = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "device_id");
+                (seq_node->head.tqh_first, "device-id");
             cuda_streams = ConfNodeLookupChildValue
-                (seq_node->head.tqh_first, "cuda_streams");
+                (seq_node->head.tqh_first, "cuda-streams");
 
             /* packet_buffer_size */
             if (packet_buffer_limit == NULL || strcasecmp(packet_buffer_limit, "") == 0) {