]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer/expectation: clean up storage id logic
authorVictor Julien <victor@inliniac.net>
Fri, 9 Apr 2021 08:15:39 +0000 (10:15 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 3 May 2022 07:38:27 +0000 (09:38 +0200)
(cherry picked from commit 4b3be245065062a3970c6aafa70d25bde969873e)

src/app-layer-expectation.c
src/app-layer-expectation.h
src/app-layer-ftp.c

index c920a1999115880b6e2e239d531d0016310b30da..0aa4797762cc8cc9822d527abcaa723f362d5dac 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2017-2020 Open Information Security Foundation
+/* Copyright (C) 2017-2021 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -38,7 +38,7 @@
  * AppLayerExpectationGetDataId():
  *
  * ```
- * data = (char *)FlowGetStorageById(f, AppLayerExpectationGetDataId());
+ * data = (char *)FlowGetStorageById(f, AppLayerExpectationGetFlowId());
  * ```
  * This storage can be used to store information that are only available in the
  * parent connection and could be useful in the parent connection. For instance
@@ -63,8 +63,8 @@
 
 #include "util-print.h"
 
-static int g_expectation_id = -1;
-static int g_expectation_data_id = -1;
+static int g_ippair_expectation_id = -1;
+static int g_flow_expectation_id = -1;
 
 SC_ATOMIC_DECLARE(uint32_t, expectation_count);
 
@@ -146,8 +146,10 @@ uint64_t ExpectationGetCounter(void)
 
 void AppLayerExpectationSetup(void)
 {
-    g_expectation_id = IPPairStorageRegister("expectation", sizeof(void *), NULL, ExpectationListFree);
-    g_expectation_data_id = FlowStorageRegister("expectation", sizeof(void *), NULL, ExpectationDataFree);
+    g_ippair_expectation_id =
+            IPPairStorageRegister("expectation", sizeof(void *), NULL, ExpectationListFree);
+    g_flow_expectation_id =
+            FlowStorageRegister("expectation", sizeof(void *), NULL, ExpectationDataFree);
     SC_ATOMIC_INIT(expectation_count);
 }
 
@@ -177,7 +179,7 @@ static ExpectationList *AppLayerExpectationLookup(Flow *f, IPPair **ipp)
         return NULL;
     }
 
-    return IPPairGetStorageById(*ipp, g_expectation_id);
+    return IPPairGetStorageById(*ipp, g_ippair_expectation_id);
 }
 
 
@@ -190,7 +192,7 @@ static ExpectationList *AppLayerExpectationRemove(IPPair *ipp,
     SC_ATOMIC_SUB(expectation_count, 1);
     exp_list->length--;
     if (exp_list->length == 0) {
-        IPPairSetStorageById(ipp, g_expectation_id, NULL);
+        IPPairSetStorageById(ipp, g_ippair_expectation_id, NULL);
         ExpectationListFree(exp_list);
         exp_list = NULL;
     }
@@ -240,7 +242,7 @@ int AppLayerExpectationCreate(Flow *f, int direction, Port src, Port dst,
     if (ipp == NULL)
         goto error;
 
-    exp_list = IPPairGetStorageById(ipp, g_expectation_id);
+    exp_list = IPPairGetStorageById(ipp, g_ippair_expectation_id);
     if (exp_list) {
         CIRCLEQ_INSERT_HEAD(&exp_list->list, exp, entries);
         /* In case there is already EXPECTATION_MAX_LEVEL expectations waiting to be fullfill,
@@ -262,7 +264,7 @@ int AppLayerExpectationCreate(Flow *f, int direction, Port src, Port dst,
         exp_list->length = 0;
         CIRCLEQ_INIT(&exp_list->list);
         CIRCLEQ_INSERT_HEAD(&exp_list->list, exp, entries);
-        IPPairSetStorageById(ipp, g_expectation_id, exp_list);
+        IPPairSetStorageById(ipp, g_ippair_expectation_id, exp_list);
     }
 
     exp_list->length += 1;
@@ -284,9 +286,9 @@ error:
  *
  * \return expectation data identifier
  */
-int AppLayerExpectationGetDataId(void)
+int AppLayerExpectationGetFlowId(void)
 {
-    return g_expectation_data_id;
+    return g_flow_expectation_id;
 }
 
 /**
@@ -328,13 +330,13 @@ AppProto AppLayerExpectationHandle(Flow *f, uint8_t flags)
             if (f->alproto_tc == ALPROTO_UNKNOWN) {
                 f->alproto_tc = alproto;
             }
-            void *fdata = FlowGetStorageById(f, g_expectation_data_id);
+            void *fdata = FlowGetStorageById(f, g_flow_expectation_id);
             if (fdata) {
                 /* We already have an expectation so let's clean this one */
                 ExpectationDataFree(exp->data);
             } else {
                 /* Transfer ownership of Expectation data to the Flow */
-                if (FlowSetStorageById(f, g_expectation_data_id, exp->data) != 0) {
+                if (FlowSetStorageById(f, g_flow_expectation_id, exp->data) != 0) {
                     SCLogDebug("Unable to set flow storage");
                 }
             }
index 6f707a65c8ee46c5171985cf0d31921fe99f417e..6a2ba195b18595899d9ea23d89fe500dd9bf6432 100644 (file)
@@ -28,7 +28,7 @@ void AppLayerExpectationSetup(void);
 int AppLayerExpectationCreate(Flow *f, int direction, Port src, Port dst,
                               AppProto alproto, void *data);
 AppProto AppLayerExpectationHandle(Flow *f, uint8_t flags);
-int AppLayerExpectationGetDataId(void);
+int AppLayerExpectationGetFlowId(void);
 
 void AppLayerExpectationClean(Flow *f);
 
index 38dd05c33fd3ae825c4668bf31a0632118325693..4ca994fbaac4a8bd1302893e46b4ef4c56d781af 100644 (file)
@@ -1100,14 +1100,15 @@ static AppLayerResult FTPDataParse(Flow *f, FtpDataState *ftpdata_state,
     /* we depend on detection engine for file pruning */
     flags |= FILE_USE_DETECT;
     if (ftpdata_state->files == NULL) {
-        struct FtpTransferCmd *data = (struct FtpTransferCmd *)FlowGetStorageById(f, AppLayerExpectationGetDataId());
+        struct FtpTransferCmd *data =
+                (struct FtpTransferCmd *)FlowGetStorageById(f, AppLayerExpectationGetFlowId());
         if (data == NULL) {
             SCReturnStruct(APP_LAYER_ERROR);
         }
 
         ftpdata_state->files = FileContainerAlloc();
         if (ftpdata_state->files == NULL) {
-            FlowFreeStorageById(f, AppLayerExpectationGetDataId());
+            FlowFreeStorageById(f, AppLayerExpectationGetFlowId());
             SCReturnStruct(APP_LAYER_ERROR);
         }
 
@@ -1137,7 +1138,7 @@ static AppLayerResult FTPDataParse(Flow *f, FtpDataState *ftpdata_state,
             SCLogDebug("Can't open file");
             ret = -1;
         }
-        FlowFreeStorageById(f, AppLayerExpectationGetDataId());
+        FlowFreeStorageById(f, AppLayerExpectationGetFlowId());
         ftpdata_state->tx_data.files_opened = 1;
     } else {
         if (input_len != 0) {