From: Mats Klepsland Date: Wed, 4 May 2016 08:00:26 +0000 (+0200) Subject: tx: do not store ProgressCompletionStatus per ipproto X-Git-Tag: suricata-3.1RC1~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4b918b6c4acfde858cf9662631df105daf37efb;p=thirdparty%2Fsuricata.git tx: do not store ProgressCompletionStatus per ipproto Change AppLayerParserRegisterGetStateProgressCompletionStatus to only store one ProgressCompletionStatus callback function for each alproto, instead of storing one for each ipproto. This enables us to use AppLayerParserGetStateProgressCompletionStatus in functions where we do not know the ipproto used. --- diff --git a/src/app-layer-dns-tcp.c b/src/app-layer-dns-tcp.c index 9e85ca2981..54c34ba6a3 100644 --- a/src/app-layer-dns-tcp.c +++ b/src/app-layer-dns-tcp.c @@ -664,7 +664,7 @@ void RegisterDNSTCPParsers(void) AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_DNS, DNSGetTxCnt); AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_DNS, DNSGetAlstateProgress); - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_TCP, ALPROTO_DNS, + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_DNS, DNSGetAlstateProgressCompletionStatus); DNSAppLayerRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_DNS); } else { diff --git a/src/app-layer-dns-udp.c b/src/app-layer-dns-udp.c index dcb2f5aa18..ffe61aa8d9 100644 --- a/src/app-layer-dns-udp.c +++ b/src/app-layer-dns-udp.c @@ -422,7 +422,7 @@ void RegisterDNSUDPParsers(void) DNSGetTxCnt); AppLayerParserRegisterGetStateProgressFunc(IPPROTO_UDP, ALPROTO_DNS, DNSGetAlstateProgress); - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_UDP, ALPROTO_DNS, + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_DNS, DNSGetAlstateProgressCompletionStatus); DNSAppLayerRegisterGetEventInfo(IPPROTO_UDP, ALPROTO_DNS); diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 4e76c5feb2..c1d68bf7b0 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -2769,7 +2769,7 @@ void RegisterHTPParsers(void) AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_HTTP, HTPStateGetAlstateProgress); AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_HTTP, HTPStateGetTxCnt); AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_HTTP, HTPStateGetTx); - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_TCP, ALPROTO_HTTP, + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_HTTP, HTPStateGetAlstateProgressCompletionStatus); AppLayerParserRegisterHasEventsFunc(IPPROTO_TCP, ALPROTO_HTTP, HTPHasEvents); AppLayerParserRegisterGetEventsFunc(IPPROTO_TCP, ALPROTO_HTTP, HTPGetEvents); diff --git a/src/app-layer-modbus.c b/src/app-layer-modbus.c index 2b18752560..77a735da87 100644 --- a/src/app-layer-modbus.c +++ b/src/app-layer-modbus.c @@ -1483,7 +1483,7 @@ void RegisterModbusParsers(void) AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_MODBUS, ModbusStateTxFree); AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_MODBUS, ModbusGetAlstateProgress); - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_TCP, ALPROTO_MODBUS, + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_MODBUS, ModbusGetAlstateProgressCompletionStatus); AppLayerParserRegisterGetEventInfo(IPPROTO_TCP, ALPROTO_MODBUS, ModbusStateGetEventInfo); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index d885a76198..f3985625e4 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -449,13 +449,12 @@ void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, SCReturn; } -void AppLayerParserRegisterGetStateProgressCompletionStatus(uint8_t ipproto, - AppProto alproto, +void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto, int (*StateGetProgressCompletionStatus)(uint8_t direction)) { SCEnter(); - alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto]. + alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto]. StateGetProgressCompletionStatus = StateGetProgressCompletionStatus; SCReturn; @@ -555,7 +554,7 @@ void AppLayerParserSetTransactionInspectId(AppLayerParserState *pstate, int direction = (flags & STREAM_TOSERVER) ? 0 : 1; uint64_t total_txs = AppLayerParserGetTxCnt(ipproto, alproto, alstate); uint64_t idx = AppLayerParserGetTransactionInspectId(pstate, flags); - int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(ipproto, alproto, flags); + int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(alproto, flags); void *tx; int state_progress; @@ -663,7 +662,7 @@ uint64_t AppLayerTransactionGetActiveLogOnly(Flow *f, uint8_t flags) /* logger is disabled, return highest 'complete' tx id */ uint64_t total_txs = AppLayerParserGetTxCnt(f->proto, f->alproto, f->alstate); uint64_t idx = AppLayerParserGetTransactionInspectId(f->alparser, flags); - int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->proto, f->alproto, flags); + int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->alproto, flags); void *tx; int state_progress; @@ -739,7 +738,7 @@ int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, SCEnter(); int r = 0; if (unlikely(IS_DISRUPTED(flags))) { - r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto]. + r = alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto]. StateGetProgressCompletionStatus(flags); } else { r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto]. @@ -766,12 +765,12 @@ void *AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint SCReturnPtr(r, "void *"); } -int AppLayerParserGetStateProgressCompletionStatus(uint8_t ipproto, AppProto alproto, - uint8_t direction) +int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, + uint8_t direction) { SCEnter(); int r = 0; - r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto]. + r = alp_ctx.ctxs[FLOW_PROTO_DEFAULT][alproto]. StateGetProgressCompletionStatus(direction); SCReturnInt(r); } diff --git a/src/app-layer-parser.h b/src/app-layer-parser.h index 2dee75e7c7..a5eb374706 100644 --- a/src/app-layer-parser.h +++ b/src/app-layer-parser.h @@ -136,8 +136,7 @@ void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t (*StateGetTxCnt)(void *alstate)); void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id)); -void AppLayerParserRegisterGetStateProgressCompletionStatus(uint8_t ipproto, - AppProto alproto, +void AppLayerParserRegisterGetStateProgressCompletionStatus(AppProto alproto, int (*StateGetStateProgressCompletionStatus)(uint8_t direction)); void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int (*StateGetEventInfo)(const char *event_name, int *event_id, @@ -171,8 +170,7 @@ int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t direction); uint64_t AppLayerParserGetTxCnt(uint8_t ipproto, AppProto alproto, void *alstate); void *AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id); -int AppLayerParserGetStateProgressCompletionStatus(uint8_t ipproto, AppProto alproto, - uint8_t direction); +int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction); int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name, int *event_id, AppLayerEventType *event_type); diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index c7385d8d5a..d89b2c3588 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -1642,7 +1642,7 @@ void RegisterSMTPParsers(void) AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_SMTP, SMTPStateGetAlstateProgress); AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_SMTP, SMTPStateGetTxCnt); AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_SMTP, SMTPStateGetTx); - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_TCP, ALPROTO_SMTP, + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_SMTP, SMTPStateGetAlstateProgressCompletionStatus); AppLayerParserRegisterTruncateFunc(IPPROTO_TCP, ALPROTO_SMTP, SMTPStateTruncate); } else { diff --git a/src/app-layer-ssl.c b/src/app-layer-ssl.c index 6869614d41..cde8497e90 100644 --- a/src/app-layer-ssl.c +++ b/src/app-layer-ssl.c @@ -1740,7 +1740,7 @@ void RegisterSSLParsers(void) AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_TLS, SSLGetAlstateProgress); - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_TCP, ALPROTO_TLS, + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_TLS, SSLGetAlstateProgressCompletionStatus); /* Get the value of no reassembly option from the config file */ diff --git a/src/app-layer-template.c b/src/app-layer-template.c index 5eafa67e1a..9506ea8415 100644 --- a/src/app-layer-template.c +++ b/src/app-layer-template.c @@ -501,8 +501,8 @@ void RegisterTemplateParsers(void) TemplateGetTxCnt); /* Transaction handling. */ - AppLayerParserRegisterGetStateProgressCompletionStatus(IPPROTO_TCP, - ALPROTO_TEMPLATE, TemplateGetAlstateProgressCompletionStatus); + AppLayerParserRegisterGetStateProgressCompletionStatus(ALPROTO_TEMPLATE, + TemplateGetAlstateProgressCompletionStatus); AppLayerParserRegisterGetStateProgressFunc(IPPROTO_TCP, ALPROTO_TEMPLATE, TemplateGetStateProgress); AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_TEMPLATE, diff --git a/src/detect-engine-apt-event.c b/src/detect-engine-apt-event.c index 5ca416892d..344102970a 100644 --- a/src/detect-engine-apt-event.c +++ b/src/detect-engine-apt-event.c @@ -68,7 +68,7 @@ int DetectEngineAptEventInspect(ThreadVars *tv, return DETECT_ENGINE_INSPECT_SIG_MATCH; } else { if (AppLayerParserGetStateProgress(f->proto, alproto, tx, flags) == - AppLayerParserGetStateProgressCompletionStatus(f->proto, alproto, flags)) + AppLayerParserGetStateProgressCompletionStatus(alproto, flags)) { return DETECT_ENGINE_INSPECT_SIG_CANT_MATCH; } else { diff --git a/src/detect-engine-state.c b/src/detect-engine-state.c index 436fdf1259..7069972ac4 100644 --- a/src/detect-engine-state.c +++ b/src/detect-engine-state.c @@ -581,7 +581,7 @@ int DeStateDetectStartDetection(ThreadVars *tv, DetectEngineCtx *de_ctx, /* if this is the last tx in our list, and it's incomplete: then * we store the state so that ContinueDetection knows about it */ int tx_is_done = (AppLayerParserGetStateProgress(f->proto, alproto, tx, flags) >= - AppLayerParserGetStateProgressCompletionStatus(f->proto, alproto, flags)); + AppLayerParserGetStateProgressCompletionStatus(alproto, flags)); /* see if we need to consider the next tx in our decision to add * a sig to the 'no inspect array'. */ int next_tx_no_progress = 0; @@ -1048,7 +1048,7 @@ void DeStateDetectContinueDetection(ThreadVars *tv, DetectEngineCtx *de_ctx, void *inspect_tx = AppLayerParserGetTx(f->proto, alproto, alstate, inspect_tx_id); if (inspect_tx != NULL) { int a = AppLayerParserGetStateProgress(f->proto, alproto, inspect_tx, flags); - int b = AppLayerParserGetStateProgressCompletionStatus(f->proto, alproto, flags); + int b = AppLayerParserGetStateProgressCompletionStatus(alproto, flags); if (a < b) { inspect_tx_inprogress = 1; } diff --git a/src/output-streaming.c b/src/output-streaming.c index d416cbc3c6..73aa115b40 100644 --- a/src/output-streaming.c +++ b/src/output-streaming.c @@ -147,11 +147,11 @@ int HttpBodyIterator(Flow *f, int close, void *cbdata, uint8_t iflags) HtpState *s = f->alstate; if (s != NULL && s->conn != NULL) { int tx_progress_done_value_ts = - AppLayerParserGetStateProgressCompletionStatus(IPPROTO_TCP, - ALPROTO_HTTP, STREAM_TOSERVER); + AppLayerParserGetStateProgressCompletionStatus(ALPROTO_HTTP, + STREAM_TOSERVER); int tx_progress_done_value_tc = - AppLayerParserGetStateProgressCompletionStatus(IPPROTO_TCP, - ALPROTO_HTTP, STREAM_TOCLIENT); + AppLayerParserGetStateProgressCompletionStatus(ALPROTO_HTTP, + STREAM_TOCLIENT); // for each tx uint64_t tx_id = 0; diff --git a/src/output-tx.c b/src/output-tx.c index ca9216478b..1e3396bd5f 100644 --- a/src/output-tx.c +++ b/src/output-tx.c @@ -120,10 +120,10 @@ static TmEcode OutputTxLog(ThreadVars *tv, Packet *p, void *thread_data, PacketQ uint64_t total_txs = AppLayerParserGetTxCnt(p->proto, alproto, alstate); uint64_t tx_id = AppLayerParserGetTransactionLogId(f->alparser); int tx_progress_done_value_ts = - AppLayerParserGetStateProgressCompletionStatus(p->proto, alproto, + AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOSERVER); int tx_progress_done_value_tc = - AppLayerParserGetStateProgressCompletionStatus(p->proto, alproto, + AppLayerParserGetStateProgressCompletionStatus(alproto, STREAM_TOCLIENT); for (; tx_id < total_txs; tx_id++) {