From 00561f415c3a1622f8835c84ba2db7e7ff0fbe61 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 8 Nov 2010 16:45:00 -0800 Subject: [PATCH] flow: New function flow_wildcards_is_exact(). --- lib/classifier.c | 2 +- lib/flow.c | 8 ++++++++ lib/flow.h | 2 ++ tests/test-classifier.c | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index f3b5d5d2d..c57c7e564 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -479,7 +479,7 @@ classifier_find_rule_exactly(const struct classifier *cls, } head = find_equal(table, &target->flow, flow_hash(&target->flow, 0)); - if (!target->wc.wildcards) { + if (flow_wildcards_is_exact(&target->wc)) { return head; } FOR_EACH_RULE_IN_LIST (rule, head) { diff --git a/lib/flow.c b/lib/flow.c index 0b6541f6f..3ac353081 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -420,6 +420,14 @@ flow_wildcards_init_exact(struct flow_wildcards *wc) memset(wc->reg_masks, 0xff, sizeof wc->reg_masks); } +/* Returns true if 'wc' is exact-match, false if 'wc' wildcards any bits or + * fields. */ +bool +flow_wildcards_is_exact(const struct flow_wildcards *wc) +{ + return !wc->wildcards; +} + static inline uint32_t combine_nw_bits(uint32_t wb1, uint32_t wb2, int shift) { diff --git a/lib/flow.h b/lib/flow.h index a19a9ae5e..b30a885d4 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -150,6 +150,8 @@ ovs_be32 flow_nw_bits_to_mask(uint32_t wildcards, int shift); void flow_wildcards_init(struct flow_wildcards *, uint32_t wildcards); void flow_wildcards_init_exact(struct flow_wildcards *); +bool flow_wildcards_is_exact(const struct flow_wildcards *); + bool flow_wildcards_set_nw_src_mask(struct flow_wildcards *, ovs_be32); bool flow_wildcards_set_nw_dst_mask(struct flow_wildcards *, ovs_be32); void flow_wildcards_set_reg_mask(struct flow_wildcards *, diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 45700ed9e..063f718fb 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -136,7 +136,8 @@ tcls_insert(struct tcls *tcls, const struct test_rule *rule) { size_t i; - assert(rule->cls_rule.wc.wildcards || rule->cls_rule.priority == UINT_MAX); + assert(!flow_wildcards_is_exact(&rule->cls_rule.wc) + || rule->cls_rule.priority == UINT_MAX); for (i = 0; i < tcls->n_rules; i++) { const struct cls_rule *pos = &tcls->rules[i]->cls_rule; if (cls_rule_equal(pos, &rule->cls_rule)) { -- 2.20.1