From 6b1517c0b83ca10c50be4dd6cc9076b1e62dddaa Mon Sep 17 00:00:00 2001 From: Ken Steele Date: Thu, 13 Feb 2014 23:21:53 -0500 Subject: [PATCH] Remove case_state usage The case_state in MPMs was just to track when a pid could have no-case and case-sensitive matches for the same PID. Now that can't happen after fixing bug 1110, so remove the code and storage for case_state. --- src/util-mpm-ac-bs.c | 43 ++++++++++-------------------------- src/util-mpm-ac-bs.h | 3 +-- src/util-mpm-ac-gfbs.c | 23 ++------------------ src/util-mpm-ac-gfbs.h | 3 +-- src/util-mpm-ac-tile.c | 26 ++++------------------ src/util-mpm-ac-tile.h | 3 +-- src/util-mpm-ac.c | 49 +++++++++++------------------------------- src/util-mpm-ac.h | 3 +-- 8 files changed, 34 insertions(+), 119 deletions(-) diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index e451bed327..b247eb73ac 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -1202,32 +1202,15 @@ int SCACBSPreparePatterns(MpmCtx *mpm_ctx) memset(ctx->pid_pat_list, 0, (ctx->max_pat_id + 1) * sizeof(SCACBSPatternList)); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { - if (ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE) { - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 1) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; - } else { - //if (memcmp(ctx->parray[i]->original_pat, ctx->parray[i]->ci, - // ctx->parray[i]->len) != 0) { - ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len); - if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); - exit(EXIT_FAILURE); - } - memcpy(ctx->pid_pat_list[ctx->parray[i]->id].cs, - ctx->parray[i]->original_pat, ctx->parray[i]->len); - ctx->pid_pat_list[ctx->parray[i]->id].patlen = ctx->parray[i]->len; - - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 2) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; - //} + if (!(ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE)) { + ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len); + if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { + SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + exit(EXIT_FAILURE); + } + memcpy(ctx->pid_pat_list[ctx->parray[i]->id].cs, + ctx->parray[i]->original_pat, ctx->parray[i]->len); + ctx->pid_pat_list[ctx->parray[i]->id].patlen = ctx->parray[i]->len; } } @@ -1495,9 +1478,7 @@ uint32_t SCACBSSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { ; @@ -1578,9 +1559,7 @@ uint32_t SCACBSSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { ; diff --git a/src/util-mpm-ac-bs.h b/src/util-mpm-ac-bs.h index 94dceb3f4f..46e196dd44 100644 --- a/src/util-mpm-ac-bs.h +++ b/src/util-mpm-ac-bs.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -45,7 +45,6 @@ typedef struct SCACBSPattern_ { typedef struct SCACBSPatternList_ { uint8_t *cs; uint16_t patlen; - uint16_t case_state; } SCACBSPatternList; typedef struct SCACBSOutputTable_ { diff --git a/src/util-mpm-ac-gfbs.c b/src/util-mpm-ac-gfbs.c index 5a9aade147..eb91d4e158 100644 --- a/src/util-mpm-ac-gfbs.c +++ b/src/util-mpm-ac-gfbs.c @@ -1073,14 +1073,7 @@ int SCACGfbsPreparePatterns(MpmCtx *mpm_ctx) memset(ctx->pid_pat_list, 0, (ctx->max_pat_id + 1) * sizeof(SCACGfbsPatternList)); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { - if (ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE) { - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 1) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; - } else { + if (!(ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE)) { ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len); if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); @@ -1089,13 +1082,6 @@ int SCACGfbsPreparePatterns(MpmCtx *mpm_ctx) memcpy(ctx->pid_pat_list[ctx->parray[i]->id].cs, ctx->parray[i]->original_pat, ctx->parray[i]->len); ctx->pid_pat_list[ctx->parray[i]->id].patlen = ctx->parray[i]->len; - - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 2) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; } } @@ -1404,9 +1390,7 @@ uint32_t SCACGfbsSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { @@ -1531,9 +1515,6 @@ uint32_t SCACGfbsSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } continue; } diff --git a/src/util-mpm-ac-gfbs.h b/src/util-mpm-ac-gfbs.h index 9b939a0d46..e790c685b7 100644 --- a/src/util-mpm-ac-gfbs.h +++ b/src/util-mpm-ac-gfbs.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -45,7 +45,6 @@ typedef struct SCACGfbsPattern_ { typedef struct SCACGfbsPatternList_ { uint8_t *cs; uint16_t patlen; - uint16_t case_state; } SCACGfbsPatternList; typedef struct SCACGfbsOutputTable_ { diff --git a/src/util-mpm-ac-tile.c b/src/util-mpm-ac-tile.c index 8f2a59f05d..cf32200394 100644 --- a/src/util-mpm-ac-tile.c +++ b/src/util-mpm-ac-tile.c @@ -1202,14 +1202,7 @@ int SCACTilePreparePatterns(MpmCtx *mpm_ctx) memset(ctx->pid_pat_list, 0, (ctx->max_pat_id + 1) * sizeof(SCACTilePatternList)); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { - if (ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE) { - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 1) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; - } else { + if (!(ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE)) { ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len); if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); @@ -1218,13 +1211,6 @@ int SCACTilePreparePatterns(MpmCtx *mpm_ctx) memcpy(ctx->pid_pat_list[ctx->parray[i]->id].cs, ctx->parray[i]->original_pat, ctx->parray[i]->len); ctx->pid_pat_list[ctx->parray[i]->id].patlen = ctx->parray[i]->len; - - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 2) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; } } @@ -1436,9 +1422,7 @@ int CheckMatch(SCACTileSearchCtx *ctx, PatternMatcherQueue *pmq, uint16_t patlen = pid_pat_list[lower_pid].patlen; if (SCMemcmp(pid_pat_list[lower_pid].cs, buf_offset - patlen, patlen) != 0) { /* inside loop */ - if (pid_pat_list[lower_pid].case_state != 3) { - continue; - } + continue; } } if (bitarray[(lower_pid) / 8] & (1 << ((lower_pid) % 8))) { @@ -1506,10 +1490,8 @@ uint32_t SCACTileSearchLarge(SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ct if (SCMemcmp(pid_pat_list[pids[k] & 0x0000FFFF].cs, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { - /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + /* inside loop */ + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { diff --git a/src/util-mpm-ac-tile.h b/src/util-mpm-ac-tile.h index 7dacbf361f..17653c6576 100644 --- a/src/util-mpm-ac-tile.h +++ b/src/util-mpm-ac-tile.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Open Information Security Foundation +/* Copyright (C) 2013-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -46,7 +46,6 @@ typedef struct SCACTilePattern_ { typedef struct SCACTilePatternList_ { uint8_t *cs; uint16_t patlen; - uint16_t case_state; } SCACTilePatternList; typedef struct SCACTileOutputTable_ { diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 09eab9029b..7f081a247b 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -1006,32 +1006,15 @@ int SCACPreparePatterns(MpmCtx *mpm_ctx) memset(ctx->pid_pat_list, 0, (ctx->max_pat_id + 1) * sizeof(SCACPatternList)); for (i = 0; i < mpm_ctx->pattern_cnt; i++) { - if (ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE) { - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 1) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 1; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; - } else { - //if (memcmp(ctx->parray[i]->original_pat, ctx->parray[i]->ci, - // ctx->parray[i]->len) != 0) { - ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len); - if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { - SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); - exit(EXIT_FAILURE); - } - memcpy(ctx->pid_pat_list[ctx->parray[i]->id].cs, - ctx->parray[i]->original_pat, ctx->parray[i]->len); - ctx->pid_pat_list[ctx->parray[i]->id].patlen = ctx->parray[i]->len; - - if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 0) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else if (ctx->pid_pat_list[ctx->parray[i]->id].case_state == 2) - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 2; - else - ctx->pid_pat_list[ctx->parray[i]->id].case_state = 3; - //} + if (!(ctx->parray[i]->flags & MPM_PATTERN_FLAG_NOCASE)) { + ctx->pid_pat_list[ctx->parray[i]->id].cs = SCMalloc(ctx->parray[i]->len); + if (ctx->pid_pat_list[ctx->parray[i]->id].cs == NULL) { + SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); + exit(EXIT_FAILURE); + } + memcpy(ctx->pid_pat_list[ctx->parray[i]->id].cs, + ctx->parray[i]->original_pat, ctx->parray[i]->len); + ctx->pid_pat_list[ctx->parray[i]->id].patlen = ctx->parray[i]->len; } } @@ -1264,9 +1247,7 @@ uint32_t SCACSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { ; @@ -1305,9 +1286,7 @@ uint32_t SCACSearch(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, buf + i - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { ; @@ -1973,9 +1952,7 @@ uint32_t SCACCudaPacketResultsProcessing(Packet *p, MpmCtx *mpm_ctx, buf + offset - pid_pat_list[pids[k] & 0x0000FFFF].patlen + 1, pid_pat_list[pids[k] & 0x0000FFFF].patlen) != 0) { /* inside loop */ - if (pid_pat_list[pids[k] & 0x0000FFFF].case_state != 3) { - continue; - } + continue; } if (pmq->pattern_id_bitarray[(pids[k] & 0x0000FFFF) / 8] & (1 << ((pids[k] & 0x0000FFFF) % 8))) { ; diff --git a/src/util-mpm-ac.h b/src/util-mpm-ac.h index 18491f7cb3..e2319528d1 100644 --- a/src/util-mpm-ac.h +++ b/src/util-mpm-ac.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2010 Open Information Security Foundation +/* Copyright (C) 2007-2014 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -58,7 +58,6 @@ typedef struct SCACPattern_ { typedef struct SCACPatternList_ { uint8_t *cs; uint16_t patlen; - uint16_t case_state; } SCACPatternList; typedef struct SCACOutputTable_ {