diff --git a/src/detect-engine-analyzer.c b/src/detect-engine-analyzer.c index 742e34f026..3746afd6d7 100644 --- a/src/detect-engine-analyzer.c +++ b/src/detect-engine-analyzer.c @@ -2110,11 +2110,8 @@ int FirewallAnalyzer(const DetectEngineCtx *de_ctx) const char *name = AppLayerParserGetStateNameById(IPPROTO_TCP, a, state, STREAM_TOSERVER); if (name == NULL) { - if (state == 0) - name = "request-started"; - else if (state == complete_state_ts) - name = "request-complete"; - else + name = DetectFirewallAppGenericHookName(state, complete_state_ts, STREAM_TOSERVER); + if (name == NULL) name = "unknown"; } @@ -2136,11 +2133,8 @@ int FirewallAnalyzer(const DetectEngineCtx *de_ctx) const char *name = AppLayerParserGetStateNameById(IPPROTO_TCP, a, state, STREAM_TOCLIENT); if (name == NULL) { - if (state == 0) - name = "response-started"; - else if (state == complete_state_tc) - name = "response-complete"; - else + name = DetectFirewallAppGenericHookName(state, complete_state_tc, STREAM_TOCLIENT); + if (name == NULL) name = "unknown"; } char table_name[128]; diff --git a/src/detect-parse.c b/src/detect-parse.c index ed399e7c50..cef252b73c 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -1141,6 +1141,20 @@ static bool IsBuiltIn(const char *n) return false; } +/** + * \brief Generic start/complete hook alias for an app progress state, in config + * form (hyphens), or NULL for intermediate states. + */ +const char *DetectFirewallAppGenericHookName( + const uint8_t state, const uint8_t complete_state, const int direction) +{ + if (state == 0) + return (direction == STREAM_TOSERVER) ? "request-started" : "response-started"; + if (state == complete_state) + return (direction == STREAM_TOSERVER) ? "request-complete" : "response-complete"; + return NULL; +} + /** \brief register app hooks as generic lists * * Register each hook in each app protocol as: diff --git a/src/detect-parse.h b/src/detect-parse.h index 53aff021d2..44568741f3 100644 --- a/src/detect-parse.h +++ b/src/detect-parse.h @@ -118,6 +118,9 @@ void DetectRegisterAppLayerHookLists(void); const char *ActionScopeToString(enum ActionScope s); +const char *DetectFirewallAppGenericHookName( + const uint8_t state, const uint8_t complete_state, const int direction); + struct DetectFirewallPolicy; void DetectFirewallPolicyToString(const struct DetectFirewallPolicy *p, char *out, size_t out_size); int DetectFirewallInitDefaultPolicies(DetectEngineCtx *);