]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer API optimizations and cleanups
authorVictor Julien <victor@inliniac.net>
Sat, 11 Feb 2017 12:02:53 +0000 (13:02 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 15 May 2017 12:13:37 +0000 (14:13 +0200)
src/app-layer-detect-proto.c
src/app-layer-parser.c
src/app-layer-parser.h
src/app-layer.c
src/detect-engine-state.c
src/detect.c
src/flow-timeout.c
src/flow.c
src/output-tx.c

index 555eeadde60b739f4f20ac797e2e5b1cd8f54694..8eb92639f7d419dfb046eaca23a8c9ccc9a3b82f 100644 (file)
@@ -1657,7 +1657,7 @@ void AppLayerProtoDetectReset(Flow *f)
     f->probing_parser_toserver_alproto_masks = 0;
     f->probing_parser_toclient_alproto_masks = 0;
 
-    AppLayerParserStateCleanup(f->proto, f->alproto, f->alstate, f->alparser);
+    AppLayerParserStateCleanup(f, f->alstate, f->alparser);
     f->alstate = NULL;
     f->alparser = NULL;
     f->alproto    = ALPROTO_UNKNOWN;
index 44a03368cb36f57761abdbba1c8a30c6dec5ae7a..021e8039cf9e6f761a3d267359b70a633db33d47 100644 (file)
@@ -883,8 +883,8 @@ uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto)
     SCReturnCT(r, "uint8_t");
 }
 
-uint64_t AppLayerParserGetTransactionActive(uint8_t ipproto, AppProto alproto,
-                                            AppLayerParserState *pstate, uint8_t direction)
+uint64_t AppLayerParserGetTransactionActive(const Flow *f,
+        AppLayerParserState *pstate, uint8_t direction)
 {
     SCEnter();
 
@@ -892,7 +892,7 @@ uint64_t AppLayerParserGetTransactionActive(uint8_t ipproto, AppProto alproto,
 
     uint64_t log_id = pstate->log_id;
     uint64_t inspect_id = pstate->inspect_id[direction & STREAM_TOSERVER ? 0 : 1];
-    if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].logger == TRUE) {
+    if (alp_ctx.ctxs[f->protomap][f->alproto].logger == TRUE) {
         active_id = (log_id < inspect_id) ? log_id : inspect_id;
     } else {
         active_id = inspect_id;
@@ -933,14 +933,14 @@ DetectEngineState *AppLayerParserGetTxDetectState(uint8_t ipproto, AppProto alpr
     SCReturnPtr(s, "DetectEngineState");
 }
 
-int AppLayerParserSetTxDetectState(uint8_t ipproto, AppProto alproto,
+int AppLayerParserSetTxDetectState(const Flow *f,
                                    void *alstate, void *tx, DetectEngineState *s)
 {
     int r;
     SCEnter();
-    if ((alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].GetTxDetectState(tx) != NULL))
+    if ((alp_ctx.ctxs[f->protomap][f->alproto].GetTxDetectState(tx) != NULL))
         SCReturnInt(-EBUSY);
-    r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].SetTxDetectState(alstate, tx, s);
+    r = alp_ctx.ctxs[f->protomap][f->alproto].SetTxDetectState(alstate, tx, s);
     SCReturnInt(r);
 }
 
@@ -1104,7 +1104,7 @@ void AppLayerParserSetEOF(AppLayerParserState *pstate)
     SCReturn;
 }
 
-int AppLayerParserHasDecoderEvents(uint8_t ipproto, AppProto alproto,
+int AppLayerParserHasDecoderEvents(const Flow *f,
                                    void *alstate, AppLayerParserState *pstate,
                                    uint8_t flags)
 {
@@ -1117,10 +1117,10 @@ int AppLayerParserHasDecoderEvents(uint8_t ipproto, AppProto alproto,
     uint64_t tx_id;
     uint64_t max_id;
 
-    if (AppLayerParserProtocolIsTxEventAware(ipproto, alproto)) {
+    if (AppLayerParserProtocolIsTxEventAware(f->proto, f->alproto)) {
         /* fast path if supported by alproto */
-        if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].StateHasEvents != NULL) {
-            if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
+        if (alp_ctx.ctxs[f->protomap][f->alproto].StateHasEvents != NULL) {
+            if (alp_ctx.ctxs[f->protomap][f->alproto].
                 StateHasEvents(alstate) == 1)
             {
                 goto present;
@@ -1128,9 +1128,9 @@ int AppLayerParserHasDecoderEvents(uint8_t ipproto, AppProto alproto,
         } else {
             /* check each tx */
             tx_id = AppLayerParserGetTransactionInspectId(pstate, flags);
-            max_id = AppLayerParserGetTxCnt(ipproto, alproto, alstate);
+            max_id = AppLayerParserGetTxCnt(f->proto, f->alproto, alstate);
             for ( ; tx_id < max_id; tx_id++) {
-                decoder_events = AppLayerParserGetEventsByTx(ipproto, alproto, alstate, tx_id);
+                decoder_events = AppLayerParserGetEventsByTx(f->proto, f->alproto, alstate, tx_id);
                 if (decoder_events && decoder_events->cnt)
                     goto present;
             }
@@ -1209,19 +1209,19 @@ void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t st
     SCReturn;
 }
 
-uint32_t AppLayerParserGetStreamDepth(uint8_t ipproto, AppProto alproto)
+uint32_t AppLayerParserGetStreamDepth(const Flow *f)
 {
-    SCReturnInt(alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].stream_depth);
+    SCReturnInt(alp_ctx.ctxs[f->protomap][f->alproto].stream_depth);
 }
 
 /***** Cleanup *****/
 
-void AppLayerParserStateCleanup(uint8_t ipproto, AppProto alproto, void *alstate,
+void AppLayerParserStateCleanup(const Flow *f, void *alstate,
                                 AppLayerParserState *pstate)
 {
     SCEnter();
 
-    AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto];
+    AppLayerParserProtoCtx *ctx = &alp_ctx.ctxs[f->protomap][f->alproto];
 
     if (ctx->StateFree != NULL && alstate != NULL)
         ctx->StateFree(alstate);
index e887e0008b0c9377a8f7563f7015c57258b61cae..83e6672d0083ac0c2702908c5f05c43e528abda1 100644 (file)
@@ -188,7 +188,7 @@ int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t dir
 int AppLayerParserGetEventInfo(uint8_t ipproto, AppProto alproto, const char *event_name,
                     int *event_id, AppLayerEventType *event_type);
 
-uint64_t AppLayerParserGetTransactionActive(uint8_t ipproto, AppProto alproto, AppLayerParserState *pstate, uint8_t direction);
+uint64_t AppLayerParserGetTransactionActive(const Flow *f, AppLayerParserState *pstate, uint8_t direction);
 
 uint8_t AppLayerParserGetFirstDataDir(uint8_t ipproto, AppProto alproto);
 
@@ -196,7 +196,7 @@ int AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto);
 int AppLayerParserSupportsTxDetectState(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(uint8_t ipproto, AppProto alproto, void *alstate, void *tx, DetectEngineState *s);
+int AppLayerParserSetTxDetectState(const Flow *f, void *alstate, void *tx, DetectEngineState *s);
 
 uint64_t AppLayerParserGetTxMpmIDs(uint8_t ipproto, AppProto alproto, void *tx);
 int AppLayerParserSetTxMpmIDs(uint8_t ipproto, AppProto alproto, void *tx, uint64_t);
@@ -206,7 +206,7 @@ int AppLayerParserSetTxMpmIDs(uint8_t ipproto, AppProto alproto, void *tx, uint6
 int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *tctx, Flow *f, AppProto alproto,
                    uint8_t flags, uint8_t *input, uint32_t input_len);
 void AppLayerParserSetEOF(AppLayerParserState *pstate);
-int AppLayerParserHasDecoderEvents(uint8_t ipproto, AppProto alproto, void *alstate, AppLayerParserState *pstate,
+int AppLayerParserHasDecoderEvents(const Flow *f, void *alstate, AppLayerParserState *pstate,
                         uint8_t flags);
 int AppLayerParserIsTxAware(AppProto alproto);
 int AppLayerParserProtocolIsTxAware(uint8_t ipproto, AppProto alproto);
@@ -215,11 +215,11 @@ int AppLayerParserProtocolSupportsTxs(uint8_t ipproto, AppProto alproto);
 int AppLayerParserProtocolHasLogger(uint8_t ipproto, AppProto alproto);
 void AppLayerParserTriggerRawStreamReassembly(Flow *f, int direction);
 void AppLayerParserSetStreamDepth(uint8_t ipproto, AppProto alproto, uint32_t stream_depth);
-uint32_t AppLayerParserGetStreamDepth(uint8_t ipproto, AppProto alproto);
+uint32_t AppLayerParserGetStreamDepth(const Flow *f);
 
 /***** Cleanup *****/
 
-void AppLayerParserStateCleanup(uint8_t ipproto, AppProto alproto, void *alstate, AppLayerParserState *pstate);
+void AppLayerParserStateCleanup(const Flow *f, void *alstate, AppLayerParserState *pstate);
 
 void AppLayerParserRegisterProtocolParsers(void);
 
index dd0907aef8eab8fc1a4d52fea6c0b7e83f08f256..667363cd02a445897530886e5de2a510e667b066 100644 (file)
@@ -342,7 +342,7 @@ static int TCPProtoDetect(ThreadVars *tv,
 
         StreamTcpSetStreamFlagAppProtoDetectionCompleted(stream);
         TcpSessionSetReassemblyDepth(ssn,
-                AppLayerParserGetStreamDepth(f->proto, f->alproto));
+                AppLayerParserGetStreamDepth(f));
         FlagPacketFlow(p, f, flags);
 
         /* account flow if we have both sides */
@@ -496,7 +496,7 @@ static int TCPProtoDetect(ThreadVars *tv,
                         APPLAYER_DETECT_PROTOCOL_ONLY_ONE_DIRECTION);
                 StreamTcpSetStreamFlagAppProtoDetectionCompleted(stream);
                 TcpSessionSetReassemblyDepth(ssn,
-                        AppLayerParserGetStreamDepth(f->proto, f->alproto));
+                        AppLayerParserGetStreamDepth(f));
                 *alproto = ALPROTO_FAILED;
                 FlagPacketFlow(p, f, flags);
 
index 6ba9dc979c50909fa405a471a37e8936e2a93229..b8a98fccad18daa5e141a49ba9692561ef46afe7 100644 (file)
@@ -317,7 +317,7 @@ static void StoreStateTxFileOnly(DetectEngineThreadCtx *det_ctx,
             destate = DetectEngineStateAlloc();
             if (destate == NULL)
                 return;
-            if (AppLayerParserSetTxDetectState(f->proto, f->alproto, f->alstate, tx, destate) < 0) {
+            if (AppLayerParserSetTxDetectState(f, f->alstate, tx, destate) < 0) {
                 DetectEngineStateFree(destate);
                 return;
             }
@@ -342,7 +342,7 @@ static void StoreStateTx(DetectEngineThreadCtx *det_ctx,
             destate = DetectEngineStateAlloc();
             if (destate == NULL)
                 return;
-            if (AppLayerParserSetTxDetectState(f->proto, f->alproto, f->alstate, tx, destate) < 0) {
+            if (AppLayerParserSetTxDetectState(f, f->alstate, tx, destate) < 0) {
                 DetectEngineStateFree(destate);
                 return;
             }
index 458aef4c9d3c0584510e1c51a0094e9535be6479..be63e61b364e448fb541918d2265c6a92509c2e6 100644 (file)
@@ -1013,8 +1013,7 @@ void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineT
                 SCLogDebug("packet doesn't have established flag set (proto %d)", p->proto);
             }
 
-            app_decoder_events = AppLayerParserHasDecoderEvents(pflow->proto,
-                                                                pflow->alproto,
+            app_decoder_events = AppLayerParserHasDecoderEvents(pflow,
                                                                 pflow->alstate,
                                                                 pflow->alparser,
                                                                 flow_flags);
index 9547b617ec57c01b170b1a03f078d8f3edf5ce25..f2c5718c03fd574c2dd6f928e27c3e43bb79132f 100644 (file)
@@ -322,13 +322,11 @@ int FlowForceReassemblyNeedReassembly(Flow *f, int *server, int *client)
     {
         uint64_t total_txs = AppLayerParserGetTxCnt(f->proto, f->alproto, f->alstate);
 
-        if (AppLayerParserGetTransactionActive(f->proto, f->alproto,
-                                               f->alparser, STREAM_TOCLIENT) < total_txs)
+        if (AppLayerParserGetTransactionActive(f, f->alparser, STREAM_TOCLIENT) < total_txs)
         {
             *server = STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION;
         }
-        if (AppLayerParserGetTransactionActive(f->proto, f->alproto,
-                                               f->alparser, STREAM_TOSERVER) < total_txs)
+        if (AppLayerParserGetTransactionActive(f, f->alparser, STREAM_TOSERVER) < total_txs)
         {
             *client = STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION;
         }
index 50075d975f01c273d3262890d1eb7665338fb992..c371b54e16e76620a5eacce92fc55638caec2d81 100644 (file)
@@ -94,7 +94,7 @@ void FlowCleanupAppLayer(Flow *f)
     if (f == NULL || f->proto == 0)
         return;
 
-    AppLayerParserStateCleanup(f->proto, f->alproto, f->alstate, f->alparser);
+    AppLayerParserStateCleanup(f, f->alstate, f->alparser);
     f->alstate = NULL;
     f->alparser = NULL;
     return;
index 74afe11c100a1d6f73c208d54d953ec00ef96b72..575bf5aa06a4c7aa2944e97ef419a92547a508fc 100644 (file)
@@ -148,7 +148,7 @@ static TmEcode OutputTxLog(ThreadVars *tv, Packet *p, void *thread_data)
 
     Flow * const f = p->flow;
 
-    AppProto alproto = f->alproto;
+    const AppProto alproto = f->alproto;
 
     if (AppLayerParserProtocolIsTxAware(p->proto, alproto) == 0)
         goto end;