2 * Copyright (c) 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "classifier.h"
21 #include <netinet/in.h>
22 #include "dynamic-string.h"
27 static struct cls_table *find_table(const struct classifier *,
28 const struct flow_wildcards *);
29 static struct cls_table *insert_table(struct classifier *,
30 const struct flow_wildcards *);
32 static struct cls_table *classifier_first_table(const struct classifier *);
33 static struct cls_table *classifier_next_table(const struct classifier *,
34 const struct cls_table *);
35 static void destroy_table(struct classifier *, struct cls_table *);
37 static bool should_include(const struct cls_table *, int include);
39 static struct cls_rule *find_match(const struct cls_table *,
41 static struct cls_rule *find_equal(struct cls_table *, const struct flow *,
43 static struct cls_rule *insert_rule(struct cls_table *, struct cls_rule *);
45 static bool flow_equal_except(const struct flow *, const struct flow *,
46 const struct flow_wildcards *);
47 static void zero_wildcards(struct flow *, const struct flow_wildcards *);
49 /* Iterates RULE over HEAD and all of the cls_rules on HEAD->list. */
50 #define FOR_EACH_RULE_IN_LIST(RULE, HEAD) \
51 for ((RULE) = (HEAD); (RULE) != NULL; (RULE) = next_rule_in_list(RULE))
52 #define FOR_EACH_RULE_IN_LIST_SAFE(RULE, NEXT, HEAD) \
53 for ((RULE) = (HEAD); \
54 (RULE) != NULL && ((NEXT) = next_rule_in_list(RULE), true); \
57 static struct cls_rule *next_rule_in_list(struct cls_rule *);
59 static struct cls_table *
60 cls_table_from_hmap_node(const struct hmap_node *node)
62 return node ? CONTAINER_OF(node, struct cls_table, hmap_node) : NULL;
65 static struct cls_rule *
66 cls_rule_from_hmap_node(const struct hmap_node *node)
68 return node ? CONTAINER_OF(node, struct cls_rule, hmap_node) : NULL;
71 /* Returns the cls_table within 'cls' that has no wildcards, or NULL if there
74 classifier_exact_table(const struct classifier *cls)
76 struct flow_wildcards exact_wc;
77 flow_wildcards_init_exact(&exact_wc);
78 return find_table(cls, &exact_wc);
81 /* Returns the first rule in 'table', or a null pointer if 'table' is NULL. */
83 cls_table_first_rule(const struct cls_table *table)
85 return table ? cls_rule_from_hmap_node(hmap_first(&table->rules)) : NULL;
88 /* Returns the next rule in 'table' following 'rule', or a null pointer if
89 * 'rule' is the last rule in 'table'. */
91 cls_table_next_rule(const struct cls_table *table, const struct cls_rule *rule)
94 = CONTAINER_OF(rule->list.next, struct cls_rule, hmap_node);
96 return (next->priority < rule->priority
98 : cls_rule_from_hmap_node(hmap_next(&table->rules,
102 /* Converts the flow in 'flow' into a cls_rule in 'rule', with the given
103 * 'wildcards' and 'priority'. */
105 cls_rule_init(const struct flow *flow, const struct flow_wildcards *wildcards,
106 unsigned int priority, struct cls_rule *rule)
109 rule->wc = *wildcards;
110 rule->priority = priority;
111 cls_rule_zero_wildcarded_fields(rule);
114 /* Converts the flow in 'flow' into an exact-match cls_rule in 'rule', with the
115 * given 'priority'. (For OpenFlow 1.0, exact-match rule are always highest
116 * priority, so 'priority' should be at least 65535.) */
118 cls_rule_init_exact(const struct flow *flow,
119 unsigned int priority, struct cls_rule *rule)
122 flow_wildcards_init_exact(&rule->wc);
123 rule->priority = priority;
126 /* Converts the ofp_match in 'match' (with format 'flow_format', one of NXFF_*)
127 * into a cls_rule in 'rule', with the given 'priority'. 'cookie' is used
128 * when 'flow_format' is NXFF_TUN_ID_FROM_COOKIE. */
130 cls_rule_from_match(const struct ofp_match *match, unsigned int priority,
131 int flow_format, uint64_t cookie,
132 struct cls_rule *rule)
134 flow_from_match(match, flow_format, cookie, &rule->flow, &rule->wc);
135 rule->priority = !rule->wc.wildcards ? UINT16_MAX : priority;
136 cls_rule_zero_wildcarded_fields(rule);
139 /* Initializes 'rule' as a "catch-all" rule that matches every packet, with
140 * priority 'priority'. */
142 cls_rule_init_catchall(struct cls_rule *rule, unsigned int priority)
144 memset(&rule->flow, 0, sizeof rule->flow);
145 flow_wildcards_init(&rule->wc, OVSFW_ALL);
146 rule->priority = priority;
149 /* For each bit or field wildcarded in 'rule', sets the corresponding bit or
150 * field in 'flow' to all-0-bits. It is important to maintain this invariant
151 * in a clr_rule that might be inserted into a classifier.
153 * It is never necessary to call this function directly for a cls_rule that is
154 * initialized or modified only by cls_rule_*() functions. It is useful to
155 * restore the invariant in a cls_rule whose 'wc' member is modified by hand.
158 cls_rule_zero_wildcarded_fields(struct cls_rule *rule)
160 zero_wildcards(&rule->flow, &rule->wc);
164 cls_rule_set_in_port(struct cls_rule *rule, uint16_t odp_port)
166 rule->wc.wildcards &= ~OFPFW_IN_PORT;
167 rule->flow.in_port = odp_port;
171 cls_rule_set_dl_type(struct cls_rule *rule, ovs_be16 dl_type)
173 rule->wc.wildcards &= ~OFPFW_DL_TYPE;
174 rule->flow.dl_type = dl_type;
178 cls_rule_set_dl_src(struct cls_rule *rule, const uint8_t dl_src[ETH_ADDR_LEN])
180 rule->wc.wildcards &= ~OFPFW_DL_SRC;
181 memcpy(rule->flow.dl_src, dl_src, ETH_ADDR_LEN);
185 cls_rule_set_dl_dst(struct cls_rule *rule, const uint8_t dl_dst[ETH_ADDR_LEN])
187 rule->wc.wildcards &= ~OFPFW_DL_DST;
188 memcpy(rule->flow.dl_dst, dl_dst, ETH_ADDR_LEN);
192 cls_rule_set_dl_tci(struct cls_rule *rule, ovs_be16 tci)
194 return cls_rule_set_dl_tci_masked(rule, tci, htons(0xffff));
198 cls_rule_set_dl_tci_masked(struct cls_rule *rule, ovs_be16 tci, ovs_be16 mask)
200 switch (ntohs(mask)) {
202 if (tci == htons(0)) {
203 /* Match only packets that have no 802.1Q header. */
204 rule->wc.wildcards &= ~(OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP);
205 rule->flow.dl_vlan = htons(OFP_VLAN_NONE);
206 rule->flow.dl_vlan_pcp = 0;
208 } else if (tci & htons(VLAN_CFI)) {
209 /* Match only packets that have a specific 802.1Q VID and PCP. */
210 rule->wc.wildcards &= ~(OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP);
211 rule->flow.dl_vlan = htons(vlan_tci_to_vid(tci));
212 rule->flow.dl_vlan_pcp = vlan_tci_to_pcp(tci);
220 if (!(tci & htons(VLAN_CFI))) {
223 /* Match only packets that have a specific 802.1Q VID. */
224 cls_rule_set_dl_vlan(rule, tci & htons(VLAN_VID_MASK));
225 rule->wc.wildcards |= OFPFW_DL_VLAN_PCP;
226 rule->flow.dl_vlan_pcp = 0;
231 if (!(tci & htons(VLAN_CFI))) {
234 /* Match only packets that have a specific 802.1Q PCP. */
235 cls_rule_set_dl_vlan_pcp(rule, vlan_tci_to_pcp(tci));
236 rule->wc.wildcards |= OFPFW_DL_VLAN;
237 rule->flow.dl_vlan = 0;
242 /* Match anything. */
243 rule->wc.wildcards |= OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP;
244 rule->flow.dl_vlan = htons(0);
245 rule->flow.dl_vlan_pcp = 0;
254 cls_rule_set_dl_vlan(struct cls_rule *rule, ovs_be16 dl_vlan)
256 if (dl_vlan != htons(OFP_VLAN_NONE)) {
257 dl_vlan &= htons(VLAN_VID_MASK);
260 rule->wc.wildcards &= ~OFPFW_DL_VLAN;
261 rule->flow.dl_vlan = dl_vlan;
265 cls_rule_set_dl_vlan_pcp(struct cls_rule *rule, uint8_t dl_vlan_pcp)
267 rule->wc.wildcards &= ~OFPFW_DL_VLAN_PCP;
268 rule->flow.dl_vlan_pcp = dl_vlan_pcp & 0x07;
272 cls_rule_set_tp_src(struct cls_rule *rule, ovs_be16 tp_src)
274 rule->wc.wildcards &= ~OFPFW_TP_SRC;
275 rule->flow.tp_src = tp_src;
279 cls_rule_set_tp_dst(struct cls_rule *rule, ovs_be16 tp_dst)
281 rule->wc.wildcards &= ~OFPFW_TP_DST;
282 rule->flow.tp_dst = tp_dst;
286 cls_rule_set_nw_proto(struct cls_rule *rule, uint8_t nw_proto)
288 rule->wc.wildcards &= ~OFPFW_NW_PROTO;
289 rule->flow.nw_proto = nw_proto;
293 cls_rule_set_nw_src(struct cls_rule *rule, ovs_be32 nw_src)
295 cls_rule_set_nw_src_masked(rule, nw_src, htonl(UINT32_MAX));
299 cls_rule_set_nw_src_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask)
301 if (flow_wildcards_set_nw_src_mask(&rule->wc, mask)) {
302 rule->flow.nw_src = ip & mask;
310 cls_rule_set_nw_dst(struct cls_rule *rule, ovs_be32 nw_dst)
312 cls_rule_set_nw_dst_masked(rule, nw_dst, htonl(UINT32_MAX));
316 cls_rule_set_nw_dst_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask)
318 if (flow_wildcards_set_nw_dst_mask(&rule->wc, mask)) {
319 rule->flow.nw_dst = ip & mask;
327 cls_rule_set_nw_tos(struct cls_rule *rule, uint8_t nw_tos)
329 rule->wc.wildcards &= ~OFPFW_NW_TOS;
330 rule->flow.nw_tos = nw_tos & IP_DSCP_MASK;
334 cls_rule_set_icmp_type(struct cls_rule *rule, uint8_t icmp_type)
336 rule->wc.wildcards &= ~OFPFW_ICMP_TYPE;
337 rule->flow.icmp_type = htons(icmp_type);
342 cls_rule_set_icmp_code(struct cls_rule *rule, uint8_t icmp_code)
344 rule->wc.wildcards &= ~OFPFW_ICMP_CODE;
345 rule->flow.icmp_code = htons(icmp_code);
348 /* Converts 'rule' to a string and returns the string. The caller must free
349 * the string (with free()). */
351 cls_rule_to_string(const struct cls_rule *rule)
353 struct ds s = DS_EMPTY_INITIALIZER;
354 ds_put_format(&s, "wildcards=%x priority=%u ",
355 rule->wc.wildcards, rule->priority);
356 flow_format(&s, &rule->flow);
360 /* Prints cls_rule 'rule', for debugging.
362 * (The output could be improved and expanded, but this was good enough to
363 * debug the classifier.) */
365 cls_rule_print(const struct cls_rule *rule)
367 printf("wildcards=%x priority=%u ", rule->wc.wildcards, rule->priority);
368 flow_print(stdout, &rule->flow);
372 /* Initializes 'cls' as a classifier that initially contains no classification
375 classifier_init(struct classifier *cls)
378 hmap_init(&cls->tables);
381 /* Destroys 'cls'. Rules within 'cls', if any, are not freed; this is the
382 * caller's responsibility. */
384 classifier_destroy(struct classifier *cls)
387 struct cls_table *table, *next_table;
389 HMAP_FOR_EACH_SAFE (table, next_table, hmap_node, &cls->tables) {
390 hmap_destroy(&table->rules);
391 hmap_remove(&cls->tables, &table->hmap_node);
394 hmap_destroy(&cls->tables);
398 /* Returns true if 'cls' contains no classification rules, false otherwise. */
400 classifier_is_empty(const struct classifier *cls)
402 return cls->n_rules == 0;
405 /* Returns the number of rules in 'classifier'. */
407 classifier_count(const struct classifier *cls)
412 /* Returns the number of rules in 'classifier' that have no wildcards. */
414 classifier_count_exact(const struct classifier *cls)
416 struct cls_table *exact_table = classifier_exact_table(cls);
417 return exact_table ? exact_table->n_table_rules : 0;
420 /* Inserts 'rule' into 'cls'. Until 'rule' is removed from 'cls', the caller
421 * must not modify or free it.
423 * If 'cls' already contains an identical rule (including wildcards, values of
424 * fixed fields, and priority), replaces the old rule by 'rule' and returns the
425 * rule that was replaced. The caller takes ownership of the returned rule and
426 * is thus responsible for freeing it, etc., as necessary.
428 * Returns NULL if 'cls' does not contain a rule with an identical key, after
429 * inserting the new rule. In this case, no rules are displaced by the new
430 * rule, even rules that cannot have any effect because the new rule matches a
431 * superset of their flows and has higher priority. */
433 classifier_insert(struct classifier *cls, struct cls_rule *rule)
435 struct cls_rule *old_rule;
436 struct cls_table *table;
438 table = find_table(cls, &rule->wc);
440 table = insert_table(cls, &rule->wc);
443 old_rule = insert_rule(table, rule);
445 table->n_table_rules++;
451 /* Removes 'rule' from 'cls'. It is the caller's responsibility to free
452 * 'rule', if this is desirable. */
454 classifier_remove(struct classifier *cls, struct cls_rule *rule)
456 struct cls_rule *head;
457 struct cls_table *table;
459 table = find_table(cls, &rule->wc);
460 head = find_equal(table, &rule->flow, rule->hmap_node.hash);
462 list_remove(&rule->list);
463 } else if (list_is_empty(&rule->list)) {
464 hmap_remove(&table->rules, &rule->hmap_node);
466 struct cls_rule *next = CONTAINER_OF(rule->list.next,
467 struct cls_rule, list);
469 list_remove(&rule->list);
470 hmap_replace(&table->rules, &rule->hmap_node, &next->hmap_node);
473 if (--table->n_table_rules == 0 && !table->n_refs) {
474 destroy_table(cls, table);
480 /* Finds and returns the highest-priority rule in 'cls' that matches 'flow'.
481 * Returns a null pointer if no rules in 'cls' match 'flow'. If multiple rules
482 * of equal priority match 'flow', returns one arbitrarily.
484 * 'include' is a combination of CLS_INC_* values that specify tables to
485 * include in the search. */
487 classifier_lookup(const struct classifier *cls, const struct flow *flow,
490 struct cls_table *table;
491 struct cls_rule *best;
494 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
495 if (should_include(table, include)) {
496 struct cls_rule *rule = find_match(table, flow);
497 if (rule && (!best || rule->priority > best->priority)) {
505 /* Finds and returns a rule in 'cls' with exactly the same priority and
506 * matching criteria as 'target'. Returns a null pointer if 'cls' doesn't
507 * contain an exact match.
509 * Priority is ignored for exact-match rules (because OpenFlow 1.0 always
510 * treats exact-match rules as highest priority). */
512 classifier_find_rule_exactly(const struct classifier *cls,
513 const struct cls_rule *target)
515 struct cls_rule *head, *rule;
516 struct cls_table *table;
518 table = find_table(cls, &target->wc);
523 head = find_equal(table, &target->flow, flow_hash(&target->flow, 0));
524 if (!target->wc.wildcards) {
527 FOR_EACH_RULE_IN_LIST (rule, head) {
528 if (target->priority >= rule->priority) {
529 return target->priority == rule->priority ? rule : NULL;
535 /* Checks if 'target' would overlap any other rule in 'cls'. Two rules are
536 * considered to overlap if both rules have the same priority and a packet
537 * could match both. */
539 classifier_rule_overlaps(const struct classifier *cls,
540 const struct cls_rule *target)
542 struct cls_table *table;
544 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
545 struct flow_wildcards wc;
546 struct cls_rule *head;
548 flow_wildcards_combine(&wc, &target->wc, &table->wc);
549 HMAP_FOR_EACH (head, hmap_node, &table->rules) {
550 struct cls_rule *rule;
552 FOR_EACH_RULE_IN_LIST (rule, head) {
553 if (rule->priority == target->priority
554 && flow_equal_except(&target->flow, &rule->flow, &wc)) {
564 /* Searches 'cls' for rules that exactly match 'target' or are more specific
565 * than 'target'. That is, a given 'rule' matches 'target' if, for every
568 * - 'target' and 'rule' specify the same (non-wildcarded) value for the
571 * - 'target' wildcards the field,
575 * - 'target' and 'rule' specify different values for the field, or
577 * - 'target' specifies a value for the field but 'rule' wildcards it.
579 * Equivalently, the truth table for whether a field matches is:
584 * +---------+---------+
585 * t wild | yes | yes |
587 * r +---------+---------+
588 * g exact | no |if values|
590 * t +---------+---------+
592 * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
593 * commands and by OpenFlow 1.0 aggregate and flow stats.
595 * Ignores target->priority.
597 * 'callback' is allowed to delete the rule that is passed as its argument, but
598 * it must not delete (or move) any other rules in 'cls' that have the same
599 * wildcards as the argument rule. */
601 classifier_for_each_match(const struct classifier *cls_,
602 const struct cls_rule *target,
603 int include, cls_cb_func *callback, void *aux)
605 struct classifier *cls = (struct classifier *) cls_;
606 struct cls_table *table, *next_table;
608 for (table = classifier_first_table(cls); table; table = next_table) {
609 if (should_include(table, include)
610 && !flow_wildcards_has_extra(&table->wc, &target->wc)) {
611 /* We have eliminated the "no" case in the truth table above. Two
612 * of the three remaining cases are trivial. We only need to check
613 * the fourth case, where both 'rule' and 'target' require an exact
615 struct cls_rule *head, *next_head;
618 HMAP_FOR_EACH_SAFE (head, next_head, hmap_node, &table->rules) {
619 if (flow_equal_except(&head->flow, &target->flow,
621 struct cls_rule *rule, *next_rule;
623 FOR_EACH_RULE_IN_LIST_SAFE (rule, next_rule, head) {
628 next_table = classifier_next_table(cls, table);
629 if (!--table->n_refs && !table->n_table_rules) {
630 destroy_table(cls, table);
633 next_table = classifier_next_table(cls, table);
638 /* 'callback' is allowed to delete the rule that is passed as its argument, but
639 * it must not delete (or move) any other rules in 'cls' that have the same
640 * wildcards as the argument rule.
642 * If 'include' is CLS_INC_EXACT then CLASSIFIER_FOR_EACH_EXACT_RULE is
643 * probably easier to use. */
645 classifier_for_each(const struct classifier *cls_, int include,
646 cls_cb_func *callback, void *aux)
648 struct classifier *cls = (struct classifier *) cls_;
649 struct cls_table *table, *next_table;
651 for (table = classifier_first_table(cls); table; table = next_table) {
652 if (should_include(table, include)) {
653 struct cls_rule *head, *next_head;
656 HMAP_FOR_EACH_SAFE (head, next_head, hmap_node, &table->rules) {
657 struct cls_rule *rule, *next_rule;
659 FOR_EACH_RULE_IN_LIST_SAFE (rule, next_rule, head) {
663 next_table = classifier_next_table(cls, table);
664 if (!--table->n_refs && !table->n_table_rules) {
665 destroy_table(cls, table);
668 next_table = classifier_next_table(cls, table);
673 static struct cls_table *
674 find_table(const struct classifier *cls, const struct flow_wildcards *wc)
676 struct cls_table *table;
678 HMAP_FOR_EACH_IN_BUCKET (table, hmap_node, flow_wildcards_hash(wc),
680 if (flow_wildcards_equal(wc, &table->wc)) {
687 static struct cls_table *
688 insert_table(struct classifier *cls, const struct flow_wildcards *wc)
690 struct cls_table *table;
692 table = xzalloc(sizeof *table);
693 hmap_init(&table->rules);
695 hmap_insert(&cls->tables, &table->hmap_node, flow_wildcards_hash(wc));
700 static struct cls_table *
701 classifier_first_table(const struct classifier *cls)
703 return cls_table_from_hmap_node(hmap_first(&cls->tables));
706 static struct cls_table *
707 classifier_next_table(const struct classifier *cls,
708 const struct cls_table *table)
710 return cls_table_from_hmap_node(hmap_next(&cls->tables,
715 destroy_table(struct classifier *cls, struct cls_table *table)
717 hmap_remove(&cls->tables, &table->hmap_node);
718 hmap_destroy(&table->rules);
722 /* Returns true if 'table' should be included by an operation with the
723 * specified 'include' (a combination of CLS_INC_*). */
725 should_include(const struct cls_table *table, int include)
727 return include & (table->wc.wildcards ? CLS_INC_WILD : CLS_INC_EXACT);
730 static struct cls_rule *
731 find_match(const struct cls_table *table, const struct flow *flow)
733 struct cls_rule *rule;
737 zero_wildcards(&f, &table->wc);
738 HMAP_FOR_EACH_WITH_HASH (rule, hmap_node, flow_hash(&f, 0),
740 if (flow_equal(&f, &rule->flow)) {
747 static struct cls_rule *
748 find_equal(struct cls_table *table, const struct flow *flow, uint32_t hash)
750 struct cls_rule *head;
752 HMAP_FOR_EACH_WITH_HASH (head, hmap_node, hash, &table->rules) {
753 if (flow_equal(&head->flow, flow)) {
760 static struct cls_rule *
761 insert_rule(struct cls_table *table, struct cls_rule *new)
763 struct cls_rule *head;
765 new->hmap_node.hash = flow_hash(&new->flow, 0);
767 head = find_equal(table, &new->flow, new->hmap_node.hash);
769 hmap_insert(&table->rules, &new->hmap_node, new->hmap_node.hash);
770 list_init(&new->list);
773 /* Scan the list for the insertion point that will keep the list in
774 * order of decreasing priority. */
775 struct cls_rule *rule;
776 FOR_EACH_RULE_IN_LIST (rule, head) {
777 if (new->priority >= rule->priority) {
779 /* 'new' is the new highest-priority flow in the list. */
780 hmap_replace(&table->rules,
781 &rule->hmap_node, &new->hmap_node);
784 if (new->priority == rule->priority) {
785 list_replace(&new->list, &rule->list);
788 list_insert(&rule->list, &new->list);
794 /* Insert 'new' at the end of the list. */
795 list_push_back(&head->list, &new->list);
800 static struct cls_rule *
801 next_rule_in_list(struct cls_rule *rule)
803 struct cls_rule *next = OBJECT_CONTAINING(rule->list.next, next, list);
804 return next->priority < rule->priority ? next : NULL;
808 flow_equal_except(const struct flow *a, const struct flow *b,
809 const struct flow_wildcards *wildcards)
811 const uint32_t wc = wildcards->wildcards;
813 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37);
815 return ((wc & NXFW_TUN_ID || a->tun_id == b->tun_id)
816 && !((a->nw_src ^ b->nw_src) & wildcards->nw_src_mask)
817 && !((a->nw_dst ^ b->nw_dst) & wildcards->nw_dst_mask)
818 && (wc & OFPFW_IN_PORT || a->in_port == b->in_port)
819 && (wc & OFPFW_DL_VLAN || a->dl_vlan == b->dl_vlan)
820 && (wc & OFPFW_DL_TYPE || a->dl_type == b->dl_type)
821 && (wc & OFPFW_TP_SRC || a->tp_src == b->tp_src)
822 && (wc & OFPFW_TP_DST || a->tp_dst == b->tp_dst)
823 && (wc & OFPFW_DL_SRC || eth_addr_equals(a->dl_src, b->dl_src))
824 && (wc & OFPFW_DL_DST || eth_addr_equals(a->dl_dst, b->dl_dst))
825 && (wc & OFPFW_NW_PROTO || a->nw_proto == b->nw_proto)
826 && (wc & OFPFW_DL_VLAN_PCP || a->dl_vlan_pcp == b->dl_vlan_pcp)
827 && (wc & OFPFW_NW_TOS || a->nw_tos == b->nw_tos));
831 zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
833 const uint32_t wc = wildcards->wildcards;
835 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37);
837 if (wc & NXFW_TUN_ID) {
840 flow->nw_src &= wildcards->nw_src_mask;
841 flow->nw_dst &= wildcards->nw_dst_mask;
842 if (wc & OFPFW_IN_PORT) {
845 if (wc & OFPFW_DL_VLAN) {
848 if (wc & OFPFW_DL_TYPE) {
851 if (wc & OFPFW_TP_SRC) {
854 if (wc & OFPFW_TP_DST) {
857 if (wc & OFPFW_DL_SRC) {
858 memset(flow->dl_src, 0, sizeof flow->dl_src);
860 if (wc & OFPFW_DL_DST) {
861 memset(flow->dl_dst, 0, sizeof flow->dl_dst);
863 if (wc & OFPFW_NW_PROTO) {
866 if (wc & OFPFW_DL_VLAN_PCP) {
867 flow->dl_vlan_pcp = 0;
869 if (wc & OFPFW_NW_TOS) {