packets: Fix eth_addr_equal_except().
authorEthan Jackson <ethan@nicira.com>
Thu, 7 Jun 2012 00:37:46 +0000 (17:37 -0700)
committerEthan Jackson <ethan@nicira.com>
Thu, 7 Jun 2012 00:37:46 +0000 (17:37 -0700)
It turns out that eth_addr_equal_except() computed the exact
opposite of what it purported to.  It returned true if the two
arguments where *not* equal.  This is extremely confusing, so this
patch changes it.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
lib/classifier.c
lib/packets.h
tests/test-classifier.c

index 327a8b2ccdc3aa8a601e6ce8d2b1a51b91bae4e2..d19840ceb01e8b99c99bc73506e6f5e8cf6993f4 100644 (file)
@@ -1204,10 +1204,10 @@ flow_equal_except(const struct flow *a, const struct flow *b,
             && (wc & FWW_DL_TYPE || a->dl_type == b->dl_type)
             && !((a->tp_src ^ b->tp_src) & wildcards->tp_src_mask)
             && !((a->tp_dst ^ b->tp_dst) & wildcards->tp_dst_mask)
-            && !eth_addr_equal_except(a->dl_src, b->dl_src,
-                    wildcards->dl_src_mask)
-            && !eth_addr_equal_except(a->dl_dst, b->dl_dst,
-                    wildcards->dl_dst_mask)
+            && eth_addr_equal_except(a->dl_src, b->dl_src,
+                                     wildcards->dl_src_mask)
+            && eth_addr_equal_except(a->dl_dst, b->dl_dst,
+                                     wildcards->dl_dst_mask)
             && (wc & FWW_NW_PROTO || a->nw_proto == b->nw_proto)
             && (wc & FWW_NW_TTL || a->nw_ttl == b->nw_ttl)
             && (wc & FWW_NW_DSCP || !((a->nw_tos ^ b->nw_tos) & IP_DSCP_MASK))
index 00c2b75bf13fde9602ffecdabb244bedee73985a..afe4b6b3353a2faef8d73021a066e23f74e4b7f5 100644 (file)
@@ -84,12 +84,12 @@ static inline bool eth_addr_equal_except(const uint8_t a[ETH_ADDR_LEN],
                                     const uint8_t b[ETH_ADDR_LEN],
                                     const uint8_t mask[ETH_ADDR_LEN])
 {
-    return (((a[0] ^ b[0]) & mask[0])
-            || ((a[1] ^ b[1]) & mask[1])
-            || ((a[2] ^ b[2]) & mask[2])
-            || ((a[3] ^ b[3]) & mask[3])
-            || ((a[4] ^ b[4]) & mask[4])
-            || ((a[5] ^ b[5]) & mask[5]));
+    return !(((a[0] ^ b[0]) & mask[0])
+             || ((a[1] ^ b[1]) & mask[1])
+             || ((a[2] ^ b[2]) & mask[2])
+             || ((a[3] ^ b[3]) & mask[3])
+             || ((a[4] ^ b[4]) & mask[4])
+             || ((a[5] ^ b[5]) & mask[5]));
 }
 static inline uint64_t eth_addr_to_uint64(const uint8_t ea[ETH_ADDR_LEN])
 {
index 7403159d681e8c51af5f70b875539c614ab541b4..25f6edb4e433ac928a832ef4d4e0388a50c2c531 100644 (file)
@@ -203,11 +203,11 @@ match(const struct cls_rule *wild, const struct flow *fixed)
         } else if (f_idx == CLS_F_IDX_TP_DST) {
             eq = !((fixed->tp_dst ^ wild->flow.tp_dst) & wild->wc.tp_dst_mask);
         } else if (f_idx == CLS_F_IDX_DL_SRC) {
-            eq = !eth_addr_equal_except(fixed->dl_src, wild->flow.dl_src,
-                                        wild->wc.dl_src_mask);
+            eq = eth_addr_equal_except(fixed->dl_src, wild->flow.dl_src,
+                                       wild->wc.dl_src_mask);
         } else if (f_idx == CLS_F_IDX_DL_DST) {
-            eq = !eth_addr_equal_except(fixed->dl_dst, wild->flow.dl_dst,
-                                        wild->wc.dl_dst_mask);
+            eq = eth_addr_equal_except(fixed->dl_dst, wild->flow.dl_dst,
+                                       wild->wc.dl_dst_mask);
         } else if (f_idx == CLS_F_IDX_VLAN_TCI) {
             eq = !((fixed->vlan_tci ^ wild->flow.vlan_tci)
                    & wild->wc.vlan_tci_mask);