]> git.proxmox.com Git - mirror_ovs.git/blob - lib/match.c
lib: Use MAP_FOR_EACH_INDEX to improve readability.
[mirror_ovs.git] / lib / match.c
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
3 *
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:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <config.h>
18 #include "match.h"
19 #include <stdlib.h>
20 #include "byte-order.h"
21 #include "dynamic-string.h"
22 #include "ofp-util.h"
23 #include "packets.h"
24
25 /* Converts the flow in 'flow' into a match in 'match', with the given
26 * 'wildcards'. */
27 void
28 match_init(struct match *match,
29 const struct flow *flow, const struct flow_wildcards *wc)
30 {
31 match->flow = *flow;
32 match->wc = *wc;
33 match_zero_wildcarded_fields(match);
34 }
35
36 /* Converts a flow into a match. It sets the wildcard masks based on
37 * the packet contents. It will not set the mask for fields that do not
38 * make sense for the packet type. */
39 void
40 match_wc_init(struct match *match, const struct flow *flow)
41 {
42 match->flow = *flow;
43
44 flow_wildcards_init_for_packet(&match->wc, flow);
45 WC_MASK_FIELD(&match->wc, regs);
46 WC_MASK_FIELD(&match->wc, metadata);
47 }
48
49 /* Initializes 'match' as a "catch-all" match that matches every packet. */
50 void
51 match_init_catchall(struct match *match)
52 {
53 memset(&match->flow, 0, sizeof match->flow);
54 flow_wildcards_init_catchall(&match->wc);
55 }
56
57 /* For each bit or field wildcarded in 'match', sets the corresponding bit or
58 * field in 'flow' to all-0-bits. It is important to maintain this invariant
59 * in a match that might be inserted into a classifier.
60 *
61 * It is never necessary to call this function directly for a match that is
62 * initialized or modified only by match_*() functions. It is useful to
63 * restore the invariant in a match whose 'wc' member is modified by hand.
64 */
65 void
66 match_zero_wildcarded_fields(struct match *match)
67 {
68 flow_zero_wildcards(&match->flow, &match->wc);
69 }
70
71 void
72 match_set_dp_hash(struct match *match, uint32_t value)
73 {
74 match_set_dp_hash_masked(match, value, UINT32_MAX);
75 }
76
77 void
78 match_set_dp_hash_masked(struct match *match, uint32_t value, uint32_t mask)
79 {
80 match->wc.masks.dp_hash = mask;
81 match->flow.dp_hash = value & mask;
82 }
83
84 void
85 match_set_recirc_id(struct match *match, uint32_t value)
86 {
87 match->flow.recirc_id = value;
88 match->wc.masks.recirc_id = UINT32_MAX;
89 }
90
91 void
92 match_set_reg(struct match *match, unsigned int reg_idx, uint32_t value)
93 {
94 match_set_reg_masked(match, reg_idx, value, UINT32_MAX);
95 }
96
97 void
98 match_set_reg_masked(struct match *match, unsigned int reg_idx,
99 uint32_t value, uint32_t mask)
100 {
101 ovs_assert(reg_idx < FLOW_N_REGS);
102 flow_wildcards_set_reg_mask(&match->wc, reg_idx, mask);
103 match->flow.regs[reg_idx] = value & mask;
104 }
105
106 void
107 match_set_xreg(struct match *match, unsigned int xreg_idx, uint64_t value)
108 {
109 match_set_xreg_masked(match, xreg_idx, value, UINT64_MAX);
110 }
111
112 void
113 match_set_xreg_masked(struct match *match, unsigned int xreg_idx,
114 uint64_t value, uint64_t mask)
115 {
116 ovs_assert(xreg_idx < FLOW_N_XREGS);
117 flow_wildcards_set_xreg_mask(&match->wc, xreg_idx, mask);
118 flow_set_xreg(&match->flow, xreg_idx, value & mask);
119 }
120
121 void
122 match_set_actset_output(struct match *match, ofp_port_t actset_output)
123 {
124 match->wc.masks.actset_output = u16_to_ofp(UINT16_MAX);
125 match->flow.actset_output = actset_output;
126 }
127
128 void
129 match_set_metadata(struct match *match, ovs_be64 metadata)
130 {
131 match_set_metadata_masked(match, metadata, OVS_BE64_MAX);
132 }
133
134 void
135 match_set_metadata_masked(struct match *match,
136 ovs_be64 metadata, ovs_be64 mask)
137 {
138 match->wc.masks.metadata = mask;
139 match->flow.metadata = metadata & mask;
140 }
141
142 void
143 match_set_tun_id(struct match *match, ovs_be64 tun_id)
144 {
145 match_set_tun_id_masked(match, tun_id, OVS_BE64_MAX);
146 }
147
148 void
149 match_set_tun_id_masked(struct match *match, ovs_be64 tun_id, ovs_be64 mask)
150 {
151 match->wc.masks.tunnel.tun_id = mask;
152 match->flow.tunnel.tun_id = tun_id & mask;
153 }
154
155 void
156 match_set_tun_src(struct match *match, ovs_be32 src)
157 {
158 match_set_tun_src_masked(match, src, OVS_BE32_MAX);
159 }
160
161 void
162 match_set_tun_src_masked(struct match *match, ovs_be32 src, ovs_be32 mask)
163 {
164 match->wc.masks.tunnel.ip_src = mask;
165 match->flow.tunnel.ip_src = src & mask;
166 }
167
168 void
169 match_set_tun_dst(struct match *match, ovs_be32 dst)
170 {
171 match_set_tun_dst_masked(match, dst, OVS_BE32_MAX);
172 }
173
174 void
175 match_set_tun_dst_masked(struct match *match, ovs_be32 dst, ovs_be32 mask)
176 {
177 match->wc.masks.tunnel.ip_dst = mask;
178 match->flow.tunnel.ip_dst = dst & mask;
179 }
180
181 void
182 match_set_tun_ttl(struct match *match, uint8_t ttl)
183 {
184 match_set_tun_ttl_masked(match, ttl, UINT8_MAX);
185 }
186
187 void
188 match_set_tun_ttl_masked(struct match *match, uint8_t ttl, uint8_t mask)
189 {
190 match->wc.masks.tunnel.ip_ttl = mask;
191 match->flow.tunnel.ip_ttl = ttl & mask;
192 }
193
194 void
195 match_set_tun_tos(struct match *match, uint8_t tos)
196 {
197 match_set_tun_tos_masked(match, tos, UINT8_MAX);
198 }
199
200 void
201 match_set_tun_tos_masked(struct match *match, uint8_t tos, uint8_t mask)
202 {
203 match->wc.masks.tunnel.ip_tos = mask;
204 match->flow.tunnel.ip_tos = tos & mask;
205 }
206
207 void
208 match_set_tun_flags(struct match *match, uint16_t flags)
209 {
210 match_set_tun_flags_masked(match, flags, UINT16_MAX);
211 }
212
213 void
214 match_set_tun_flags_masked(struct match *match, uint16_t flags, uint16_t mask)
215 {
216 match->wc.masks.tunnel.flags = mask;
217 match->flow.tunnel.flags = flags & mask;
218 }
219
220 void
221 match_set_in_port(struct match *match, ofp_port_t ofp_port)
222 {
223 match->wc.masks.in_port.ofp_port = u16_to_ofp(UINT16_MAX);
224 match->flow.in_port.ofp_port = ofp_port;
225 }
226
227 void
228 match_set_skb_priority(struct match *match, uint32_t skb_priority)
229 {
230 match->wc.masks.skb_priority = UINT32_MAX;
231 match->flow.skb_priority = skb_priority;
232 }
233
234 void
235 match_set_pkt_mark(struct match *match, uint32_t pkt_mark)
236 {
237 match_set_pkt_mark_masked(match, pkt_mark, UINT32_MAX);
238 }
239
240 void
241 match_set_pkt_mark_masked(struct match *match, uint32_t pkt_mark, uint32_t mask)
242 {
243 match->flow.pkt_mark = pkt_mark & mask;
244 match->wc.masks.pkt_mark = mask;
245 }
246
247 void
248 match_set_dl_type(struct match *match, ovs_be16 dl_type)
249 {
250 match->wc.masks.dl_type = OVS_BE16_MAX;
251 match->flow.dl_type = dl_type;
252 }
253
254 /* Modifies 'value_src' so that the Ethernet address must match 'value_dst'
255 * exactly. 'mask_dst' is set to all 1s. */
256 static void
257 set_eth(const uint8_t value_src[ETH_ADDR_LEN],
258 uint8_t value_dst[ETH_ADDR_LEN],
259 uint8_t mask_dst[ETH_ADDR_LEN])
260 {
261 memcpy(value_dst, value_src, ETH_ADDR_LEN);
262 memset(mask_dst, 0xff, ETH_ADDR_LEN);
263 }
264
265 /* Modifies 'value_src' so that the Ethernet address must match 'value_src'
266 * after each byte is ANDed with the appropriate byte in 'mask_src'.
267 * 'mask_dst' is set to 'mask_src' */
268 static void
269 set_eth_masked(const uint8_t value_src[ETH_ADDR_LEN],
270 const uint8_t mask_src[ETH_ADDR_LEN],
271 uint8_t value_dst[ETH_ADDR_LEN],
272 uint8_t mask_dst[ETH_ADDR_LEN])
273 {
274 size_t i;
275
276 for (i = 0; i < ETH_ADDR_LEN; i++) {
277 value_dst[i] = value_src[i] & mask_src[i];
278 mask_dst[i] = mask_src[i];
279 }
280 }
281
282 /* Modifies 'rule' so that the source Ethernet address must match 'dl_src'
283 * exactly. */
284 void
285 match_set_dl_src(struct match *match, const uint8_t dl_src[ETH_ADDR_LEN])
286 {
287 set_eth(dl_src, match->flow.dl_src, match->wc.masks.dl_src);
288 }
289
290 /* Modifies 'rule' so that the source Ethernet address must match 'dl_src'
291 * after each byte is ANDed with the appropriate byte in 'mask'. */
292 void
293 match_set_dl_src_masked(struct match *match,
294 const uint8_t dl_src[ETH_ADDR_LEN],
295 const uint8_t mask[ETH_ADDR_LEN])
296 {
297 set_eth_masked(dl_src, mask, match->flow.dl_src, match->wc.masks.dl_src);
298 }
299
300 /* Modifies 'match' so that the Ethernet address must match 'dl_dst'
301 * exactly. */
302 void
303 match_set_dl_dst(struct match *match, const uint8_t dl_dst[ETH_ADDR_LEN])
304 {
305 set_eth(dl_dst, match->flow.dl_dst, match->wc.masks.dl_dst);
306 }
307
308 /* Modifies 'match' so that the Ethernet address must match 'dl_dst' after each
309 * byte is ANDed with the appropriate byte in 'mask'.
310 *
311 * This function will assert-fail if 'mask' is invalid. Only 'mask' values
312 * accepted by flow_wildcards_is_dl_dst_mask_valid() are allowed. */
313 void
314 match_set_dl_dst_masked(struct match *match,
315 const uint8_t dl_dst[ETH_ADDR_LEN],
316 const uint8_t mask[ETH_ADDR_LEN])
317 {
318 set_eth_masked(dl_dst, mask, match->flow.dl_dst, match->wc.masks.dl_dst);
319 }
320
321 void
322 match_set_dl_tci(struct match *match, ovs_be16 tci)
323 {
324 match_set_dl_tci_masked(match, tci, htons(0xffff));
325 }
326
327 void
328 match_set_dl_tci_masked(struct match *match, ovs_be16 tci, ovs_be16 mask)
329 {
330 match->flow.vlan_tci = tci & mask;
331 match->wc.masks.vlan_tci = mask;
332 }
333
334 /* Modifies 'match' so that the VLAN VID is wildcarded. If the PCP is already
335 * wildcarded, then 'match' will match a packet regardless of whether it has an
336 * 802.1Q header or not. */
337 void
338 match_set_any_vid(struct match *match)
339 {
340 if (match->wc.masks.vlan_tci & htons(VLAN_PCP_MASK)) {
341 match->wc.masks.vlan_tci &= ~htons(VLAN_VID_MASK);
342 match->flow.vlan_tci &= ~htons(VLAN_VID_MASK);
343 } else {
344 match_set_dl_tci_masked(match, htons(0), htons(0));
345 }
346 }
347
348 /* Modifies 'match' depending on 'dl_vlan':
349 *
350 * - If 'dl_vlan' is htons(OFP_VLAN_NONE), makes 'match' match only packets
351 * without an 802.1Q header.
352 *
353 * - Otherwise, makes 'match' match only packets with an 802.1Q header whose
354 * VID equals the low 12 bits of 'dl_vlan'.
355 */
356 void
357 match_set_dl_vlan(struct match *match, ovs_be16 dl_vlan)
358 {
359 flow_set_dl_vlan(&match->flow, dl_vlan);
360 if (dl_vlan == htons(OFP10_VLAN_NONE)) {
361 match->wc.masks.vlan_tci = OVS_BE16_MAX;
362 } else {
363 match->wc.masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
364 }
365 }
366
367 /* Sets the VLAN VID that 'match' matches to 'vid', which is interpreted as an
368 * OpenFlow 1.2 "vlan_vid" value, that is, the low 13 bits of 'vlan_tci' (VID
369 * plus CFI). */
370 void
371 match_set_vlan_vid(struct match *match, ovs_be16 vid)
372 {
373 match_set_vlan_vid_masked(match, vid, htons(VLAN_VID_MASK | VLAN_CFI));
374 }
375
376
377 /* Sets the VLAN VID that 'flow' matches to 'vid', which is interpreted as an
378 * OpenFlow 1.2 "vlan_vid" value, that is, the low 13 bits of 'vlan_tci' (VID
379 * plus CFI), with the corresponding 'mask'. */
380 void
381 match_set_vlan_vid_masked(struct match *match, ovs_be16 vid, ovs_be16 mask)
382 {
383 ovs_be16 pcp_mask = htons(VLAN_PCP_MASK);
384 ovs_be16 vid_mask = htons(VLAN_VID_MASK | VLAN_CFI);
385
386 mask &= vid_mask;
387 flow_set_vlan_vid(&match->flow, vid & mask);
388 match->wc.masks.vlan_tci = mask | (match->wc.masks.vlan_tci & pcp_mask);
389 }
390
391 /* Modifies 'match' so that the VLAN PCP is wildcarded. If the VID is already
392 * wildcarded, then 'match' will match a packet regardless of whether it has an
393 * 802.1Q header or not. */
394 void
395 match_set_any_pcp(struct match *match)
396 {
397 if (match->wc.masks.vlan_tci & htons(VLAN_VID_MASK)) {
398 match->wc.masks.vlan_tci &= ~htons(VLAN_PCP_MASK);
399 match->flow.vlan_tci &= ~htons(VLAN_PCP_MASK);
400 } else {
401 match_set_dl_tci_masked(match, htons(0), htons(0));
402 }
403 }
404
405 /* Modifies 'match' so that it matches only packets with an 802.1Q header whose
406 * PCP equals the low 3 bits of 'dl_vlan_pcp'. */
407 void
408 match_set_dl_vlan_pcp(struct match *match, uint8_t dl_vlan_pcp)
409 {
410 flow_set_vlan_pcp(&match->flow, dl_vlan_pcp);
411 match->wc.masks.vlan_tci |= htons(VLAN_CFI | VLAN_PCP_MASK);
412 }
413
414 /* Modifies 'match' so that the MPLS label 'idx' matches 'lse' exactly. */
415 void
416 match_set_mpls_lse(struct match *match, int idx, ovs_be32 lse)
417 {
418 match->wc.masks.mpls_lse[idx] = OVS_BE32_MAX;
419 match->flow.mpls_lse[idx] = lse;
420 }
421
422 /* Modifies 'match' so that the MPLS label is wildcarded. */
423 void
424 match_set_any_mpls_label(struct match *match, int idx)
425 {
426 match->wc.masks.mpls_lse[idx] &= ~htonl(MPLS_LABEL_MASK);
427 flow_set_mpls_label(&match->flow, idx, htonl(0));
428 }
429
430 /* Modifies 'match' so that it matches only packets with an MPLS header whose
431 * label equals the low 20 bits of 'mpls_label'. */
432 void
433 match_set_mpls_label(struct match *match, int idx, ovs_be32 mpls_label)
434 {
435 match->wc.masks.mpls_lse[idx] |= htonl(MPLS_LABEL_MASK);
436 flow_set_mpls_label(&match->flow, idx, mpls_label);
437 }
438
439 /* Modifies 'match' so that the MPLS TC is wildcarded. */
440 void
441 match_set_any_mpls_tc(struct match *match, int idx)
442 {
443 match->wc.masks.mpls_lse[idx] &= ~htonl(MPLS_TC_MASK);
444 flow_set_mpls_tc(&match->flow, idx, 0);
445 }
446
447 /* Modifies 'match' so that it matches only packets with an MPLS header whose
448 * Traffic Class equals the low 3 bits of 'mpls_tc'. */
449 void
450 match_set_mpls_tc(struct match *match, int idx, uint8_t mpls_tc)
451 {
452 match->wc.masks.mpls_lse[idx] |= htonl(MPLS_TC_MASK);
453 flow_set_mpls_tc(&match->flow, idx, mpls_tc);
454 }
455
456 /* Modifies 'match' so that the MPLS stack flag is wildcarded. */
457 void
458 match_set_any_mpls_bos(struct match *match, int idx)
459 {
460 match->wc.masks.mpls_lse[idx] &= ~htonl(MPLS_BOS_MASK);
461 flow_set_mpls_bos(&match->flow, idx, 0);
462 }
463
464 /* Modifies 'match' so that it matches only packets with an MPLS header whose
465 * Stack Flag equals the lower bit of 'mpls_bos' */
466 void
467 match_set_mpls_bos(struct match *match, int idx, uint8_t mpls_bos)
468 {
469 match->wc.masks.mpls_lse[idx] |= htonl(MPLS_BOS_MASK);
470 flow_set_mpls_bos(&match->flow, idx, mpls_bos);
471 }
472
473 /* Modifies 'match' so that the MPLS LSE is wildcarded. */
474 void
475 match_set_any_mpls_lse(struct match *match, int idx)
476 {
477 match->wc.masks.mpls_lse[idx] = htonl(0);
478 flow_set_mpls_lse(&match->flow, idx, htonl(0));
479 }
480
481 void
482 match_set_tp_src(struct match *match, ovs_be16 tp_src)
483 {
484 match_set_tp_src_masked(match, tp_src, OVS_BE16_MAX);
485 }
486
487 void
488 match_set_tp_src_masked(struct match *match, ovs_be16 port, ovs_be16 mask)
489 {
490 match->flow.tp_src = port & mask;
491 match->wc.masks.tp_src = mask;
492 }
493
494 void
495 match_set_tp_dst(struct match *match, ovs_be16 tp_dst)
496 {
497 match_set_tp_dst_masked(match, tp_dst, OVS_BE16_MAX);
498 }
499
500 void
501 match_set_tp_dst_masked(struct match *match, ovs_be16 port, ovs_be16 mask)
502 {
503 match->flow.tp_dst = port & mask;
504 match->wc.masks.tp_dst = mask;
505 }
506
507 void
508 match_set_tcp_flags(struct match *match, ovs_be16 flags)
509 {
510 match_set_tcp_flags_masked(match, flags, OVS_BE16_MAX);
511 }
512
513 void
514 match_set_tcp_flags_masked(struct match *match, ovs_be16 flags, ovs_be16 mask)
515 {
516 match->flow.tcp_flags = flags & mask;
517 match->wc.masks.tcp_flags = mask;
518 }
519
520 void
521 match_set_nw_proto(struct match *match, uint8_t nw_proto)
522 {
523 match->flow.nw_proto = nw_proto;
524 match->wc.masks.nw_proto = UINT8_MAX;
525 }
526
527 void
528 match_set_nw_src(struct match *match, ovs_be32 nw_src)
529 {
530 match->flow.nw_src = nw_src;
531 match->wc.masks.nw_src = OVS_BE32_MAX;
532 }
533
534 void
535 match_set_nw_src_masked(struct match *match,
536 ovs_be32 nw_src, ovs_be32 mask)
537 {
538 match->flow.nw_src = nw_src & mask;
539 match->wc.masks.nw_src = mask;
540 }
541
542 void
543 match_set_nw_dst(struct match *match, ovs_be32 nw_dst)
544 {
545 match->flow.nw_dst = nw_dst;
546 match->wc.masks.nw_dst = OVS_BE32_MAX;
547 }
548
549 void
550 match_set_nw_dst_masked(struct match *match, ovs_be32 ip, ovs_be32 mask)
551 {
552 match->flow.nw_dst = ip & mask;
553 match->wc.masks.nw_dst = mask;
554 }
555
556 void
557 match_set_nw_dscp(struct match *match, uint8_t nw_dscp)
558 {
559 match->wc.masks.nw_tos |= IP_DSCP_MASK;
560 match->flow.nw_tos &= ~IP_DSCP_MASK;
561 match->flow.nw_tos |= nw_dscp & IP_DSCP_MASK;
562 }
563
564 void
565 match_set_nw_ecn(struct match *match, uint8_t nw_ecn)
566 {
567 match->wc.masks.nw_tos |= IP_ECN_MASK;
568 match->flow.nw_tos &= ~IP_ECN_MASK;
569 match->flow.nw_tos |= nw_ecn & IP_ECN_MASK;
570 }
571
572 void
573 match_set_nw_ttl(struct match *match, uint8_t nw_ttl)
574 {
575 match->wc.masks.nw_ttl = UINT8_MAX;
576 match->flow.nw_ttl = nw_ttl;
577 }
578
579 void
580 match_set_nw_frag(struct match *match, uint8_t nw_frag)
581 {
582 match->wc.masks.nw_frag |= FLOW_NW_FRAG_MASK;
583 match->flow.nw_frag = nw_frag;
584 }
585
586 void
587 match_set_nw_frag_masked(struct match *match,
588 uint8_t nw_frag, uint8_t mask)
589 {
590 match->flow.nw_frag = nw_frag & mask;
591 match->wc.masks.nw_frag = mask;
592 }
593
594 void
595 match_set_icmp_type(struct match *match, uint8_t icmp_type)
596 {
597 match_set_tp_src(match, htons(icmp_type));
598 }
599
600 void
601 match_set_icmp_code(struct match *match, uint8_t icmp_code)
602 {
603 match_set_tp_dst(match, htons(icmp_code));
604 }
605
606 void
607 match_set_arp_sha(struct match *match, const uint8_t sha[ETH_ADDR_LEN])
608 {
609 memcpy(match->flow.arp_sha, sha, ETH_ADDR_LEN);
610 memset(match->wc.masks.arp_sha, UINT8_MAX, ETH_ADDR_LEN);
611 }
612
613 void
614 match_set_arp_sha_masked(struct match *match,
615 const uint8_t arp_sha[ETH_ADDR_LEN],
616 const uint8_t mask[ETH_ADDR_LEN])
617 {
618 set_eth_masked(arp_sha, mask,
619 match->flow.arp_sha, match->wc.masks.arp_sha);
620 }
621
622 void
623 match_set_arp_tha(struct match *match, const uint8_t tha[ETH_ADDR_LEN])
624 {
625 memcpy(match->flow.arp_tha, tha, ETH_ADDR_LEN);
626 memset(match->wc.masks.arp_tha, UINT8_MAX, ETH_ADDR_LEN);
627 }
628
629 void
630 match_set_arp_tha_masked(struct match *match,
631 const uint8_t arp_tha[ETH_ADDR_LEN],
632 const uint8_t mask[ETH_ADDR_LEN])
633 {
634 set_eth_masked(arp_tha, mask,
635 match->flow.arp_tha, match->wc.masks.arp_tha);
636 }
637
638 void
639 match_set_ipv6_src(struct match *match, const struct in6_addr *src)
640 {
641 match->flow.ipv6_src = *src;
642 match->wc.masks.ipv6_src = in6addr_exact;
643 }
644
645 void
646 match_set_ipv6_src_masked(struct match *match, const struct in6_addr *src,
647 const struct in6_addr *mask)
648 {
649 match->flow.ipv6_src = ipv6_addr_bitand(src, mask);
650 match->wc.masks.ipv6_src = *mask;
651 }
652
653 void
654 match_set_ipv6_dst(struct match *match, const struct in6_addr *dst)
655 {
656 match->flow.ipv6_dst = *dst;
657 match->wc.masks.ipv6_dst = in6addr_exact;
658 }
659
660 void
661 match_set_ipv6_dst_masked(struct match *match, const struct in6_addr *dst,
662 const struct in6_addr *mask)
663 {
664 match->flow.ipv6_dst = ipv6_addr_bitand(dst, mask);
665 match->wc.masks.ipv6_dst = *mask;
666 }
667
668 void
669 match_set_ipv6_label(struct match *match, ovs_be32 ipv6_label)
670 {
671 match->wc.masks.ipv6_label = OVS_BE32_MAX;
672 match->flow.ipv6_label = ipv6_label;
673 }
674
675
676 void
677 match_set_ipv6_label_masked(struct match *match, ovs_be32 ipv6_label,
678 ovs_be32 mask)
679 {
680 match->flow.ipv6_label = ipv6_label & mask;
681 match->wc.masks.ipv6_label = mask;
682 }
683
684 void
685 match_set_nd_target(struct match *match, const struct in6_addr *target)
686 {
687 match->flow.nd_target = *target;
688 match->wc.masks.nd_target = in6addr_exact;
689 }
690
691 void
692 match_set_nd_target_masked(struct match *match,
693 const struct in6_addr *target,
694 const struct in6_addr *mask)
695 {
696 match->flow.nd_target = ipv6_addr_bitand(target, mask);
697 match->wc.masks.nd_target = *mask;
698 }
699
700 /* Returns true if 'a' and 'b' wildcard the same fields and have the same
701 * values for fixed fields, otherwise false. */
702 bool
703 match_equal(const struct match *a, const struct match *b)
704 {
705 return (flow_wildcards_equal(&a->wc, &b->wc)
706 && flow_equal(&a->flow, &b->flow));
707 }
708
709 /* Returns a hash value for the flow and wildcards in 'match', starting from
710 * 'basis'. */
711 uint32_t
712 match_hash(const struct match *match, uint32_t basis)
713 {
714 return flow_wildcards_hash(&match->wc, flow_hash(&match->flow, basis));
715 }
716
717 static bool
718 match_has_default_recirc_id(const struct match *m)
719 {
720 return m->flow.recirc_id == 0 && (m->wc.masks.recirc_id == UINT32_MAX ||
721 m->wc.masks.recirc_id == 0);
722 }
723
724 static bool
725 match_has_default_dp_hash(const struct match *m)
726 {
727 return ((m->flow.dp_hash | m->wc.masks.dp_hash) == 0);
728 }
729
730 /* Return true if the hidden fields of the match are set to the default values.
731 * The default values equals to those set up by match_init_hidden_fields(). */
732 bool
733 match_has_default_hidden_fields(const struct match *m)
734 {
735 return match_has_default_recirc_id(m) && match_has_default_dp_hash(m);
736 }
737
738 void
739 match_init_hidden_fields(struct match *m)
740 {
741 match_set_recirc_id(m, 0);
742 match_set_dp_hash_masked(m, 0, 0);
743 }
744
745 static void
746 format_eth_masked(struct ds *s, const char *name,
747 const uint8_t eth[ETH_ADDR_LEN],
748 const uint8_t mask[ETH_ADDR_LEN])
749 {
750 if (!eth_addr_is_zero(mask)) {
751 ds_put_format(s, "%s=", name);
752 eth_format_masked(eth, mask, s);
753 ds_put_char(s, ',');
754 }
755 }
756
757 static void
758 format_ip_netmask(struct ds *s, const char *name, ovs_be32 ip,
759 ovs_be32 netmask)
760 {
761 if (netmask) {
762 ds_put_format(s, "%s=", name);
763 ip_format_masked(ip, netmask, s);
764 ds_put_char(s, ',');
765 }
766 }
767
768 static void
769 format_ipv6_netmask(struct ds *s, const char *name,
770 const struct in6_addr *addr,
771 const struct in6_addr *netmask)
772 {
773 if (!ipv6_mask_is_any(netmask)) {
774 ds_put_format(s, "%s=", name);
775 print_ipv6_masked(s, addr, netmask);
776 ds_put_char(s, ',');
777 }
778 }
779
780 static void
781 format_be16_masked(struct ds *s, const char *name,
782 ovs_be16 value, ovs_be16 mask)
783 {
784 if (mask != htons(0)) {
785 ds_put_format(s, "%s=", name);
786 if (mask == OVS_BE16_MAX) {
787 ds_put_format(s, "%"PRIu16, ntohs(value));
788 } else {
789 ds_put_format(s, "0x%"PRIx16"/0x%"PRIx16,
790 ntohs(value), ntohs(mask));
791 }
792 ds_put_char(s, ',');
793 }
794 }
795
796 static void
797 format_be32_masked(struct ds *s, const char *name,
798 ovs_be32 value, ovs_be32 mask)
799 {
800 if (mask != htonl(0)) {
801 ds_put_format(s, "%s=", name);
802 if (mask == OVS_BE32_MAX) {
803 ds_put_format(s, "%"PRIu32, ntohl(value));
804 } else {
805 ds_put_format(s, "0x%"PRIx32"/0x%"PRIx32,
806 ntohl(value), ntohl(mask));
807 }
808 ds_put_char(s, ',');
809 }
810 }
811
812 static void
813 format_uint32_masked(struct ds *s, const char *name,
814 uint32_t value, uint32_t mask)
815 {
816 if (mask) {
817 ds_put_format(s, "%s=%#"PRIx32, name, value);
818 if (mask != UINT32_MAX) {
819 ds_put_format(s, "/%#"PRIx32, mask);
820 }
821 ds_put_char(s, ',');
822 }
823 }
824
825 static void
826 format_be64_masked(struct ds *s, const char *name,
827 ovs_be64 value, ovs_be64 mask)
828 {
829 if (mask != htonll(0)) {
830 ds_put_format(s, "%s=%#"PRIx64, name, ntohll(value));
831 if (mask != OVS_BE64_MAX) {
832 ds_put_format(s, "/%#"PRIx64, ntohll(mask));
833 }
834 ds_put_char(s, ',');
835 }
836 }
837
838 static void
839 format_flow_tunnel(struct ds *s, const struct match *match)
840 {
841 const struct flow_wildcards *wc = &match->wc;
842 const struct flow_tnl *tnl = &match->flow.tunnel;
843
844 format_be64_masked(s, "tun_id", tnl->tun_id, wc->masks.tunnel.tun_id);
845 format_ip_netmask(s, "tun_src", tnl->ip_src, wc->masks.tunnel.ip_src);
846 format_ip_netmask(s, "tun_dst", tnl->ip_dst, wc->masks.tunnel.ip_dst);
847
848 if (wc->masks.tunnel.ip_tos) {
849 ds_put_format(s, "tun_tos=%"PRIx8",", tnl->ip_tos);
850 }
851 if (wc->masks.tunnel.ip_ttl) {
852 ds_put_format(s, "tun_ttl=%"PRIu8",", tnl->ip_ttl);
853 }
854 if (wc->masks.tunnel.flags) {
855 format_flags(s, flow_tun_flag_to_string, tnl->flags, '|');
856 ds_put_char(s, ',');
857 }
858 }
859
860 /* Appends a string representation of 'match' to 's'. If 'priority' is
861 * different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
862 void
863 match_format(const struct match *match, struct ds *s, int priority)
864 {
865 const struct flow_wildcards *wc = &match->wc;
866 size_t start_len = s->length;
867 const struct flow *f = &match->flow;
868 bool skip_type = false;
869 bool skip_proto = false;
870
871 int i;
872
873 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 28);
874
875 if (priority != OFP_DEFAULT_PRIORITY) {
876 ds_put_format(s, "priority=%d,", priority);
877 }
878
879 format_uint32_masked(s, "pkt_mark", f->pkt_mark, wc->masks.pkt_mark);
880
881 if (wc->masks.recirc_id) {
882 format_uint32_masked(s, "recirc_id", f->recirc_id,
883 wc->masks.recirc_id);
884 }
885
886 if (f->dp_hash && wc->masks.dp_hash) {
887 format_uint32_masked(s, "dp_hash", f->dp_hash,
888 wc->masks.dp_hash);
889 }
890
891 if (wc->masks.skb_priority) {
892 ds_put_format(s, "skb_priority=%#"PRIx32",", f->skb_priority);
893 }
894
895 if (wc->masks.actset_output) {
896 ds_put_cstr(s, "actset_output=");
897 ofputil_format_port(f->actset_output, s);
898 ds_put_char(s, ',');
899 }
900
901 if (wc->masks.dl_type) {
902 skip_type = true;
903 if (f->dl_type == htons(ETH_TYPE_IP)) {
904 if (wc->masks.nw_proto) {
905 skip_proto = true;
906 if (f->nw_proto == IPPROTO_ICMP) {
907 ds_put_cstr(s, "icmp,");
908 } else if (f->nw_proto == IPPROTO_IGMP) {
909 ds_put_cstr(s, "igmp,");
910 } else if (f->nw_proto == IPPROTO_TCP) {
911 ds_put_cstr(s, "tcp,");
912 } else if (f->nw_proto == IPPROTO_UDP) {
913 ds_put_cstr(s, "udp,");
914 } else if (f->nw_proto == IPPROTO_SCTP) {
915 ds_put_cstr(s, "sctp,");
916 } else {
917 ds_put_cstr(s, "ip,");
918 skip_proto = false;
919 }
920 } else {
921 ds_put_cstr(s, "ip,");
922 }
923 } else if (f->dl_type == htons(ETH_TYPE_IPV6)) {
924 if (wc->masks.nw_proto) {
925 skip_proto = true;
926 if (f->nw_proto == IPPROTO_ICMPV6) {
927 ds_put_cstr(s, "icmp6,");
928 } else if (f->nw_proto == IPPROTO_TCP) {
929 ds_put_cstr(s, "tcp6,");
930 } else if (f->nw_proto == IPPROTO_UDP) {
931 ds_put_cstr(s, "udp6,");
932 } else if (f->nw_proto == IPPROTO_SCTP) {
933 ds_put_cstr(s, "sctp6,");
934 } else {
935 ds_put_cstr(s, "ipv6,");
936 skip_proto = false;
937 }
938 } else {
939 ds_put_cstr(s, "ipv6,");
940 }
941 } else if (f->dl_type == htons(ETH_TYPE_ARP)) {
942 ds_put_cstr(s, "arp,");
943 } else if (f->dl_type == htons(ETH_TYPE_RARP)) {
944 ds_put_cstr(s, "rarp,");
945 } else if (f->dl_type == htons(ETH_TYPE_MPLS)) {
946 ds_put_cstr(s, "mpls,");
947 } else if (f->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
948 ds_put_cstr(s, "mplsm,");
949 } else {
950 skip_type = false;
951 }
952 }
953 for (i = 0; i < FLOW_N_REGS; i++) {
954 #define REGNAME_LEN 20
955 char regname[REGNAME_LEN];
956 if (snprintf(regname, REGNAME_LEN, "reg%d", i) >= REGNAME_LEN) {
957 strcpy(regname, "reg?");
958 }
959 format_uint32_masked(s, regname, f->regs[i], wc->masks.regs[i]);
960 }
961
962 format_flow_tunnel(s, match);
963
964 format_be64_masked(s, "metadata", f->metadata, wc->masks.metadata);
965
966 if (wc->masks.in_port.ofp_port) {
967 ds_put_cstr(s, "in_port=");
968 ofputil_format_port(f->in_port.ofp_port, s);
969 ds_put_char(s, ',');
970 }
971 if (wc->masks.vlan_tci) {
972 ovs_be16 vid_mask = wc->masks.vlan_tci & htons(VLAN_VID_MASK);
973 ovs_be16 pcp_mask = wc->masks.vlan_tci & htons(VLAN_PCP_MASK);
974 ovs_be16 cfi = wc->masks.vlan_tci & htons(VLAN_CFI);
975
976 if (cfi && f->vlan_tci & htons(VLAN_CFI)
977 && (!vid_mask || vid_mask == htons(VLAN_VID_MASK))
978 && (!pcp_mask || pcp_mask == htons(VLAN_PCP_MASK))
979 && (vid_mask || pcp_mask)) {
980 if (vid_mask) {
981 ds_put_format(s, "dl_vlan=%"PRIu16",",
982 vlan_tci_to_vid(f->vlan_tci));
983 }
984 if (pcp_mask) {
985 ds_put_format(s, "dl_vlan_pcp=%d,",
986 vlan_tci_to_pcp(f->vlan_tci));
987 }
988 } else if (wc->masks.vlan_tci == htons(0xffff)) {
989 ds_put_format(s, "vlan_tci=0x%04"PRIx16",", ntohs(f->vlan_tci));
990 } else {
991 ds_put_format(s, "vlan_tci=0x%04"PRIx16"/0x%04"PRIx16",",
992 ntohs(f->vlan_tci), ntohs(wc->masks.vlan_tci));
993 }
994 }
995 format_eth_masked(s, "dl_src", f->dl_src, wc->masks.dl_src);
996 format_eth_masked(s, "dl_dst", f->dl_dst, wc->masks.dl_dst);
997 if (!skip_type && wc->masks.dl_type) {
998 ds_put_format(s, "dl_type=0x%04"PRIx16",", ntohs(f->dl_type));
999 }
1000 if (f->dl_type == htons(ETH_TYPE_IPV6)) {
1001 format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->masks.ipv6_src);
1002 format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->masks.ipv6_dst);
1003 if (wc->masks.ipv6_label) {
1004 if (wc->masks.ipv6_label == OVS_BE32_MAX) {
1005 ds_put_format(s, "ipv6_label=0x%05"PRIx32",",
1006 ntohl(f->ipv6_label));
1007 } else {
1008 ds_put_format(s, "ipv6_label=0x%05"PRIx32"/0x%05"PRIx32",",
1009 ntohl(f->ipv6_label),
1010 ntohl(wc->masks.ipv6_label));
1011 }
1012 }
1013 } else if (f->dl_type == htons(ETH_TYPE_ARP) ||
1014 f->dl_type == htons(ETH_TYPE_RARP)) {
1015 format_ip_netmask(s, "arp_spa", f->nw_src, wc->masks.nw_src);
1016 format_ip_netmask(s, "arp_tpa", f->nw_dst, wc->masks.nw_dst);
1017 } else {
1018 format_ip_netmask(s, "nw_src", f->nw_src, wc->masks.nw_src);
1019 format_ip_netmask(s, "nw_dst", f->nw_dst, wc->masks.nw_dst);
1020 }
1021 if (!skip_proto && wc->masks.nw_proto) {
1022 if (f->dl_type == htons(ETH_TYPE_ARP) ||
1023 f->dl_type == htons(ETH_TYPE_RARP)) {
1024 ds_put_format(s, "arp_op=%"PRIu8",", f->nw_proto);
1025 } else {
1026 ds_put_format(s, "nw_proto=%"PRIu8",", f->nw_proto);
1027 }
1028 }
1029 if (f->dl_type == htons(ETH_TYPE_ARP) ||
1030 f->dl_type == htons(ETH_TYPE_RARP)) {
1031 format_eth_masked(s, "arp_sha", f->arp_sha, wc->masks.arp_sha);
1032 format_eth_masked(s, "arp_tha", f->arp_tha, wc->masks.arp_tha);
1033 }
1034 if (wc->masks.nw_tos & IP_DSCP_MASK) {
1035 ds_put_format(s, "nw_tos=%"PRIu8",", f->nw_tos & IP_DSCP_MASK);
1036 }
1037 if (wc->masks.nw_tos & IP_ECN_MASK) {
1038 ds_put_format(s, "nw_ecn=%"PRIu8",", f->nw_tos & IP_ECN_MASK);
1039 }
1040 if (wc->masks.nw_ttl) {
1041 ds_put_format(s, "nw_ttl=%"PRIu8",", f->nw_ttl);
1042 }
1043 if (wc->masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK)) {
1044 ds_put_format(s, "mpls_label=%"PRIu32",",
1045 mpls_lse_to_label(f->mpls_lse[0]));
1046 }
1047 if (wc->masks.mpls_lse[0] & htonl(MPLS_TC_MASK)) {
1048 ds_put_format(s, "mpls_tc=%"PRIu8",",
1049 mpls_lse_to_tc(f->mpls_lse[0]));
1050 }
1051 if (wc->masks.mpls_lse[0] & htonl(MPLS_TTL_MASK)) {
1052 ds_put_format(s, "mpls_ttl=%"PRIu8",",
1053 mpls_lse_to_ttl(f->mpls_lse[0]));
1054 }
1055 if (wc->masks.mpls_lse[0] & htonl(MPLS_BOS_MASK)) {
1056 ds_put_format(s, "mpls_bos=%"PRIu8",",
1057 mpls_lse_to_bos(f->mpls_lse[0]));
1058 }
1059 format_be32_masked(s, "mpls_lse1", f->mpls_lse[1], wc->masks.mpls_lse[1]);
1060 format_be32_masked(s, "mpls_lse2", f->mpls_lse[2], wc->masks.mpls_lse[2]);
1061
1062 switch (wc->masks.nw_frag) {
1063 case FLOW_NW_FRAG_ANY | FLOW_NW_FRAG_LATER:
1064 ds_put_format(s, "nw_frag=%s,",
1065 f->nw_frag & FLOW_NW_FRAG_ANY
1066 ? (f->nw_frag & FLOW_NW_FRAG_LATER ? "later" : "first")
1067 : (f->nw_frag & FLOW_NW_FRAG_LATER ? "<error>" : "no"));
1068 break;
1069
1070 case FLOW_NW_FRAG_ANY:
1071 ds_put_format(s, "nw_frag=%s,",
1072 f->nw_frag & FLOW_NW_FRAG_ANY ? "yes" : "no");
1073 break;
1074
1075 case FLOW_NW_FRAG_LATER:
1076 ds_put_format(s, "nw_frag=%s,",
1077 f->nw_frag & FLOW_NW_FRAG_LATER ? "later" : "not_later");
1078 break;
1079 }
1080 if (f->dl_type == htons(ETH_TYPE_IP) &&
1081 f->nw_proto == IPPROTO_ICMP) {
1082 format_be16_masked(s, "icmp_type", f->tp_src, wc->masks.tp_src);
1083 format_be16_masked(s, "icmp_code", f->tp_dst, wc->masks.tp_dst);
1084 } else if (f->dl_type == htons(ETH_TYPE_IP) &&
1085 f->nw_proto == IPPROTO_IGMP) {
1086 format_be16_masked(s, "igmp_type", f->tp_src, wc->masks.tp_src);
1087 format_be16_masked(s, "igmp_code", f->tp_dst, wc->masks.tp_dst);
1088 } else if (f->dl_type == htons(ETH_TYPE_IPV6) &&
1089 f->nw_proto == IPPROTO_ICMPV6) {
1090 format_be16_masked(s, "icmp_type", f->tp_src, wc->masks.tp_src);
1091 format_be16_masked(s, "icmp_code", f->tp_dst, wc->masks.tp_dst);
1092 format_ipv6_netmask(s, "nd_target", &f->nd_target,
1093 &wc->masks.nd_target);
1094 format_eth_masked(s, "nd_sll", f->arp_sha, wc->masks.arp_sha);
1095 format_eth_masked(s, "nd_tll", f->arp_tha, wc->masks.arp_tha);
1096 } else {
1097 format_be16_masked(s, "tp_src", f->tp_src, wc->masks.tp_src);
1098 format_be16_masked(s, "tp_dst", f->tp_dst, wc->masks.tp_dst);
1099 }
1100 if (is_ip_any(f) && f->nw_proto == IPPROTO_TCP && wc->masks.tcp_flags) {
1101 uint16_t mask = TCP_FLAGS(wc->masks.tcp_flags);
1102
1103 if (mask == TCP_FLAGS(OVS_BE16_MAX)) {
1104 ds_put_cstr(s, "tcp_flags=");
1105 if (f->tcp_flags) {
1106 format_flags(s, packet_tcp_flag_to_string, ntohs(f->tcp_flags),
1107 '|');
1108 } else {
1109 ds_put_cstr(s, "0"); /* Zero flags. */
1110 }
1111 } else if (mask) {
1112 format_flags_masked(s, "tcp_flags", packet_tcp_flag_to_string,
1113 ntohs(f->tcp_flags), mask);
1114 }
1115 }
1116
1117 if (s->length > start_len) {
1118 ds_chomp(s, ',');
1119 }
1120 }
1121
1122 /* Converts 'match' to a string and returns the string. If 'priority' is
1123 * different from OFP_DEFAULT_PRIORITY, includes it in the string. The caller
1124 * must free the string (with free()). */
1125 char *
1126 match_to_string(const struct match *match, int priority)
1127 {
1128 struct ds s = DS_EMPTY_INITIALIZER;
1129 match_format(match, &s, priority);
1130 return ds_steal_cstr(&s);
1131 }
1132
1133 void
1134 match_print(const struct match *match)
1135 {
1136 char *s = match_to_string(match, OFP_DEFAULT_PRIORITY);
1137 puts(s);
1138 free(s);
1139 }
1140 \f
1141 /* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst'
1142 * with minimatch_destroy(). */
1143 void
1144 minimatch_init(struct minimatch *dst, const struct match *src)
1145 {
1146 minimask_init(&dst->mask, &src->wc);
1147 miniflow_init_with_minimask(&dst->flow, &src->flow, &dst->mask);
1148 }
1149
1150 /* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst'
1151 * with minimatch_destroy(). */
1152 void
1153 minimatch_clone(struct minimatch *dst, const struct minimatch *src)
1154 {
1155 miniflow_clone(&dst->flow, &src->flow);
1156 minimask_clone(&dst->mask, &src->mask);
1157 }
1158
1159 /* Initializes 'dst' with the data in 'src', destroying 'src'. The caller must
1160 * eventually free 'dst' with minimatch_destroy(). */
1161 void
1162 minimatch_move(struct minimatch *dst, struct minimatch *src)
1163 {
1164 miniflow_move(&dst->flow, &src->flow);
1165 minimask_move(&dst->mask, &src->mask);
1166 }
1167
1168 /* Frees any memory owned by 'match'. Does not free the storage in which
1169 * 'match' itself resides; the caller is responsible for that. */
1170 void
1171 minimatch_destroy(struct minimatch *match)
1172 {
1173 miniflow_destroy(&match->flow);
1174 minimask_destroy(&match->mask);
1175 }
1176
1177 /* Initializes 'dst' as a copy of 'src'. */
1178 void
1179 minimatch_expand(const struct minimatch *src, struct match *dst)
1180 {
1181 miniflow_expand(&src->flow, &dst->flow);
1182 minimask_expand(&src->mask, &dst->wc);
1183 }
1184
1185 /* Returns true if 'a' and 'b' match the same packets, false otherwise. */
1186 bool
1187 minimatch_equal(const struct minimatch *a, const struct minimatch *b)
1188 {
1189 return (miniflow_equal(&a->flow, &b->flow)
1190 && minimask_equal(&a->mask, &b->mask));
1191 }
1192
1193 /* Returns true if 'target' satisifies 'match', that is, if each bit for which
1194 * 'match' specifies a particular value has the correct value in 'target'.
1195 *
1196 * This function is equivalent to miniflow_equal_flow_in_minimask(&match->flow,
1197 * target, &match->mask) but it is faster because of the invariant that
1198 * match->flow.map and match->mask.map are the same. */
1199 bool
1200 minimatch_matches_flow(const struct minimatch *match,
1201 const struct flow *target)
1202 {
1203 const uint32_t *target_u32 = (const uint32_t *) target;
1204 const uint32_t *flowp = miniflow_get_u32_values(&match->flow);
1205 const uint32_t *maskp = miniflow_get_u32_values(&match->mask.masks);
1206 int idx;
1207
1208 MAP_FOR_EACH_INDEX(idx, match->flow.map) {
1209 if ((*flowp++ ^ target_u32[idx]) & *maskp++) {
1210 return false;
1211 }
1212 }
1213
1214 return true;
1215 }
1216
1217 /* Appends a string representation of 'match' to 's'. If 'priority' is
1218 * different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
1219 void
1220 minimatch_format(const struct minimatch *match, struct ds *s, int priority)
1221 {
1222 struct match megamatch;
1223
1224 minimatch_expand(match, &megamatch);
1225 match_format(&megamatch, s, priority);
1226 }
1227
1228 /* Converts 'match' to a string and returns the string. If 'priority' is
1229 * different from OFP_DEFAULT_PRIORITY, includes it in the string. The caller
1230 * must free the string (with free()). */
1231 char *
1232 minimatch_to_string(const struct minimatch *match, int priority)
1233 {
1234 struct match megamatch;
1235
1236 minimatch_expand(match, &megamatch);
1237 return match_to_string(&megamatch, priority);
1238 }