[ovs-dev] [RFC PATCH 2/8] ofpacts_check: Remove unnecessary flow copying.

Jarno Rajahalme jarno.rajahalme at nsn.com
Thu Jun 20 14:26:17 UTC 2013


Signed-off-by: Jarno Rajahalme <jarno.rajahalme at nsn.com>
---
 lib/ofp-actions.c |   34 +++++++++++-----------------------
 lib/ofp-actions.h |    3 ++-
 2 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index c9e000f..7a2851e 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -1141,9 +1141,9 @@ exit:
     return error;
 }
 
+/* May modify flow->dl_type, caller must restore it. */
 static enum ofperr
-ofpact_check__(const struct ofpact *a, const struct flow *flow, int max_ports,
-               ovs_be16 *dl_type)
+ofpact_check__(const struct ofpact *a, struct flow *flow, int max_ports)
 {
     const struct ofpact_enqueue *enqueue;
 
@@ -1215,11 +1215,11 @@ ofpact_check__(const struct ofpact *a, const struct flow *flow, int max_ports,
         return 0;
 
     case OFPACT_PUSH_MPLS:
-        *dl_type = ofpact_get_PUSH_MPLS(a)->ethertype;
+        flow->dl_type = ofpact_get_PUSH_MPLS(a)->ethertype;
         return 0;
 
     case OFPACT_POP_MPLS:
-        *dl_type = ofpact_get_POP_MPLS(a)->ethertype;
+        flow->dl_type = ofpact_get_POP_MPLS(a)->ethertype;
         return 0;
 
     case OFPACT_SAMPLE:
@@ -1240,33 +1240,21 @@ ofpact_check__(const struct ofpact *a, const struct flow *flow, int max_ports,
  * switch with no more than 'max_ports' ports. */
 enum ofperr
 ofpacts_check(const struct ofpact ofpacts[], size_t ofpacts_len,
-              const struct flow *flow, int max_ports)
+              struct flow *flow, int max_ports)
 {
     const struct ofpact *a;
     ovs_be16 dl_type = flow->dl_type;
-    struct flow updated_flow;
+    enum ofperr error = 0;
 
     OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
-        enum ofperr error;
-
-        /* If the dl_type was changed by an action then its new value
-         * should be present in the flow passed to ofpact_check__(). */
-        if (flow->dl_type != dl_type) {
-            /* Only copy flow at most once */
-            if (flow != &updated_flow) {
-                updated_flow = *flow;
-                flow = &updated_flow;
-            }
-            updated_flow.dl_type = dl_type;
-        }
-
-        error = ofpact_check__(a, flow, max_ports, &dl_type);
+        error = ofpact_check__(a, flow, max_ports);
         if (error) {
-            return error;
+            goto out;
         }
     }
-
-    return 0;
+out:
+    flow->dl_type = dl_type; /* Restore. */
+    return error;
 }
 
 /* Verifies that the 'ofpacts_len' bytes of actions in 'ofpacts' are
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
index 4e7fb5c..bba3927 100644
--- a/lib/ofp-actions.h
+++ b/lib/ofp-actions.h
@@ -492,8 +492,9 @@ enum ofperr ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow,
                                                  unsigned int instructions_len,
                                                  uint8_t table_id,
                                                  struct ofpbuf *ofpacts);
+/* May temporarily modify flow */
 enum ofperr ofpacts_check(const struct ofpact[], size_t ofpacts_len,
-                          const struct flow *, int max_ports);
+                          struct flow *, int max_ports);
 enum ofperr ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len);
 
 /* Converting ofpacts to OpenFlow. */
-- 
1.7.10.4




More information about the dev mailing list