firewall: share the generic app hook name helper

Mapping an app-layer progress state to its generic request-/response-
hook alias was hardcoded in multiple places.

This commit adds a wrapper to unify it to a single function.
It returns the config-form (hyphenated) name, or NULL for an
intermediate state.

Ticket: 8770
(cherry picked from commit 1aa0259876)
pull/16123/head
Lukas Sismis 3 weeks ago committed by Victor Julien
parent c3134d4ab8
commit 400e750496

@ -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];

@ -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:

@ -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 *);

Loading…
Cancel
Save