classifier: Change classifier_rule_overlaps() to take a cls_rule *.
authorBen Pfaff <blp@nicira.com>
Tue, 19 Oct 2010 20:04:52 +0000 (13:04 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Oct 2010 16:53:51 +0000 (09:53 -0700)
There's no benefit to spelling out all of the components of a cls_rule
separately.  Just use cls_rule itself.

lib/classifier.c
lib/classifier.h
ofproto/ofproto.c

index 091e0ca1fcb430d8e9181a5d55e8b293c4a4fdbf..ae2019fdad3cf8cdb570d394eba5544d3c165489 100644 (file)
@@ -299,24 +299,20 @@ classifier_find_rule_exactly(const struct classifier *cls,
     return NULL;
 }
 
-/* Checks if the flow defined by 'target' with 'wildcards' at 'priority'
- * overlaps with any other rule at the same priority in the classifier.
- * Two rules are considered overlapping if a packet could match both. */
+/* Checks if 'target' would overlap any other rule in 'cls'.  Two rules are
+ * considered to overlap if both rules have the same priority and a packet
+ * could match both. */
 bool
 classifier_rule_overlaps(const struct classifier *cls,
-                         const struct flow *target, uint32_t wildcards,
-                         unsigned int priority)
+                         const struct cls_rule *target)
 {
-    struct cls_rule target_rule;
     const struct hmap *tbl;
 
-    if (!wildcards) {
-        return search_exact_table(cls, flow_hash(target, 0), target) ?
-            true : false;
+    if (!target->wc.wildcards) {
+        return (search_exact_table(cls, flow_hash(&target->flow, 0),
+                                   &target->flow) != NULL);
     }
 
-    cls_rule_from_flow(target, wildcards, priority, &target_rule);
-
     for (tbl = &cls->tables[0]; tbl < &cls->tables[CLS_N_FIELDS]; tbl++) {
         struct cls_bucket *bucket;
 
@@ -324,8 +320,8 @@ classifier_rule_overlaps(const struct classifier *cls,
             struct cls_rule *rule;
 
             LIST_FOR_EACH (rule, node.list, &bucket->rules) {
-                if (rule->priority == priority
-                    && rules_match_2wild(rule, &target_rule, 0)) {
+                if (rule->priority == target->priority
+                    && rules_match_2wild(rule, target, 0)) {
                     return true;
                 }
             }
index 46df77d7f60d1bb60868748d3a6dac0d3551a82c..d2e2b8bd5f443283f883a56bb7b55fb68a358209 100644 (file)
@@ -147,8 +147,8 @@ void classifier_insert_exact(struct classifier *, struct cls_rule *);
 void classifier_remove(struct classifier *, struct cls_rule *);
 struct cls_rule *classifier_lookup(const struct classifier *,
                                    const struct flow *, int include);
-bool classifier_rule_overlaps(const struct classifier *, const struct flow *,
-                              uint32_t wildcards, unsigned int priority);
+bool classifier_rule_overlaps(const struct classifier *,
+                              const struct cls_rule *);
 
 typedef void cls_cb_func(struct cls_rule *, void *aux);
 
index 4d2172e55486348fda6dbfba65dd9c0c928b1692..0caeef08f618044f109b54d8291791569020f458 100644 (file)
@@ -3619,13 +3619,11 @@ add_flow(struct ofproto *p, struct ofconn *ofconn,
     int error;
 
     if (ofm->flags & htons(OFPFF_CHECK_OVERLAP)) {
-        struct flow flow;
-        uint32_t wildcards;
+        struct cls_rule cr;
 
-        flow_from_match(&ofm->match, p->tun_id_from_cookie, ofm->cookie,
-                        &flow, &wildcards);
-        if (classifier_rule_overlaps(&p->cls, &flow, wildcards,
-                                     ntohs(ofm->priority))) {
+        cls_rule_from_match(&ofm->match, ntohs(ofm->priority),
+                            p->tun_id_from_cookie, ofm->cookie, &cr);
+        if (classifier_rule_overlaps(&p->cls, &cr)) {
             return ofp_mkerr(OFPET_FLOW_MOD_FAILED, OFPFMFC_OVERLAP);
         }
     }