Remove unused variables and functions.
[sliver-openvswitch.git] / lib / match.c
index 51ed1b9..93f61f9 100644 (file)
 #include "dynamic-string.h"
 #include "ofp-util.h"
 #include "packets.h"
-#include "vlog.h"
-
-VLOG_DEFINE_THIS_MODULE(match);
-
 
 /* Converts the flow in 'flow' into a match in 'match', with the given
  * 'wildcards'. */
@@ -181,7 +177,7 @@ match_set_reg_masked(struct match *match, unsigned int reg_idx,
 void
 match_set_metadata(struct match *match, ovs_be64 metadata)
 {
-    match_set_metadata_masked(match, metadata, htonll(UINT64_MAX));
+    match_set_metadata_masked(match, metadata, OVS_BE64_MAX);
 }
 
 void
@@ -195,7 +191,7 @@ match_set_metadata_masked(struct match *match,
 void
 match_set_tun_id(struct match *match, ovs_be64 tun_id)
 {
-    match_set_tun_id_masked(match, tun_id, htonll(UINT64_MAX));
+    match_set_tun_id_masked(match, tun_id, OVS_BE64_MAX);
 }
 
 void
@@ -208,7 +204,7 @@ match_set_tun_id_masked(struct match *match, ovs_be64 tun_id, ovs_be64 mask)
 void
 match_set_tun_src(struct match *match, ovs_be32 src)
 {
-    match_set_tun_src_masked(match, src, htonl(UINT32_MAX));
+    match_set_tun_src_masked(match, src, OVS_BE32_MAX);
 }
 
 void
@@ -221,7 +217,7 @@ match_set_tun_src_masked(struct match *match, ovs_be32 src, ovs_be32 mask)
 void
 match_set_tun_dst(struct match *match, ovs_be32 dst)
 {
-    match_set_tun_dst_masked(match, dst, htonl(UINT32_MAX));
+    match_set_tun_dst_masked(match, dst, OVS_BE32_MAX);
 }
 
 void
@@ -300,7 +296,7 @@ match_set_pkt_mark_masked(struct match *match, uint32_t pkt_mark, uint32_t mask)
 void
 match_set_dl_type(struct match *match, ovs_be16 dl_type)
 {
-    match->wc.masks.dl_type = htons(UINT16_MAX);
+    match->wc.masks.dl_type = OVS_BE16_MAX;
     match->flow.dl_type = dl_type;
 }
 
@@ -411,7 +407,7 @@ match_set_dl_vlan(struct match *match, ovs_be16 dl_vlan)
 {
     flow_set_dl_vlan(&match->flow, dl_vlan);
     if (dl_vlan == htons(OFP10_VLAN_NONE)) {
-        match->wc.masks.vlan_tci = htons(UINT16_MAX);
+        match->wc.masks.vlan_tci = OVS_BE16_MAX;
     } else {
         match->wc.masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
     }
@@ -518,7 +514,7 @@ match_set_mpls_bos(struct match *match, uint8_t mpls_bos)
 void
 match_set_tp_src(struct match *match, ovs_be16 tp_src)
 {
-    match_set_tp_src_masked(match, tp_src, htons(UINT16_MAX));
+    match_set_tp_src_masked(match, tp_src, OVS_BE16_MAX);
 }
 
 void
@@ -531,7 +527,7 @@ match_set_tp_src_masked(struct match *match, ovs_be16 port, ovs_be16 mask)
 void
 match_set_tp_dst(struct match *match, ovs_be16 tp_dst)
 {
-    match_set_tp_dst_masked(match, tp_dst, htons(UINT16_MAX));
+    match_set_tp_dst_masked(match, tp_dst, OVS_BE16_MAX);
 }
 
 void
@@ -552,7 +548,7 @@ void
 match_set_nw_src(struct match *match, ovs_be32 nw_src)
 {
     match->flow.nw_src = nw_src;
-    match->wc.masks.nw_src = htonl(UINT32_MAX);
+    match->wc.masks.nw_src = OVS_BE32_MAX;
 }
 
 void
@@ -567,7 +563,7 @@ void
 match_set_nw_dst(struct match *match, ovs_be32 nw_dst)
 {
     match->flow.nw_dst = nw_dst;
-    match->wc.masks.nw_dst = htonl(UINT32_MAX);
+    match->wc.masks.nw_dst = OVS_BE32_MAX;
 }
 
 void
@@ -692,7 +688,7 @@ match_set_ipv6_dst_masked(struct match *match, const struct in6_addr *dst,
 void
 match_set_ipv6_label(struct match *match, ovs_be32 ipv6_label)
 {
-    match->wc.masks.ipv6_label = htonl(UINT32_MAX);
+    match->wc.masks.ipv6_label = OVS_BE32_MAX;
     match->flow.ipv6_label = ipv6_label;
 }
 
@@ -779,7 +775,7 @@ format_be16_masked(struct ds *s, const char *name,
 {
     if (mask != htons(0)) {
         ds_put_format(s, "%s=", name);
-        if (mask == htons(UINT16_MAX)) {
+        if (mask == OVS_BE16_MAX) {
             ds_put_format(s, "%"PRIu16, ntohs(value));
         } else {
             ds_put_format(s, "0x%"PRIx16"/0x%"PRIx16,
@@ -798,7 +794,7 @@ format_flow_tunnel(struct ds *s, const struct match *match)
     switch (wc->masks.tunnel.tun_id) {
     case 0:
         break;
-    case CONSTANT_HTONLL(UINT64_MAX):
+    case OVS_BE64_MAX:
         ds_put_format(s, "tun_id=%#"PRIx64",", ntohll(tnl->tun_id));
         break;
     default:
@@ -835,7 +831,7 @@ match_format(const struct match *match, struct ds *s, unsigned int priority)
 
     int i;
 
-    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 20);
+    BUILD_ASSERT_DECL(FLOW_WC_SEQ == 21);
 
     if (priority != OFP_DEFAULT_PRIORITY) {
         ds_put_format(s, "priority=%u,", priority);
@@ -926,7 +922,7 @@ match_format(const struct match *match, struct ds *s, unsigned int priority)
     switch (wc->masks.metadata) {
     case 0:
         break;
-    case CONSTANT_HTONLL(UINT64_MAX):
+    case OVS_BE64_MAX:
         ds_put_format(s, "metadata=%#"PRIx64",", ntohll(f->metadata));
         break;
     default:
@@ -972,7 +968,7 @@ match_format(const struct match *match, struct ds *s, unsigned int priority)
         format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->masks.ipv6_src);
         format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->masks.ipv6_dst);
         if (wc->masks.ipv6_label) {
-            if (wc->masks.ipv6_label == htonl(UINT32_MAX)) {
+            if (wc->masks.ipv6_label == OVS_BE32_MAX) {
                 ds_put_format(s, "ipv6_label=0x%05"PRIx32",",
                               ntohl(f->ipv6_label));
             } else {
@@ -1091,8 +1087,8 @@ match_print(const struct match *match)
 void
 minimatch_init(struct minimatch *dst, const struct match *src)
 {
-    miniflow_init(&dst->flow, &src->flow);
     minimask_init(&dst->mask, &src->wc);
+    miniflow_init_with_minimask(&dst->flow, &src->flow, &dst->mask);
 }
 
 /* Initializes 'dst' as a copy of 'src'.  The caller must eventually free 'dst'
@@ -1145,6 +1141,35 @@ minimatch_hash(const struct minimatch *match, uint32_t basis)
     return miniflow_hash(&match->flow, minimask_hash(&match->mask, basis));
 }
 
+/* Returns true if 'target' satisifies 'match', that is, if each bit for which
+ * 'match' specifies a particular value has the correct value in 'target'.
+ *
+ * This function is equivalent to miniflow_equal_flow_in_minimask(&match->flow,
+ * target, &match->mask) but it is faster because of the invariant that
+ * match->flow.map and match->mask.map are the same. */
+bool
+minimatch_matches_flow(const struct minimatch *match,
+                       const struct flow *target)
+{
+    const uint32_t *target_u32 = (const uint32_t *) target;
+    const uint32_t *flowp = match->flow.values;
+    const uint32_t *maskp = match->mask.masks.values;
+    int i;
+
+    for (i = 0; i < MINI_N_MAPS; i++) {
+        uint32_t map;
+
+        for (map = match->flow.map[i]; map; map = zero_rightmost_1bit(map)) {
+            if ((*flowp++ ^ target_u32[raw_ctz(map)]) & *maskp++) {
+                return false;
+            }
+        }
+        target_u32 += 32;
+    }
+
+    return true;
+}
+
 /* Appends a string representation of 'match' to 's'.  If 'priority' is
  * different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
 void