[ovs-dev] [PATCH 7/8] lib/classifier: Clarify find_match_wc().

Jarno Rajahalme jrajahalme at nicira.com
Mon Jun 9 18:53:54 UTC 2014


Reduce the number of goto statements by returning via a new helper
fill_range_wc() when no match is found.

Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 lib/classifier.c |   37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/lib/classifier.c b/lib/classifier.c
index 2d47310..2ed28d2 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -1454,6 +1454,17 @@ miniflow_and_mask_matches_flow_wc(const struct miniflow *flow,
     return true;
 }
 
+/* Unwildcard the fields looked up so far, if any. */
+static struct cls_match *
+fill_range_wc(const struct cls_subtable *subtable, struct flow_wildcards *wc,
+              uint8_t to)
+{
+    if (to) {
+        flow_wildcards_fold_minimask_range(wc, &subtable->mask, 0, to);
+    }
+    return NULL;
+}
+
 static struct cls_match *
 find_match_wc(const struct cls_subtable *subtable, const struct flow *flow,
               struct trie_ctx trie_ctx[CLS_MAX_TRIES], unsigned int n_tries,
@@ -1477,16 +1488,17 @@ find_match_wc(const struct cls_subtable *subtable, const struct flow *flow,
 
         if (check_tries(trie_ctx, n_tries, subtable->trie_plen, ofs, flow,
                         wc)) {
-            goto range_out;
+            /* 'wc' bits for the trie field set, now unwildcard the preceding
+             * bits used so far. */
+            return fill_range_wc(subtable, wc, ofs.start);
         }
         hash = flow_hash_in_minimask_range(flow, &subtable->mask, ofs.start,
                                            ofs.end, &basis);
-        ofs.start = ofs.end;
         inode = hindex_node_with_hash(&subtable->indices[i], hash);
         if (!inode) {
-            /* No match, can stop immediately, but must fold in the mask
-             * covered so far. */
-            goto range_out;
+            /* No match, can stop immediately, but must fold in the bits
+             * used in lookup so far. */
+            return fill_range_wc(subtable, wc, ofs.end);
         }
 
         /* If we have narrowed down to a single rule already, check whether
@@ -1502,11 +1514,12 @@ find_match_wc(const struct cls_subtable *subtable, const struct flow *flow,
             }
             return NULL;
         }
+        ofs.start = ofs.end;
     }
     ofs.end = FLOW_U32S;
     /* Trie check for the final range. */
     if (check_tries(trie_ctx, n_tries, subtable->trie_plen, ofs, flow, wc)) {
-        goto range_out;
+        return fill_range_wc(subtable, wc, ofs.start);
     }
     hash = flow_hash_in_minimask_range(flow, &subtable->mask, ofs.start,
                                        ofs.end, &basis);
@@ -1525,20 +1538,14 @@ find_match_wc(const struct cls_subtable *subtable, const struct flow *flow,
         ((OVS_FORCE ovs_be32 *)&wc->masks)[TP_PORTS_OFS32] |=
             mask & htonl(~0 << (32 - mbits));
 
-        ofs.start = TP_PORTS_OFS32;
-        goto range_out;
+        /* Unwildcard all bits in the mask upto the ports, as they were used
+         * to determine there is no match. */
+        return fill_range_wc(subtable, wc, TP_PORTS_OFS32);
     }
 
     /* Must unwildcard all the fields, as they were looked at. */
     flow_wildcards_fold_minimask(wc, &subtable->mask);
     return rule;
-
-range_out:
-    /* Must unwildcard the fields looked up so far, if any. */
-    if (ofs.start) {
-        flow_wildcards_fold_minimask_range(wc, &subtable->mask, 0, ofs.start);
-    }
-    return NULL;
 }
 
 static struct cls_match *
-- 
1.7.10.4




More information about the dev mailing list