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 /* Converts 'rule' to a string and returns the string. The caller must free
311 * the string (with free()). */
313 cls_rule_to_string(const struct cls_rule *rule)
315 struct ds s = DS_EMPTY_INITIALIZER;
316 ds_put_format(&s, "wildcards=%x priority=%u ",
317 rule->wc.wildcards, rule->priority);
318 flow_format(&s, &rule->flow);
322 /* Prints cls_rule 'rule', for debugging.
324 * (The output could be improved and expanded, but this was good enough to
325 * debug the classifier.) */
327 cls_rule_print(const struct cls_rule *rule)
329 printf("wildcards=%x priority=%u ", rule->wc.wildcards, rule->priority);
330 flow_print(stdout, &rule->flow);
334 /* Initializes 'cls' as a classifier that initially contains no classification
337 classifier_init(struct classifier *cls)
340 hmap_init(&cls->tables);
343 /* Destroys 'cls'. Rules within 'cls', if any, are not freed; this is the
344 * caller's responsibility. */
346 classifier_destroy(struct classifier *cls)
349 struct cls_table *table, *next_table;
351 HMAP_FOR_EACH_SAFE (table, next_table, hmap_node, &cls->tables) {
352 hmap_destroy(&table->rules);
353 hmap_remove(&cls->tables, &table->hmap_node);
356 hmap_destroy(&cls->tables);
360 /* Returns true if 'cls' contains no classification rules, false otherwise. */
362 classifier_is_empty(const struct classifier *cls)
364 return cls->n_rules == 0;
367 /* Returns the number of rules in 'classifier'. */
369 classifier_count(const struct classifier *cls)
374 /* Inserts 'rule' into 'cls'. Until 'rule' is removed from 'cls', the caller
375 * must not modify or free it.
377 * If 'cls' already contains an identical rule (including wildcards, values of
378 * fixed fields, and priority), replaces the old rule by 'rule' and returns the
379 * rule that was replaced. The caller takes ownership of the returned rule and
380 * is thus responsible for freeing it, etc., as necessary.
382 * Returns NULL if 'cls' does not contain a rule with an identical key, after
383 * inserting the new rule. In this case, no rules are displaced by the new
384 * rule, even rules that cannot have any effect because the new rule matches a
385 * superset of their flows and has higher priority. */
387 classifier_insert(struct classifier *cls, struct cls_rule *rule)
389 struct cls_rule *old_rule;
390 struct cls_table *table;
392 table = find_table(cls, &rule->wc);
394 table = insert_table(cls, &rule->wc);
397 old_rule = insert_rule(table, rule);
399 table->n_table_rules++;
405 /* Removes 'rule' from 'cls'. It is the caller's responsibility to free
406 * 'rule', if this is desirable. */
408 classifier_remove(struct classifier *cls, struct cls_rule *rule)
410 struct cls_rule *head;
411 struct cls_table *table;
413 table = find_table(cls, &rule->wc);
414 head = find_equal(table, &rule->flow, rule->hmap_node.hash);
416 list_remove(&rule->list);
417 } else if (list_is_empty(&rule->list)) {
418 hmap_remove(&table->rules, &rule->hmap_node);
420 struct cls_rule *next = CONTAINER_OF(rule->list.next,
421 struct cls_rule, list);
423 list_remove(&rule->list);
424 hmap_replace(&table->rules, &rule->hmap_node, &next->hmap_node);
427 if (--table->n_table_rules == 0) {
428 destroy_table(cls, table);
434 /* Finds and returns the highest-priority rule in 'cls' that matches 'flow'.
435 * Returns a null pointer if no rules in 'cls' match 'flow'. If multiple rules
436 * of equal priority match 'flow', returns one arbitrarily. */
438 classifier_lookup(const struct classifier *cls, const struct flow *flow)
440 struct cls_table *table;
441 struct cls_rule *best;
444 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
445 struct cls_rule *rule = find_match(table, flow);
446 if (rule && (!best || rule->priority > best->priority)) {
453 /* Finds and returns a rule in 'cls' with exactly the same priority and
454 * matching criteria as 'target'. Returns a null pointer if 'cls' doesn't
455 * contain an exact match.
457 * Priority is ignored for exact-match rules (because OpenFlow 1.0 always
458 * treats exact-match rules as highest priority). */
460 classifier_find_rule_exactly(const struct classifier *cls,
461 const struct cls_rule *target)
463 struct cls_rule *head, *rule;
464 struct cls_table *table;
466 table = find_table(cls, &target->wc);
471 head = find_equal(table, &target->flow, flow_hash(&target->flow, 0));
472 if (!target->wc.wildcards) {
475 FOR_EACH_RULE_IN_LIST (rule, head) {
476 if (target->priority >= rule->priority) {
477 return target->priority == rule->priority ? rule : NULL;
483 /* Checks if 'target' would overlap any other rule in 'cls'. Two rules are
484 * considered to overlap if both rules have the same priority and a packet
485 * could match both. */
487 classifier_rule_overlaps(const struct classifier *cls,
488 const struct cls_rule *target)
490 struct cls_table *table;
492 HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
493 struct flow_wildcards wc;
494 struct cls_rule *head;
496 flow_wildcards_combine(&wc, &target->wc, &table->wc);
497 HMAP_FOR_EACH (head, hmap_node, &table->rules) {
498 struct cls_rule *rule;
500 FOR_EACH_RULE_IN_LIST (rule, head) {
501 if (rule->priority == target->priority
502 && flow_equal_except(&target->flow, &rule->flow, &wc)) {
515 rule_matches(const struct cls_rule *rule, const struct cls_rule *target)
518 || flow_equal_except(&rule->flow, &target->flow, &target->wc));
521 static struct cls_rule *
522 search_table(const struct cls_table *table, const struct cls_rule *target)
524 if (!target || !flow_wildcards_has_extra(&table->wc, &target->wc)) {
525 struct cls_rule *rule;
527 HMAP_FOR_EACH (rule, hmap_node, &table->rules) {
528 if (rule_matches(rule, target)) {
536 /* Initializes 'cursor' for iterating through 'cls' rules that exactly match
537 * 'target' or are more specific than 'target'. That is, a given 'rule'
538 * matches 'target' if, for every field:
540 * - 'target' and 'rule' specify the same (non-wildcarded) value for the
543 * - 'target' wildcards the field,
547 * - 'target' and 'rule' specify different values for the field, or
549 * - 'target' specifies a value for the field but 'rule' wildcards it.
551 * Equivalently, the truth table for whether a field matches is:
556 * +---------+---------+
557 * t wild | yes | yes |
559 * r +---------+---------+
560 * g exact | no |if values|
562 * t +---------+---------+
564 * This is the matching rule used by OpenFlow 1.0 non-strict OFPT_FLOW_MOD
565 * commands and by OpenFlow 1.0 aggregate and flow stats.
567 * Ignores target->priority.
569 * 'target' may be NULL to iterate over every rule in 'cls'. */
571 cls_cursor_init(struct cls_cursor *cursor, const struct classifier *cls,
572 const struct cls_rule *target)
575 cursor->target = target;
578 /* Returns the first matching cls_rule in 'cursor''s iteration, or a null
579 * pointer if there are no matches. */
581 cls_cursor_first(struct cls_cursor *cursor)
583 struct cls_table *table;
585 for (table = classifier_first_table(cursor->cls); table;
586 table = classifier_next_table(cursor->cls, table)) {
587 struct cls_rule *rule = search_table(table, cursor->target);
589 cursor->table = table;
597 /* Returns the next matching cls_rule in 'cursor''s iteration, or a null
598 * pointer if there are no more matches. */
600 cls_cursor_next(struct cls_cursor *cursor, struct cls_rule *rule)
602 const struct cls_table *table;
603 struct cls_rule *next;
605 next = next_rule_in_list__(rule);
606 if (next->priority < rule->priority) {
610 /* 'next' is the head of the list, that is, the rule that is included in
611 * the table's hmap. (This is important when the classifier contains rules
612 * that differ only in priority.) */
614 HMAP_FOR_EACH_CONTINUE (rule, hmap_node, &cursor->table->rules) {
615 if (rule_matches(rule, cursor->target)) {
620 for (table = classifier_next_table(cursor->cls, cursor->table); table;
621 table = classifier_next_table(cursor->cls, table)) {
622 rule = search_table(table, cursor->target);
624 cursor->table = table;
632 static struct cls_table *
633 find_table(const struct classifier *cls, const struct flow_wildcards *wc)
635 struct cls_table *table;
637 HMAP_FOR_EACH_IN_BUCKET (table, hmap_node, flow_wildcards_hash(wc),
639 if (flow_wildcards_equal(wc, &table->wc)) {
646 static struct cls_table *
647 insert_table(struct classifier *cls, const struct flow_wildcards *wc)
649 struct cls_table *table;
651 table = xzalloc(sizeof *table);
652 hmap_init(&table->rules);
654 hmap_insert(&cls->tables, &table->hmap_node, flow_wildcards_hash(wc));
659 static struct cls_table *
660 classifier_first_table(const struct classifier *cls)
662 return cls_table_from_hmap_node(hmap_first(&cls->tables));
665 static struct cls_table *
666 classifier_next_table(const struct classifier *cls,
667 const struct cls_table *table)
669 return cls_table_from_hmap_node(hmap_next(&cls->tables,
674 destroy_table(struct classifier *cls, struct cls_table *table)
676 hmap_remove(&cls->tables, &table->hmap_node);
677 hmap_destroy(&table->rules);
681 static struct cls_rule *
682 find_match(const struct cls_table *table, const struct flow *flow)
684 struct cls_rule *rule;
688 zero_wildcards(&f, &table->wc);
689 HMAP_FOR_EACH_WITH_HASH (rule, hmap_node, flow_hash(&f, 0),
691 if (flow_equal(&f, &rule->flow)) {
698 static struct cls_rule *
699 find_equal(struct cls_table *table, const struct flow *flow, uint32_t hash)
701 struct cls_rule *head;
703 HMAP_FOR_EACH_WITH_HASH (head, hmap_node, hash, &table->rules) {
704 if (flow_equal(&head->flow, flow)) {
711 static struct cls_rule *
712 insert_rule(struct cls_table *table, struct cls_rule *new)
714 struct cls_rule *head;
716 new->hmap_node.hash = flow_hash(&new->flow, 0);
718 head = find_equal(table, &new->flow, new->hmap_node.hash);
720 hmap_insert(&table->rules, &new->hmap_node, new->hmap_node.hash);
721 list_init(&new->list);
724 /* Scan the list for the insertion point that will keep the list in
725 * order of decreasing priority. */
726 struct cls_rule *rule;
727 FOR_EACH_RULE_IN_LIST (rule, head) {
728 if (new->priority >= rule->priority) {
730 /* 'new' is the new highest-priority flow in the list. */
731 hmap_replace(&table->rules,
732 &rule->hmap_node, &new->hmap_node);
735 if (new->priority == rule->priority) {
736 list_replace(&new->list, &rule->list);
739 list_insert(&rule->list, &new->list);
745 /* Insert 'new' at the end of the list. */
746 list_push_back(&head->list, &new->list);
751 static struct cls_rule *
752 next_rule_in_list__(struct cls_rule *rule)
754 struct cls_rule *next = OBJECT_CONTAINING(rule->list.next, next, list);
758 static struct cls_rule *
759 next_rule_in_list(struct cls_rule *rule)
761 struct cls_rule *next = next_rule_in_list__(rule);
762 return next->priority < rule->priority ? next : NULL;
766 flow_equal_except(const struct flow *a, const struct flow *b,
767 const struct flow_wildcards *wildcards)
769 const uint32_t wc = wildcards->wildcards;
772 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37 + FLOW_N_REGS * 4);
774 for (i = 0; i < FLOW_N_REGS; i++) {
775 if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) {
780 return ((wc & NXFW_TUN_ID || a->tun_id == b->tun_id)
781 && !((a->nw_src ^ b->nw_src) & wildcards->nw_src_mask)
782 && !((a->nw_dst ^ b->nw_dst) & wildcards->nw_dst_mask)
783 && (wc & OFPFW_IN_PORT || a->in_port == b->in_port)
784 && (wc & OFPFW_DL_VLAN || a->dl_vlan == b->dl_vlan)
785 && (wc & OFPFW_DL_TYPE || a->dl_type == b->dl_type)
786 && (wc & OFPFW_TP_SRC || a->tp_src == b->tp_src)
787 && (wc & OFPFW_TP_DST || a->tp_dst == b->tp_dst)
788 && (wc & OFPFW_DL_SRC || eth_addr_equals(a->dl_src, b->dl_src))
789 && (wc & OFPFW_DL_DST
790 || (!((a->dl_dst[0] ^ b->dl_dst[0]) & 0xfe)
791 && a->dl_dst[1] == b->dl_dst[1]
792 && a->dl_dst[2] == b->dl_dst[2]
793 && a->dl_dst[3] == b->dl_dst[3]
794 && a->dl_dst[4] == b->dl_dst[4]
795 && a->dl_dst[5] == b->dl_dst[5]))
796 && (wc & FWW_ETH_MCAST || !((a->dl_dst[0] ^ b->dl_dst[0]) & 0x01))
797 && (wc & OFPFW_NW_PROTO || a->nw_proto == b->nw_proto)
798 && (wc & OFPFW_DL_VLAN_PCP || a->dl_vlan_pcp == b->dl_vlan_pcp)
799 && (wc & OFPFW_NW_TOS || a->nw_tos == b->nw_tos));
803 zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
805 const uint32_t wc = wildcards->wildcards;
808 BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 37 + 4 * FLOW_N_REGS);
810 for (i = 0; i < FLOW_N_REGS; i++) {
811 flow->regs[i] &= wildcards->reg_masks[i];
813 if (wc & NXFW_TUN_ID) {
816 flow->nw_src &= wildcards->nw_src_mask;
817 flow->nw_dst &= wildcards->nw_dst_mask;
818 if (wc & OFPFW_IN_PORT) {
821 if (wc & OFPFW_DL_VLAN) {
824 if (wc & OFPFW_DL_TYPE) {
827 if (wc & OFPFW_TP_SRC) {
830 if (wc & OFPFW_TP_DST) {
833 if (wc & OFPFW_DL_SRC) {
834 memset(flow->dl_src, 0, sizeof flow->dl_src);
836 if (wc & OFPFW_DL_DST) {
837 flow->dl_dst[0] &= 0x01;
838 memset(&flow->dl_dst[1], 0, 5);
840 if (wc & FWW_ETH_MCAST) {
841 flow->dl_dst[0] &= 0xfe;
843 if (wc & OFPFW_NW_PROTO) {
846 if (wc & OFPFW_DL_VLAN_PCP) {
847 flow->dl_vlan_pcp = 0;
849 if (wc & OFPFW_NW_TOS) {