From: Philippe Antoine Date: Mon, 2 Sep 2024 08:47:07 +0000 (+0200) Subject: frames: use dynamic number of app-layer protos X-Git-Tag: suricata-8.0.0-beta1~608 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=911cd628fc4a45b651132bb77982be52657c687b;p=thirdparty%2Fsuricata.git frames: use dynamic number of app-layer protos Ticket: 5053 --- diff --git a/src/app-layer-frames.c b/src/app-layer-frames.c index 432bd020d2..3fa4c34547 100644 --- a/src/app-layer-frames.c +++ b/src/app-layer-frames.c @@ -33,15 +33,25 @@ struct FrameConfig { SC_ATOMIC_DECLARE(uint64_t, types); }; -static struct FrameConfig frame_config[ALPROTO_MAX]; +/* This array should be allocated to contain ALPROTO_MAX protocols. */ +static struct FrameConfig *frame_config; void FrameConfigInit(void) { + frame_config = SCCalloc(ALPROTO_MAX, sizeof(struct FrameConfig)); + if (unlikely(frame_config == NULL)) { + FatalError("Unable to alloc frame_config."); + } for (AppProto p = 0; p < ALPROTO_MAX; p++) { SC_ATOMIC_INIT(frame_config[p].types); } } +void FrameConfigDeInit(void) +{ + SCFree(frame_config); +} + void FrameConfigEnableAll(void) { const uint64_t bits = UINT64_MAX; diff --git a/src/app-layer-frames.h b/src/app-layer-frames.h index f49bead57b..f1d5135d89 100644 --- a/src/app-layer-frames.h +++ b/src/app-layer-frames.h @@ -106,6 +106,7 @@ FramesContainer *AppLayerFramesGetContainer(Flow *f); FramesContainer *AppLayerFramesSetupContainer(Flow *f); void FrameConfigInit(void); +void FrameConfigDeInit(void); void FrameConfigEnableAll(void); void FrameConfigEnable(const AppProto p, const uint8_t type); diff --git a/src/app-layer.c b/src/app-layer.c index 5c910d0bc9..da69fbe4ba 100644 --- a/src/app-layer.c +++ b/src/app-layer.c @@ -1041,6 +1041,7 @@ int AppLayerSetup(void) AppLayerProtoDetectPrepareState(); AppLayerSetupCounters(); + FrameConfigInit(); SCReturnInt(0); } @@ -1053,6 +1054,7 @@ int AppLayerDeSetup(void) AppLayerParserDeSetup(); AppLayerDeSetupCounters(); + FrameConfigDeInit(); SCReturnInt(0); } diff --git a/src/suricata.c b/src/suricata.c index ee9dfc0b5b..6a01b55dd3 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -361,7 +361,6 @@ void GlobalsInitPreConfig(void) SupportFastPatternForSigMatchTypes(); SCThresholdConfGlobalInit(); SCProtoNameInit(); - FrameConfigInit(); } void GlobalsDestroy(void)