From 00b0a41b55dc6f876c313a228c470ab2fbdd25a7 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 10 Oct 2017 11:54:02 +0200 Subject: [PATCH] http: move from MpmIDs to DetectFlags API --- src/app-layer-htp.c | 27 +++++++++++++++++++-------- src/app-layer-htp.h | 5 +++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 76c14aa0bc..d420214676 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -2748,26 +2748,37 @@ static int HTPSetTxDetectState(void *alstate, void *vtx, DetectEngineState *s) return 0; } -static uint64_t HTPGetTxMpmIDs(void *vtx) +static uint64_t HTPGetTxDetectFlags(void *vtx, uint8_t dir) { htp_tx_t *tx = (htp_tx_t *)vtx; HtpTxUserData *tx_ud = htp_tx_get_user_data(tx); - return tx_ud ? tx_ud->mpm_ids : 0; + if (tx_ud) { + if (dir & STREAM_TOSERVER) { + return tx_ud->detect_flags_ts; + } else { + return tx_ud->detect_flags_tc; + } + } + return 0; } -static int HTPSetTxMpmIDs(void *vtx, uint64_t mpm_ids) +static void HTPSetTxDetectFlags(void *vtx, uint8_t dir, uint64_t detect_flags) { htp_tx_t *tx = (htp_tx_t *)vtx; HtpTxUserData *tx_ud = htp_tx_get_user_data(tx); if (tx_ud == NULL) { tx_ud = HTPMalloc(sizeof(*tx_ud)); if (unlikely(tx_ud == NULL)) - return -ENOMEM; + return; memset(tx_ud, 0, sizeof(*tx_ud)); htp_tx_set_user_data(tx, tx_ud); } - tx_ud->mpm_ids = mpm_ids; - return 0; + if (dir & STREAM_TOSERVER) { + tx_ud->detect_flags_ts = detect_flags; + } else { + tx_ud->detect_flags_tc = detect_flags; + } + return; } static int HTPRegisterPatternsForProtocolDetection(void) @@ -2858,8 +2869,8 @@ void RegisterHTPParsers(void) AppLayerParserRegisterDetectStateFuncs(IPPROTO_TCP, ALPROTO_HTTP, HTPStateHasTxDetectState, HTPGetTxDetectState, HTPSetTxDetectState); - AppLayerParserRegisterMpmIDsFuncs(IPPROTO_TCP, ALPROTO_HTTP, - HTPGetTxMpmIDs, HTPSetTxMpmIDs); + AppLayerParserRegisterDetectFlagsFuncs(IPPROTO_TCP, ALPROTO_HTTP, + HTPGetTxDetectFlags, HTPSetTxDetectFlags); AppLayerParserRegisterParser(IPPROTO_TCP, ALPROTO_HTTP, STREAM_TOSERVER, HTPHandleRequestData); diff --git a/src/app-layer-htp.h b/src/app-layer-htp.h index 60e89a84f6..3ea4558b97 100644 --- a/src/app-layer-htp.h +++ b/src/app-layer-htp.h @@ -188,8 +188,9 @@ typedef struct HtpBody_ { /** Now the Body Chunks will be stored per transaction, at * the tx user data */ typedef struct HtpTxUserData_ { - /** flags to track which mpm has run */ - uint64_t mpm_ids; + /** detection engine flags */ + uint64_t detect_flags_ts; + uint64_t detect_flags_tc; /* Body of the request (if any) */ uint8_t request_body_init;