From 6279da0fbd643ea365f338bb5c27246da09f9aaa Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 6 Mar 2015 19:37:55 +0100 Subject: [PATCH] http: support per TX destate storage --- src/app-layer-htp.c | 24 ++++++++++++++++++++++++ src/app-layer-htp.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 399dd7a2ae..e1a513a8ea 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -2629,6 +2629,28 @@ static void HTPStateTruncate(void *state, uint8_t direction) } } +static DetectEngineState *HTPGetTxDetectState(void *vtx) +{ + htp_tx_t *tx = (htp_tx_t *)vtx; + HtpTxUserData *tx_ud = htp_tx_get_user_data(tx); + return tx_ud ? tx_ud->de_state : NULL; +} + +static int HTPSetTxDetectState(void *vtx, DetectEngineState *s) +{ + 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; + memset(tx_ud, 0, sizeof(*tx_ud)); + htp_tx_set_user_data(tx, tx_ud); + } + tx_ud->de_state = s; + return 0; +} + static int HTPRegisterPatternsForProtocolDetection(void) { /* toserver */ @@ -2758,6 +2780,8 @@ void RegisterHTPParsers(void) AppLayerParserRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_HTTP, HTPStateGetEventInfo); AppLayerParserRegisterTruncateFunc(IPPROTO_TCP, ALPROTO_HTTP, HTPStateTruncate); + AppLayerParserRegisterDetectStateFuncs(IPPROTO_TCP, ALPROTO_HTTP, + HTPGetTxDetectState, HTPSetTxDetectState); AppLayerParserRegisterParser(IPPROTO_TCP, ALPROTO_HTTP, STREAM_TOSERVER, HTPHandleRequestData); diff --git a/src/app-layer-htp.h b/src/app-layer-htp.h index e3cad8a1e4..fca9efe37f 100644 --- a/src/app-layer-htp.h +++ b/src/app-layer-htp.h @@ -36,6 +36,7 @@ #include "util-radix-tree.h" #include "util-file.h" #include "app-layer-htp-mem.h" +#include "detect-engine-state.h" #include @@ -228,6 +229,7 @@ typedef struct HtpTxUserData_ { uint8_t request_body_type; uint8_t response_body_type; + DetectEngineState *de_state; } HtpTxUserData; typedef struct HtpState_ {