]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/action: minor action parsing cleanup
authorVictor Julien <vjulien@oisf.net>
Thu, 27 Feb 2025 11:21:50 +0000 (12:21 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 10 Mar 2025 11:23:08 +0000 (12:23 +0100)
Preparation for explicit action scope parsing.

src/detect-parse.c

index 9c711d14c2547feaf67a0cfb08a5a5190c4fbd58..2675b4369f5e92443da642f51b6dcc7736f303ae 100644 (file)
@@ -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;
 }