From: Victor Julien Date: Fri, 9 Apr 2021 08:15:39 +0000 (+0200) Subject: app-layer/expectation: clean up storage id logic X-Git-Tag: suricata-6.0.6~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=781712a3387688c10c872ffa64ebde3a0003d923;p=thirdparty%2Fsuricata.git app-layer/expectation: clean up storage id logic (cherry picked from commit 4b3be245065062a3970c6aafa70d25bde969873e) --- diff --git a/src/app-layer-expectation.c b/src/app-layer-expectation.c index c920a19991..0aa4797762 100644 --- a/src/app-layer-expectation.c +++ b/src/app-layer-expectation.c @@ -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"); } } diff --git a/src/app-layer-expectation.h b/src/app-layer-expectation.h index 6f707a65c8..6a2ba195b1 100644 --- a/src/app-layer-expectation.h +++ b/src/app-layer-expectation.h @@ -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); diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index 38dd05c33f..4ca994fbaa 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -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) {