From: Anoop Saldanha Date: Fri, 23 Mar 2012 03:18:10 +0000 (+0530) Subject: b2g cuda up, compiling and running X-Git-Tag: suricata-1.3beta1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2995867328531a6473705359587f79a0e1d3c861;p=thirdparty%2Fsuricata.git b2g cuda up, compiling and running --- diff --git a/src/cuda-packet-batcher.c b/src/cuda-packet-batcher.c index cf3eb94e8c..d850c3bd26 100644 --- a/src/cuda-packet-batcher.c +++ b/src/cuda-packet-batcher.c @@ -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; } diff --git a/src/detect-engine-mpm.c b/src/detect-engine-mpm.c index b08c6dd325..304d23fda9 100644 --- a/src/detect-engine-mpm.c +++ b/src/detect-engine-mpm.c @@ -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 } diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index 70e0857102..b3a01bfd85 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -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) diff --git a/src/util-mpm-b2g-cuda.h b/src/util-mpm-b2g-cuda.h index d0191a2459..6281bfba2e 100644 --- a/src/util-mpm-b2g-cuda.h +++ b/src/util-mpm-b2g-cuda.h @@ -53,6 +53,7 @@ typedef struct B2gCudaPattern_ { uint8_t *ci; struct B2gCudaPattern_ *next; uint32_t id; + uint8_t *original_pat; } B2gCudaPattern; typedef struct B2gCudaHashItem_ { diff --git a/src/util-mpm.c b/src/util-mpm.c index 463745d501..35934aa19b 100644 --- a/src/util-mpm.c +++ b/src/util-mpm.c @@ -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) {