From: Victor Julien Date: Thu, 27 Feb 2025 11:21:50 +0000 (+0100) Subject: detect/action: minor action parsing cleanup X-Git-Tag: suricata-8.0.0-beta1~279 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aceb9b76f3ef65897b842260d96e42340614e85;p=thirdparty%2Fsuricata.git detect/action: minor action parsing cleanup Preparation for explicit action scope parsing. --- diff --git a/src/detect-parse.c b/src/detect-parse.c index 9c711d14c2..2675b4369f 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -1214,45 +1214,57 @@ static int SigParseActionRejectValidate(const char *action) return 1; } -/** - * \brief Parses the action that has been used by the Signature and allots it - * to its Signature instance. - * - * \param s Pointer to the Signature instance to which the action belongs. - * \param action Pointer to the action string used by the Signature. - * - * \retval 0 On successfully parsing the action string and adding it to the - * Signature. - * \retval -1 On failure. +/** \retval 0 on error + * \retval flags on success */ -static int SigParseAction(Signature *s, const char *action) +static uint8_t ActionStringToFlags(const char *action) { if (strcasecmp(action, "alert") == 0) { - s->action = ACTION_ALERT; + return ACTION_ALERT; } else if (strcasecmp(action, "drop") == 0) { - s->action = ACTION_DROP | ACTION_ALERT; + return ACTION_DROP | ACTION_ALERT; } else if (strcasecmp(action, "pass") == 0) { - s->action = ACTION_PASS; + return ACTION_PASS; } else if (strcasecmp(action, "reject") == 0 || strcasecmp(action, "rejectsrc") == 0) { if (!(SigParseActionRejectValidate(action))) - return -1; - s->action = ACTION_REJECT | ACTION_DROP | ACTION_ALERT; + return 0; + return ACTION_REJECT | ACTION_DROP | ACTION_ALERT; } else if (strcasecmp(action, "rejectdst") == 0) { if (!(SigParseActionRejectValidate(action))) - return -1; - s->action = ACTION_REJECT_DST | ACTION_DROP | ACTION_ALERT; + return 0; + return ACTION_REJECT_DST | ACTION_DROP | ACTION_ALERT; } else if (strcasecmp(action, "rejectboth") == 0) { if (!(SigParseActionRejectValidate(action))) - return -1; - s->action = ACTION_REJECT_BOTH | ACTION_DROP | ACTION_ALERT; + return 0; + return ACTION_REJECT_BOTH | ACTION_DROP | ACTION_ALERT; } else if (strcasecmp(action, "config") == 0) { - s->action = ACTION_CONFIG; + return ACTION_CONFIG; } else { SCLogError("An invalid action \"%s\" was given", action); - return -1; + return 0; } +} + +/** + * \brief Parses the action that has been used by the Signature and allots it + * to its Signature instance. + * + * \param s Pointer to the Signature instance to which the action belongs. + * \param action Pointer to the action string used by the Signature. + * + * \retval 0 On successfully parsing the action string and adding it to the + * Signature. + * \retval -1 On failure. + */ +static int SigParseAction(Signature *s, const char *action) +{ + uint8_t flags = ActionStringToFlags(action); + if (flags == 0) + return -1; + + s->action = flags; return 0; }