ofp-actions: simplify ofpacts_from_openflow1[01]
authorIsaku Yamahata <yamahata@valinux.co.jp>
Wed, 18 Jul 2012 11:41:15 +0000 (20:41 +0900)
committerBen Pfaff <blp@nicira.com>
Wed, 18 Jul 2012 16:07:27 +0000 (09:07 -0700)
Those logic is same, so simplify it. This will be also use for OF12.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/ofp-actions.c

index 566ccdae7e597e7c4ee82031d24e7e1a45850e4e..0874cc46ac6fed714c03dead65a4d80cc3bdda97 100644 (file)
@@ -450,14 +450,16 @@ log_bad_action(const union ofp_action *actions, size_t n_actions, size_t ofs,
 }
 
 static enum ofperr
-ofpacts_from_openflow10(const union ofp_action *in, size_t n_in,
-                        struct ofpbuf *out)
+ofpacts_from_openflow(const union ofp_action *in, size_t n_in,
+                      struct ofpbuf *out,
+                      enum ofperr (*ofpact_from_openflow)(
+                          const union ofp_action *a, struct ofpbuf *out))
 {
     const union ofp_action *a;
     size_t left;
 
     ACTION_FOR_EACH (a, left, in, n_in) {
-        enum ofperr error = ofpact_from_openflow10(a, out);
+        enum ofperr error = ofpact_from_openflow(a, out);
         if (error) {
             log_bad_action(in, n_in, a - in, error);
             return error;
@@ -473,6 +475,13 @@ ofpacts_from_openflow10(const union ofp_action *in, size_t n_in,
     return 0;
 }
 
+static enum ofperr
+ofpacts_from_openflow10(const union ofp_action *in, size_t n_in,
+                        struct ofpbuf *out)
+{
+    return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow10);
+}
+
 static enum ofperr
 ofpacts_pull_actions(struct ofpbuf *openflow, unsigned int actions_len,
                      struct ofpbuf *ofpacts,
@@ -659,24 +668,7 @@ static enum ofperr
 ofpacts_from_openflow11(const union ofp_action *in, size_t n_in,
                         struct ofpbuf *out)
 {
-    const union ofp_action *a;
-    size_t left;
-
-    ACTION_FOR_EACH (a, left, in, n_in) {
-        enum ofperr error = ofpact_from_openflow11(a, out);
-        if (error) {
-            VLOG_WARN_RL(&rl, "bad action at offset %td (%s)",
-                         (a - in) * sizeof *a, ofperr_get_name(error));
-            return error;
-        }
-    }
-    if (left) {
-        VLOG_WARN_RL(&rl, "bad action format at offset %zu",
-                     (n_in - left) * sizeof *a);
-        return OFPERR_OFPBAC_BAD_LEN;
-    }
-
-    return 0;
+    return ofpacts_from_openflow(in, n_in, out, ofpact_from_openflow11);
 }
 \f
 /* OpenFlow 1.1 instructions. */
@@ -846,14 +838,8 @@ ofpacts_pull_openflow11_actions(struct ofpbuf *openflow,
                                 unsigned int actions_len,
                                 struct ofpbuf *ofpacts)
 {
-    enum ofperr error;
-
-    error = ofpacts_pull_actions(openflow, actions_len, ofpacts,
-                                 ofpacts_from_openflow11);
-    if (!error) {
-        ofpact_pad(ofpacts);
-    }
-    return error;
+    return ofpacts_pull_actions(openflow, actions_len, ofpacts,
+                                ofpacts_from_openflow11);
 }
 
 enum ofperr
@@ -904,8 +890,6 @@ ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
         }
     }
 
-    ofpact_pad(ofpacts);
-
     if (insts[OVSINST_OFPIT11_GOTO_TABLE] ||
         insts[OVSINST_OFPIT11_WRITE_METADATA] ||
         insts[OVSINST_OFPIT11_WRITE_ACTIONS] ||