From: Jason Ish Date: Wed, 10 Nov 2021 15:51:15 +0000 (-0600) Subject: app-layer: remove tx detect state setter and getter X-Git-Tag: suricata-7.0.0-beta1~1194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ad71b96daa2b2655691cfce2a15ccd754d9b290;p=thirdparty%2Fsuricata.git app-layer: remove tx detect state setter and getter Instead access detect state through AppLayerParserGetTxData. --- diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index cf80cc9387..106d8fb00e 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -1144,23 +1144,6 @@ int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto) return FALSE; } -DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx) -{ - SCEnter(); - AppLayerTxData *d = AppLayerParserGetTxData(ipproto, alproto, tx); - DetectEngineState *s = d->de_state; - SCReturnPtr(s, "DetectEngineState"); -} - -int AppLayerParserSetTxDetectState(const Flow *f, - void *tx, DetectEngineState *s) -{ - SCEnter(); - AppLayerTxData *d = alp_ctx.ctxs[f->protomap][f->alproto].GetTxData(tx); - d->de_state = s; - SCReturnInt(0); -} - AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx) { SCEnter(); diff --git a/src/app-layer-parser.h b/src/app-layer-parser.h index e8304ccfc7..7624a2e769 100644 --- a/src/app-layer-parser.h +++ b/src/app-layer-parser.h @@ -252,9 +252,6 @@ uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState * uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto); int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto); -int AppLayerParserHasTxDetectState(uint8_t ipproto, AppProto alproto, void *alstate); -DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alproto, void *tx); -int AppLayerParserSetTxDetectState(const Flow *f, void *tx, DetectEngineState *s); AppLayerTxData *AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx); void AppLayerParserApplyTxConfig(uint8_t ipproto, AppProto alproto, diff --git a/src/detect-engine-state.c b/src/detect-engine-state.c index a5cf9696bc..d9f40bd6de 100644 --- a/src/detect-engine-state.c +++ b/src/detect-engine-state.c @@ -222,19 +222,20 @@ void DetectRunStoreStateTx( uint32_t inspect_flags, uint8_t flow_flags, const uint16_t file_no_match) { - DetectEngineState *destate = AppLayerParserGetTxDetectState(f->proto, f->alproto, tx); - if (destate == NULL) { - destate = DetectEngineStateAlloc(); - if (destate == NULL) - return; - if (AppLayerParserSetTxDetectState(f, tx, destate) < 0) { - DetectEngineStateFree(destate); + AppLayerTxData *tx_data = AppLayerParserGetTxData(f->proto, f->alproto, tx); + BUG_ON(tx_data == NULL); + if (tx_data == NULL) { + SCLogDebug("No TX data for %" PRIu64, tx_id); + return; + } + if (tx_data->de_state == NULL) { + tx_data->de_state = DetectEngineStateAlloc(); + if (tx_data->de_state == NULL) return; - } SCLogDebug("destate created for %"PRIu64, tx_id); } - DeStateSignatureAppend(destate, s, inspect_flags, flow_flags); - StoreStateTxHandleFiles(sgh, f, destate, flow_flags, tx_id, file_no_match); + DeStateSignatureAppend(tx_data->de_state, s, inspect_flags, flow_flags); + StoreStateTxHandleFiles(sgh, f, tx_data->de_state, flow_flags, tx_id, file_no_match); SCLogDebug("Stored for TX %"PRIu64, tx_id); } @@ -296,8 +297,11 @@ void DetectEngineStateResetTxs(Flow *f) for ( ; inspect_tx_id < total_txs; inspect_tx_id++) { void *inspect_tx = AppLayerParserGetTx(f->proto, f->alproto, alstate, inspect_tx_id); if (inspect_tx != NULL) { - DetectEngineState *tx_de_state = AppLayerParserGetTxDetectState(f->proto, f->alproto, inspect_tx); - ResetTxState(tx_de_state); + AppLayerTxData *txd = AppLayerParserGetTxData(f->proto, f->alproto, inspect_tx); + BUG_ON(txd == NULL); + if (txd) { + ResetTxState(txd->de_state); + } } } } @@ -625,7 +629,9 @@ static int DeStateSigTest02(void) void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f.alstate, 0); FAIL_IF_NULL(tx); - DetectEngineState *tx_de_state = AppLayerParserGetTxDetectState(IPPROTO_TCP, ALPROTO_HTTP1, tx); + AppLayerTxData *tx_data = AppLayerParserGetTxData(IPPROTO_TCP, ALPROTO_HTTP1, tx); + FAIL_IF_NULL(tx_data); + DetectEngineState *tx_de_state = tx_data->de_state; FAIL_IF_NULL(tx_de_state); FAIL_IF(tx_de_state->dir_state[0].cnt != 1); /* http_header(mpm): 5, uri: 3, method: 6, cookie: 7 */ diff --git a/src/detect.c b/src/detect.c index bb1be9d9a9..8b6ff9c8eb 100644 --- a/src/detect.c +++ b/src/detect.c @@ -1235,7 +1235,7 @@ static DetectTransaction GetDetectTx(const uint8_t ipproto, const AppProto alpro const int tx_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx_ptr, flow_flags); const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1; - DetectEngineState *tx_de_state = AppLayerParserGetTxDetectState(ipproto, alproto, tx_ptr); + DetectEngineState *tx_de_state = txd->de_state; DetectEngineStateDirection *tx_dir_state = tx_de_state ? &tx_de_state->dir_state[dir_int] : NULL; uint64_t prefilter_flags = detect_flags & APP_LAYER_TX_PREFILTER_MASK; DEBUG_VALIDATE_BUG_ON(prefilter_flags & APP_LAYER_TX_RESERVED_FLAGS);