[ovs-discuss] [ACLv2 16/19] flow: Add flow_equal_wildcarded function.

Jesse Gross jesse at nicira.com
Sat Aug 15 02:13:24 UTC 2009


Checks whether two functions are equal given a set of wildcards.
---
 lib/flow.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 lib/flow.h |    1 +
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/lib/flow.c b/lib/flow.c
index eb44f0f..d2bd86e 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -465,3 +465,45 @@ flow_wildcard_to_string(flow_t *flow, uint32_t wildcards, int verbosity)
     }
     return ds_cstr(&f);
 }
+
+bool
+flow_equal_wildcarded(flow_t *a, flow_t *b, uint32_t wildcards)
+{
+    uint32_t srcip_mask;
+    uint32_t dstip_mask;
+
+    srcip_mask = flow_nw_bits_to_mask(wildcards, OFPFW_NW_SRC_SHIFT);
+    dstip_mask = flow_nw_bits_to_mask(wildcards, OFPFW_NW_DST_SHIFT);
+
+    if (a->in_port != b->in_port && !(wildcards & OFPFW_IN_PORT)) {
+        return false;
+    } else if (a->dl_vlan != b->dl_vlan && !(wildcards & OFPFW_DL_VLAN)) {
+        return false;
+    } else if (memcmp(a->dl_src, b->dl_src, ETH_ADDR_LEN) != 0 &&
+               !(wildcards & OFPFW_DL_SRC)) {
+        return false;
+    } else if (memcmp(a->dl_dst, b->dl_dst, ETH_ADDR_LEN) != 0 &&
+               !(wildcards & OFPFW_DL_DST)) {
+        return false;
+    } else if (a->dl_type != b->dl_type && !(wildcards & OFPFW_DL_TYPE)) {
+        return false;
+    } else if ((a->nw_src ^ b->nw_src) & srcip_mask) {
+        return false;
+    } else if ((a->nw_dst ^ b->nw_dst) & dstip_mask) {
+        return false;
+    } else if (a->nw_proto != b->nw_proto && !(wildcards & OFPFW_NW_PROTO)) {
+        return false;
+    } else if (a->tp_src != b->tp_src && !(wildcards & OFPFW_TP_SRC)) {
+        return false;
+    } else if (a->tp_dst != b->tp_dst && !(wildcards & OFPFW_TP_DST)) {
+        return false;
+    } else if (memcmp(a->ar_sha, b->ar_sha, ETH_ADDR_LEN) != 0 &&
+               !(wildcards & NICFW_AR_SHA)) {
+        return false;
+    } else if (memcmp(a->ar_tha, b->ar_tha, ETH_ADDR_LEN) != 0 &&
+               !(wildcards & NICFW_AR_THA)) {
+        return false;
+    }
+
+    return true;
+}
diff --git a/lib/flow.h b/lib/flow.h
index 0ccf733..66da04b 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -72,6 +72,7 @@ void flow_print(FILE *, const flow_t *);
 char *flow_wildcard_to_string(flow_t *flow, uint32_t wildcards, int verbosity);
 static inline int flow_compare(const flow_t *, const flow_t *);
 static inline bool flow_equal(const flow_t *, const flow_t *);
+bool flow_equal_wildcarded(flow_t *a, flow_t *b, uint32_t wildcards);
 static inline size_t flow_hash(const flow_t *, uint32_t basis);
 
 static inline int
-- 
1.6.0.4





More information about the discuss mailing list