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 "byte-order.h"
23 #include "dynamic-string.h"
29 static struct cls_table *find_table(const struct classifier *,
30 const struct flow_wildcards *);
31 static struct cls_table *insert_table(struct classifier *,
32 const struct flow_wildcards *);
34 static struct cls_table *classifier_first_table(const struct classifier *);
35 static struct cls_table *classifier_next_table(const struct classifier *,
36 const struct cls_table *);
37 static void destroy_table(struct classifier *, struct cls_table *);
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 *);
58 static struct cls_rule *next_rule_in_list(struct cls_rule *);
60 static struct cls_table *
61 cls_table_from_hmap_node(const struct hmap_node *node)
63 return node ? CONTAINER_OF(node, struct cls_table, hmap_node) : NULL;
66 /* Converts the flow in 'flow' into a cls_rule in 'rule', with the given
67 * 'wildcards' and 'priority'. */
69 cls_rule_init(const struct flow *flow, const struct flow_wildcards *wildcards,
70 unsigned int priority, struct cls_rule *rule)
73 rule->wc = *wildcards;
74 rule->priority = priority;
75 cls_rule_zero_wildcarded_fields(rule);
78 /* Converts the flow in 'flow' into an exact-match cls_rule in 'rule', with the
79 * given 'priority'. (For OpenFlow 1.0, exact-match rule are always highest
80 * priority, so 'priority' should be at least 65535.) */
82 cls_rule_init_exact(const struct flow *flow,
83 unsigned int priority, struct cls_rule *rule)
86 flow_wildcards_init_exact(&rule->wc);
87 rule->priority = priority;
90 /* Initializes 'rule' as a "catch-all" rule that matches every packet, with
91 * priority 'priority'. */
93 cls_rule_init_catchall(struct cls_rule *rule, unsigned int priority)
95 memset(&rule->flow, 0, sizeof rule->flow);
96 flow_wildcards_init_catchall(&rule->wc);
97 rule->priority = priority;
100 /* For each bit or field wildcarded in 'rule', sets the corresponding bit or
101 * field in 'flow' to all-0-bits. It is important to maintain this invariant
102 * in a clr_rule that might be inserted into a classifier.
104 * It is never necessary to call this function directly for a cls_rule that is
105 * initialized or modified only by cls_rule_*() functions. It is useful to
106 * restore the invariant in a cls_rule whose 'wc' member is modified by hand.
109 cls_rule_zero_wildcarded_fields(struct cls_rule *rule)
111 zero_wildcards(&rule->flow, &rule->wc);
115 cls_rule_set_reg(struct cls_rule *rule, unsigned int reg_idx, uint32_t value)
117 cls_rule_set_reg_masked(rule, reg_idx, value, UINT32_MAX);
121 cls_rule_set_reg_masked(struct cls_rule *rule, unsigned int reg_idx,
122 uint32_t value, uint32_t mask)
124 assert(reg_idx < FLOW_N_REGS);
125 flow_wildcards_set_reg_mask(&rule->wc, reg_idx, mask);
126 rule->flow.regs[reg_idx] = value & mask;
130 cls_rule_set_tun_id(struct cls_rule *rule, ovs_be32 tun_id)
132 rule->wc.wildcards &= ~FWW_TUN_ID;
133 rule->flow.tun_id = tun_id;
137 cls_rule_set_in_port(struct cls_rule *rule, uint16_t odp_port)
139 rule->wc.wildcards &= ~FWW_IN_PORT;
140 rule->flow.in_port = odp_port;
144 cls_rule_set_dl_type(struct cls_rule *rule, ovs_be16 dl_type)
146 rule->wc.wildcards &= ~FWW_DL_TYPE;
147 rule->flow.dl_type = dl_type;
151 cls_rule_set_dl_src(struct cls_rule *rule, const uint8_t dl_src[ETH_ADDR_LEN])
153 rule->wc.wildcards &= ~FWW_DL_SRC;
154 memcpy(rule->flow.dl_src, dl_src, ETH_ADDR_LEN);
158 cls_rule_set_dl_dst(struct cls_rule *rule, const uint8_t dl_dst[ETH_ADDR_LEN])
160 rule->wc.wildcards &= ~(FWW_DL_DST | FWW_ETH_MCAST);
161 memcpy(rule->flow.dl_dst, dl_dst, ETH_ADDR_LEN);
165 cls_rule_set_dl_tci(struct cls_rule *rule, ovs_be16 tci)
167 cls_rule_set_dl_tci_masked(rule, tci, htons(0xffff));
171 cls_rule_set_dl_tci_masked(struct cls_rule *rule, ovs_be16 tci, ovs_be16 mask)
173 rule->flow.vlan_tci = tci & mask;
174 rule->wc.vlan_tci_mask = mask;
177 /* Modifies 'rule' so that the VLAN VID is wildcarded. If the PCP is already
178 * wildcarded, then 'rule' will match a packet regardless of whether it has an
179 * 802.1Q header or not. */
181 cls_rule_set_any_vid(struct cls_rule *rule)
183 if (rule->wc.vlan_tci_mask & htons(VLAN_PCP_MASK)) {
184 rule->wc.vlan_tci_mask &= ~htons(VLAN_VID_MASK);
185 rule->flow.vlan_tci &= ~htons(VLAN_VID_MASK);
187 cls_rule_set_dl_tci_masked(rule, htons(0), htons(0));
191 /* Modifies 'rule' depending on 'dl_vlan':
193 * - If 'dl_vlan' is htons(OFP_VLAN_NONE), makes 'rule' match only packets
194 * without an 802.1Q header.
196 * - Otherwise, makes 'rule' match only packets with an 802.1Q header whose
197 * VID equals the low 12 bits of 'dl_vlan'.
200 cls_rule_set_dl_vlan(struct cls_rule *rule, ovs_be16 dl_vlan)
202 if (dl_vlan == htons(OFP_VLAN_NONE)) {
203 cls_rule_set_dl_tci(rule, htons(0));
205 dl_vlan &= htons(VLAN_VID_MASK);
206 rule->flow.vlan_tci &= ~htons(VLAN_VID_MASK);
207 rule->flow.vlan_tci |= htons(VLAN_CFI) | dl_vlan;
208 rule->wc.vlan_tci_mask |= htons(VLAN_VID_MASK | VLAN_CFI);
212 /* Modifies 'rule' so that the VLAN PCP is wildcarded. If the VID is already
213 * wildcarded, then 'rule' will match a packet regardless of whether it has an
214 * 802.1Q header or not. */
216 cls_rule_set_any_pcp(struct cls_rule *rule)
218 if (rule->wc.vlan_tci_mask & htons(VLAN_VID_MASK)) {
219 rule->wc.vlan_tci_mask &= ~htons(VLAN_PCP_MASK);
220 rule->flow.vlan_tci &= ~htons(VLAN_PCP_MASK);
222 cls_rule_set_dl_tci_masked(rule, htons(0), htons(0));
226 /* Modifies 'rule' so that it matches only packets with an 802.1Q header whose
227 * PCP equals the low 3 bits of 'dl_vlan_pcp'. */
229 cls_rule_set_dl_vlan_pcp(struct cls_rule *rule, uint8_t dl_vlan_pcp)
232 rule->flow.vlan_tci &= ~htons(VLAN_PCP_MASK);
233 rule->flow.vlan_tci |= htons((dl_vlan_pcp << VLAN_PCP_SHIFT) | VLAN_CFI);
234 rule->wc.vlan_tci_mask |= htons(VLAN_CFI | VLAN_PCP_MASK);
238 cls_rule_set_tp_src(struct cls_rule *rule, ovs_be16 tp_src)
240 rule->wc.wildcards &= ~FWW_TP_SRC;
241 rule->flow.tp_src = tp_src;
245 cls_rule_set_tp_dst(struct cls_rule *rule, ovs_be16 tp_dst)
247 rule->wc.wildcards &= ~FWW_TP_DST;
248 rule->flow.tp_dst = tp_dst;
252 cls_rule_set_nw_proto(struct cls_rule *rule, uint8_t nw_proto)
254 rule->wc.wildcards &= ~FWW_NW_PROTO;
255 rule->flow.nw_proto = nw_proto;
259 cls_rule_set_nw_src(struct cls_rule *rule, ovs_be32 nw_src)
261 cls_rule_set_nw_src_masked(rule, nw_src, htonl(UINT32_MAX));
265 cls_rule_set_nw_src_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask)
267 if (flow_wildcards_set_nw_src_mask(&rule->wc, mask)) {
268 rule->flow.nw_src = ip & mask;
276 cls_rule_set_nw_dst(struct cls_rule *rule, ovs_be32 nw_dst)
278 cls_rule_set_nw_dst_masked(rule, nw_dst, htonl(UINT32_MAX));
282 cls_rule_set_nw_dst_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask)
284 if (flow_wildcards_set_nw_dst_mask(&rule->wc, mask)) {
285 rule->flow.nw_dst = ip & mask;
293 cls_rule_set_nw_tos(struct cls_rule *rule, uint8_t nw_tos)
295 rule->wc.wildcards &= ~FWW_NW_TOS;
296 rule->flow.nw_tos = nw_tos & IP_DSCP_MASK;
300 cls_rule_set_icmp_type(struct cls_rule *rule, uint8_t icmp_type)
302 rule->wc.wildcards &= ~FWW_TP_SRC;
303 rule->flow.icmp_type = htons(icmp_type);
308 cls_rule_set_icmp_code(struct cls_rule *rule, uint8_t icmp_code)
310 rule->wc.wildcards &= ~FWW_TP_DST;
311 rule->flow.icmp_code = htons(icmp_code);
314 /* Returns true if 'a' and 'b' have the same priority, wildcard the same
315 * fields, and have the same values for fixed fields, otherwise false. */
317 cls_rule_equal(const struct cls_rule *a, const struct cls_rule *b)
319 return (a->priority == b->priority
320 && flow_wildcards_equal(&a->wc, &b->wc)
321 && flow_equal(&a->flow, &b->flow));
324 /* Converts 'rule' to a string and returns the string. The caller must free
325 * the string (with free()). */
327 cls_rule_to_string(const struct cls_rule *rule)
329 struct ds s = DS_EMPTY_INITIALIZER;
330 ds_put_format(&s, "wildcards=%x priority=%u ",
331 rule->wc.wildcards, rule->priority);
332 flow_format(&s, &rule->flow);
336 /* Prints cls_rule 'rule', for debugging.
338 * (The output could be improved and expanded, but this was good enough to
339 * debug the classifier.) */
341 cls_rule_print(const struct cls_rule *rule)
343 printf("wildcards=%x priority=%u ", rule->wc.wildcards, rule->priority);
344 flow_print(stdout, &rule->flow);
348 /* Initializes 'cls' as a classifier that initially contains no classification
351 classifier_init(struct classifier *cls)
354 hmap_init(&cls->tables);
357 /* Destroys 'cls'. Rules within 'cls', if any, are not freed; this is the
358 * caller's responsibility. */
360 classifier_destroy(struct classifier *cls)
363 struct cls_table *table, *next_table;
365 HMAP_FOR_EACH_SAFE (table, next_table, hmap_node, &cls->tables) {
366 hmap_destroy(&table->rules);
367 hmap_remove(&cls->tables, &table->hmap_node);
370 hmap_destroy(&cls->tables);
374 /* Returns true if 'cls' contains no classification rules, false otherwise. */
376 classifier_is_empty(const struct classifier *cls)
378 return cls->n_rules == 0;
381 /* Returns the number of rules in 'classifier'. */
383 classifier_count(const struct classifier *cls)
388 /* Inserts 'rule' into 'cls'. Until 'rule' is removed from 'cls', the caller
389 * must not modify or free it.
391 * If 'cls' already contains an identical rule (including wildcards, values of
392 * fixed fields, and priority), replaces the old rule by 'rule' and returns the
393 * rule that was replaced. The caller takes ownership of the returned rule and
394 * is thus responsible for freeing it, etc., as necessary.
396 * Returns NULL if 'cls' does not contain a rule with an identical key, after
397 * inserting the new rule. In this case, no rules are displaced by the new
398 * rule, even rules that cannot have any effect because the new rule matches a
399 * superset of their flows and has higher priority. */
401 classifier_insert(struct classifier *cls, struct cls_rule *rule)
403 struct cls_rule *old_rule;
404 struct cls_table *table;
406 table = find_table(cls, &rule->wc);
408 table = insert_table(cls, &rule->wc);
411 old_rule = insert_rule(table, rule);
413 table->n_table_rules++;
419 /* Removes 'rule' from 'cls'. It is the caller's responsibility to free
420 * 'rule', if this is desirable. */
422 classifier_remove(struct classifier *cls, struct cls_rule *rule)
424 struct cls_rule *head;
425 struct cls_table *table;
427 table = find_table(cls, &rule->wc);
428 head = find_equal(table, &rule->flow, rule->hmap_node.hash);
430 list_remove(&rule->list);
431 } else if (list_is_empty(&rule->list)) {
432 hmap_remove(&table->rules, &rule->hmap_node);
434 struct cls_rule *next = CONTAINER_OF(rule->list.next,
435 struct cls_rule, list);
437 list_remove(&rule->list);
438 hmap_replace(&table->rules, &rule->hmap_node, &next->hmap_node);
441 if (--table->n_table_rules == 0) {
442 destroy_table(cls, table);
448 /* Finds and returns the highest-priority rule in 'cls' that matches 'flow'.
449 * Returns a null pointer if no rules in 'cls' match 'flow'. If multiple rules
450 * of equal priority match 'flow', returns one arbitrarily. */
452 classifier_lookup(const struct classifier *cls, const struct flow *flow)
454 struct cls_table *table;
455 struct cls_rule *best;
458 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
459 struct cls_rule *rule = find_match(table, flow);
460 if (rule && (!best || rule->priority > best->priority)) {
467 /* Finds and returns a rule in 'cls' with exactly the same priority and
468 * matching criteria as 'target'. Returns a null pointer if 'cls' doesn't
469 * contain an exact match.
471 * Priority is ignored for exact-match rules (because OpenFlow 1.0 always
472 * treats exact-match rules as highest priority). */
474 classifier_find_rule_exactly(const struct classifier *cls,
475 const struct cls_rule *target)
477 struct cls_rule *head, *rule;
478 struct cls_table *table;
480 table = find_table(cls, &target->wc);
485 head = find_equal(table, &target->flow, flow_hash(&target->flow, 0));
486 if (flow_wildcards_is_exact(&target->wc)) {
489 FOR_EACH_RULE_IN_LIST (rule, head) {
490 if (target->priority >= rule->priority) {
491 return target->priority == rule->priority ? rule : NULL;
497 /* Checks if 'target' would overlap any other rule in 'cls'. Two rules are
498 * considered to overlap if both rules have the same priority and a packet
499 * could match both. */
501 classifier_rule_overlaps(const struct classifier *cls,
502 const struct cls_rule *target)
504 struct cls_table *table;
506 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
507 struct flow_wildcards wc;
508 struct cls_rule *head;
510 flow_wildcards_combine(&wc, &target->wc, &table->wc);
511 HMAP_FOR_EACH (head, hmap_node, &table->rules) {
512 struct cls_rule *rule;
514 FOR_EACH_RULE_IN_LIST (rule, head) {
515 if (rule->priority == target->priority
516 && flow_equal_except(&target->flow, &rule->flow, &wc)) {
529 rule_matches(const struct cls_rule *rule, const struct cls_rule *target)
532 || flow_equal_except(&rule->flow, &target->flow, &target->wc));
535 static struct cls_rule *
536 search_table(const struct cls_table *table, const struct cls_rule *target)
538 if (!target || !flow_wildcards_has_extra(&table->wc, &target->wc)) {
539 struct cls_rule *rule;
541 HMAP_FOR_EACH (rule, hmap_node, &table->rules) {
542 if (rule_matches(rule, target)) {
550 /* Initializes 'cursor' for iterating through 'cls' rules that exactly match
551 * 'target' or are more specific than 'target'. That is, a given 'rule'
552 * matches 'target' if, for every field:
554 * - 'target' and 'rule' specify the same (non-wildcarded) value for the
557 * - 'target' wildcards the field,
561 * - 'target' and 'rule' specify different values for the field, or
563 * - 'target' specifies a value for the field but 'rule' wildcards it.
565 * Equivalently, the truth table for whether a field matches is:
570 * +---------+---------+
571 * t wild | yes | yes |
573 * r +---------+---------+
574 * g exact | no |if values|
576 * t +---------+---------+
578 * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
579 * commands and by OpenFlow 1.0 aggregate and flow stats.
581 * Ignores target->priority.
583 * 'target' may be NULL to iterate over every rule in 'cls'. */
585 cls_cursor_init(struct cls_cursor *cursor, const struct classifier *cls,
586 const struct cls_rule *target)
589 cursor->target = target;
592 /* Returns the first matching cls_rule in 'cursor''s iteration, or a null
593 * pointer if there are no matches. */
595 cls_cursor_first(struct cls_cursor *cursor)
597 struct cls_table *table;
599 for (table = classifier_first_table(cursor->cls); table;
600 table = classifier_next_table(cursor->cls, table)) {
601 struct cls_rule *rule = search_table(table, cursor->target);
603 cursor->table = table;
611 /* Returns the next matching cls_rule in 'cursor''s iteration, or a null
612 * pointer if there are no more matches. */
614 cls_cursor_next(struct cls_cursor *cursor, struct cls_rule *rule)
616 const struct cls_table *table;
617 struct cls_rule *next;
619 next = next_rule_in_list__(rule);
620 if (next->priority < rule->priority) {
624 /* 'next' is the head of the list, that is, the rule that is included in
625 * the table's hmap. (This is important when the classifier contains rules
626 * that differ only in priority.) */
628 HMAP_FOR_EACH_CONTINUE (rule, hmap_node, &cursor->table->rules) {
629 if (rule_matches(rule, cursor->target)) {
634 for (table = classifier_next_table(cursor->cls, cursor->table); table;
635 table = classifier_next_table(cursor->cls, table)) {
636 rule = search_table(table, cursor->target);
638 cursor->table = table;
646 static struct cls_table *
647 find_table(const struct classifier *cls, const struct flow_wildcards *wc)
649 struct cls_table *table;
651 HMAP_FOR_EACH_IN_BUCKET (table, hmap_node, flow_wildcards_hash(wc),
653 if (flow_wildcards_equal(wc, &table->wc)) {
660 static struct cls_table *
661 insert_table(struct classifier *cls, const struct flow_wildcards *wc)
663 struct cls_table *table;
665 table = xzalloc(sizeof *table);
666 hmap_init(&table->rules);
668 hmap_insert(&cls->tables, &table->hmap_node, flow_wildcards_hash(wc));
673 static struct cls_table *
674 classifier_first_table(const struct classifier *cls)
676 return cls_table_from_hmap_node(hmap_first(&cls->tables));
679 static struct cls_table *
680 classifier_next_table(const struct classifier *cls,
681 const struct cls_table *table)
683 return cls_table_from_hmap_node(hmap_next(&cls->tables,
688 destroy_table(struct classifier *cls, struct cls_table *table)
690 hmap_remove(&cls->tables, &table->hmap_node);
691 hmap_destroy(&table->rules);
695 static struct cls_rule *
696 find_match(const struct cls_table *table, const struct flow *flow)
698 struct cls_rule *rule;
702 zero_wildcards(&f, &table->wc);
703 HMAP_FOR_EACH_WITH_HASH (rule, hmap_node, flow_hash(&f, 0),
705 if (flow_equal(&f, &rule->flow)) {
712 static struct cls_rule *
713 find_equal(struct cls_table *table, const struct flow *flow, uint32_t hash)
715 struct cls_rule *head;
717 HMAP_FOR_EACH_WITH_HASH (head, hmap_node, hash, &table->rules) {
718 if (flow_equal(&head->flow, flow)) {
725 static struct cls_rule *
726 insert_rule(struct cls_table *table, struct cls_rule *new)
728 struct cls_rule *head;
730 new->hmap_node.hash = flow_hash(&new->flow, 0);
732 head = find_equal(table, &new->flow, new->hmap_node.hash);
734 hmap_insert(&table->rules, &new->hmap_node, new->hmap_node.hash);
735 list_init(&new->list);
738 /* Scan the list for the insertion point that will keep the list in
739 * order of decreasing priority. */
740 struct cls_rule *rule;
741 FOR_EACH_RULE_IN_LIST (rule, head) {
742 if (new->priority >= rule->priority) {
744 /* 'new' is the new highest-priority flow in the list. */
745 hmap_replace(&table->rules,
746 &rule->hmap_node, &new->hmap_node);
749 if (new->priority == rule->priority) {
750 list_replace(&new->list, &rule->list);
753 list_insert(&rule->list, &new->list);
759 /* Insert 'new' at the end of the list. */
760 list_push_back(&head->list, &new->list);
765 static struct cls_rule *
766 next_rule_in_list__(struct cls_rule *rule)
768 struct cls_rule *next = OBJECT_CONTAINING(rule->list.next, next, list);
772 static struct cls_rule *
773 next_rule_in_list(struct cls_rule *rule)
775 struct cls_rule *next = next_rule_in_list__(rule);
776 return next->priority < rule->priority ? next : NULL;
780 flow_equal_except(const struct flow *a, const struct flow *b,
781 const struct flow_wildcards *wildcards)
783 const flow_wildcards_t wc = wildcards->wildcards;
786 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 36 + FLOW_N_REGS * 4);
788 for (i = 0; i < FLOW_N_REGS; i++) {
789 if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) {
794 return ((wc & FWW_TUN_ID || a->tun_id == b->tun_id)
795 && !((a->nw_src ^ b->nw_src) & wildcards->nw_src_mask)
796 && !((a->nw_dst ^ b->nw_dst) & wildcards->nw_dst_mask)
797 && (wc & FWW_IN_PORT || a->in_port == b->in_port)
798 && !((a->vlan_tci ^ b->vlan_tci) & wildcards->vlan_tci_mask)
799 && (wc & FWW_DL_TYPE || a->dl_type == b->dl_type)
800 && (wc & FWW_TP_SRC || a->tp_src == b->tp_src)
801 && (wc & FWW_TP_DST || a->tp_dst == b->tp_dst)
802 && (wc & FWW_DL_SRC || eth_addr_equals(a->dl_src, b->dl_src))
804 || (!((a->dl_dst[0] ^ b->dl_dst[0]) & 0xfe)
805 && a->dl_dst[1] == b->dl_dst[1]
806 && a->dl_dst[2] == b->dl_dst[2]
807 && a->dl_dst[3] == b->dl_dst[3]
808 && a->dl_dst[4] == b->dl_dst[4]
809 && a->dl_dst[5] == b->dl_dst[5]))
810 && (wc & FWW_ETH_MCAST
811 || !((a->dl_dst[0] ^ b->dl_dst[0]) & 0x01))
812 && (wc & FWW_NW_PROTO || a->nw_proto == b->nw_proto)
813 && (wc & FWW_NW_TOS || a->nw_tos == b->nw_tos));
817 zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
819 const flow_wildcards_t wc = wildcards->wildcards;
822 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 36 + 4 * FLOW_N_REGS);
824 for (i = 0; i < FLOW_N_REGS; i++) {
825 flow->regs[i] &= wildcards->reg_masks[i];
827 if (wc & FWW_TUN_ID) {
830 flow->nw_src &= wildcards->nw_src_mask;
831 flow->nw_dst &= wildcards->nw_dst_mask;
832 if (wc & FWW_IN_PORT) {
835 flow->vlan_tci &= wildcards->vlan_tci_mask;
836 if (wc & FWW_DL_TYPE) {
839 if (wc & FWW_TP_SRC) {
842 if (wc & FWW_TP_DST) {
845 if (wc & FWW_DL_SRC) {
846 memset(flow->dl_src, 0, sizeof flow->dl_src);
848 if (wc & FWW_DL_DST) {
849 flow->dl_dst[0] &= 0x01;
850 memset(&flow->dl_dst[1], 0, 5);
852 if (wc & FWW_ETH_MCAST) {
853 flow->dl_dst[0] &= 0xfe;
855 if (wc & FWW_NW_PROTO) {
858 if (wc & FWW_NW_TOS) {