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 struct cls_rule *find_match(const struct cls_table *,
39 static struct cls_rule *find_equal(struct cls_table *, const struct flow *,
41 static struct cls_rule *insert_rule(struct cls_table *, struct cls_rule *);
43 static bool flow_equal_except(const struct flow *, const struct flow *,
44 const struct flow_wildcards *);
45 static void zero_wildcards(struct flow *, const struct flow_wildcards *);
47 /* Iterates RULE over HEAD and all of the cls_rules on HEAD->list. */
48 #define FOR_EACH_RULE_IN_LIST(RULE, HEAD) \
49 for ((RULE) = (HEAD); (RULE) != NULL; (RULE) = next_rule_in_list(RULE))
50 #define FOR_EACH_RULE_IN_LIST_SAFE(RULE, NEXT, HEAD) \
51 for ((RULE) = (HEAD); \
52 (RULE) != NULL && ((NEXT) = next_rule_in_list(RULE), true); \
55 static struct cls_rule *next_rule_in_list__(struct cls_rule *);
56 static struct cls_rule *next_rule_in_list(struct cls_rule *);
58 static struct cls_table *
59 cls_table_from_hmap_node(const struct hmap_node *node)
61 return node ? CONTAINER_OF(node, struct cls_table, hmap_node) : NULL;
64 /* Converts the flow in 'flow' into a cls_rule in 'rule', with the given
65 * 'wildcards' and 'priority'. */
67 cls_rule_init(const struct flow *flow, const struct flow_wildcards *wildcards,
68 unsigned int priority, struct cls_rule *rule)
71 rule->wc = *wildcards;
72 rule->priority = priority;
73 cls_rule_zero_wildcarded_fields(rule);
76 /* Converts the flow in 'flow' into an exact-match cls_rule in 'rule', with the
77 * given 'priority'. (For OpenFlow 1.0, exact-match rule are always highest
78 * priority, so 'priority' should be at least 65535.) */
80 cls_rule_init_exact(const struct flow *flow,
81 unsigned int priority, struct cls_rule *rule)
84 flow_wildcards_init_exact(&rule->wc);
85 rule->priority = priority;
88 /* Converts the ofp_match in 'match' (with format 'flow_format', one of NXFF_*)
89 * into a cls_rule in 'rule', with the given 'priority'. 'cookie' is used
90 * when 'flow_format' is NXFF_TUN_ID_FROM_COOKIE. */
92 cls_rule_from_match(const struct ofp_match *match, unsigned int priority,
93 int flow_format, uint64_t cookie,
94 struct cls_rule *rule)
96 flow_from_match(match, flow_format, cookie, &rule->flow, &rule->wc);
97 rule->priority = !rule->wc.wildcards ? UINT16_MAX : priority;
98 cls_rule_zero_wildcarded_fields(rule);
101 /* Initializes 'rule' as a "catch-all" rule that matches every packet, with
102 * priority 'priority'. */
104 cls_rule_init_catchall(struct cls_rule *rule, unsigned int priority)
106 memset(&rule->flow, 0, sizeof rule->flow);
107 flow_wildcards_init(&rule->wc, OVSFW_ALL | FWW_ALL);
108 rule->priority = priority;
111 /* For each bit or field wildcarded in 'rule', sets the corresponding bit or
112 * field in 'flow' to all-0-bits. It is important to maintain this invariant
113 * in a clr_rule that might be inserted into a classifier.
115 * It is never necessary to call this function directly for a cls_rule that is
116 * initialized or modified only by cls_rule_*() functions. It is useful to
117 * restore the invariant in a cls_rule whose 'wc' member is modified by hand.
120 cls_rule_zero_wildcarded_fields(struct cls_rule *rule)
122 zero_wildcards(&rule->flow, &rule->wc);
126 cls_rule_set_in_port(struct cls_rule *rule, uint16_t odp_port)
128 rule->wc.wildcards &= ~OFPFW_IN_PORT;
129 rule->flow.in_port = odp_port;
133 cls_rule_set_dl_type(struct cls_rule *rule, ovs_be16 dl_type)
135 rule->wc.wildcards &= ~OFPFW_DL_TYPE;
136 rule->flow.dl_type = dl_type;
140 cls_rule_set_dl_src(struct cls_rule *rule, const uint8_t dl_src[ETH_ADDR_LEN])
142 rule->wc.wildcards &= ~OFPFW_DL_SRC;
143 memcpy(rule->flow.dl_src, dl_src, ETH_ADDR_LEN);
147 cls_rule_set_dl_dst(struct cls_rule *rule, const uint8_t dl_dst[ETH_ADDR_LEN])
149 rule->wc.wildcards &= ~(OFPFW_DL_DST | FWW_ETH_MCAST);
150 memcpy(rule->flow.dl_dst, dl_dst, ETH_ADDR_LEN);
154 cls_rule_set_dl_tci(struct cls_rule *rule, ovs_be16 tci)
156 return cls_rule_set_dl_tci_masked(rule, tci, htons(0xffff));
160 cls_rule_set_dl_tci_masked(struct cls_rule *rule, ovs_be16 tci, ovs_be16 mask)
162 switch (ntohs(mask)) {
164 if (tci == htons(0)) {
165 /* Match only packets that have no 802.1Q header. */
166 rule->wc.wildcards &= ~(OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP);
167 rule->flow.dl_vlan = htons(OFP_VLAN_NONE);
168 rule->flow.dl_vlan_pcp = 0;
170 } else if (tci & htons(VLAN_CFI)) {
171 /* Match only packets that have a specific 802.1Q VID and PCP. */
172 rule->wc.wildcards &= ~(OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP);
173 rule->flow.dl_vlan = htons(vlan_tci_to_vid(tci));
174 rule->flow.dl_vlan_pcp = vlan_tci_to_pcp(tci);
182 if (!(tci & htons(VLAN_CFI))) {
185 /* Match only packets that have a specific 802.1Q VID. */
186 cls_rule_set_dl_vlan(rule, tci & htons(VLAN_VID_MASK));
187 rule->wc.wildcards |= OFPFW_DL_VLAN_PCP;
188 rule->flow.dl_vlan_pcp = 0;
193 if (!(tci & htons(VLAN_CFI))) {
196 /* Match only packets that have a specific 802.1Q PCP. */
197 cls_rule_set_dl_vlan_pcp(rule, vlan_tci_to_pcp(tci));
198 rule->wc.wildcards |= OFPFW_DL_VLAN;
199 rule->flow.dl_vlan = 0;
204 /* Match anything. */
205 rule->wc.wildcards |= OFPFW_DL_VLAN | OFPFW_DL_VLAN_PCP;
206 rule->flow.dl_vlan = htons(0);
207 rule->flow.dl_vlan_pcp = 0;
216 cls_rule_set_dl_vlan(struct cls_rule *rule, ovs_be16 dl_vlan)
218 if (dl_vlan != htons(OFP_VLAN_NONE)) {
219 dl_vlan &= htons(VLAN_VID_MASK);
222 rule->wc.wildcards &= ~OFPFW_DL_VLAN;
223 rule->flow.dl_vlan = dl_vlan;
227 cls_rule_set_dl_vlan_pcp(struct cls_rule *rule, uint8_t dl_vlan_pcp)
229 rule->wc.wildcards &= ~OFPFW_DL_VLAN_PCP;
230 rule->flow.dl_vlan_pcp = dl_vlan_pcp & 0x07;
234 cls_rule_set_tp_src(struct cls_rule *rule, ovs_be16 tp_src)
236 rule->wc.wildcards &= ~OFPFW_TP_SRC;
237 rule->flow.tp_src = tp_src;
241 cls_rule_set_tp_dst(struct cls_rule *rule, ovs_be16 tp_dst)
243 rule->wc.wildcards &= ~OFPFW_TP_DST;
244 rule->flow.tp_dst = tp_dst;
248 cls_rule_set_nw_proto(struct cls_rule *rule, uint8_t nw_proto)
250 rule->wc.wildcards &= ~OFPFW_NW_PROTO;
251 rule->flow.nw_proto = nw_proto;
255 cls_rule_set_nw_src(struct cls_rule *rule, ovs_be32 nw_src)
257 cls_rule_set_nw_src_masked(rule, nw_src, htonl(UINT32_MAX));
261 cls_rule_set_nw_src_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask)
263 if (flow_wildcards_set_nw_src_mask(&rule->wc, mask)) {
264 rule->flow.nw_src = ip & mask;
272 cls_rule_set_nw_dst(struct cls_rule *rule, ovs_be32 nw_dst)
274 cls_rule_set_nw_dst_masked(rule, nw_dst, htonl(UINT32_MAX));
278 cls_rule_set_nw_dst_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask)
280 if (flow_wildcards_set_nw_dst_mask(&rule->wc, mask)) {
281 rule->flow.nw_dst = ip & mask;
289 cls_rule_set_nw_tos(struct cls_rule *rule, uint8_t nw_tos)
291 rule->wc.wildcards &= ~OFPFW_NW_TOS;
292 rule->flow.nw_tos = nw_tos & IP_DSCP_MASK;
296 cls_rule_set_icmp_type(struct cls_rule *rule, uint8_t icmp_type)
298 rule->wc.wildcards &= ~OFPFW_ICMP_TYPE;
299 rule->flow.icmp_type = htons(icmp_type);
304 cls_rule_set_icmp_code(struct cls_rule *rule, uint8_t icmp_code)
306 rule->wc.wildcards &= ~OFPFW_ICMP_CODE;
307 rule->flow.icmp_code = htons(icmp_code);
310 /* Returns true if 'a' and 'b' have the same priority, wildcard the same
311 * fields, and have the same values for fixed fields, otherwise false. */
313 cls_rule_equal(const struct cls_rule *a, const struct cls_rule *b)
315 return (a->priority == b->priority
316 && flow_wildcards_equal(&a->wc, &b->wc)
317 && flow_equal(&a->flow, &b->flow));
320 /* Converts 'rule' to a string and returns the string. The caller must free
321 * the string (with free()). */
323 cls_rule_to_string(const struct cls_rule *rule)
325 struct ds s = DS_EMPTY_INITIALIZER;
326 ds_put_format(&s, "wildcards=%x priority=%u ",
327 rule->wc.wildcards, rule->priority);
328 flow_format(&s, &rule->flow);
332 /* Prints cls_rule 'rule', for debugging.
334 * (The output could be improved and expanded, but this was good enough to
335 * debug the classifier.) */
337 cls_rule_print(const struct cls_rule *rule)
339 printf("wildcards=%x priority=%u ", rule->wc.wildcards, rule->priority);
340 flow_print(stdout, &rule->flow);
344 /* Initializes 'cls' as a classifier that initially contains no classification
347 classifier_init(struct classifier *cls)
350 hmap_init(&cls->tables);
353 /* Destroys 'cls'. Rules within 'cls', if any, are not freed; this is the
354 * caller's responsibility. */
356 classifier_destroy(struct classifier *cls)
359 struct cls_table *table, *next_table;
361 HMAP_FOR_EACH_SAFE (table, next_table, hmap_node, &cls->tables) {
362 hmap_destroy(&table->rules);
363 hmap_remove(&cls->tables, &table->hmap_node);
366 hmap_destroy(&cls->tables);
370 /* Returns true if 'cls' contains no classification rules, false otherwise. */
372 classifier_is_empty(const struct classifier *cls)
374 return cls->n_rules == 0;
377 /* Returns the number of rules in 'classifier'. */
379 classifier_count(const struct classifier *cls)
384 /* Inserts 'rule' into 'cls'. Until 'rule' is removed from 'cls', the caller
385 * must not modify or free it.
387 * If 'cls' already contains an identical rule (including wildcards, values of
388 * fixed fields, and priority), replaces the old rule by 'rule' and returns the
389 * rule that was replaced. The caller takes ownership of the returned rule and
390 * is thus responsible for freeing it, etc., as necessary.
392 * Returns NULL if 'cls' does not contain a rule with an identical key, after
393 * inserting the new rule. In this case, no rules are displaced by the new
394 * rule, even rules that cannot have any effect because the new rule matches a
395 * superset of their flows and has higher priority. */
397 classifier_insert(struct classifier *cls, struct cls_rule *rule)
399 struct cls_rule *old_rule;
400 struct cls_table *table;
402 table = find_table(cls, &rule->wc);
404 table = insert_table(cls, &rule->wc);
407 old_rule = insert_rule(table, rule);
409 table->n_table_rules++;
415 /* Removes 'rule' from 'cls'. It is the caller's responsibility to free
416 * 'rule', if this is desirable. */
418 classifier_remove(struct classifier *cls, struct cls_rule *rule)
420 struct cls_rule *head;
421 struct cls_table *table;
423 table = find_table(cls, &rule->wc);
424 head = find_equal(table, &rule->flow, rule->hmap_node.hash);
426 list_remove(&rule->list);
427 } else if (list_is_empty(&rule->list)) {
428 hmap_remove(&table->rules, &rule->hmap_node);
430 struct cls_rule *next = CONTAINER_OF(rule->list.next,
431 struct cls_rule, list);
433 list_remove(&rule->list);
434 hmap_replace(&table->rules, &rule->hmap_node, &next->hmap_node);
437 if (--table->n_table_rules == 0) {
438 destroy_table(cls, table);
444 /* Finds and returns the highest-priority rule in 'cls' that matches 'flow'.
445 * Returns a null pointer if no rules in 'cls' match 'flow'. If multiple rules
446 * of equal priority match 'flow', returns one arbitrarily. */
448 classifier_lookup(const struct classifier *cls, const struct flow *flow)
450 struct cls_table *table;
451 struct cls_rule *best;
454 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
455 struct cls_rule *rule = find_match(table, flow);
456 if (rule && (!best || rule->priority > best->priority)) {
463 /* Finds and returns a rule in 'cls' with exactly the same priority and
464 * matching criteria as 'target'. Returns a null pointer if 'cls' doesn't
465 * contain an exact match.
467 * Priority is ignored for exact-match rules (because OpenFlow 1.0 always
468 * treats exact-match rules as highest priority). */
470 classifier_find_rule_exactly(const struct classifier *cls,
471 const struct cls_rule *target)
473 struct cls_rule *head, *rule;
474 struct cls_table *table;
476 table = find_table(cls, &target->wc);
481 head = find_equal(table, &target->flow, flow_hash(&target->flow, 0));
482 if (!target->wc.wildcards) {
485 FOR_EACH_RULE_IN_LIST (rule, head) {
486 if (target->priority >= rule->priority) {
487 return target->priority == rule->priority ? rule : NULL;
493 /* Checks if 'target' would overlap any other rule in 'cls'. Two rules are
494 * considered to overlap if both rules have the same priority and a packet
495 * could match both. */
497 classifier_rule_overlaps(const struct classifier *cls,
498 const struct cls_rule *target)
500 struct cls_table *table;
502 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
503 struct flow_wildcards wc;
504 struct cls_rule *head;
506 flow_wildcards_combine(&wc, &target->wc, &table->wc);
507 HMAP_FOR_EACH (head, hmap_node, &table->rules) {
508 struct cls_rule *rule;
510 FOR_EACH_RULE_IN_LIST (rule, head) {
511 if (rule->priority == target->priority
512 && flow_equal_except(&target->flow, &rule->flow, &wc)) {
525 rule_matches(const struct cls_rule *rule, const struct cls_rule *target)
528 || flow_equal_except(&rule->flow, &target->flow, &target->wc));
531 static struct cls_rule *
532 search_table(const struct cls_table *table, const struct cls_rule *target)
534 if (!target || !flow_wildcards_has_extra(&table->wc, &target->wc)) {
535 struct cls_rule *rule;
537 HMAP_FOR_EACH (rule, hmap_node, &table->rules) {
538 if (rule_matches(rule, target)) {
546 /* Initializes 'cursor' for iterating through 'cls' rules that exactly match
547 * 'target' or are more specific than 'target'. That is, a given 'rule'
548 * matches 'target' if, for every field:
550 * - 'target' and 'rule' specify the same (non-wildcarded) value for the
553 * - 'target' wildcards the field,
557 * - 'target' and 'rule' specify different values for the field, or
559 * - 'target' specifies a value for the field but 'rule' wildcards it.
561 * Equivalently, the truth table for whether a field matches is:
566 * +---------+---------+
567 * t wild | yes | yes |
569 * r +---------+---------+
570 * g exact | no |if values|
572 * t +---------+---------+
574 * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
575 * commands and by OpenFlow 1.0 aggregate and flow stats.
577 * Ignores target->priority.
579 * 'target' may be NULL to iterate over every rule in 'cls'. */
581 cls_cursor_init(struct cls_cursor *cursor, const struct classifier *cls,
582 const struct cls_rule *target)
585 cursor->target = target;
588 /* Returns the first matching cls_rule in 'cursor''s iteration, or a null
589 * pointer if there are no matches. */
591 cls_cursor_first(struct cls_cursor *cursor)
593 struct cls_table *table;
595 for (table = classifier_first_table(cursor->cls); table;
596 table = classifier_next_table(cursor->cls, table)) {
597 struct cls_rule *rule = search_table(table, cursor->target);
599 cursor->table = table;
607 /* Returns the next matching cls_rule in 'cursor''s iteration, or a null
608 * pointer if there are no more matches. */
610 cls_cursor_next(struct cls_cursor *cursor, struct cls_rule *rule)
612 const struct cls_table *table;
613 struct cls_rule *next;
615 next = next_rule_in_list__(rule);
616 if (next->priority < rule->priority) {
620 /* 'next' is the head of the list, that is, the rule that is included in
621 * the table's hmap. (This is important when the classifier contains rules
622 * that differ only in priority.) */
624 HMAP_FOR_EACH_CONTINUE (rule, hmap_node, &cursor->table->rules) {
625 if (rule_matches(rule, cursor->target)) {
630 for (table = classifier_next_table(cursor->cls, cursor->table); table;
631 table = classifier_next_table(cursor->cls, table)) {
632 rule = search_table(table, cursor->target);
634 cursor->table = table;
642 static struct cls_table *
643 find_table(const struct classifier *cls, const struct flow_wildcards *wc)
645 struct cls_table *table;
647 HMAP_FOR_EACH_IN_BUCKET (table, hmap_node, flow_wildcards_hash(wc),
649 if (flow_wildcards_equal(wc, &table->wc)) {
656 static struct cls_table *
657 insert_table(struct classifier *cls, const struct flow_wildcards *wc)
659 struct cls_table *table;
661 table = xzalloc(sizeof *table);
662 hmap_init(&table->rules);
664 hmap_insert(&cls->tables, &table->hmap_node, flow_wildcards_hash(wc));
669 static struct cls_table *
670 classifier_first_table(const struct classifier *cls)
672 return cls_table_from_hmap_node(hmap_first(&cls->tables));
675 static struct cls_table *
676 classifier_next_table(const struct classifier *cls,
677 const struct cls_table *table)
679 return cls_table_from_hmap_node(hmap_next(&cls->tables,
684 destroy_table(struct classifier *cls, struct cls_table *table)
686 hmap_remove(&cls->tables, &table->hmap_node);
687 hmap_destroy(&table->rules);
691 static struct cls_rule *
692 find_match(const struct cls_table *table, const struct flow *flow)
694 struct cls_rule *rule;
698 zero_wildcards(&f, &table->wc);
699 HMAP_FOR_EACH_WITH_HASH (rule, hmap_node, flow_hash(&f, 0),
701 if (flow_equal(&f, &rule->flow)) {
708 static struct cls_rule *
709 find_equal(struct cls_table *table, const struct flow *flow, uint32_t hash)
711 struct cls_rule *head;
713 HMAP_FOR_EACH_WITH_HASH (head, hmap_node, hash, &table->rules) {
714 if (flow_equal(&head->flow, flow)) {
721 static struct cls_rule *
722 insert_rule(struct cls_table *table, struct cls_rule *new)
724 struct cls_rule *head;
726 new->hmap_node.hash = flow_hash(&new->flow, 0);
728 head = find_equal(table, &new->flow, new->hmap_node.hash);
730 hmap_insert(&table->rules, &new->hmap_node, new->hmap_node.hash);
731 list_init(&new->list);
734 /* Scan the list for the insertion point that will keep the list in
735 * order of decreasing priority. */
736 struct cls_rule *rule;
737 FOR_EACH_RULE_IN_LIST (rule, head) {
738 if (new->priority >= rule->priority) {
740 /* 'new' is the new highest-priority flow in the list. */
741 hmap_replace(&table->rules,
742 &rule->hmap_node, &new->hmap_node);
745 if (new->priority == rule->priority) {
746 list_replace(&new->list, &rule->list);
749 list_insert(&rule->list, &new->list);
755 /* Insert 'new' at the end of the list. */
756 list_push_back(&head->list, &new->list);
761 static struct cls_rule *
762 next_rule_in_list__(struct cls_rule *rule)
764 struct cls_rule *next = OBJECT_CONTAINING(rule->list.next, next, list);
768 static struct cls_rule *
769 next_rule_in_list(struct cls_rule *rule)
771 struct cls_rule *next = next_rule_in_list__(rule);
772 return next->priority < rule->priority ? next : NULL;
776 flow_equal_except(const struct flow *a, const struct flow *b,
777 const struct flow_wildcards *wildcards)
779 const uint32_t wc = wildcards->wildcards;
782 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37 + FLOW_N_REGS * 4);
784 for (i = 0; i < FLOW_N_REGS; i++) {
785 if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) {
790 return ((wc & NXFW_TUN_ID || a->tun_id == b->tun_id)
791 && !((a->nw_src ^ b->nw_src) & wildcards->nw_src_mask)
792 && !((a->nw_dst ^ b->nw_dst) & wildcards->nw_dst_mask)
793 && (wc & OFPFW_IN_PORT || a->in_port == b->in_port)
794 && (wc & OFPFW_DL_VLAN || a->dl_vlan == b->dl_vlan)
795 && (wc & OFPFW_DL_TYPE || a->dl_type == b->dl_type)
796 && (wc & OFPFW_TP_SRC || a->tp_src == b->tp_src)
797 && (wc & OFPFW_TP_DST || a->tp_dst == b->tp_dst)
798 && (wc & OFPFW_DL_SRC || eth_addr_equals(a->dl_src, b->dl_src))
799 && (wc & OFPFW_DL_DST
800 || (!((a->dl_dst[0] ^ b->dl_dst[0]) & 0xfe)
801 && a->dl_dst[1] == b->dl_dst[1]
802 && a->dl_dst[2] == b->dl_dst[2]
803 && a->dl_dst[3] == b->dl_dst[3]
804 && a->dl_dst[4] == b->dl_dst[4]
805 && a->dl_dst[5] == b->dl_dst[5]))
806 && (wc & FWW_ETH_MCAST || !((a->dl_dst[0] ^ b->dl_dst[0]) & 0x01))
807 && (wc & OFPFW_NW_PROTO || a->nw_proto == b->nw_proto)
808 && (wc & OFPFW_DL_VLAN_PCP || a->dl_vlan_pcp == b->dl_vlan_pcp)
809 && (wc & OFPFW_NW_TOS || a->nw_tos == b->nw_tos));
813 zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
815 const uint32_t wc = wildcards->wildcards;
818 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37 + 4 * FLOW_N_REGS);
820 for (i = 0; i < FLOW_N_REGS; i++) {
821 flow->regs[i] &= wildcards->reg_masks[i];
823 if (wc & NXFW_TUN_ID) {
826 flow->nw_src &= wildcards->nw_src_mask;
827 flow->nw_dst &= wildcards->nw_dst_mask;
828 if (wc & OFPFW_IN_PORT) {
831 if (wc & OFPFW_DL_VLAN) {
834 if (wc & OFPFW_DL_TYPE) {
837 if (wc & OFPFW_TP_SRC) {
840 if (wc & OFPFW_TP_DST) {
843 if (wc & OFPFW_DL_SRC) {
844 memset(flow->dl_src, 0, sizeof flow->dl_src);
846 if (wc & OFPFW_DL_DST) {
847 flow->dl_dst[0] &= 0x01;
848 memset(&flow->dl_dst[1], 0, 5);
850 if (wc & FWW_ETH_MCAST) {
851 flow->dl_dst[0] &= 0xfe;
853 if (wc & OFPFW_NW_PROTO) {
856 if (wc & OFPFW_DL_VLAN_PCP) {
857 flow->dl_vlan_pcp = 0;
859 if (wc & OFPFW_NW_TOS) {