dpctl: When parsing actions, don't let "drop" be preceded by other actions.
authorBen Pfaff <blp@nicira.com>
Wed, 15 Apr 2009 17:01:30 +0000 (10:01 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 15 Apr 2009 17:01:30 +0000 (10:01 -0700)
The dpctl manpage says that "drop" must not be used with other actions,
but we were only checking for other actions *after* it, not just ones
before it.

utilities/dpctl.c

index 3e0227e73d62212b0a96bdc99e92cc650e78b64c..5fa5fa4bbcd6bc808807c974d0e24b0c15bbbbb1 100644 (file)
@@ -925,9 +925,10 @@ str_to_action(char *str, struct ofpbuf *b)
     char *act, *arg;
     char *saveptr = NULL;
     bool drop = false;
+    int n_actions;
 
-    for (act = strtok_r(str, ", \t\r\n", &saveptr); act;
-         act = strtok_r(NULL, ", \t\r\n", &saveptr)) 
+    for (act = strtok_r(str, ", \t\r\n", &saveptr), n_actions = 0; act;
+         act = strtok_r(NULL, ", \t\r\n", &saveptr), n_actions++
     {
         uint16_t port;
 
@@ -963,7 +964,11 @@ str_to_action(char *str, struct ofpbuf *b)
         } else if (!strcasecmp(act, "drop")) {
             /* A drop action in OpenFlow occurs by just not setting 
              * an action. */
-            drop=true;
+            drop = true;
+            if (n_actions) {
+                ofp_fatal(0, "Drop actions must not be preceded by other "
+                          "actions");
+            }
 #ifdef SUPPORT_SNAT
         } else if (!strcasecmp(act, "nat")) {
             struct nx_action_snat *sa;