[ovs-dev] [PATCH] flow: Zero wildcarded fields in flow_from_match().

Jesse Gross jesse at nicira.com
Fri May 7 23:07:39 UTC 2010


If a field is wildcarded in struct ofp_match then rather than copy
over the value, just zero it out.  This is particularly important
with the tun_id field which is overloaded onto the cookie but it
is also generally nicer to have a canonicalized form.
---
 lib/flow.c |   72 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index 38ad72a..45f33d6 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -273,34 +273,60 @@ flow_to_match(const flow_t *flow, uint32_t wildcards, bool tun_id_from_cookie,
 
 void
 flow_from_match(const struct ofp_match *match, bool tun_id_from_cookie,
-                uint64_t cookie, flow_t *flow, uint32_t *wildcards)
+                uint64_t cookie, flow_t *flow, uint32_t *flow_wildcards)
 {
-    if (wildcards) {
-        *wildcards = ntohl(match->wildcards);
+    uint32_t wildcards;
 
-        if (!tun_id_from_cookie) {
-            *wildcards |= NXFW_TUN_ID;
-        }
+    wildcards = ntohl(match->wildcards);
+    if (!tun_id_from_cookie) {
+        wildcards |= NXFW_TUN_ID;
     }
-    flow->nw_src = match->nw_src;
-    flow->nw_dst = match->nw_dst;
-    if (tun_id_from_cookie) {
+
+    if (flow_wildcards) {
+        *flow_wildcards = wildcards;
+    }
+
+    memset(flow, 0, sizeof flow);
+
+    flow->nw_src = match->nw_src &
+                   flow_nw_bits_to_mask(wildcards, OFPFW_NW_SRC_SHIFT);
+    flow->nw_dst = match->nw_dst &
+                   flow_nw_bits_to_mask(wildcards, OFPFW_NW_DST_SHIFT);
+
+    if (tun_id_from_cookie && !(wildcards & NXFW_TUN_ID)) {
         flow->tun_id = htonl(ntohll(cookie) >> 32);
-    } else {
-        flow->tun_id = 0;
     }
-    flow->in_port = (match->in_port == htons(OFPP_LOCAL) ? ODPP_LOCAL
-                     : ntohs(match->in_port));
-    flow->dl_vlan = match->dl_vlan;
-    flow->dl_vlan_pcp = match->dl_vlan_pcp;
-    flow->dl_type = match->dl_type;
-    flow->tp_src = match->tp_src;
-    flow->tp_dst = match->tp_dst;
-    memcpy(flow->dl_src, match->dl_src, ETH_ADDR_LEN);
-    memcpy(flow->dl_dst, match->dl_dst, ETH_ADDR_LEN);
-    flow->nw_tos = match->nw_tos;
-    flow->nw_proto = match->nw_proto;
-    memset(flow->reserved, 0, sizeof flow->reserved);
+    if (!(wildcards & OFPFW_IN_PORT)) {
+        flow->in_port = (match->in_port == htons(OFPP_LOCAL) ? ODPP_LOCAL
+                         : ntohs(match->in_port));
+    }
+    if (!(wildcards & OFPFW_DL_VLAN)) {
+        flow->dl_vlan = match->dl_vlan;
+    }
+    if (!(wildcards & OFPFW_DL_VLAN_PCP)) {
+        flow->dl_vlan_pcp = match->dl_vlan_pcp;
+    }
+    if (!(wildcards & OFPFW_DL_TYPE)) {
+        flow->dl_type = match->dl_type;
+    }
+    if (!(wildcards & OFPFW_TP_SRC)) {
+        flow->tp_src = match->tp_src;
+    }
+    if (!(wildcards & OFPFW_TP_DST)) {
+        flow->tp_dst = match->tp_dst;
+    }
+    if (!(wildcards & OFPFW_DL_SRC)) {
+        memcpy(flow->dl_src, match->dl_src, ETH_ADDR_LEN);
+    }
+    if (!(wildcards & OFPFW_DL_DST)) {
+        memcpy(flow->dl_dst, match->dl_dst, ETH_ADDR_LEN);
+    }
+    if (!(wildcards & OFPFW_NW_TOS)) {
+        flow->nw_tos = match->nw_tos;
+    }
+    if (!(wildcards & OFPFW_NW_PROTO)) {
+        flow->nw_proto = match->nw_proto;
+    }
 }
 
 char *
-- 
1.7.0.4





More information about the dev mailing list