2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
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 "openvswitch/match.h"
21 #include "byte-order.h"
23 #include "openvswitch/dynamic-string.h"
24 #include "openvswitch/meta-flow.h"
25 #include "openvswitch/ofp-port.h"
27 #include "tun-metadata.h"
28 #include "openvswitch/nsh.h"
30 /* Converts the flow in 'flow' into a match in 'match', with the given
33 match_init(struct match
*match
,
34 const struct flow
*flow
, const struct flow_wildcards
*wc
)
38 match_zero_wildcarded_fields(match
);
39 memset(&match
->tun_md
, 0, sizeof match
->tun_md
);
42 /* Converts a flow into a match. It sets the wildcard masks based on
43 * the packet contents. It will not set the mask for fields that do not
44 * make sense for the packet type. */
46 match_wc_init(struct match
*match
, const struct flow
*flow
)
50 flow_wildcards_init_for_packet(&match
->wc
, flow
);
51 WC_MASK_FIELD(&match
->wc
, regs
);
52 WC_MASK_FIELD(&match
->wc
, metadata
);
54 memset(&match
->tun_md
, 0, sizeof match
->tun_md
);
57 /* Initializes 'match' as a "catch-all" match that matches every packet. */
59 match_init_catchall(struct match
*match
)
61 memset(&match
->flow
, 0, sizeof match
->flow
);
62 flow_wildcards_init_catchall(&match
->wc
);
63 memset(&match
->tun_md
, 0, sizeof match
->tun_md
);
66 /* For each bit or field wildcarded in 'match', sets the corresponding bit or
67 * field in 'flow' to all-0-bits. It is important to maintain this invariant
68 * in a match that might be inserted into a classifier.
70 * It is never necessary to call this function directly for a match that is
71 * initialized or modified only by match_*() functions. It is useful to
72 * restore the invariant in a match whose 'wc' member is modified by hand.
75 match_zero_wildcarded_fields(struct match
*match
)
77 flow_zero_wildcards(&match
->flow
, &match
->wc
);
81 match_set_dp_hash(struct match
*match
, uint32_t value
)
83 match_set_dp_hash_masked(match
, value
, UINT32_MAX
);
87 match_set_dp_hash_masked(struct match
*match
, uint32_t value
, uint32_t mask
)
89 match
->wc
.masks
.dp_hash
= mask
;
90 match
->flow
.dp_hash
= value
& mask
;
94 match_set_recirc_id(struct match
*match
, uint32_t value
)
96 match
->flow
.recirc_id
= value
;
97 match
->wc
.masks
.recirc_id
= UINT32_MAX
;
101 match_set_conj_id(struct match
*match
, uint32_t value
)
103 match
->flow
.conj_id
= value
;
104 match
->wc
.masks
.conj_id
= UINT32_MAX
;
108 match_set_reg(struct match
*match
, unsigned int reg_idx
, uint32_t value
)
110 match_set_reg_masked(match
, reg_idx
, value
, UINT32_MAX
);
114 match_set_reg_masked(struct match
*match
, unsigned int reg_idx
,
115 uint32_t value
, uint32_t mask
)
117 ovs_assert(reg_idx
< FLOW_N_REGS
);
118 flow_wildcards_set_reg_mask(&match
->wc
, reg_idx
, mask
);
119 match
->flow
.regs
[reg_idx
] = value
& mask
;
123 match_set_xreg(struct match
*match
, unsigned int xreg_idx
, uint64_t value
)
125 match_set_xreg_masked(match
, xreg_idx
, value
, UINT64_MAX
);
129 match_set_xreg_masked(struct match
*match
, unsigned int xreg_idx
,
130 uint64_t value
, uint64_t mask
)
132 ovs_assert(xreg_idx
< FLOW_N_XREGS
);
133 flow_wildcards_set_xreg_mask(&match
->wc
, xreg_idx
, mask
);
134 flow_set_xreg(&match
->flow
, xreg_idx
, value
& mask
);
138 match_set_xxreg(struct match
*match
, unsigned int xxreg_idx
, ovs_u128 value
)
140 match_set_xxreg_masked(match
, xxreg_idx
, value
, OVS_U128_MAX
);
144 match_set_xxreg_masked(struct match
*match
, unsigned int xxreg_idx
,
145 ovs_u128 value
, ovs_u128 mask
)
147 ovs_assert(xxreg_idx
< FLOW_N_XXREGS
);
148 flow_wildcards_set_xxreg_mask(&match
->wc
, xxreg_idx
, mask
);
149 flow_set_xxreg(&match
->flow
, xxreg_idx
, ovs_u128_and(value
, mask
));
153 match_set_actset_output(struct match
*match
, ofp_port_t actset_output
)
155 match
->wc
.masks
.actset_output
= u16_to_ofp(UINT16_MAX
);
156 match
->flow
.actset_output
= actset_output
;
160 match_set_metadata(struct match
*match
, ovs_be64 metadata
)
162 match_set_metadata_masked(match
, metadata
, OVS_BE64_MAX
);
166 match_set_metadata_masked(struct match
*match
,
167 ovs_be64 metadata
, ovs_be64 mask
)
169 match
->wc
.masks
.metadata
= mask
;
170 match
->flow
.metadata
= metadata
& mask
;
174 match_set_tun_id(struct match
*match
, ovs_be64 tun_id
)
176 match_set_tun_id_masked(match
, tun_id
, OVS_BE64_MAX
);
180 match_set_tun_id_masked(struct match
*match
, ovs_be64 tun_id
, ovs_be64 mask
)
182 match
->wc
.masks
.tunnel
.tun_id
= mask
;
183 match
->flow
.tunnel
.tun_id
= tun_id
& mask
;
187 match_set_tun_src(struct match
*match
, ovs_be32 src
)
189 match_set_tun_src_masked(match
, src
, OVS_BE32_MAX
);
193 match_set_tun_src_masked(struct match
*match
, ovs_be32 src
, ovs_be32 mask
)
195 match
->wc
.masks
.tunnel
.ip_src
= mask
;
196 match
->flow
.tunnel
.ip_src
= src
& mask
;
200 match_set_tun_dst(struct match
*match
, ovs_be32 dst
)
202 match_set_tun_dst_masked(match
, dst
, OVS_BE32_MAX
);
206 match_set_tun_dst_masked(struct match
*match
, ovs_be32 dst
, ovs_be32 mask
)
208 match
->wc
.masks
.tunnel
.ip_dst
= mask
;
209 match
->flow
.tunnel
.ip_dst
= dst
& mask
;
213 match_set_tun_ipv6_src(struct match
*match
, const struct in6_addr
*src
)
215 match
->flow
.tunnel
.ipv6_src
= *src
;
216 match
->wc
.masks
.tunnel
.ipv6_src
= in6addr_exact
;
220 match_set_tun_ipv6_src_masked(struct match
*match
, const struct in6_addr
*src
,
221 const struct in6_addr
*mask
)
223 match
->flow
.tunnel
.ipv6_src
= ipv6_addr_bitand(src
, mask
);
224 match
->wc
.masks
.tunnel
.ipv6_src
= *mask
;
228 match_set_tun_ipv6_dst(struct match
*match
, const struct in6_addr
*dst
)
230 match
->flow
.tunnel
.ipv6_dst
= *dst
;
231 match
->wc
.masks
.tunnel
.ipv6_dst
= in6addr_exact
;
235 match_set_tun_ipv6_dst_masked(struct match
*match
, const struct in6_addr
*dst
,
236 const struct in6_addr
*mask
)
238 match
->flow
.tunnel
.ipv6_dst
= ipv6_addr_bitand(dst
, mask
);
239 match
->wc
.masks
.tunnel
.ipv6_dst
= *mask
;
243 match_set_tun_ttl(struct match
*match
, uint8_t ttl
)
245 match_set_tun_ttl_masked(match
, ttl
, UINT8_MAX
);
249 match_set_tun_ttl_masked(struct match
*match
, uint8_t ttl
, uint8_t mask
)
251 match
->wc
.masks
.tunnel
.ip_ttl
= mask
;
252 match
->flow
.tunnel
.ip_ttl
= ttl
& mask
;
256 match_set_tun_tos(struct match
*match
, uint8_t tos
)
258 match_set_tun_tos_masked(match
, tos
, UINT8_MAX
);
262 match_set_tun_tos_masked(struct match
*match
, uint8_t tos
, uint8_t mask
)
264 match
->wc
.masks
.tunnel
.ip_tos
= mask
;
265 match
->flow
.tunnel
.ip_tos
= tos
& mask
;
269 match_set_tun_flags(struct match
*match
, uint16_t flags
)
271 match_set_tun_flags_masked(match
, flags
, UINT16_MAX
);
275 match_set_tun_flags_masked(struct match
*match
, uint16_t flags
, uint16_t mask
)
277 mask
&= FLOW_TNL_PUB_F_MASK
;
279 match
->wc
.masks
.tunnel
.flags
= mask
;
280 match
->flow
.tunnel
.flags
= flags
& mask
;
284 match_set_tun_tp_dst(struct match
*match
, ovs_be16 tp_dst
)
286 match_set_tun_tp_dst_masked(match
, tp_dst
, OVS_BE16_MAX
);
290 match_set_tun_tp_dst_masked(struct match
*match
, ovs_be16 port
, ovs_be16 mask
)
292 match
->wc
.masks
.tunnel
.tp_dst
= mask
;
293 match
->flow
.tunnel
.tp_dst
= port
& mask
;
297 match_set_tun_gbp_id_masked(struct match
*match
, ovs_be16 gbp_id
, ovs_be16 mask
)
299 match
->wc
.masks
.tunnel
.gbp_id
= mask
;
300 match
->flow
.tunnel
.gbp_id
= gbp_id
& mask
;
304 match_set_tun_gbp_id(struct match
*match
, ovs_be16 gbp_id
)
306 match_set_tun_gbp_id_masked(match
, gbp_id
, OVS_BE16_MAX
);
310 match_set_tun_gbp_flags_masked(struct match
*match
, uint8_t flags
, uint8_t mask
)
312 match
->wc
.masks
.tunnel
.gbp_flags
= mask
;
313 match
->flow
.tunnel
.gbp_flags
= flags
& mask
;
317 match_set_tun_gbp_flags(struct match
*match
, uint8_t flags
)
319 match_set_tun_gbp_flags_masked(match
, flags
, UINT8_MAX
);
323 match_set_tun_erspan_ver_masked(struct match
*match
, uint8_t ver
, uint8_t mask
)
325 match
->wc
.masks
.tunnel
.erspan_ver
= ver
;
326 match
->flow
.tunnel
.erspan_ver
= ver
& mask
;
330 match_set_tun_erspan_ver(struct match
*match
, uint8_t ver
)
332 match_set_tun_erspan_ver_masked(match
, ver
, UINT8_MAX
);
336 match_set_tun_erspan_idx_masked(struct match
*match
, uint32_t erspan_idx
,
339 match
->wc
.masks
.tunnel
.erspan_idx
= mask
;
340 match
->flow
.tunnel
.erspan_idx
= erspan_idx
& mask
;
344 match_set_tun_erspan_idx(struct match
*match
, uint32_t erspan_idx
)
346 match_set_tun_erspan_idx_masked(match
, erspan_idx
, UINT32_MAX
);
350 match_set_tun_erspan_dir_masked(struct match
*match
, uint8_t dir
,
353 match
->wc
.masks
.tunnel
.erspan_dir
= dir
;
354 match
->flow
.tunnel
.erspan_dir
= dir
& mask
;
358 match_set_tun_erspan_dir(struct match
*match
, uint8_t dir
)
360 match_set_tun_erspan_dir_masked(match
, dir
, UINT8_MAX
);
364 match_set_tun_erspan_hwid_masked(struct match
*match
, uint8_t hwid
,
367 match
->wc
.masks
.tunnel
.erspan_hwid
= hwid
;
368 match
->flow
.tunnel
.erspan_hwid
= hwid
& mask
;
372 match_set_tun_erspan_hwid(struct match
*match
, uint8_t hwid
)
374 match_set_tun_erspan_hwid_masked(match
, hwid
, UINT8_MAX
);
378 match_set_in_port(struct match
*match
, ofp_port_t ofp_port
)
380 match
->wc
.masks
.in_port
.ofp_port
= u16_to_ofp(UINT16_MAX
);
381 match
->flow
.in_port
.ofp_port
= ofp_port
;
385 match_set_skb_priority(struct match
*match
, uint32_t skb_priority
)
387 match
->wc
.masks
.skb_priority
= UINT32_MAX
;
388 match
->flow
.skb_priority
= skb_priority
;
392 match_set_pkt_mark(struct match
*match
, uint32_t pkt_mark
)
394 match_set_pkt_mark_masked(match
, pkt_mark
, UINT32_MAX
);
398 match_set_pkt_mark_masked(struct match
*match
, uint32_t pkt_mark
, uint32_t mask
)
400 match
->flow
.pkt_mark
= pkt_mark
& mask
;
401 match
->wc
.masks
.pkt_mark
= mask
;
405 match_set_ct_state(struct match
*match
, uint32_t ct_state
)
407 match_set_ct_state_masked(match
, ct_state
, UINT32_MAX
);
411 match_set_ct_state_masked(struct match
*match
, uint32_t ct_state
, uint32_t mask
)
413 match
->flow
.ct_state
= ct_state
& mask
& UINT8_MAX
;
414 match
->wc
.masks
.ct_state
= mask
& UINT8_MAX
;
418 match_set_ct_zone(struct match
*match
, uint16_t ct_zone
)
420 match
->flow
.ct_zone
= ct_zone
;
421 match
->wc
.masks
.ct_zone
= UINT16_MAX
;
425 match_set_ct_mark(struct match
*match
, uint32_t ct_mark
)
427 match_set_ct_mark_masked(match
, ct_mark
, UINT32_MAX
);
431 match_set_ct_mark_masked(struct match
*match
, uint32_t ct_mark
,
434 match
->flow
.ct_mark
= ct_mark
& mask
;
435 match
->wc
.masks
.ct_mark
= mask
;
439 match_set_ct_label(struct match
*match
, ovs_u128 ct_label
)
443 mask
.u64
.lo
= UINT64_MAX
;
444 mask
.u64
.hi
= UINT64_MAX
;
445 match_set_ct_label_masked(match
, ct_label
, mask
);
449 match_set_ct_label_masked(struct match
*match
, ovs_u128 value
, ovs_u128 mask
)
451 match
->flow
.ct_label
.u64
.lo
= value
.u64
.lo
& mask
.u64
.lo
;
452 match
->flow
.ct_label
.u64
.hi
= value
.u64
.hi
& mask
.u64
.hi
;
453 match
->wc
.masks
.ct_label
= mask
;
457 match_set_ct_nw_src(struct match
*match
, ovs_be32 ct_nw_src
)
459 match
->flow
.ct_nw_src
= ct_nw_src
;
460 match
->wc
.masks
.ct_nw_src
= OVS_BE32_MAX
;
464 match_set_ct_nw_src_masked(struct match
*match
, ovs_be32 ct_nw_src
,
467 match
->flow
.ct_nw_src
= ct_nw_src
& mask
;
468 match
->wc
.masks
.ct_nw_src
= mask
;
472 match_set_ct_nw_dst(struct match
*match
, ovs_be32 ct_nw_dst
)
474 match
->flow
.ct_nw_dst
= ct_nw_dst
;
475 match
->wc
.masks
.ct_nw_dst
= OVS_BE32_MAX
;
479 match_set_ct_nw_dst_masked(struct match
*match
, ovs_be32 ct_nw_dst
,
482 match
->flow
.ct_nw_dst
= ct_nw_dst
& mask
;
483 match
->wc
.masks
.ct_nw_dst
= mask
;
487 match_set_ct_nw_proto(struct match
*match
, uint8_t ct_nw_proto
)
489 match
->flow
.ct_nw_proto
= ct_nw_proto
;
490 match
->wc
.masks
.ct_nw_proto
= UINT8_MAX
;
494 match_set_ct_tp_src(struct match
*match
, ovs_be16 ct_tp_src
)
496 match_set_ct_tp_src_masked(match
, ct_tp_src
, OVS_BE16_MAX
);
500 match_set_ct_tp_src_masked(struct match
*match
, ovs_be16 port
, ovs_be16 mask
)
502 match
->flow
.ct_tp_src
= port
& mask
;
503 match
->wc
.masks
.ct_tp_src
= mask
;
507 match_set_ct_tp_dst(struct match
*match
, ovs_be16 ct_tp_dst
)
509 match_set_ct_tp_dst_masked(match
, ct_tp_dst
, OVS_BE16_MAX
);
513 match_set_ct_tp_dst_masked(struct match
*match
, ovs_be16 port
, ovs_be16 mask
)
515 match
->flow
.ct_tp_dst
= port
& mask
;
516 match
->wc
.masks
.ct_tp_dst
= mask
;
520 match_set_ct_ipv6_src(struct match
*match
, const struct in6_addr
*src
)
522 match
->flow
.ct_ipv6_src
= *src
;
523 match
->wc
.masks
.ct_ipv6_src
= in6addr_exact
;
527 match_set_ct_ipv6_src_masked(struct match
*match
, const struct in6_addr
*src
,
528 const struct in6_addr
*mask
)
530 match
->flow
.ct_ipv6_src
= ipv6_addr_bitand(src
, mask
);
531 match
->wc
.masks
.ct_ipv6_src
= *mask
;
535 match_set_ct_ipv6_dst(struct match
*match
, const struct in6_addr
*dst
)
537 match
->flow
.ct_ipv6_dst
= *dst
;
538 match
->wc
.masks
.ct_ipv6_dst
= in6addr_exact
;
542 match_set_ct_ipv6_dst_masked(struct match
*match
, const struct in6_addr
*dst
,
543 const struct in6_addr
*mask
)
545 match
->flow
.ct_ipv6_dst
= ipv6_addr_bitand(dst
, mask
);
546 match
->wc
.masks
.ct_ipv6_dst
= *mask
;
550 match_set_packet_type(struct match
*match
, ovs_be32 packet_type
)
552 match
->flow
.packet_type
= packet_type
;
553 match
->wc
.masks
.packet_type
= OVS_BE32_MAX
;
556 /* If 'match' does not match on any packet type, make it match on Ethernet
557 * packets (the default packet type, as specified by OpenFlow). */
559 match_set_default_packet_type(struct match
*match
)
561 if (!match
->wc
.masks
.packet_type
) {
562 match_set_packet_type(match
, htonl(PT_ETH
));
566 /* Returns true if 'match' matches only Ethernet packets (the default packet
567 * type, as specified by OpenFlow). */
569 match_has_default_packet_type(const struct match
*match
)
571 return (match
->flow
.packet_type
== htonl(PT_ETH
)
572 && match
->wc
.masks
.packet_type
== OVS_BE32_MAX
);
575 /* A match on 'field' is being added to or has been added to 'match'. If
576 * 'field' is a data field, and 'match' does not already match on packet_type,
577 * this function make it match on the Ethernet packet_type.
579 * This function is useful because OpenFlow implicitly applies to Ethernet
580 * packets when there's no explicit packet_type, but matching on a metadata
581 * field doesn't imply anything about the packet_type and falsely inferring
582 * that it does can cause harm. A flow that matches only on metadata fields,
583 * for example, should be able to match more than just Ethernet flows. There
584 * are also important reasons that a catch-all match (one with no field matches
585 * at all) should not imply a packet_type(0,0) match. For example, a "flow
586 * dump" request that matches on no fields should return every flow in the
587 * switch, not just the flows that match on Ethernet. As a second example,
588 * OpenFlow 1.2+ special-cases "table miss" flows, that is catch-all flows with
589 * priority 0, and inferring a match on packet_type(0,0) causes such a flow not
590 * to be a table miss flow. */
592 match_add_ethernet_prereq(struct match
*match
, const struct mf_field
*field
)
594 if (field
->prereqs
!= MFP_NONE
) {
595 match_set_default_packet_type(match
);
600 match_set_dl_type(struct match
*match
, ovs_be16 dl_type
)
602 match
->wc
.masks
.dl_type
= OVS_BE16_MAX
;
603 match
->flow
.dl_type
= dl_type
;
606 /* Modifies 'value_src' so that the Ethernet address must match 'value_dst'
607 * exactly. 'mask_dst' is set to all 1s. */
609 set_eth(const struct eth_addr value_src
,
610 struct eth_addr
*value_dst
,
611 struct eth_addr
*mask_dst
)
613 *value_dst
= value_src
;
614 *mask_dst
= eth_addr_exact
;
617 /* Modifies 'value_src' so that the Ethernet address must match 'value_src'
618 * after each byte is ANDed with the appropriate byte in 'mask_src'.
619 * 'mask_dst' is set to 'mask_src' */
621 set_eth_masked(const struct eth_addr value_src
,
622 const struct eth_addr mask_src
,
623 struct eth_addr
*value_dst
, struct eth_addr
*mask_dst
)
627 for (i
= 0; i
< ARRAY_SIZE(value_dst
->be16
); i
++) {
628 value_dst
->be16
[i
] = value_src
.be16
[i
] & mask_src
.be16
[i
];
630 *mask_dst
= mask_src
;
633 /* Modifies 'rule' so that the source Ethernet address must match 'dl_src'
636 match_set_dl_src(struct match
*match
, const struct eth_addr dl_src
)
638 set_eth(dl_src
, &match
->flow
.dl_src
, &match
->wc
.masks
.dl_src
);
641 /* Modifies 'rule' so that the source Ethernet address must match 'dl_src'
642 * after each byte is ANDed with the appropriate byte in 'mask'. */
644 match_set_dl_src_masked(struct match
*match
,
645 const struct eth_addr dl_src
,
646 const struct eth_addr mask
)
648 set_eth_masked(dl_src
, mask
, &match
->flow
.dl_src
, &match
->wc
.masks
.dl_src
);
651 /* Modifies 'match' so that the Ethernet address must match 'dl_dst'
654 match_set_dl_dst(struct match
*match
, const struct eth_addr dl_dst
)
656 set_eth(dl_dst
, &match
->flow
.dl_dst
, &match
->wc
.masks
.dl_dst
);
659 /* Modifies 'match' so that the Ethernet address must match 'dl_dst' after each
660 * byte is ANDed with the appropriate byte in 'mask'.
662 * This function will assert-fail if 'mask' is invalid. Only 'mask' values
663 * accepted by flow_wildcards_is_dl_dst_mask_valid() are allowed. */
665 match_set_dl_dst_masked(struct match
*match
,
666 const struct eth_addr dl_dst
,
667 const struct eth_addr mask
)
669 set_eth_masked(dl_dst
, mask
, &match
->flow
.dl_dst
, &match
->wc
.masks
.dl_dst
);
673 match_set_dl_tci(struct match
*match
, ovs_be16 tci
)
675 match_set_dl_tci_masked(match
, tci
, htons(0xffff));
679 match_set_dl_tci_masked(struct match
*match
, ovs_be16 tci
, ovs_be16 mask
)
681 match
->flow
.vlans
[0].tci
= tci
& mask
;
682 match
->wc
.masks
.vlans
[0].tci
= mask
;
685 /* Modifies 'match' so that the VLAN VID is wildcarded. If the PCP is already
686 * wildcarded, then 'match' will match a packet regardless of whether it has an
687 * 802.1Q header or not. */
689 match_set_any_vid(struct match
*match
)
691 if (match
->wc
.masks
.vlans
[0].tci
& htons(VLAN_PCP_MASK
)) {
692 match
->wc
.masks
.vlans
[0].tci
&= ~htons(VLAN_VID_MASK
);
693 match
->flow
.vlans
[0].tci
&= ~htons(VLAN_VID_MASK
);
695 match_set_dl_tci_masked(match
, htons(0), htons(0));
699 /* Modifies 'match' depending on 'dl_vlan':
701 * - If 'dl_vlan' is htons(OFP_VLAN_NONE), makes 'match' match only packets
702 * without an 802.1Q header.
704 * - Otherwise, makes 'match' match only packets with an 802.1Q header whose
705 * VID equals the low 12 bits of 'dl_vlan'.
708 match_set_dl_vlan(struct match
*match
, ovs_be16 dl_vlan
, int id
)
710 flow_set_dl_vlan(&match
->flow
, dl_vlan
, id
);
711 if (dl_vlan
== htons(OFP10_VLAN_NONE
)) {
712 match
->wc
.masks
.vlans
[id
].tci
= OVS_BE16_MAX
;
714 match
->wc
.masks
.vlans
[id
].tci
|= htons(VLAN_VID_MASK
| VLAN_CFI
);
718 /* Sets the VLAN VID that 'match' matches to 'vid', which is interpreted as an
719 * OpenFlow 1.2 "vlan_vid" value, that is, the low 13 bits of 'vlan_tci' (VID
722 match_set_vlan_vid(struct match
*match
, ovs_be16 vid
)
724 match_set_vlan_vid_masked(match
, vid
, htons(VLAN_VID_MASK
| VLAN_CFI
));
728 /* Sets the VLAN VID that 'flow' matches to 'vid', which is interpreted as an
729 * OpenFlow 1.2 "vlan_vid" value, that is, the low 13 bits of 'vlan_tci' (VID
730 * plus CFI), with the corresponding 'mask'. */
732 match_set_vlan_vid_masked(struct match
*match
, ovs_be16 vid
, ovs_be16 mask
)
734 ovs_be16 pcp_mask
= htons(VLAN_PCP_MASK
);
735 ovs_be16 vid_mask
= htons(VLAN_VID_MASK
| VLAN_CFI
);
738 flow_set_vlan_vid(&match
->flow
, vid
& mask
);
739 match
->wc
.masks
.vlans
[0].tci
=
740 mask
| (match
->wc
.masks
.vlans
[0].tci
& pcp_mask
);
743 /* Modifies 'match' so that the VLAN PCP is wildcarded. If the VID is already
744 * wildcarded, then 'match' will match a packet regardless of whether it has an
745 * 802.1Q header or not. */
747 match_set_any_pcp(struct match
*match
)
749 if (match
->wc
.masks
.vlans
[0].tci
& htons(VLAN_VID_MASK
)) {
750 match
->wc
.masks
.vlans
[0].tci
&= ~htons(VLAN_PCP_MASK
);
751 match
->flow
.vlans
[0].tci
&= ~htons(VLAN_PCP_MASK
);
753 match_set_dl_tci_masked(match
, htons(0), htons(0));
757 /* Modifies 'match' so that it matches only packets with an 802.1Q header whose
758 * PCP equals the low 3 bits of 'dl_vlan_pcp'. */
760 match_set_dl_vlan_pcp(struct match
*match
, uint8_t dl_vlan_pcp
, int id
)
762 flow_set_vlan_pcp(&match
->flow
, dl_vlan_pcp
, id
);
763 match
->wc
.masks
.vlans
[id
].tci
|= htons(VLAN_CFI
| VLAN_PCP_MASK
);
766 /* Modifies 'match' so that the MPLS label 'idx' matches 'lse' exactly. */
768 match_set_mpls_lse(struct match
*match
, int idx
, ovs_be32 lse
)
770 match
->wc
.masks
.mpls_lse
[idx
] = OVS_BE32_MAX
;
771 match
->flow
.mpls_lse
[idx
] = lse
;
774 /* Modifies 'match' so that the MPLS label is wildcarded. */
776 match_set_any_mpls_label(struct match
*match
, int idx
)
778 match
->wc
.masks
.mpls_lse
[idx
] &= ~htonl(MPLS_LABEL_MASK
);
779 flow_set_mpls_label(&match
->flow
, idx
, htonl(0));
782 /* Modifies 'match' so that it matches only packets with an MPLS header whose
783 * label equals the low 20 bits of 'mpls_label'. */
785 match_set_mpls_label(struct match
*match
, int idx
, ovs_be32 mpls_label
)
787 match
->wc
.masks
.mpls_lse
[idx
] |= htonl(MPLS_LABEL_MASK
);
788 flow_set_mpls_label(&match
->flow
, idx
, mpls_label
);
791 /* Modifies 'match' so that the MPLS TC is wildcarded. */
793 match_set_any_mpls_tc(struct match
*match
, int idx
)
795 match
->wc
.masks
.mpls_lse
[idx
] &= ~htonl(MPLS_TC_MASK
);
796 flow_set_mpls_tc(&match
->flow
, idx
, 0);
799 /* Modifies 'match' so that it matches only packets with an MPLS header whose
800 * Traffic Class equals the low 3 bits of 'mpls_tc'. */
802 match_set_mpls_tc(struct match
*match
, int idx
, uint8_t mpls_tc
)
804 match
->wc
.masks
.mpls_lse
[idx
] |= htonl(MPLS_TC_MASK
);
805 flow_set_mpls_tc(&match
->flow
, idx
, mpls_tc
);
808 /* Modifies 'match' so that the MPLS stack flag is wildcarded. */
810 match_set_any_mpls_bos(struct match
*match
, int idx
)
812 match
->wc
.masks
.mpls_lse
[idx
] &= ~htonl(MPLS_BOS_MASK
);
813 flow_set_mpls_bos(&match
->flow
, idx
, 0);
816 /* Modifies 'match' so that it matches only packets with an MPLS header whose
817 * Stack Flag equals the lower bit of 'mpls_bos' */
819 match_set_mpls_bos(struct match
*match
, int idx
, uint8_t mpls_bos
)
821 match
->wc
.masks
.mpls_lse
[idx
] |= htonl(MPLS_BOS_MASK
);
822 flow_set_mpls_bos(&match
->flow
, idx
, mpls_bos
);
825 /* Modifies 'match' so that the TTL of MPLS label 'idx' is wildcarded. */
827 match_set_any_mpls_ttl(struct match
*match
, int idx
)
829 match
->wc
.masks
.mpls_lse
[idx
] &= ~htonl(MPLS_TTL_MASK
);
830 flow_set_mpls_ttl(&match
->flow
, idx
, 0);
833 /* Modifies 'match' so that it matches only packets in which the TTL of MPLS
834 * label 'idx' equals 'mpls_ttl'. */
836 match_set_mpls_ttl(struct match
*match
, int idx
, uint8_t mpls_ttl
)
838 match
->wc
.masks
.mpls_lse
[idx
] |= htonl(MPLS_TTL_MASK
);
839 flow_set_mpls_ttl(&match
->flow
, idx
, mpls_ttl
);
842 /* Modifies 'match' so that the MPLS LSE is wildcarded. */
844 match_set_any_mpls_lse(struct match
*match
, int idx
)
846 match
->wc
.masks
.mpls_lse
[idx
] = htonl(0);
847 flow_set_mpls_lse(&match
->flow
, idx
, htonl(0));
851 match_set_tp_src(struct match
*match
, ovs_be16 tp_src
)
853 match_set_tp_src_masked(match
, tp_src
, OVS_BE16_MAX
);
857 match_set_tp_src_masked(struct match
*match
, ovs_be16 port
, ovs_be16 mask
)
859 match
->flow
.tp_src
= port
& mask
;
860 match
->wc
.masks
.tp_src
= mask
;
864 match_set_tp_dst(struct match
*match
, ovs_be16 tp_dst
)
866 match_set_tp_dst_masked(match
, tp_dst
, OVS_BE16_MAX
);
870 match_set_tp_dst_masked(struct match
*match
, ovs_be16 port
, ovs_be16 mask
)
872 match
->flow
.tp_dst
= port
& mask
;
873 match
->wc
.masks
.tp_dst
= mask
;
877 match_set_tcp_flags(struct match
*match
, ovs_be16 flags
)
879 match_set_tcp_flags_masked(match
, flags
, OVS_BE16_MAX
);
883 match_set_tcp_flags_masked(struct match
*match
, ovs_be16 flags
, ovs_be16 mask
)
885 match
->flow
.tcp_flags
= flags
& mask
;
886 match
->wc
.masks
.tcp_flags
= mask
;
890 match_set_nw_proto(struct match
*match
, uint8_t nw_proto
)
892 match
->flow
.nw_proto
= nw_proto
;
893 match
->wc
.masks
.nw_proto
= UINT8_MAX
;
897 match_set_nw_src(struct match
*match
, ovs_be32 nw_src
)
899 match
->flow
.nw_src
= nw_src
;
900 match
->wc
.masks
.nw_src
= OVS_BE32_MAX
;
904 match_set_nw_src_masked(struct match
*match
,
905 ovs_be32 nw_src
, ovs_be32 mask
)
907 match
->flow
.nw_src
= nw_src
& mask
;
908 match
->wc
.masks
.nw_src
= mask
;
912 match_set_nw_dst(struct match
*match
, ovs_be32 nw_dst
)
914 match
->flow
.nw_dst
= nw_dst
;
915 match
->wc
.masks
.nw_dst
= OVS_BE32_MAX
;
919 match_set_nw_dst_masked(struct match
*match
, ovs_be32 ip
, ovs_be32 mask
)
921 match
->flow
.nw_dst
= ip
& mask
;
922 match
->wc
.masks
.nw_dst
= mask
;
926 match_set_nw_dscp(struct match
*match
, uint8_t nw_dscp
)
928 match
->wc
.masks
.nw_tos
|= IP_DSCP_MASK
;
929 match
->flow
.nw_tos
&= ~IP_DSCP_MASK
;
930 match
->flow
.nw_tos
|= nw_dscp
& IP_DSCP_MASK
;
934 match_set_nw_ecn(struct match
*match
, uint8_t nw_ecn
)
936 match
->wc
.masks
.nw_tos
|= IP_ECN_MASK
;
937 match
->flow
.nw_tos
&= ~IP_ECN_MASK
;
938 match
->flow
.nw_tos
|= nw_ecn
& IP_ECN_MASK
;
942 match_set_nw_ttl(struct match
*match
, uint8_t nw_ttl
)
944 match
->wc
.masks
.nw_ttl
= UINT8_MAX
;
945 match
->flow
.nw_ttl
= nw_ttl
;
949 match_set_nw_tos_masked(struct match
*match
, uint8_t nw_tos
, uint8_t mask
)
951 match
->flow
.nw_tos
= nw_tos
& mask
;
952 match
->wc
.masks
.nw_tos
= mask
;
956 match_set_nw_ttl_masked(struct match
*match
, uint8_t nw_ttl
, uint8_t mask
)
958 match
->flow
.nw_ttl
= nw_ttl
& mask
;
959 match
->wc
.masks
.nw_ttl
= mask
;
963 match_set_nw_frag(struct match
*match
, uint8_t nw_frag
)
965 match
->wc
.masks
.nw_frag
|= FLOW_NW_FRAG_MASK
;
966 match
->flow
.nw_frag
= nw_frag
;
970 match_set_nw_frag_masked(struct match
*match
,
971 uint8_t nw_frag
, uint8_t mask
)
973 match
->flow
.nw_frag
= nw_frag
& mask
;
974 match
->wc
.masks
.nw_frag
= mask
;
978 match_set_icmp_type(struct match
*match
, uint8_t icmp_type
)
980 match_set_tp_src(match
, htons(icmp_type
));
984 match_set_icmp_code(struct match
*match
, uint8_t icmp_code
)
986 match_set_tp_dst(match
, htons(icmp_code
));
990 match_set_arp_sha(struct match
*match
, const struct eth_addr sha
)
992 match
->flow
.arp_sha
= sha
;
993 match
->wc
.masks
.arp_sha
= eth_addr_exact
;
997 match_set_arp_sha_masked(struct match
*match
,
998 const struct eth_addr arp_sha
,
999 const struct eth_addr mask
)
1001 set_eth_masked(arp_sha
, mask
,
1002 &match
->flow
.arp_sha
, &match
->wc
.masks
.arp_sha
);
1006 match_set_arp_tha(struct match
*match
, const struct eth_addr tha
)
1008 match
->flow
.arp_tha
= tha
;
1009 match
->wc
.masks
.arp_tha
= eth_addr_exact
;
1013 match_set_arp_tha_masked(struct match
*match
,
1014 const struct eth_addr arp_tha
,
1015 const struct eth_addr mask
)
1017 set_eth_masked(arp_tha
, mask
,
1018 &match
->flow
.arp_tha
, &match
->wc
.masks
.arp_tha
);
1022 match_set_ipv6_src(struct match
*match
, const struct in6_addr
*src
)
1024 match
->flow
.ipv6_src
= *src
;
1025 match
->wc
.masks
.ipv6_src
= in6addr_exact
;
1029 match_set_ipv6_src_masked(struct match
*match
, const struct in6_addr
*src
,
1030 const struct in6_addr
*mask
)
1032 match
->flow
.ipv6_src
= ipv6_addr_bitand(src
, mask
);
1033 match
->wc
.masks
.ipv6_src
= *mask
;
1037 match_set_ipv6_dst(struct match
*match
, const struct in6_addr
*dst
)
1039 match
->flow
.ipv6_dst
= *dst
;
1040 match
->wc
.masks
.ipv6_dst
= in6addr_exact
;
1044 match_set_ipv6_dst_masked(struct match
*match
, const struct in6_addr
*dst
,
1045 const struct in6_addr
*mask
)
1047 match
->flow
.ipv6_dst
= ipv6_addr_bitand(dst
, mask
);
1048 match
->wc
.masks
.ipv6_dst
= *mask
;
1052 match_set_ipv6_label(struct match
*match
, ovs_be32 ipv6_label
)
1054 match
->wc
.masks
.ipv6_label
= OVS_BE32_MAX
;
1055 match
->flow
.ipv6_label
= ipv6_label
;
1060 match_set_ipv6_label_masked(struct match
*match
, ovs_be32 ipv6_label
,
1063 match
->flow
.ipv6_label
= ipv6_label
& mask
;
1064 match
->wc
.masks
.ipv6_label
= mask
;
1068 match_set_nd_target(struct match
*match
, const struct in6_addr
*target
)
1070 match
->flow
.nd_target
= *target
;
1071 match
->wc
.masks
.nd_target
= in6addr_exact
;
1075 match_set_nd_target_masked(struct match
*match
,
1076 const struct in6_addr
*target
,
1077 const struct in6_addr
*mask
)
1079 match
->flow
.nd_target
= ipv6_addr_bitand(target
, mask
);
1080 match
->wc
.masks
.nd_target
= *mask
;
1083 /* Returns true if 'a' and 'b' wildcard the same fields and have the same
1084 * values for fixed fields, otherwise false. */
1086 match_equal(const struct match
*a
, const struct match
*b
)
1088 return (flow_wildcards_equal(&a
->wc
, &b
->wc
)
1089 && flow_equal(&a
->flow
, &b
->flow
));
1092 /* Returns a hash value for the flow and wildcards in 'match', starting from
1095 match_hash(const struct match
*match
, uint32_t basis
)
1097 return flow_wildcards_hash(&match
->wc
, flow_hash(&match
->flow
, basis
));
1101 match_has_default_recirc_id(const struct match
*m
)
1103 return m
->flow
.recirc_id
== 0 && (m
->wc
.masks
.recirc_id
== UINT32_MAX
||
1104 m
->wc
.masks
.recirc_id
== 0);
1108 match_has_default_dp_hash(const struct match
*m
)
1110 return ((m
->flow
.dp_hash
| m
->wc
.masks
.dp_hash
) == 0);
1113 /* Return true if the hidden fields of the match are set to the default values.
1114 * The default values equals to those set up by match_init_hidden_fields(). */
1116 match_has_default_hidden_fields(const struct match
*m
)
1118 return match_has_default_recirc_id(m
) && match_has_default_dp_hash(m
);
1122 match_init_hidden_fields(struct match
*m
)
1124 match_set_recirc_id(m
, 0);
1125 match_set_dp_hash_masked(m
, 0, 0);
1129 format_eth_masked(struct ds
*s
, const char *name
,
1130 const struct eth_addr eth
, const struct eth_addr mask
)
1132 if (!eth_addr_is_zero(mask
)) {
1133 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1134 eth_format_masked(eth
, &mask
, s
);
1135 ds_put_char(s
, ',');
1140 format_ip_netmask(struct ds
*s
, const char *name
, ovs_be32 ip
,
1144 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1145 ip_format_masked(ip
, netmask
, s
);
1146 ds_put_char(s
, ',');
1151 format_ipv6_netmask(struct ds
*s
, const char *name
,
1152 const struct in6_addr
*addr
,
1153 const struct in6_addr
*netmask
)
1155 if (!ipv6_mask_is_any(netmask
)) {
1156 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1157 ipv6_format_masked(addr
, netmask
, s
);
1158 ds_put_char(s
, ',');
1163 format_uint8_masked(struct ds
*s
, const char *name
,
1164 uint8_t value
, uint8_t mask
)
1167 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1168 if (mask
== UINT8_MAX
) {
1169 ds_put_format(s
, "%"PRIu8
, value
);
1171 ds_put_format(s
, "0x%02"PRIx8
"/0x%02"PRIx8
, value
, mask
);
1173 ds_put_char(s
, ',');
1178 format_uint16_masked(struct ds
*s
, const char *name
,
1179 uint16_t value
, uint16_t mask
)
1182 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1183 if (mask
== UINT16_MAX
) {
1184 ds_put_format(s
, "%"PRIu16
, value
);
1186 ds_put_format(s
, "0x%"PRIx16
"/0x%"PRIx16
, value
, mask
);
1188 ds_put_char(s
, ',');
1193 format_be16_masked(struct ds
*s
, const char *name
,
1194 ovs_be16 value
, ovs_be16 mask
)
1196 if (mask
!= htons(0)) {
1197 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1198 if (mask
== OVS_BE16_MAX
) {
1199 ds_put_format(s
, "%"PRIu16
, ntohs(value
));
1201 ds_put_format(s
, "0x%"PRIx16
"/0x%"PRIx16
,
1202 ntohs(value
), ntohs(mask
));
1204 ds_put_char(s
, ',');
1209 format_be32_masked(struct ds
*s
, const char *name
,
1210 ovs_be32 value
, ovs_be32 mask
)
1212 if (mask
!= htonl(0)) {
1213 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1214 if (mask
== OVS_BE32_MAX
) {
1215 ds_put_format(s
, "%"PRIu32
, ntohl(value
));
1217 ds_put_format(s
, "0x%08"PRIx32
"/0x%08"PRIx32
,
1218 ntohl(value
), ntohl(mask
));
1220 ds_put_char(s
, ',');
1225 format_be32_masked_hex(struct ds
*s
, const char *name
,
1226 ovs_be32 value
, ovs_be32 mask
)
1228 if (mask
!= htonl(0)) {
1229 ds_put_format(s
, "%s%s=%s", colors
.param
, name
, colors
.end
);
1230 if (mask
== OVS_BE32_MAX
) {
1231 ds_put_format(s
, "0x%"PRIx32
, ntohl(value
));
1233 ds_put_format(s
, "0x%"PRIx32
"/0x%"PRIx32
,
1234 ntohl(value
), ntohl(mask
));
1236 ds_put_char(s
, ',');
1241 format_uint32_masked(struct ds
*s
, const char *name
,
1242 uint32_t value
, uint32_t mask
)
1245 ds_put_format(s
, "%s%s=%s%#"PRIx32
,
1246 colors
.param
, name
, colors
.end
, value
);
1247 if (mask
!= UINT32_MAX
) {
1248 ds_put_format(s
, "/%#"PRIx32
, mask
);
1250 ds_put_char(s
, ',');
1255 format_be64_masked(struct ds
*s
, const char *name
,
1256 ovs_be64 value
, ovs_be64 mask
)
1258 if (mask
!= htonll(0)) {
1259 ds_put_format(s
, "%s%s=%s%#"PRIx64
,
1260 colors
.param
, name
, colors
.end
, ntohll(value
));
1261 if (mask
!= OVS_BE64_MAX
) {
1262 ds_put_format(s
, "/%#"PRIx64
, ntohll(mask
));
1264 ds_put_char(s
, ',');
1269 format_flow_tunnel(struct ds
*s
, const struct match
*match
)
1271 const struct flow_wildcards
*wc
= &match
->wc
;
1272 const struct flow_tnl
*tnl
= &match
->flow
.tunnel
;
1274 format_be64_masked(s
, "tun_id", tnl
->tun_id
, wc
->masks
.tunnel
.tun_id
);
1275 format_ip_netmask(s
, "tun_src", tnl
->ip_src
, wc
->masks
.tunnel
.ip_src
);
1276 format_ip_netmask(s
, "tun_dst", tnl
->ip_dst
, wc
->masks
.tunnel
.ip_dst
);
1277 format_ipv6_netmask(s
, "tun_ipv6_src", &tnl
->ipv6_src
,
1278 &wc
->masks
.tunnel
.ipv6_src
);
1279 format_ipv6_netmask(s
, "tun_ipv6_dst", &tnl
->ipv6_dst
,
1280 &wc
->masks
.tunnel
.ipv6_dst
);
1282 if (wc
->masks
.tunnel
.gbp_id
) {
1283 format_be16_masked(s
, "tun_gbp_id", tnl
->gbp_id
,
1284 wc
->masks
.tunnel
.gbp_id
);
1287 if (wc
->masks
.tunnel
.gbp_flags
) {
1288 ds_put_format(s
, "tun_gbp_flags=%#"PRIx8
",", tnl
->gbp_flags
);
1291 if (wc
->masks
.tunnel
.ip_tos
) {
1292 ds_put_format(s
, "tun_tos=%"PRIx8
",", tnl
->ip_tos
);
1294 if (wc
->masks
.tunnel
.ip_ttl
) {
1295 ds_put_format(s
, "tun_ttl=%"PRIu8
",", tnl
->ip_ttl
);
1297 if (wc
->masks
.tunnel
.erspan_ver
) {
1298 ds_put_format(s
, "tun_erspan_ver=%"PRIu8
",", tnl
->erspan_ver
);
1300 if (wc
->masks
.tunnel
.erspan_idx
&& tnl
->erspan_ver
== 1) {
1301 ds_put_format(s
, "tun_erspan_idx=%#"PRIx32
",", tnl
->erspan_idx
);
1303 if (wc
->masks
.tunnel
.erspan_dir
&& tnl
->erspan_ver
== 2) {
1304 ds_put_format(s
, "tun_erspan_dir=%"PRIu8
",", tnl
->erspan_dir
);
1306 if (wc
->masks
.tunnel
.erspan_hwid
&& tnl
->erspan_ver
== 2) {
1307 ds_put_format(s
, "tun_erspan_hwid=%#"PRIx8
",", tnl
->erspan_hwid
);
1309 if (wc
->masks
.tunnel
.flags
& FLOW_TNL_F_MASK
) {
1310 format_flags_masked(s
, "tun_flags", flow_tun_flag_to_string
,
1311 tnl
->flags
& FLOW_TNL_F_MASK
,
1312 wc
->masks
.tunnel
.flags
& FLOW_TNL_F_MASK
,
1314 ds_put_char(s
, ',');
1316 tun_metadata_match_format(s
, match
);
1320 format_ct_label_masked(struct ds
*s
, const ovs_u128
*key
, const ovs_u128
*mask
)
1322 if (!ovs_u128_is_zero(*mask
)) {
1323 ovs_be128 value
= hton128(*key
);
1324 ds_put_format(s
, "%sct_label=%s", colors
.param
, colors
.end
);
1325 ds_put_hex(s
, &value
, sizeof value
);
1326 if (!is_all_ones(mask
, sizeof(*mask
))) {
1327 value
= hton128(*mask
);
1328 ds_put_char(s
, '/');
1329 ds_put_hex(s
, &value
, sizeof value
);
1331 ds_put_char(s
, ',');
1336 format_nsh_masked(struct ds
*s
, const struct flow
*f
, const struct flow
*m
)
1338 ovs_be32 spi_mask
= nsh_path_hdr_to_spi(m
->nsh
.path_hdr
);
1339 if (spi_mask
== htonl(NSH_SPI_MASK
>> NSH_SPI_SHIFT
)) {
1340 spi_mask
= OVS_BE32_MAX
;
1342 format_uint8_masked(s
, "nsh_flags", f
->nsh
.flags
, m
->nsh
.flags
);
1343 format_uint8_masked(s
, "nsh_ttl", f
->nsh
.ttl
, m
->nsh
.ttl
);
1344 format_uint8_masked(s
, "nsh_mdtype", f
->nsh
.mdtype
, m
->nsh
.mdtype
);
1345 format_uint8_masked(s
, "nsh_np", f
->nsh
.np
, m
->nsh
.np
);
1347 format_be32_masked_hex(s
, "nsh_spi", nsh_path_hdr_to_spi(f
->nsh
.path_hdr
),
1349 format_uint8_masked(s
, "nsh_si", nsh_path_hdr_to_si(f
->nsh
.path_hdr
),
1350 nsh_path_hdr_to_si(m
->nsh
.path_hdr
));
1351 if (m
->nsh
.mdtype
== UINT8_MAX
&& f
->nsh
.mdtype
== NSH_M_TYPE1
) {
1352 format_be32_masked_hex(s
, "nsh_c1", f
->nsh
.context
[0],
1354 format_be32_masked_hex(s
, "nsh_c2", f
->nsh
.context
[1],
1356 format_be32_masked_hex(s
, "nsh_c3", f
->nsh
.context
[2],
1358 format_be32_masked_hex(s
, "nsh_c4", f
->nsh
.context
[3],
1363 /* Appends a string representation of 'match' to 's'. If 'priority' is
1364 * different from OFP_DEFAULT_PRIORITY, includes it in 's'. If 'port_map' is
1365 * nonnull, uses it to translate port numbers to names in output. */
1367 match_format(const struct match
*match
,
1368 const struct ofputil_port_map
*port_map
,
1369 struct ds
*s
, int priority
)
1371 const struct flow_wildcards
*wc
= &match
->wc
;
1372 size_t start_len
= s
->length
;
1373 const struct flow
*f
= &match
->flow
;
1374 bool skip_type
= false;
1375 bool skip_proto
= false;
1376 ovs_be16 dl_type
= f
->dl_type
;
1377 bool is_megaflow
= false;
1380 BUILD_ASSERT_DECL(FLOW_WC_SEQ
== 41);
1382 if (priority
!= OFP_DEFAULT_PRIORITY
) {
1383 ds_put_format(s
, "%spriority=%s%d,",
1384 colors
.special
, colors
.end
, priority
);
1387 format_uint32_masked(s
, "pkt_mark", f
->pkt_mark
, wc
->masks
.pkt_mark
);
1389 if (wc
->masks
.recirc_id
) {
1390 format_uint32_masked(s
, "recirc_id", f
->recirc_id
,
1391 wc
->masks
.recirc_id
);
1395 if (wc
->masks
.dp_hash
) {
1396 format_uint32_masked(s
, "dp_hash", f
->dp_hash
,
1400 if (wc
->masks
.conj_id
) {
1401 ds_put_format(s
, "%sconj_id%s=%"PRIu32
",",
1402 colors
.param
, colors
.end
, f
->conj_id
);
1405 if (wc
->masks
.skb_priority
) {
1406 ds_put_format(s
, "%sskb_priority=%s%#"PRIx32
",",
1407 colors
.param
, colors
.end
, f
->skb_priority
);
1410 if (wc
->masks
.actset_output
) {
1411 ds_put_format(s
, "%sactset_output=%s", colors
.param
, colors
.end
);
1412 ofputil_format_port(f
->actset_output
, port_map
, s
);
1413 ds_put_char(s
, ',');
1416 if (wc
->masks
.ct_state
) {
1417 if (wc
->masks
.ct_state
== UINT8_MAX
) {
1418 ds_put_format(s
, "%sct_state=%s", colors
.param
, colors
.end
);
1420 format_flags(s
, ct_state_to_string
, f
->ct_state
, '|');
1422 ds_put_cstr(s
, "0"); /* No state. */
1425 format_flags_masked(s
, "ct_state", ct_state_to_string
,
1426 f
->ct_state
, wc
->masks
.ct_state
, UINT8_MAX
);
1428 ds_put_char(s
, ',');
1431 if (wc
->masks
.ct_zone
) {
1432 format_uint16_masked(s
, "ct_zone", f
->ct_zone
, wc
->masks
.ct_zone
);
1435 if (wc
->masks
.ct_mark
) {
1436 format_uint32_masked(s
, "ct_mark", f
->ct_mark
, wc
->masks
.ct_mark
);
1439 if (!ovs_u128_is_zero(wc
->masks
.ct_label
)) {
1440 format_ct_label_masked(s
, &f
->ct_label
, &wc
->masks
.ct_label
);
1443 format_ip_netmask(s
, "ct_nw_src", f
->ct_nw_src
,
1444 wc
->masks
.ct_nw_src
);
1445 format_ipv6_netmask(s
, "ct_ipv6_src", &f
->ct_ipv6_src
,
1446 &wc
->masks
.ct_ipv6_src
);
1447 format_ip_netmask(s
, "ct_nw_dst", f
->ct_nw_dst
,
1448 wc
->masks
.ct_nw_dst
);
1449 format_ipv6_netmask(s
, "ct_ipv6_dst", &f
->ct_ipv6_dst
,
1450 &wc
->masks
.ct_ipv6_dst
);
1451 if (wc
->masks
.ct_nw_proto
) {
1452 ds_put_format(s
, "%sct_nw_proto=%s%"PRIu8
",",
1453 colors
.param
, colors
.end
, f
->ct_nw_proto
);
1454 format_be16_masked(s
, "ct_tp_src", f
->ct_tp_src
, wc
->masks
.ct_tp_src
);
1455 format_be16_masked(s
, "ct_tp_dst", f
->ct_tp_dst
, wc
->masks
.ct_tp_dst
);
1458 if (wc
->masks
.packet_type
&&
1459 (!match_has_default_packet_type(match
) || is_megaflow
)) {
1460 format_packet_type_masked(s
, f
->packet_type
, wc
->masks
.packet_type
);
1461 ds_put_char(s
, ',');
1462 if (pt_ns(f
->packet_type
) == OFPHTN_ETHERTYPE
) {
1463 dl_type
= pt_ns_type_be(f
->packet_type
);
1467 if (wc
->masks
.dl_type
) {
1469 if (dl_type
== htons(ETH_TYPE_IP
)) {
1470 if (wc
->masks
.nw_proto
) {
1472 if (f
->nw_proto
== IPPROTO_ICMP
) {
1473 ds_put_format(s
, "%sicmp%s,", colors
.value
, colors
.end
);
1474 } else if (f
->nw_proto
== IPPROTO_IGMP
) {
1475 ds_put_format(s
, "%sigmp%s,", colors
.value
, colors
.end
);
1476 } else if (f
->nw_proto
== IPPROTO_TCP
) {
1477 ds_put_format(s
, "%stcp%s,", colors
.value
, colors
.end
);
1478 } else if (f
->nw_proto
== IPPROTO_UDP
) {
1479 ds_put_format(s
, "%sudp%s,", colors
.value
, colors
.end
);
1480 } else if (f
->nw_proto
== IPPROTO_SCTP
) {
1481 ds_put_format(s
, "%ssctp%s,", colors
.value
, colors
.end
);
1483 ds_put_format(s
, "%sip%s,", colors
.value
, colors
.end
);
1487 ds_put_format(s
, "%sip%s,", colors
.value
, colors
.end
);
1489 } else if (dl_type
== htons(ETH_TYPE_IPV6
)) {
1490 if (wc
->masks
.nw_proto
) {
1492 if (f
->nw_proto
== IPPROTO_ICMPV6
) {
1493 ds_put_format(s
, "%sicmp6%s,", colors
.value
, colors
.end
);
1494 } else if (f
->nw_proto
== IPPROTO_TCP
) {
1495 ds_put_format(s
, "%stcp6%s,", colors
.value
, colors
.end
);
1496 } else if (f
->nw_proto
== IPPROTO_UDP
) {
1497 ds_put_format(s
, "%sudp6%s,", colors
.value
, colors
.end
);
1498 } else if (f
->nw_proto
== IPPROTO_SCTP
) {
1499 ds_put_format(s
, "%ssctp6%s,", colors
.value
, colors
.end
);
1501 ds_put_format(s
, "%sipv6%s,", colors
.value
, colors
.end
);
1505 ds_put_format(s
, "%sipv6%s,", colors
.value
, colors
.end
);
1507 } else if (dl_type
== htons(ETH_TYPE_ARP
)) {
1508 ds_put_format(s
, "%sarp%s,", colors
.value
, colors
.end
);
1509 } else if (dl_type
== htons(ETH_TYPE_RARP
)) {
1510 ds_put_format(s
, "%srarp%s,", colors
.value
, colors
.end
);
1511 } else if (dl_type
== htons(ETH_TYPE_MPLS
)) {
1512 ds_put_format(s
, "%smpls%s,", colors
.value
, colors
.end
);
1513 } else if (dl_type
== htons(ETH_TYPE_MPLS_MCAST
)) {
1514 ds_put_format(s
, "%smplsm%s,", colors
.value
, colors
.end
);
1519 for (i
= 0; i
< FLOW_N_REGS
; i
++) {
1520 #define REGNAME_LEN 20
1521 char regname
[REGNAME_LEN
];
1522 if (snprintf(regname
, REGNAME_LEN
, "reg%d", i
) >= REGNAME_LEN
) {
1523 strcpy(regname
, "reg?");
1525 format_uint32_masked(s
, regname
, f
->regs
[i
], wc
->masks
.regs
[i
]);
1528 format_flow_tunnel(s
, match
);
1530 format_be64_masked(s
, "metadata", f
->metadata
, wc
->masks
.metadata
);
1532 if (wc
->masks
.in_port
.ofp_port
) {
1533 ds_put_format(s
, "%sin_port=%s", colors
.param
, colors
.end
);
1534 ofputil_format_port(f
->in_port
.ofp_port
, port_map
, s
);
1535 ds_put_char(s
, ',');
1537 for (i
= 0; i
< FLOW_MAX_VLAN_HEADERS
; i
++) {
1540 if (!wc
->masks
.vlans
[i
].tci
) {
1544 /* Print VLAN tags as dl_vlan, dl_vlan1, dl_vlan2 ... */
1548 snprintf(str_i
, sizeof(str_i
), "%d", i
);
1550 ovs_be16 vid_mask
= wc
->masks
.vlans
[i
].tci
& htons(VLAN_VID_MASK
);
1551 ovs_be16 pcp_mask
= wc
->masks
.vlans
[i
].tci
& htons(VLAN_PCP_MASK
);
1552 ovs_be16 cfi
= wc
->masks
.vlans
[i
].tci
& htons(VLAN_CFI
);
1554 if (cfi
&& f
->vlans
[i
].tci
& htons(VLAN_CFI
)
1555 && (!vid_mask
|| vid_mask
== htons(VLAN_VID_MASK
))
1556 && (!pcp_mask
|| pcp_mask
== htons(VLAN_PCP_MASK
))
1557 && (vid_mask
|| pcp_mask
)) {
1559 ds_put_format(s
, "%sdl_vlan%s=%s%"PRIu16
",",
1560 colors
.param
, str_i
, colors
.end
,
1561 vlan_tci_to_vid(f
->vlans
[i
].tci
));
1564 ds_put_format(s
, "%sdl_vlan_pcp%s=%s%d,",
1565 colors
.param
, str_i
, colors
.end
,
1566 vlan_tci_to_pcp(f
->vlans
[i
].tci
));
1568 } else if (wc
->masks
.vlans
[i
].tci
== htons(0xffff)) {
1569 ds_put_format(s
, "%svlan_tci%s=%s0x%04"PRIx16
",",
1570 colors
.param
, str_i
, colors
.end
,
1571 ntohs(f
->vlans
[i
].tci
));
1573 ds_put_format(s
, "%svlan_tci%s=%s0x%04"PRIx16
"/0x%04"PRIx16
",",
1574 colors
.param
, str_i
, colors
.end
,
1575 ntohs(f
->vlans
[i
].tci
),
1576 ntohs(wc
->masks
.vlans
[i
].tci
));
1580 format_eth_masked(s
, "dl_src", f
->dl_src
, wc
->masks
.dl_src
);
1581 format_eth_masked(s
, "dl_dst", f
->dl_dst
, wc
->masks
.dl_dst
);
1583 if (!skip_type
&& wc
->masks
.dl_type
) {
1584 ds_put_format(s
, "%sdl_type=%s0x%04"PRIx16
",",
1585 colors
.param
, colors
.end
, ntohs(dl_type
));
1587 if (dl_type
== htons(ETH_TYPE_IPV6
)) {
1588 format_ipv6_netmask(s
, "ipv6_src", &f
->ipv6_src
, &wc
->masks
.ipv6_src
);
1589 format_ipv6_netmask(s
, "ipv6_dst", &f
->ipv6_dst
, &wc
->masks
.ipv6_dst
);
1590 if (wc
->masks
.ipv6_label
) {
1591 if (wc
->masks
.ipv6_label
== OVS_BE32_MAX
) {
1592 ds_put_format(s
, "%sipv6_label=%s0x%05"PRIx32
",",
1593 colors
.param
, colors
.end
,
1594 ntohl(f
->ipv6_label
));
1596 ds_put_format(s
, "%sipv6_label=%s0x%05"PRIx32
"/0x%05"PRIx32
",",
1597 colors
.param
, colors
.end
, ntohl(f
->ipv6_label
),
1598 ntohl(wc
->masks
.ipv6_label
));
1601 } else if (dl_type
== htons(ETH_TYPE_ARP
) ||
1602 dl_type
== htons(ETH_TYPE_RARP
)) {
1603 format_ip_netmask(s
, "arp_spa", f
->nw_src
, wc
->masks
.nw_src
);
1604 format_ip_netmask(s
, "arp_tpa", f
->nw_dst
, wc
->masks
.nw_dst
);
1605 } else if (dl_type
== htons(ETH_TYPE_NSH
)) {
1606 format_nsh_masked(s
, f
, &wc
->masks
);
1608 format_ip_netmask(s
, "nw_src", f
->nw_src
, wc
->masks
.nw_src
);
1609 format_ip_netmask(s
, "nw_dst", f
->nw_dst
, wc
->masks
.nw_dst
);
1611 if (!skip_proto
&& wc
->masks
.nw_proto
) {
1612 if (dl_type
== htons(ETH_TYPE_ARP
) ||
1613 dl_type
== htons(ETH_TYPE_RARP
)) {
1614 ds_put_format(s
, "%sarp_op=%s%"PRIu8
",",
1615 colors
.param
, colors
.end
, f
->nw_proto
);
1617 ds_put_format(s
, "%snw_proto=%s%"PRIu8
",",
1618 colors
.param
, colors
.end
, f
->nw_proto
);
1621 if (dl_type
== htons(ETH_TYPE_ARP
) ||
1622 dl_type
== htons(ETH_TYPE_RARP
)) {
1623 format_eth_masked(s
, "arp_sha", f
->arp_sha
, wc
->masks
.arp_sha
);
1624 format_eth_masked(s
, "arp_tha", f
->arp_tha
, wc
->masks
.arp_tha
);
1626 if (wc
->masks
.nw_tos
& IP_DSCP_MASK
) {
1627 ds_put_format(s
, "%snw_tos=%s%d,",
1628 colors
.param
, colors
.end
, f
->nw_tos
& IP_DSCP_MASK
);
1630 if (wc
->masks
.nw_tos
& IP_ECN_MASK
) {
1631 ds_put_format(s
, "%snw_ecn=%s%d,",
1632 colors
.param
, colors
.end
, f
->nw_tos
& IP_ECN_MASK
);
1634 if (wc
->masks
.nw_ttl
) {
1635 ds_put_format(s
, "%snw_ttl=%s%d,",
1636 colors
.param
, colors
.end
, f
->nw_ttl
);
1638 if (wc
->masks
.mpls_lse
[0] & htonl(MPLS_LABEL_MASK
)) {
1639 ds_put_format(s
, "%smpls_label=%s%"PRIu32
",", colors
.param
,
1640 colors
.end
, mpls_lse_to_label(f
->mpls_lse
[0]));
1642 if (wc
->masks
.mpls_lse
[0] & htonl(MPLS_TC_MASK
)) {
1643 ds_put_format(s
, "%smpls_tc=%s%"PRIu8
",", colors
.param
, colors
.end
,
1644 mpls_lse_to_tc(f
->mpls_lse
[0]));
1646 if (wc
->masks
.mpls_lse
[0] & htonl(MPLS_TTL_MASK
)) {
1647 ds_put_format(s
, "%smpls_ttl=%s%"PRIu8
",", colors
.param
, colors
.end
,
1648 mpls_lse_to_ttl(f
->mpls_lse
[0]));
1650 if (wc
->masks
.mpls_lse
[0] & htonl(MPLS_BOS_MASK
)) {
1651 ds_put_format(s
, "%smpls_bos=%s%"PRIu8
",", colors
.param
, colors
.end
,
1652 mpls_lse_to_bos(f
->mpls_lse
[0]));
1654 format_be32_masked(s
, "mpls_lse1", f
->mpls_lse
[1], wc
->masks
.mpls_lse
[1]);
1655 format_be32_masked(s
, "mpls_lse2", f
->mpls_lse
[2], wc
->masks
.mpls_lse
[2]);
1657 switch (wc
->masks
.nw_frag
) {
1658 case FLOW_NW_FRAG_ANY
| FLOW_NW_FRAG_LATER
:
1659 ds_put_format(s
, "%snw_frag=%s%s,", colors
.param
, colors
.end
,
1660 f
->nw_frag
& FLOW_NW_FRAG_ANY
1661 ? (f
->nw_frag
& FLOW_NW_FRAG_LATER
? "later" : "first")
1662 : (f
->nw_frag
& FLOW_NW_FRAG_LATER
? "<error>" : "no"));
1665 case FLOW_NW_FRAG_ANY
:
1666 ds_put_format(s
, "%snw_frag=%s%s,", colors
.param
, colors
.end
,
1667 f
->nw_frag
& FLOW_NW_FRAG_ANY
? "yes" : "no");
1670 case FLOW_NW_FRAG_LATER
:
1671 ds_put_format(s
, "%snw_frag=%s%s,", colors
.param
, colors
.end
,
1672 f
->nw_frag
& FLOW_NW_FRAG_LATER
? "later" : "not_later");
1675 if (dl_type
== htons(ETH_TYPE_IP
) &&
1676 f
->nw_proto
== IPPROTO_ICMP
) {
1677 format_be16_masked(s
, "icmp_type", f
->tp_src
, wc
->masks
.tp_src
);
1678 format_be16_masked(s
, "icmp_code", f
->tp_dst
, wc
->masks
.tp_dst
);
1679 } else if (dl_type
== htons(ETH_TYPE_IP
) &&
1680 f
->nw_proto
== IPPROTO_IGMP
) {
1681 format_be16_masked(s
, "igmp_type", f
->tp_src
, wc
->masks
.tp_src
);
1682 format_be16_masked(s
, "igmp_code", f
->tp_dst
, wc
->masks
.tp_dst
);
1683 } else if (dl_type
== htons(ETH_TYPE_IPV6
) &&
1684 f
->nw_proto
== IPPROTO_ICMPV6
) {
1685 format_be16_masked(s
, "icmp_type", f
->tp_src
, wc
->masks
.tp_src
);
1686 format_be16_masked(s
, "icmp_code", f
->tp_dst
, wc
->masks
.tp_dst
);
1687 format_ipv6_netmask(s
, "nd_target", &f
->nd_target
,
1688 &wc
->masks
.nd_target
);
1689 format_eth_masked(s
, "nd_sll", f
->arp_sha
, wc
->masks
.arp_sha
);
1690 format_eth_masked(s
, "nd_tll", f
->arp_tha
, wc
->masks
.arp_tha
);
1692 format_be16_masked(s
, "tp_src", f
->tp_src
, wc
->masks
.tp_src
);
1693 format_be16_masked(s
, "tp_dst", f
->tp_dst
, wc
->masks
.tp_dst
);
1695 if (is_ip_any(f
) && f
->nw_proto
== IPPROTO_TCP
&& wc
->masks
.tcp_flags
) {
1696 format_flags_masked(s
, "tcp_flags", packet_tcp_flag_to_string
,
1697 ntohs(f
->tcp_flags
), TCP_FLAGS(wc
->masks
.tcp_flags
),
1698 TCP_FLAGS(OVS_BE16_MAX
));
1701 if (s
->length
> start_len
) {
1706 /* Converts 'match' to a string and returns the string. If 'priority' is
1707 * different from OFP_DEFAULT_PRIORITY, includes it in the string. If
1708 * 'port_map' is nonnull, uses it to translate port numbers to names in
1709 * output. The caller must free the string (with free()). */
1711 match_to_string(const struct match
*match
,
1712 const struct ofputil_port_map
*port_map
, int priority
)
1714 struct ds s
= DS_EMPTY_INITIALIZER
;
1715 match_format(match
, port_map
, &s
, priority
);
1716 return ds_steal_cstr(&s
);
1720 match_print(const struct match
*match
,
1721 const struct ofputil_port_map
*port_map
)
1723 char *s
= match_to_string(match
, port_map
, OFP_DEFAULT_PRIORITY
);
1728 /* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst'
1729 * with minimatch_destroy(). */
1731 minimatch_init(struct minimatch
*dst
, const struct match
*src
)
1733 struct miniflow tmp
;
1735 miniflow_map_init(&tmp
, &src
->wc
.masks
);
1736 /* Allocate two consecutive miniflows. */
1737 miniflow_alloc(dst
->flows
, 2, &tmp
);
1738 miniflow_init(dst
->flow
, &src
->flow
);
1739 minimask_init(dst
->mask
, &src
->wc
);
1741 dst
->tun_md
= tun_metadata_allocation_clone(&src
->tun_md
);
1744 /* Initializes 'match' as a "catch-all" match that matches every packet. */
1746 minimatch_init_catchall(struct minimatch
*match
)
1748 match
->flows
[0] = xcalloc(2, sizeof *match
->flow
);
1749 match
->flows
[1] = match
->flows
[0] + 1;
1750 match
->tun_md
= NULL
;
1753 /* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst'
1754 * with minimatch_destroy(). */
1756 minimatch_clone(struct minimatch
*dst
, const struct minimatch
*src
)
1758 /* Allocate two consecutive miniflows. */
1759 size_t data_size
= miniflow_alloc(dst
->flows
, 2, &src
->mask
->masks
);
1761 memcpy(miniflow_values(dst
->flow
),
1762 miniflow_get_values(src
->flow
), data_size
);
1763 memcpy(miniflow_values(&dst
->mask
->masks
),
1764 miniflow_get_values(&src
->mask
->masks
), data_size
);
1765 dst
->tun_md
= tun_metadata_allocation_clone(src
->tun_md
);
1768 /* Initializes 'dst' with the data in 'src', destroying 'src'. The caller must
1769 * eventually free 'dst' with minimatch_destroy(). */
1771 minimatch_move(struct minimatch
*dst
, struct minimatch
*src
)
1773 dst
->flow
= src
->flow
;
1774 dst
->mask
= src
->mask
;
1775 dst
->tun_md
= src
->tun_md
;
1778 /* Frees any memory owned by 'match'. Does not free the storage in which
1779 * 'match' itself resides; the caller is responsible for that. */
1781 minimatch_destroy(struct minimatch
*match
)
1784 free(match
->tun_md
);
1787 /* Initializes 'dst' as a copy of 'src'. */
1789 minimatch_expand(const struct minimatch
*src
, struct match
*dst
)
1791 miniflow_expand(src
->flow
, &dst
->flow
);
1792 minimask_expand(src
->mask
, &dst
->wc
);
1793 tun_metadata_allocation_copy(&dst
->tun_md
, src
->tun_md
);
1796 /* Returns true if 'a' and 'b' match the same packets, false otherwise. */
1798 minimatch_equal(const struct minimatch
*a
, const struct minimatch
*b
)
1800 return minimask_equal(a
->mask
, b
->mask
)
1801 && miniflow_equal(a
->flow
, b
->flow
);
1804 /* Returns a hash value for the flow and wildcards in 'match', starting from
1807 minimatch_hash(const struct minimatch
*match
, uint32_t basis
)
1809 size_t n_values
= miniflow_n_values(match
->flow
);
1810 size_t flow_size
= sizeof *match
->flow
+ MINIFLOW_VALUES_SIZE(n_values
);
1811 return hash_bytes(match
->flow
, 2 * flow_size
, basis
);
1814 /* Returns true if 'target' satisifies 'match', that is, if each bit for which
1815 * 'match' specifies a particular value has the correct value in 'target'.
1817 * This function is equivalent to miniflow_equal_flow_in_minimask(&match->flow,
1818 * target, &match->mask) but it is faster because of the invariant that
1819 * match->flow.map and match->mask.map are the same. */
1821 minimatch_matches_flow(const struct minimatch
*match
,
1822 const struct flow
*target
)
1824 const uint64_t *flowp
= miniflow_get_values(match
->flow
);
1825 const uint64_t *maskp
= miniflow_get_values(&match
->mask
->masks
);
1828 FLOWMAP_FOR_EACH_INDEX(idx
, match
->flow
->map
) {
1829 if ((*flowp
++ ^ flow_u64_value(target
, idx
)) & *maskp
++) {
1837 /* Appends a string representation of 'match' to 's'. If 'priority' is
1838 * different from OFP_DEFAULT_PRIORITY, includes it in 's'. If 'port_map' is
1839 * nonnull, uses it to translate port numbers to names in output. */
1841 minimatch_format(const struct minimatch
*match
,
1842 const struct tun_table
*tun_table
,
1843 const struct ofputil_port_map
*port_map
,
1844 struct ds
*s
, int priority
)
1846 struct match megamatch
;
1848 minimatch_expand(match
, &megamatch
);
1849 megamatch
.flow
.tunnel
.metadata
.tab
= tun_table
;
1851 match_format(&megamatch
, port_map
, s
, priority
);
1854 /* Converts 'match' to a string and returns the string. If 'priority' is
1855 * different from OFP_DEFAULT_PRIORITY, includes it in the string. The caller
1856 * must free the string (with free()). If 'port_map' is nonnull, uses it to
1857 * translate port numbers to names in output. */
1859 minimatch_to_string(const struct minimatch
*match
,
1860 const struct ofputil_port_map
*port_map
, int priority
)
1862 struct match megamatch
;
1864 minimatch_expand(match
, &megamatch
);
1865 return match_to_string(&megamatch
, port_map
, priority
);
1869 minimatch_has_default_recirc_id(const struct minimatch
*m
)
1871 uint32_t flow_recirc_id
= miniflow_get_recirc_id(m
->flow
);
1872 uint32_t mask_recirc_id
= miniflow_get_recirc_id(&m
->mask
->masks
);
1873 return flow_recirc_id
== 0 && (mask_recirc_id
== UINT32_MAX
||
1874 mask_recirc_id
== 0);
1878 minimatch_has_default_dp_hash(const struct minimatch
*m
)
1880 return (!miniflow_get_dp_hash(m
->flow
)
1881 && !miniflow_get_dp_hash(&m
->mask
->masks
));
1884 /* Return true if the hidden fields of the match are set to the default values.
1885 * The default values equals to those set up by match_init_hidden_fields(). */
1887 minimatch_has_default_hidden_fields(const struct minimatch
*m
)
1889 return (minimatch_has_default_recirc_id(m
)
1890 && minimatch_has_default_dp_hash(m
));