2 * Copyright (c) 2011, 2012, 2013, 2014 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.
19 #include "meta-flow.h"
23 #include <netinet/icmp6.h>
24 #include <netinet/ip6.h>
26 #include "classifier.h"
27 #include "dynamic-string.h"
28 #include "ofp-errors.h"
30 #include "ovs-thread.h"
34 #include "socket-util.h"
35 #include "unaligned.h"
39 VLOG_DEFINE_THIS_MODULE(meta_flow);
41 #define FLOW_U32OFS(FIELD) \
42 offsetof(struct flow, FIELD) % 4 ? -1 : offsetof(struct flow, FIELD) / 4
44 #define MF_FIELD_SIZES(MEMBER) \
45 sizeof ((union mf_value *)0)->MEMBER, \
46 8 * sizeof ((union mf_value *)0)->MEMBER
48 extern const struct mf_field mf_fields[MFF_N_IDS]; /* Silence a warning. */
50 const struct mf_field mf_fields[MFF_N_IDS] = {
56 MFF_DP_HASH, "dp_hash", NULL,
62 NXM_NX_DP_HASH, "NXM_NX_DP_HASH",
63 NXM_NX_DP_HASH, "NXM_NX_DP_HASH", 0,
64 OFPUTIL_P_NXM_OXM_ANY,
65 OFPUTIL_P_NXM_OXM_ANY,
68 MFF_RECIRC_ID, "recirc_id", NULL,
74 NXM_NX_RECIRC_ID, "NXM_NX_RECIRC_ID",
75 NXM_NX_RECIRC_ID, "NXM_NX_RECIRC_ID", 0,
76 OFPUTIL_P_NXM_OXM_ANY,
77 OFPUTIL_P_NXM_OXM_ANY,
80 MFF_TUN_ID, "tun_id", "tunnel_id",
86 NXM_NX_TUN_ID, "NXM_NX_TUN_ID",
87 OXM_OF_TUNNEL_ID, "OXM_OF_TUNNEL_ID", OFP13_VERSION,
88 OFPUTIL_P_NXM_OXM_ANY,
89 OFPUTIL_P_NXM_OXM_ANY,
90 FLOW_U32OFS(tunnel.tun_id),
92 MFF_TUN_SRC, "tun_src", NULL,
98 NXM_NX_TUN_IPV4_SRC, "NXM_NX_TUN_IPV4_SRC",
99 NXM_NX_TUN_IPV4_SRC, "NXM_NX_TUN_IPV4_SRC", 0,
100 OFPUTIL_P_NXM_OXM_ANY,
101 OFPUTIL_P_NXM_OXM_ANY,
102 FLOW_U32OFS(tunnel.ip_src),
104 MFF_TUN_DST, "tun_dst", NULL,
105 MF_FIELD_SIZES(be32),
110 NXM_NX_TUN_IPV4_DST, "NXM_NX_TUN_IPV4_DST",
111 NXM_NX_TUN_IPV4_DST, "NXM_NX_TUN_IPV4_DST", 0,
112 OFPUTIL_P_NXM_OXM_ANY,
113 OFPUTIL_P_NXM_OXM_ANY,
114 FLOW_U32OFS(tunnel.ip_dst),
116 MFF_TUN_FLAGS, "tun_flags", NULL,
117 MF_FIELD_SIZES(be16),
128 MFF_TUN_TTL, "tun_ttl", NULL,
140 MFF_TUN_TOS, "tun_tos", NULL,
152 MFF_METADATA, "metadata", NULL,
153 MF_FIELD_SIZES(be64),
158 OXM_OF_METADATA, "OXM_OF_METADATA",
159 OXM_OF_METADATA, "OXM_OF_METADATA", OFP12_VERSION,
160 OFPUTIL_P_NXM_OF11_UP,
161 OFPUTIL_P_NXM_OF11_UP,
164 MFF_IN_PORT, "in_port", NULL,
165 MF_FIELD_SIZES(be16),
170 NXM_OF_IN_PORT, "NXM_OF_IN_PORT",
171 NXM_OF_IN_PORT, "NXM_OF_IN_PORT", 0,
172 OFPUTIL_P_ANY, /* OF11+ via mapping to 32 bits. */
176 MFF_IN_PORT_OXM, "in_port_oxm", NULL,
177 MF_FIELD_SIZES(be32),
182 OXM_OF_IN_PORT, "OXM_OF_IN_PORT",
183 OXM_OF_IN_PORT, "OXM_OF_IN_PORT", OFP12_VERSION,
188 MFF_SKB_PRIORITY, "skb_priority", NULL,
189 MF_FIELD_SIZES(be32),
200 MFF_PKT_MARK, "pkt_mark", NULL,
201 MF_FIELD_SIZES(be32),
206 NXM_NX_PKT_MARK, "NXM_NX_PKT_MARK",
207 NXM_NX_PKT_MARK, "NXM_NX_PKT_MARK", 0,
208 OFPUTIL_P_NXM_OXM_ANY,
209 OFPUTIL_P_NXM_OXM_ANY,
213 #define REGISTER(IDX) \
215 MFF_REG##IDX, "reg" #IDX, NULL, \
216 MF_FIELD_SIZES(be32), \
221 NXM_NX_REG(IDX), "NXM_NX_REG" #IDX, \
222 NXM_NX_REG(IDX), "NXM_NX_REG" #IDX, 0, \
223 OFPUTIL_P_NXM_OXM_ANY, \
224 OFPUTIL_P_NXM_OXM_ANY, \
260 MFF_ETH_SRC, "eth_src", "dl_src",
266 NXM_OF_ETH_SRC, "NXM_OF_ETH_SRC",
267 OXM_OF_ETH_SRC, "OXM_OF_ETH_SRC", OFP12_VERSION,
269 OFPUTIL_P_NXM_OF11_UP, /* Bitwise masking only with NXM and OF11+! */
272 MFF_ETH_DST, "eth_dst", "dl_dst",
278 NXM_OF_ETH_DST, "NXM_OF_ETH_DST",
279 OXM_OF_ETH_DST, "OXM_OF_ETH_DST", OFP12_VERSION,
281 OFPUTIL_P_NXM_OF11_UP, /* Bitwise masking only with NXM and OF11+! */
284 MFF_ETH_TYPE, "eth_type", "dl_type",
285 MF_FIELD_SIZES(be16),
290 NXM_OF_ETH_TYPE, "NXM_OF_ETH_TYPE",
291 OXM_OF_ETH_TYPE, "OXM_OF_ETH_TYPE", OFP12_VERSION,
298 MFF_VLAN_TCI, "vlan_tci", NULL,
299 MF_FIELD_SIZES(be16),
304 NXM_OF_VLAN_TCI, "NXM_OF_VLAN_TCI",
305 NXM_OF_VLAN_TCI, "NXM_OF_VLAN_TCI", 0,
307 OFPUTIL_P_NXM_OXM_ANY,
310 MFF_DL_VLAN, "dl_vlan", NULL,
311 sizeof(ovs_be16), 12,
319 OFPUTIL_P_NXM_OXM_ANY,
322 MFF_VLAN_VID, "vlan_vid", NULL,
323 sizeof(ovs_be16), 12,
328 OXM_OF_VLAN_VID, "OXM_OF_VLAN_VID",
329 OXM_OF_VLAN_VID, "OXM_OF_VLAN_VID", OFP12_VERSION,
331 OFPUTIL_P_NXM_OXM_ANY,
334 MFF_DL_VLAN_PCP, "dl_vlan_pcp", NULL,
342 OFPUTIL_P_ANY, /* Will be mapped to NXM and OXM. */
346 MFF_VLAN_PCP, "vlan_pcp", NULL,
352 OXM_OF_VLAN_PCP, "OXM_OF_VLAN_PCP",
353 OXM_OF_VLAN_PCP, "OXM_OF_VLAN_PCP", OFP12_VERSION,
354 OFPUTIL_P_ANY, /* Will be mapped to OF10 and NXM. */
363 MFF_MPLS_LABEL, "mpls_label", NULL,
369 OXM_OF_MPLS_LABEL, "OXM_OF_MPLS_LABEL",
370 OXM_OF_MPLS_LABEL, "OXM_OF_MPLS_LABEL", OFP12_VERSION,
371 OFPUTIL_P_NXM_OF11_UP,
375 MFF_MPLS_TC, "mpls_tc", NULL,
381 OXM_OF_MPLS_TC, "OXM_OF_MPLS_TC",
382 OXM_OF_MPLS_TC, "OXM_OF_MPLS_TC", OFP12_VERSION,
383 OFPUTIL_P_NXM_OF11_UP,
387 MFF_MPLS_BOS, "mpls_bos", NULL,
393 OXM_OF_MPLS_BOS, "OXM_OF_MPLS_BOS",
394 OXM_OF_MPLS_BOS, "OXM_OF_MPLS_BOS", OFP13_VERSION,
395 OFPUTIL_P_NXM_OXM_ANY,
405 MFF_IPV4_SRC, "ip_src", "nw_src",
406 MF_FIELD_SIZES(be32),
411 NXM_OF_IP_SRC, "NXM_OF_IP_SRC",
412 OXM_OF_IPV4_SRC, "OXM_OF_IPV4_SRC", OFP12_VERSION,
414 OFPUTIL_P_NXM_OF11_UP,
417 MFF_IPV4_DST, "ip_dst", "nw_dst",
418 MF_FIELD_SIZES(be32),
423 NXM_OF_IP_DST, "NXM_OF_IP_DST",
424 OXM_OF_IPV4_DST, "OXM_OF_IPV4_DST", OFP12_VERSION,
426 OFPUTIL_P_NXM_OF11_UP,
431 MFF_IPV6_SRC, "ipv6_src", NULL,
432 MF_FIELD_SIZES(ipv6),
437 NXM_NX_IPV6_SRC, "NXM_NX_IPV6_SRC",
438 OXM_OF_IPV6_SRC, "OXM_OF_IPV6_SRC", OFP12_VERSION,
439 OFPUTIL_P_NXM_OXM_ANY,
440 OFPUTIL_P_NXM_OXM_ANY,
441 FLOW_U32OFS(ipv6_src),
443 MFF_IPV6_DST, "ipv6_dst", NULL,
444 MF_FIELD_SIZES(ipv6),
449 NXM_NX_IPV6_DST, "NXM_NX_IPV6_DST",
450 OXM_OF_IPV6_DST, "OXM_OF_IPV6_DST", OFP12_VERSION,
451 OFPUTIL_P_NXM_OXM_ANY,
452 OFPUTIL_P_NXM_OXM_ANY,
453 FLOW_U32OFS(ipv6_dst),
456 MFF_IPV6_LABEL, "ipv6_label", NULL,
462 NXM_NX_IPV6_LABEL, "NXM_NX_IPV6_LABEL",
463 OXM_OF_IPV6_FLABEL, "OXM_OF_IPV6_FLABEL", OFP12_VERSION,
464 OFPUTIL_P_NXM_OXM_ANY,
465 OFPUTIL_P_NXM_OXM_ANY,
470 MFF_IP_PROTO, "nw_proto", "ip_proto",
476 NXM_OF_IP_PROTO, "NXM_OF_IP_PROTO",
477 OXM_OF_IP_PROTO, "OXM_OF_IP_PROTO", OFP12_VERSION,
482 MFF_IP_DSCP, "nw_tos", NULL,
488 NXM_OF_IP_TOS, "NXM_OF_IP_TOS",
489 NXM_OF_IP_TOS, "NXM_OF_IP_TOS", 0,
490 OFPUTIL_P_ANY, /* Will be shifted for OXM. */
494 MFF_IP_DSCP_SHIFTED, "ip_dscp", NULL,
500 OXM_OF_IP_DSCP, "OXM_OF_IP_DSCP",
501 OXM_OF_IP_DSCP, "OXM_OF_IP_DSCP", OFP12_VERSION,
502 OFPUTIL_P_ANY, /* Will be shifted for non-OXM. */
506 MFF_IP_ECN, "nw_ecn", "ip_ecn",
512 NXM_NX_IP_ECN, "NXM_NX_IP_ECN",
513 OXM_OF_IP_ECN, "OXM_OF_IP_ECN", OFP12_VERSION,
514 OFPUTIL_P_NXM_OXM_ANY,
518 MFF_IP_TTL, "nw_ttl", NULL,
524 NXM_NX_IP_TTL, "NXM_NX_IP_TTL",
525 NXM_NX_IP_TTL, "NXM_NX_IP_TTL", 0,
526 OFPUTIL_P_NXM_OXM_ANY,
530 MFF_IP_FRAG, "ip_frag", NULL,
536 NXM_NX_IP_FRAG, "NXM_NX_IP_FRAG",
537 NXM_NX_IP_FRAG, "NXM_NX_IP_FRAG", 0,
538 OFPUTIL_P_NXM_OXM_ANY,
539 OFPUTIL_P_NXM_OXM_ANY,
544 MFF_ARP_OP, "arp_op", NULL,
545 MF_FIELD_SIZES(be16),
550 NXM_OF_ARP_OP, "NXM_OF_ARP_OP",
551 OXM_OF_ARP_OP, "OXM_OF_ARP_OP", OFP12_VERSION,
556 MFF_ARP_SPA, "arp_spa", NULL,
557 MF_FIELD_SIZES(be32),
562 NXM_OF_ARP_SPA, "NXM_OF_ARP_SPA",
563 OXM_OF_ARP_SPA, "OXM_OF_ARP_SPA", OFP12_VERSION,
565 OFPUTIL_P_NXM_OF11_UP,
568 MFF_ARP_TPA, "arp_tpa", NULL,
569 MF_FIELD_SIZES(be32),
574 NXM_OF_ARP_TPA, "NXM_OF_ARP_TPA",
575 OXM_OF_ARP_TPA, "OXM_OF_ARP_TPA", OFP12_VERSION,
577 OFPUTIL_P_NXM_OF11_UP,
580 MFF_ARP_SHA, "arp_sha", NULL,
586 NXM_NX_ARP_SHA, "NXM_NX_ARP_SHA",
587 OXM_OF_ARP_SHA, "OXM_OF_ARP_SHA", OFP12_VERSION,
588 OFPUTIL_P_NXM_OXM_ANY,
589 OFPUTIL_P_NXM_OXM_ANY,
592 MFF_ARP_THA, "arp_tha", NULL,
598 NXM_NX_ARP_THA, "NXM_NX_ARP_THA",
599 OXM_OF_ARP_THA, "OXM_OF_ARP_THA", OFP12_VERSION,
600 OFPUTIL_P_NXM_OXM_ANY,
601 OFPUTIL_P_NXM_OXM_ANY,
610 MFF_TCP_SRC, "tcp_src", "tp_src",
611 MF_FIELD_SIZES(be16),
616 NXM_OF_TCP_SRC, "NXM_OF_TCP_SRC",
617 OXM_OF_TCP_SRC, "OXM_OF_TCP_SRC", OFP12_VERSION,
619 OFPUTIL_P_NXM_OXM_ANY,
622 MFF_TCP_DST, "tcp_dst", "tp_dst",
623 MF_FIELD_SIZES(be16),
628 NXM_OF_TCP_DST, "NXM_OF_TCP_DST",
629 OXM_OF_TCP_DST, "OXM_OF_TCP_DST", OFP12_VERSION,
631 OFPUTIL_P_NXM_OXM_ANY,
634 MFF_TCP_FLAGS, "tcp_flags", NULL,
640 NXM_NX_TCP_FLAGS, "NXM_NX_TCP_FLAGS",
641 OXM_OF_TCP_FLAGS, "OXM_OF_TCP_FLAGS", OFP15_VERSION,
642 OFPUTIL_P_NXM_OXM_ANY,
643 OFPUTIL_P_NXM_OXM_ANY,
648 MFF_UDP_SRC, "udp_src", NULL,
649 MF_FIELD_SIZES(be16),
654 NXM_OF_UDP_SRC, "NXM_OF_UDP_SRC",
655 OXM_OF_UDP_SRC, "OXM_OF_UDP_SRC", OFP12_VERSION,
657 OFPUTIL_P_NXM_OXM_ANY,
660 MFF_UDP_DST, "udp_dst", NULL,
661 MF_FIELD_SIZES(be16),
666 NXM_OF_UDP_DST, "NXM_OF_UDP_DST",
667 OXM_OF_UDP_DST, "OXM_OF_UDP_DST", OFP12_VERSION,
669 OFPUTIL_P_NXM_OXM_ANY,
674 MFF_SCTP_SRC, "sctp_src", NULL,
675 MF_FIELD_SIZES(be16),
680 OXM_OF_SCTP_SRC, "OXM_OF_SCTP_SRC",
681 OXM_OF_SCTP_SRC, "OXM_OF_SCTP_SRC", OFP12_VERSION,
682 OFPUTIL_P_NXM_OF11_UP,
683 OFPUTIL_P_NXM_OXM_ANY,
686 MFF_SCTP_DST, "sctp_dst", NULL,
687 MF_FIELD_SIZES(be16),
692 OXM_OF_SCTP_DST, "OXM_OF_SCTP_DST",
693 OXM_OF_SCTP_DST, "OXM_OF_SCTP_DST", OFP12_VERSION,
694 OFPUTIL_P_NXM_OF11_UP,
695 OFPUTIL_P_NXM_OXM_ANY,
700 MFF_ICMPV4_TYPE, "icmp_type", NULL,
706 NXM_OF_ICMP_TYPE, "NXM_OF_ICMP_TYPE",
707 OXM_OF_ICMPV4_TYPE, "OXM_OF_ICMPV4_TYPE", OFP12_VERSION,
712 MFF_ICMPV4_CODE, "icmp_code", NULL,
718 NXM_OF_ICMP_CODE, "NXM_OF_ICMP_CODE",
719 OXM_OF_ICMPV4_CODE, "OXM_OF_ICMPV4_CODE", OFP12_VERSION,
726 MFF_ICMPV6_TYPE, "icmpv6_type", NULL,
732 NXM_NX_ICMPV6_TYPE, "NXM_NX_ICMPV6_TYPE",
733 OXM_OF_ICMPV6_TYPE, "OXM_OF_ICMPV6_TYPE", OFP12_VERSION,
734 OFPUTIL_P_NXM_OXM_ANY,
738 MFF_ICMPV6_CODE, "icmpv6_code", NULL,
744 NXM_NX_ICMPV6_CODE, "NXM_NX_ICMPV6_CODE",
745 OXM_OF_ICMPV6_CODE, "OXM_OF_ICMPV6_CODE", OFP12_VERSION,
746 OFPUTIL_P_NXM_OXM_ANY,
756 MFF_ND_TARGET, "nd_target", NULL,
757 MF_FIELD_SIZES(ipv6),
762 NXM_NX_ND_TARGET, "NXM_NX_ND_TARGET",
763 OXM_OF_IPV6_ND_TARGET, "OXM_OF_IPV6_ND_TARGET", OFP12_VERSION,
764 OFPUTIL_P_NXM_OXM_ANY,
765 OFPUTIL_P_NXM_OXM_ANY,
768 MFF_ND_SLL, "nd_sll", NULL,
774 NXM_NX_ND_SLL, "NXM_NX_ND_SLL",
775 OXM_OF_IPV6_ND_SLL, "OXM_OF_IPV6_ND_SLL", OFP12_VERSION,
776 OFPUTIL_P_NXM_OXM_ANY,
777 OFPUTIL_P_NXM_OXM_ANY,
780 MFF_ND_TLL, "nd_tll", NULL,
786 NXM_NX_ND_TLL, "NXM_NX_ND_TLL",
787 OXM_OF_IPV6_ND_TLL, "OXM_OF_IPV6_ND_TLL", OFP12_VERSION,
788 OFPUTIL_P_NXM_OXM_ANY,
789 OFPUTIL_P_NXM_OXM_ANY,
794 /* Maps an NXM or OXM header value to an mf_field. */
796 struct hmap_node hmap_node; /* In 'all_fields' hmap. */
797 uint32_t header; /* NXM or OXM header value. */
798 const struct mf_field *mf;
801 /* Contains 'struct nxm_field's. */
802 static struct hmap all_fields;
804 /* Maps from an mf_field's 'name' or 'extra_name' to the mf_field. */
805 static struct shash mf_by_name;
807 /* Rate limit for parse errors. These always indicate a bug in an OpenFlow
808 * controller and so there's not much point in showing a lot of them. */
809 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
811 const struct mf_field *mf_from_nxm_header__(uint32_t header);
812 static void nxm_init(void);
814 /* Returns the field with the given 'name', or a null pointer if no field has
816 const struct mf_field *
817 mf_from_name(const char *name)
820 return shash_find_data(&mf_by_name, name);
824 add_nxm_field(uint32_t header, const struct mf_field *mf)
828 f = xmalloc(sizeof *f);
829 hmap_insert(&all_fields, &f->hmap_node, hash_int(header, 0));
835 nxm_init_add_field(const struct mf_field *mf, uint32_t header)
838 ovs_assert(!mf_from_nxm_header__(header));
839 add_nxm_field(header, mf);
840 if (mf->maskable != MFM_NONE) {
841 add_nxm_field(NXM_MAKE_WILD_HEADER(header), mf);
851 hmap_init(&all_fields);
852 shash_init(&mf_by_name);
853 for (i = 0; i < MFF_N_IDS; i++) {
854 const struct mf_field *mf = &mf_fields[i];
856 ovs_assert(mf->id == i); /* Fields must be in the enum order. */
858 nxm_init_add_field(mf, mf->nxm_header);
859 if (mf->oxm_header != mf->nxm_header) {
860 nxm_init_add_field(mf, mf->oxm_header);
863 shash_add_once(&mf_by_name, mf->name, mf);
864 if (mf->extra_name) {
865 shash_add_once(&mf_by_name, mf->extra_name, mf);
873 static pthread_once_t once = PTHREAD_ONCE_INIT;
874 pthread_once(&once, nxm_do_init);
877 const struct mf_field *
878 mf_from_nxm_header(uint32_t header)
881 return mf_from_nxm_header__(header);
884 const struct mf_field *
885 mf_from_nxm_header__(uint32_t header)
887 const struct nxm_field *f;
889 HMAP_FOR_EACH_IN_BUCKET (f, hmap_node, hash_int(header, 0), &all_fields) {
890 if (f->header == header) {
899 mf_oxm_header(enum mf_field_id id, enum ofp_version oxm_version)
901 const struct mf_field *field = mf_from_id(id);
903 return (oxm_version >= field->oxm_version
905 : field->nxm_header);
908 /* Returns true if 'wc' wildcards all the bits in field 'mf', false if 'wc'
909 * specifies at least one bit in the field.
911 * The caller is responsible for ensuring that 'wc' corresponds to a flow that
912 * meets 'mf''s prerequisites. */
914 mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
918 return !wc->masks.dp_hash;
920 return !wc->masks.recirc_id;
922 return !wc->masks.tunnel.ip_src;
924 return !wc->masks.tunnel.ip_dst;
929 return !wc->masks.tunnel.tun_id;
931 return !wc->masks.metadata;
933 case MFF_IN_PORT_OXM:
934 return !wc->masks.in_port.ofp_port;
935 case MFF_SKB_PRIORITY:
936 return !wc->masks.skb_priority;
938 return !wc->masks.pkt_mark;
940 return !wc->masks.regs[mf->id - MFF_REG0];
943 return eth_addr_is_zero(wc->masks.dl_src);
945 return eth_addr_is_zero(wc->masks.dl_dst);
947 return !wc->masks.dl_type;
951 return eth_addr_is_zero(wc->masks.arp_sha);
955 return eth_addr_is_zero(wc->masks.arp_tha);
958 return !wc->masks.vlan_tci;
960 return !(wc->masks.vlan_tci & htons(VLAN_VID_MASK));
962 return !(wc->masks.vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI));
963 case MFF_DL_VLAN_PCP:
965 return !(wc->masks.vlan_tci & htons(VLAN_PCP_MASK));
968 return !(wc->masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK));
970 return !(wc->masks.mpls_lse[0] & htonl(MPLS_TC_MASK));
972 return !(wc->masks.mpls_lse[0] & htonl(MPLS_BOS_MASK));
975 return !wc->masks.nw_src;
977 return !wc->masks.nw_dst;
980 return ipv6_mask_is_any(&wc->masks.ipv6_src);
982 return ipv6_mask_is_any(&wc->masks.ipv6_dst);
985 return !wc->masks.ipv6_label;
988 return !wc->masks.nw_proto;
990 case MFF_IP_DSCP_SHIFTED:
991 return !(wc->masks.nw_tos & IP_DSCP_MASK);
993 return !(wc->masks.nw_tos & IP_ECN_MASK);
995 return !wc->masks.nw_ttl;
998 return ipv6_mask_is_any(&wc->masks.nd_target);
1001 return !(wc->masks.nw_frag & FLOW_NW_FRAG_MASK);
1004 return !wc->masks.nw_proto;
1006 return !wc->masks.nw_src;
1008 return !wc->masks.nw_dst;
1013 case MFF_ICMPV4_TYPE:
1014 case MFF_ICMPV6_TYPE:
1015 return !wc->masks.tp_src;
1019 case MFF_ICMPV4_CODE:
1020 case MFF_ICMPV6_CODE:
1021 return !wc->masks.tp_dst;
1023 return !wc->masks.tcp_flags;
1031 /* Initializes 'mask' with the wildcard bit pattern for field 'mf' within 'wc'.
1032 * Each bit in 'mask' will be set to 1 if the bit is significant for matching
1033 * purposes, or to 0 if it is wildcarded.
1035 * The caller is responsible for ensuring that 'wc' corresponds to a flow that
1036 * meets 'mf''s prerequisites. */
1038 mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc,
1039 union mf_value *mask)
1041 mf_get_value(mf, &wc->masks, mask);
1044 /* Tests whether 'mask' is a valid wildcard bit pattern for 'mf'. Returns true
1045 * if the mask is valid, false otherwise. */
1047 mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask)
1049 switch (mf->maskable) {
1051 return (is_all_zeros((const uint8_t *) mask, mf->n_bytes) ||
1052 is_all_ones((const uint8_t *) mask, mf->n_bytes));
1061 /* Returns true if 'flow' meets the prerequisites for 'mf', false otherwise. */
1063 mf_are_prereqs_ok(const struct mf_field *mf, const struct flow *flow)
1065 switch (mf->prereqs) {
1070 return (flow->dl_type == htons(ETH_TYPE_ARP) ||
1071 flow->dl_type == htons(ETH_TYPE_RARP));
1073 return flow->dl_type == htons(ETH_TYPE_IP);
1075 return flow->dl_type == htons(ETH_TYPE_IPV6);
1077 return (flow->vlan_tci & htons(VLAN_CFI)) != 0;
1079 return eth_type_mpls(flow->dl_type);
1081 return is_ip_any(flow);
1084 return is_ip_any(flow) && flow->nw_proto == IPPROTO_TCP;
1086 return is_ip_any(flow) && flow->nw_proto == IPPROTO_UDP;
1088 return is_ip_any(flow) && flow->nw_proto == IPPROTO_SCTP;
1090 return is_icmpv4(flow);
1092 return is_icmpv6(flow);
1095 return (is_icmpv6(flow)
1096 && flow->tp_dst == htons(0)
1097 && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
1098 flow->tp_src == htons(ND_NEIGHBOR_ADVERT)));
1099 case MFP_ND_SOLICIT:
1100 return (is_icmpv6(flow)
1101 && flow->tp_dst == htons(0)
1102 && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)));
1104 return (is_icmpv6(flow)
1105 && flow->tp_dst == htons(0)
1106 && (flow->tp_src == htons(ND_NEIGHBOR_ADVERT)));
1112 /* Set field and it's prerequisities in the mask.
1113 * This is only ever called for writeable 'mf's, but we do not make the
1114 * distinction here. */
1116 mf_mask_field_and_prereqs(const struct mf_field *mf, struct flow *mask)
1118 static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
1120 mf_set_flow_value(mf, &exact_match_mask, mask);
1122 switch (mf->prereqs) {
1124 case MFP_ND_SOLICIT:
1126 mask->tp_src = OVS_BE16_MAX;
1127 mask->tp_dst = OVS_BE16_MAX;
1134 mask->nw_proto = 0xff;
1141 mask->dl_type = OVS_BE16_MAX;
1144 mask->vlan_tci |= htons(VLAN_CFI);
1152 /* Returns true if 'value' may be a valid value *as part of a masked match*,
1155 * A value is not rejected just because it is not valid for the field in
1156 * question, but only if it doesn't make sense to test the bits in question at
1157 * all. For example, the MFF_VLAN_TCI field will never have a nonzero value
1158 * without the VLAN_CFI bit being set, but we can't reject those values because
1159 * it is still legitimate to test just for those bits (see the documentation
1160 * for NXM_OF_VLAN_TCI in nicira-ext.h). On the other hand, there is never a
1161 * reason to set the low bit of MFF_IP_DSCP to 1, so we reject that. */
1163 mf_is_value_valid(const struct mf_field *mf, const union mf_value *value)
1176 case MFF_SKB_PRIORITY:
1199 case MFF_ICMPV4_TYPE:
1200 case MFF_ICMPV4_CODE:
1201 case MFF_ICMPV6_TYPE:
1202 case MFF_ICMPV6_CODE:
1208 case MFF_IN_PORT_OXM: {
1210 return !ofputil_port_from_ofp11(value->be32, &port);
1214 return !(value->u8 & ~IP_DSCP_MASK);
1215 case MFF_IP_DSCP_SHIFTED:
1216 return !(value->u8 & (~IP_DSCP_MASK >> 2));
1218 return !(value->u8 & ~IP_ECN_MASK);
1220 return !(value->u8 & ~FLOW_NW_FRAG_MASK);
1222 return !(value->be16 & ~htons(0x0fff));
1225 return !(value->be16 & htons(0xff00));
1228 return !(value->be16 & htons(VLAN_CFI | VLAN_PCP_MASK));
1230 return !(value->be16 & htons(VLAN_PCP_MASK));
1232 case MFF_DL_VLAN_PCP:
1234 return !(value->u8 & ~(VLAN_PCP_MASK >> VLAN_PCP_SHIFT));
1236 case MFF_IPV6_LABEL:
1237 return !(value->be32 & ~htonl(IPV6_LABEL_MASK));
1239 case MFF_MPLS_LABEL:
1240 return !(value->be32 & ~htonl(MPLS_LABEL_MASK >> MPLS_LABEL_SHIFT));
1243 return !(value->u8 & ~(MPLS_TC_MASK >> MPLS_TC_SHIFT));
1246 return !(value->u8 & ~(MPLS_BOS_MASK >> MPLS_BOS_SHIFT));
1254 /* Copies the value of field 'mf' from 'flow' into 'value'. The caller is
1255 * responsible for ensuring that 'flow' meets 'mf''s prerequisites. */
1257 mf_get_value(const struct mf_field *mf, const struct flow *flow,
1258 union mf_value *value)
1262 value->be32 = htonl(flow->dp_hash);
1265 value->be32 = htonl(flow->recirc_id);
1268 value->be64 = flow->tunnel.tun_id;
1271 value->be32 = flow->tunnel.ip_src;
1274 value->be32 = flow->tunnel.ip_dst;
1277 value->be16 = htons(flow->tunnel.flags);
1280 value->u8 = flow->tunnel.ip_ttl;
1283 value->u8 = flow->tunnel.ip_tos;
1287 value->be64 = flow->metadata;
1291 value->be16 = htons(ofp_to_u16(flow->in_port.ofp_port));
1293 case MFF_IN_PORT_OXM:
1294 value->be32 = ofputil_port_to_ofp11(flow->in_port.ofp_port);
1297 case MFF_SKB_PRIORITY:
1298 value->be32 = htonl(flow->skb_priority);
1302 value->be32 = htonl(flow->pkt_mark);
1306 value->be32 = htonl(flow->regs[mf->id - MFF_REG0]);
1310 memcpy(value->mac, flow->dl_src, ETH_ADDR_LEN);
1314 memcpy(value->mac, flow->dl_dst, ETH_ADDR_LEN);
1318 value->be16 = flow->dl_type;
1322 value->be16 = flow->vlan_tci;
1326 value->be16 = flow->vlan_tci & htons(VLAN_VID_MASK);
1329 value->be16 = flow->vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI);
1332 case MFF_DL_VLAN_PCP:
1334 value->u8 = vlan_tci_to_pcp(flow->vlan_tci);
1337 case MFF_MPLS_LABEL:
1338 value->be32 = htonl(mpls_lse_to_label(flow->mpls_lse[0]));
1342 value->u8 = mpls_lse_to_tc(flow->mpls_lse[0]);
1346 value->u8 = mpls_lse_to_bos(flow->mpls_lse[0]);
1350 value->be32 = flow->nw_src;
1354 value->be32 = flow->nw_dst;
1358 value->ipv6 = flow->ipv6_src;
1362 value->ipv6 = flow->ipv6_dst;
1365 case MFF_IPV6_LABEL:
1366 value->be32 = flow->ipv6_label;
1370 value->u8 = flow->nw_proto;
1374 value->u8 = flow->nw_tos & IP_DSCP_MASK;
1377 case MFF_IP_DSCP_SHIFTED:
1378 value->u8 = flow->nw_tos >> 2;
1382 value->u8 = flow->nw_tos & IP_ECN_MASK;
1386 value->u8 = flow->nw_ttl;
1390 value->u8 = flow->nw_frag;
1394 value->be16 = htons(flow->nw_proto);
1398 value->be32 = flow->nw_src;
1402 value->be32 = flow->nw_dst;
1407 memcpy(value->mac, flow->arp_sha, ETH_ADDR_LEN);
1412 memcpy(value->mac, flow->arp_tha, ETH_ADDR_LEN);
1418 value->be16 = flow->tp_src;
1424 value->be16 = flow->tp_dst;
1428 value->be16 = flow->tcp_flags;
1431 case MFF_ICMPV4_TYPE:
1432 case MFF_ICMPV6_TYPE:
1433 value->u8 = ntohs(flow->tp_src);
1436 case MFF_ICMPV4_CODE:
1437 case MFF_ICMPV6_CODE:
1438 value->u8 = ntohs(flow->tp_dst);
1442 value->ipv6 = flow->nd_target;
1451 /* Makes 'match' match field 'mf' exactly, with the value matched taken from
1452 * 'value'. The caller is responsible for ensuring that 'match' meets 'mf''s
1455 mf_set_value(const struct mf_field *mf,
1456 const union mf_value *value, struct match *match)
1460 match_set_dp_hash(match, ntohl(value->be32));
1463 match_set_recirc_id(match, ntohl(value->be32));
1466 match_set_tun_id(match, value->be64);
1469 match_set_tun_src(match, value->be32);
1472 match_set_tun_dst(match, value->be32);
1475 match_set_tun_flags(match, ntohs(value->be16));
1478 match_set_tun_tos(match, value->u8);
1481 match_set_tun_ttl(match, value->u8);
1485 match_set_metadata(match, value->be64);
1489 match_set_in_port(match, u16_to_ofp(ntohs(value->be16)));
1492 case MFF_IN_PORT_OXM: {
1494 ofputil_port_from_ofp11(value->be32, &port);
1495 match_set_in_port(match, port);
1499 case MFF_SKB_PRIORITY:
1500 match_set_skb_priority(match, ntohl(value->be32));
1504 match_set_pkt_mark(match, ntohl(value->be32));
1508 match_set_reg(match, mf->id - MFF_REG0, ntohl(value->be32));
1512 match_set_dl_src(match, value->mac);
1516 match_set_dl_dst(match, value->mac);
1520 match_set_dl_type(match, value->be16);
1524 match_set_dl_tci(match, value->be16);
1528 match_set_dl_vlan(match, value->be16);
1531 match_set_vlan_vid(match, value->be16);
1534 case MFF_DL_VLAN_PCP:
1536 match_set_dl_vlan_pcp(match, value->u8);
1539 case MFF_MPLS_LABEL:
1540 match_set_mpls_label(match, 0, value->be32);
1544 match_set_mpls_tc(match, 0, value->u8);
1548 match_set_mpls_bos(match, 0, value->u8);
1552 match_set_nw_src(match, value->be32);
1556 match_set_nw_dst(match, value->be32);
1560 match_set_ipv6_src(match, &value->ipv6);
1564 match_set_ipv6_dst(match, &value->ipv6);
1567 case MFF_IPV6_LABEL:
1568 match_set_ipv6_label(match, value->be32);
1572 match_set_nw_proto(match, value->u8);
1576 match_set_nw_dscp(match, value->u8);
1579 case MFF_IP_DSCP_SHIFTED:
1580 match_set_nw_dscp(match, value->u8 << 2);
1584 match_set_nw_ecn(match, value->u8);
1588 match_set_nw_ttl(match, value->u8);
1592 match_set_nw_frag(match, value->u8);
1596 match_set_nw_proto(match, ntohs(value->be16));
1600 match_set_nw_src(match, value->be32);
1604 match_set_nw_dst(match, value->be32);
1609 match_set_arp_sha(match, value->mac);
1614 match_set_arp_tha(match, value->mac);
1620 match_set_tp_src(match, value->be16);
1626 match_set_tp_dst(match, value->be16);
1630 match_set_tcp_flags(match, value->be16);
1633 case MFF_ICMPV4_TYPE:
1634 case MFF_ICMPV6_TYPE:
1635 match_set_icmp_type(match, value->u8);
1638 case MFF_ICMPV4_CODE:
1639 case MFF_ICMPV6_CODE:
1640 match_set_icmp_code(match, value->u8);
1644 match_set_nd_target(match, &value->ipv6);
1653 /* Unwildcard 'mask' member field described by 'mf'. The caller is
1654 * responsible for ensuring that 'mask' meets 'mf''s prerequisites. */
1656 mf_mask_field(const struct mf_field *mf, struct flow *mask)
1658 static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
1660 /* For MFF_DL_VLAN, we cannot send a all 1's to flow_set_dl_vlan()
1661 * as that will be considered as OFP10_VLAN_NONE. So consider it as a
1662 * special case. For the rest, calling mf_set_flow_value() is good
1664 if (mf->id == MFF_DL_VLAN) {
1665 flow_set_dl_vlan(mask, htons(VLAN_VID_MASK));
1667 mf_set_flow_value(mf, &exact_match_mask, mask);
1671 /* Sets 'flow' member field described by 'mf' to 'value'. The caller is
1672 * responsible for ensuring that 'flow' meets 'mf''s prerequisites.*/
1674 mf_set_flow_value(const struct mf_field *mf,
1675 const union mf_value *value, struct flow *flow)
1679 flow->dp_hash = ntohl(value->be32);
1682 flow->recirc_id = ntohl(value->be32);
1685 flow->tunnel.tun_id = value->be64;
1688 flow->tunnel.ip_src = value->be32;
1691 flow->tunnel.ip_dst = value->be32;
1694 flow->tunnel.flags = ntohs(value->be16);
1697 flow->tunnel.ip_tos = value->u8;
1700 flow->tunnel.ip_ttl = value->u8;
1704 flow->metadata = value->be64;
1708 flow->in_port.ofp_port = u16_to_ofp(ntohs(value->be16));
1711 case MFF_IN_PORT_OXM: {
1713 ofputil_port_from_ofp11(value->be32, &port);
1714 flow->in_port.ofp_port = port;
1718 case MFF_SKB_PRIORITY:
1719 flow->skb_priority = ntohl(value->be32);
1723 flow->pkt_mark = ntohl(value->be32);
1727 flow->regs[mf->id - MFF_REG0] = ntohl(value->be32);
1731 memcpy(flow->dl_src, value->mac, ETH_ADDR_LEN);
1735 memcpy(flow->dl_dst, value->mac, ETH_ADDR_LEN);
1739 flow->dl_type = value->be16;
1743 flow->vlan_tci = value->be16;
1747 flow_set_dl_vlan(flow, value->be16);
1750 flow_set_vlan_vid(flow, value->be16);
1753 case MFF_DL_VLAN_PCP:
1755 flow_set_vlan_pcp(flow, value->u8);
1758 case MFF_MPLS_LABEL:
1759 flow_set_mpls_label(flow, 0, value->be32);
1763 flow_set_mpls_tc(flow, 0, value->u8);
1767 flow_set_mpls_bos(flow, 0, value->u8);
1771 flow->nw_src = value->be32;
1775 flow->nw_dst = value->be32;
1779 flow->ipv6_src = value->ipv6;
1783 flow->ipv6_dst = value->ipv6;
1786 case MFF_IPV6_LABEL:
1787 flow->ipv6_label = value->be32 & ~htonl(IPV6_LABEL_MASK);
1791 flow->nw_proto = value->u8;
1795 flow->nw_tos &= ~IP_DSCP_MASK;
1796 flow->nw_tos |= value->u8 & IP_DSCP_MASK;
1799 case MFF_IP_DSCP_SHIFTED:
1800 flow->nw_tos &= ~IP_DSCP_MASK;
1801 flow->nw_tos |= value->u8 << 2;
1805 flow->nw_tos &= ~IP_ECN_MASK;
1806 flow->nw_tos |= value->u8 & IP_ECN_MASK;
1810 flow->nw_ttl = value->u8;
1814 flow->nw_frag = value->u8 & FLOW_NW_FRAG_MASK;
1818 flow->nw_proto = ntohs(value->be16);
1822 flow->nw_src = value->be32;
1826 flow->nw_dst = value->be32;
1831 memcpy(flow->arp_sha, value->mac, ETH_ADDR_LEN);
1836 memcpy(flow->arp_tha, value->mac, ETH_ADDR_LEN);
1842 flow->tp_src = value->be16;
1848 flow->tp_dst = value->be16;
1852 flow->tcp_flags = value->be16;
1855 case MFF_ICMPV4_TYPE:
1856 case MFF_ICMPV6_TYPE:
1857 flow->tp_src = htons(value->u8);
1860 case MFF_ICMPV4_CODE:
1861 case MFF_ICMPV6_CODE:
1862 flow->tp_dst = htons(value->u8);
1866 flow->nd_target = value->ipv6;
1875 /* Returns true if 'mf' has a zero value in 'flow', false if it is nonzero.
1877 * The caller is responsible for ensuring that 'flow' meets 'mf''s
1880 mf_is_zero(const struct mf_field *mf, const struct flow *flow)
1882 union mf_value value;
1884 mf_get_value(mf, flow, &value);
1885 return is_all_zeros((const uint8_t *) &value, mf->n_bytes);
1888 /* Makes 'match' wildcard field 'mf'.
1890 * The caller is responsible for ensuring that 'match' meets 'mf''s
1893 mf_set_wild(const struct mf_field *mf, struct match *match)
1897 match->flow.dp_hash = 0;
1898 match->wc.masks.dp_hash = 0;
1901 match->flow.recirc_id = 0;
1902 match->wc.masks.recirc_id = 0;
1905 match_set_tun_id_masked(match, htonll(0), htonll(0));
1908 match_set_tun_src_masked(match, htonl(0), htonl(0));
1911 match_set_tun_dst_masked(match, htonl(0), htonl(0));
1914 match_set_tun_flags_masked(match, 0, 0);
1917 match_set_tun_tos_masked(match, 0, 0);
1920 match_set_tun_ttl_masked(match, 0, 0);
1924 match_set_metadata_masked(match, htonll(0), htonll(0));
1928 case MFF_IN_PORT_OXM:
1929 match->flow.in_port.ofp_port = 0;
1930 match->wc.masks.in_port.ofp_port = 0;
1933 case MFF_SKB_PRIORITY:
1934 match->flow.skb_priority = 0;
1935 match->wc.masks.skb_priority = 0;
1939 match->flow.pkt_mark = 0;
1940 match->wc.masks.pkt_mark = 0;
1944 match_set_reg_masked(match, mf->id - MFF_REG0, 0, 0);
1948 memset(match->flow.dl_src, 0, ETH_ADDR_LEN);
1949 memset(match->wc.masks.dl_src, 0, ETH_ADDR_LEN);
1953 memset(match->flow.dl_dst, 0, ETH_ADDR_LEN);
1954 memset(match->wc.masks.dl_dst, 0, ETH_ADDR_LEN);
1958 match->flow.dl_type = htons(0);
1959 match->wc.masks.dl_type = htons(0);
1963 match_set_dl_tci_masked(match, htons(0), htons(0));
1968 match_set_any_vid(match);
1971 case MFF_DL_VLAN_PCP:
1973 match_set_any_pcp(match);
1976 case MFF_MPLS_LABEL:
1977 match_set_any_mpls_label(match, 0);
1981 match_set_any_mpls_tc(match, 0);
1985 match_set_any_mpls_bos(match, 0);
1990 match_set_nw_src_masked(match, htonl(0), htonl(0));
1995 match_set_nw_dst_masked(match, htonl(0), htonl(0));
1999 memset(&match->wc.masks.ipv6_src, 0, sizeof match->wc.masks.ipv6_src);
2000 memset(&match->flow.ipv6_src, 0, sizeof match->flow.ipv6_src);
2004 memset(&match->wc.masks.ipv6_dst, 0, sizeof match->wc.masks.ipv6_dst);
2005 memset(&match->flow.ipv6_dst, 0, sizeof match->flow.ipv6_dst);
2008 case MFF_IPV6_LABEL:
2009 match->wc.masks.ipv6_label = htonl(0);
2010 match->flow.ipv6_label = htonl(0);
2014 match->wc.masks.nw_proto = 0;
2015 match->flow.nw_proto = 0;
2019 case MFF_IP_DSCP_SHIFTED:
2020 match->wc.masks.nw_tos &= ~IP_DSCP_MASK;
2021 match->flow.nw_tos &= ~IP_DSCP_MASK;
2025 match->wc.masks.nw_tos &= ~IP_ECN_MASK;
2026 match->flow.nw_tos &= ~IP_ECN_MASK;
2030 match->wc.masks.nw_ttl = 0;
2031 match->flow.nw_ttl = 0;
2035 match->wc.masks.nw_frag |= FLOW_NW_FRAG_MASK;
2036 match->flow.nw_frag &= ~FLOW_NW_FRAG_MASK;
2040 match->wc.masks.nw_proto = 0;
2041 match->flow.nw_proto = 0;
2046 memset(match->flow.arp_sha, 0, ETH_ADDR_LEN);
2047 memset(match->wc.masks.arp_sha, 0, ETH_ADDR_LEN);
2052 memset(match->flow.arp_tha, 0, ETH_ADDR_LEN);
2053 memset(match->wc.masks.arp_tha, 0, ETH_ADDR_LEN);
2059 case MFF_ICMPV4_TYPE:
2060 case MFF_ICMPV6_TYPE:
2061 match->wc.masks.tp_src = htons(0);
2062 match->flow.tp_src = htons(0);
2068 case MFF_ICMPV4_CODE:
2069 case MFF_ICMPV6_CODE:
2070 match->wc.masks.tp_dst = htons(0);
2071 match->flow.tp_dst = htons(0);
2075 match->wc.masks.tcp_flags = htons(0);
2076 match->flow.tcp_flags = htons(0);
2080 memset(&match->wc.masks.nd_target, 0,
2081 sizeof match->wc.masks.nd_target);
2082 memset(&match->flow.nd_target, 0, sizeof match->flow.nd_target);
2091 /* Makes 'match' match field 'mf' with the specified 'value' and 'mask'.
2092 * 'value' specifies a value to match and 'mask' specifies a wildcard pattern,
2093 * with a 1-bit indicating that the corresponding value bit must match and a
2094 * 0-bit indicating a don't-care.
2096 * If 'mask' is NULL or points to all-1-bits, then this call is equivalent to
2097 * mf_set_value(mf, value, match). If 'mask' points to all-0-bits, then this
2098 * call is equivalent to mf_set_wild(mf, match).
2100 * 'mask' must be a valid mask for 'mf' (see mf_is_mask_valid()). The caller
2101 * is responsible for ensuring that 'match' meets 'mf''s prerequisites. */
2102 enum ofputil_protocol
2103 mf_set(const struct mf_field *mf,
2104 const union mf_value *value, const union mf_value *mask,
2105 struct match *match)
2107 if (!mask || is_all_ones((const uint8_t *) mask, mf->n_bytes)) {
2108 mf_set_value(mf, value, match);
2109 return mf->usable_protocols;
2110 } else if (is_all_zeros((const uint8_t *) mask, mf->n_bytes)) {
2111 mf_set_wild(mf, match);
2112 return OFPUTIL_P_ANY;
2118 case MFF_IN_PORT_OXM:
2119 case MFF_SKB_PRIORITY:
2122 case MFF_DL_VLAN_PCP:
2124 case MFF_MPLS_LABEL:
2130 case MFF_IP_DSCP_SHIFTED:
2133 case MFF_ICMPV4_TYPE:
2134 case MFF_ICMPV4_CODE:
2135 case MFF_ICMPV6_TYPE:
2136 case MFF_ICMPV6_CODE:
2137 return OFPUTIL_P_NONE;
2140 match_set_dp_hash_masked(match, ntohl(value->be32), ntohl(mask->be32));
2143 match_set_tun_id_masked(match, value->be64, mask->be64);
2146 match_set_tun_src_masked(match, value->be32, mask->be32);
2149 match_set_tun_dst_masked(match, value->be32, mask->be32);
2152 match_set_tun_flags_masked(match, ntohs(value->be16), ntohs(mask->be16));
2155 match_set_tun_ttl_masked(match, value->u8, mask->u8);
2158 match_set_tun_tos_masked(match, value->u8, mask->u8);
2162 match_set_metadata_masked(match, value->be64, mask->be64);
2166 match_set_reg_masked(match, mf->id - MFF_REG0,
2167 ntohl(value->be32), ntohl(mask->be32));
2171 match_set_pkt_mark_masked(match, ntohl(value->be32),
2176 match_set_dl_dst_masked(match, value->mac, mask->mac);
2180 match_set_dl_src_masked(match, value->mac, mask->mac);
2185 match_set_arp_sha_masked(match, value->mac, mask->mac);
2190 match_set_arp_tha_masked(match, value->mac, mask->mac);
2194 match_set_dl_tci_masked(match, value->be16, mask->be16);
2198 match_set_vlan_vid_masked(match, value->be16, mask->be16);
2202 match_set_nw_src_masked(match, value->be32, mask->be32);
2206 match_set_nw_dst_masked(match, value->be32, mask->be32);
2210 match_set_ipv6_src_masked(match, &value->ipv6, &mask->ipv6);
2214 match_set_ipv6_dst_masked(match, &value->ipv6, &mask->ipv6);
2217 case MFF_IPV6_LABEL:
2218 if ((mask->be32 & htonl(IPV6_LABEL_MASK)) == htonl(IPV6_LABEL_MASK)) {
2219 mf_set_value(mf, value, match);
2221 match_set_ipv6_label_masked(match, value->be32, mask->be32);
2226 match_set_nd_target_masked(match, &value->ipv6, &mask->ipv6);
2230 match_set_nw_frag_masked(match, value->u8, mask->u8);
2234 match_set_nw_src_masked(match, value->be32, mask->be32);
2238 match_set_nw_dst_masked(match, value->be32, mask->be32);
2244 match_set_tp_src_masked(match, value->be16, mask->be16);
2250 match_set_tp_dst_masked(match, value->be16, mask->be16);
2254 match_set_tcp_flags_masked(match, value->be16, mask->be16);
2262 return mf->usable_protocols_bitwise;
2265 return ip_is_cidr(mask->be32) ? mf->usable_protocols :
2266 mf->usable_protocols_bitwise;
2270 mf_check__(const struct mf_subfield *sf, const struct flow *flow,
2274 VLOG_WARN_RL(&rl, "unknown %s field", type);
2275 return OFPERR_OFPBAC_BAD_SET_TYPE;
2276 } else if (!sf->n_bits) {
2277 VLOG_WARN_RL(&rl, "zero bit %s field %s", type, sf->field->name);
2278 return OFPERR_OFPBAC_BAD_SET_LEN;
2279 } else if (sf->ofs >= sf->field->n_bits) {
2280 VLOG_WARN_RL(&rl, "bit offset %d exceeds %d-bit width of %s field %s",
2281 sf->ofs, sf->field->n_bits, type, sf->field->name);
2282 return OFPERR_OFPBAC_BAD_SET_LEN;
2283 } else if (sf->ofs + sf->n_bits > sf->field->n_bits) {
2284 VLOG_WARN_RL(&rl, "bit offset %d and width %d exceeds %d-bit width "
2285 "of %s field %s", sf->ofs, sf->n_bits,
2286 sf->field->n_bits, type, sf->field->name);
2287 return OFPERR_OFPBAC_BAD_SET_LEN;
2288 } else if (flow && !mf_are_prereqs_ok(sf->field, flow)) {
2289 VLOG_WARN_RL(&rl, "%s field %s lacks correct prerequisites",
2290 type, sf->field->name);
2291 return OFPERR_OFPBAC_MATCH_INCONSISTENT;
2297 /* Checks whether 'sf' is valid for reading a subfield out of 'flow'. Returns
2298 * 0 if so, otherwise an OpenFlow error code (e.g. as returned by
2301 mf_check_src(const struct mf_subfield *sf, const struct flow *flow)
2303 return mf_check__(sf, flow, "source");
2306 /* Checks whether 'sf' is valid for writing a subfield into 'flow'. Returns 0
2307 * if so, otherwise an OpenFlow error code (e.g. as returned by
2310 mf_check_dst(const struct mf_subfield *sf, const struct flow *flow)
2312 int error = mf_check__(sf, flow, "destination");
2313 if (!error && !sf->field->writable) {
2314 VLOG_WARN_RL(&rl, "destination field %s is not writable",
2316 return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
2321 /* Copies the value and wildcard bit pattern for 'mf' from 'match' into the
2322 * 'value' and 'mask', respectively. */
2324 mf_get(const struct mf_field *mf, const struct match *match,
2325 union mf_value *value, union mf_value *mask)
2327 mf_get_value(mf, &match->flow, value);
2328 mf_get_mask(mf, &match->wc, mask);
2332 mf_from_integer_string(const struct mf_field *mf, const char *s,
2333 uint8_t *valuep, uint8_t *maskp)
2335 unsigned long long int integer, mask;
2340 integer = strtoull(s, &tail, 0);
2341 if (errno || (*tail != '\0' && *tail != '/')) {
2346 mask = strtoull(tail + 1, &tail, 0);
2347 if (errno || *tail != '\0') {
2354 for (i = mf->n_bytes - 1; i >= 0; i--) {
2355 valuep[i] = integer;
2361 return xasprintf("%s: value too large for %u-byte field %s",
2362 s, mf->n_bytes, mf->name);
2367 return xasprintf("%s: bad syntax for %s", s, mf->name);
2371 mf_from_ethernet_string(const struct mf_field *mf, const char *s,
2372 uint8_t mac[ETH_ADDR_LEN],
2373 uint8_t mask[ETH_ADDR_LEN])
2377 ovs_assert(mf->n_bytes == ETH_ADDR_LEN);
2380 if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(mac), &n)
2381 && n == strlen(s)) {
2382 memset(mask, 0xff, ETH_ADDR_LEN);
2387 if (ovs_scan(s, ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT"%n",
2388 ETH_ADDR_SCAN_ARGS(mac), ETH_ADDR_SCAN_ARGS(mask), &n)
2389 && n == strlen(s)) {
2393 return xasprintf("%s: invalid Ethernet address", s);
2397 mf_from_ipv4_string(const struct mf_field *mf, const char *s,
2398 ovs_be32 *ip, ovs_be32 *mask)
2402 ovs_assert(mf->n_bytes == sizeof *ip);
2404 if (ovs_scan(s, IP_SCAN_FMT"/"IP_SCAN_FMT,
2405 IP_SCAN_ARGS(ip), IP_SCAN_ARGS(mask))) {
2407 } else if (ovs_scan(s, IP_SCAN_FMT"/%d", IP_SCAN_ARGS(ip), &prefix)) {
2408 if (prefix <= 0 || prefix > 32) {
2409 return xasprintf("%s: network prefix bits not between 0 and "
2412 *mask = be32_prefix_mask(prefix);
2413 } else if (ovs_scan(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip))) {
2414 *mask = OVS_BE32_MAX;
2416 return xasprintf("%s: invalid IP address", s);
2422 mf_from_ipv6_string(const struct mf_field *mf, const char *s,
2423 struct in6_addr *value, struct in6_addr *mask)
2425 char *str = xstrdup(s);
2426 char *save_ptr = NULL;
2427 const char *name, *netmask;
2430 ovs_assert(mf->n_bytes == sizeof *value);
2432 name = strtok_r(str, "/", &save_ptr);
2433 retval = name ? lookup_ipv6(name, value) : EINVAL;
2437 err = xasprintf("%s: could not convert to IPv6 address", str);
2443 netmask = strtok_r(NULL, "/", &save_ptr);
2445 if (inet_pton(AF_INET6, netmask, mask) != 1) {
2446 int prefix = atoi(netmask);
2447 if (prefix <= 0 || prefix > 128) {
2449 return xasprintf("%s: prefix bits not between 1 and 128", s);
2451 *mask = ipv6_create_mask(prefix);
2455 *mask = in6addr_exact;
2463 mf_from_ofp_port_string(const struct mf_field *mf, const char *s,
2464 ovs_be16 *valuep, ovs_be16 *maskp)
2468 ovs_assert(mf->n_bytes == sizeof(ovs_be16));
2470 if (ofputil_port_from_string(s, &port)) {
2471 *valuep = htons(ofp_to_u16(port));
2472 *maskp = OVS_BE16_MAX;
2475 return xasprintf("%s: port value out of range for %s", s, mf->name);
2479 mf_from_ofp_port_string32(const struct mf_field *mf, const char *s,
2480 ovs_be32 *valuep, ovs_be32 *maskp)
2484 ovs_assert(mf->n_bytes == sizeof(ovs_be32));
2485 if (ofputil_port_from_string(s, &port)) {
2486 *valuep = ofputil_port_to_ofp11(port);
2487 *maskp = OVS_BE32_MAX;
2490 return xasprintf("%s: port value out of range for %s", s, mf->name);
2493 struct frag_handling {
2499 static const struct frag_handling all_frags[] = {
2500 #define A FLOW_NW_FRAG_ANY
2501 #define L FLOW_NW_FRAG_LATER
2502 /* name mask value */
2505 { "first", A|L, A },
2506 { "later", A|L, A|L },
2511 { "not_later", L, 0 },
2518 mf_from_frag_string(const char *s, uint8_t *valuep, uint8_t *maskp)
2520 const struct frag_handling *h;
2522 for (h = all_frags; h < &all_frags[ARRAY_SIZE(all_frags)]; h++) {
2523 if (!strcasecmp(s, h->name)) {
2524 /* We force the upper bits of the mask on to make mf_parse_value()
2525 * happy (otherwise it will never think it's an exact match.) */
2526 *maskp = h->mask | ~FLOW_NW_FRAG_MASK;
2532 return xasprintf("%s: unknown fragment type (valid types are \"no\", "
2533 "\"yes\", \"first\", \"later\", \"not_first\"", s);
2537 parse_flow_tun_flags(const char *s_, const char *(*bit_to_string)(uint32_t),
2540 uint32_t result = 0;
2541 char *save_ptr = NULL;
2544 char *s = xstrdup(s_);
2546 for (name = strtok_r((char *)s, " |", &save_ptr); name;
2547 name = strtok_r(NULL, " |", &save_ptr)) {
2549 unsigned long long int flags;
2552 if (ovs_scan(name, "%lli", &flags)) {
2556 name_len = strlen(name);
2557 for (bit = 1; bit; bit <<= 1) {
2558 const char *fname = bit_to_string(bit);
2565 len = strlen(fname);
2566 if (len != name_len) {
2569 if (!strncmp(name, fname, len)) {
2581 *res = htons(result);
2588 mf_from_tun_flags_string(const char *s, ovs_be16 *valuep, ovs_be16 *maskp)
2590 if (!parse_flow_tun_flags(s, flow_tun_flag_to_string, valuep)) {
2591 *maskp = OVS_BE16_MAX;
2595 return xasprintf("%s: unknown tunnel flags (valid flags are \"df\", "
2596 "\"csum\", \"key\")", s);
2600 mf_from_tcp_flags_string(const char *s, ovs_be16 *flagsp, ovs_be16 *maskp)
2607 if (ovs_scan(s, "%"SCNi16"/%"SCNi16"%n", &flags, &mask, &n) && !s[n]) {
2608 *flagsp = htons(flags);
2609 *maskp = htons(mask);
2612 if (ovs_scan(s, "%"SCNi16"%n", &flags, &n) && !s[n]) {
2613 *flagsp = htons(flags);
2614 *maskp = OVS_BE16_MAX;
2618 while (*s != '\0') {
2630 return xasprintf("%s: TCP flag must be preceded by '+' (for SET) "
2631 "or '-' (NOT SET)", s);
2635 name_len = strcspn(s,"+-");
2637 for (bit = 1; bit; bit <<= 1) {
2638 const char *fname = packet_tcp_flag_to_string(bit);
2645 len = strlen(fname);
2646 if (len != name_len) {
2649 if (!strncmp(s, fname, len)) {
2651 return xasprintf("%s: Each TCP flag can be specified only "
2663 return xasprintf("%s: unknown TCP flag(s)", s);
2668 *flagsp = htons(flags);
2669 *maskp = htons(mask);
2674 /* Parses 's', a string value for field 'mf', into 'value' and 'mask'. Returns
2675 * NULL if successful, otherwise a malloc()'d string describing the error. */
2677 mf_parse(const struct mf_field *mf, const char *s,
2678 union mf_value *value, union mf_value *mask)
2682 if (!strcmp(s, "*")) {
2683 memset(value, 0, mf->n_bytes);
2684 memset(mask, 0, mf->n_bytes);
2688 switch (mf->string) {
2690 case MFS_HEXADECIMAL:
2691 error = mf_from_integer_string(mf, s,
2692 (uint8_t *) value, (uint8_t *) mask);
2696 error = mf_from_ethernet_string(mf, s, value->mac, mask->mac);
2700 error = mf_from_ipv4_string(mf, s, &value->be32, &mask->be32);
2704 error = mf_from_ipv6_string(mf, s, &value->ipv6, &mask->ipv6);
2708 error = mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16);
2711 case MFS_OFP_PORT_OXM:
2712 error = mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32);
2716 error = mf_from_frag_string(s, &value->u8, &mask->u8);
2720 ovs_assert(mf->n_bytes == sizeof(ovs_be16));
2721 error = mf_from_tun_flags_string(s, &value->be16, &mask->be16);
2725 ovs_assert(mf->n_bytes == sizeof(ovs_be16));
2726 error = mf_from_tcp_flags_string(s, &value->be16, &mask->be16);
2733 if (!error && !mf_is_mask_valid(mf, mask)) {
2734 error = xasprintf("%s: invalid mask for field %s", s, mf->name);
2739 /* Parses 's', a string value for field 'mf', into 'value'. Returns NULL if
2740 * successful, otherwise a malloc()'d string describing the error. */
2742 mf_parse_value(const struct mf_field *mf, const char *s, union mf_value *value)
2744 union mf_value mask;
2747 error = mf_parse(mf, s, value, &mask);
2752 if (!is_all_ones((const uint8_t *) &mask, mf->n_bytes)) {
2753 return xasprintf("%s: wildcards not allowed here", s);
2759 mf_format_integer_string(const struct mf_field *mf, const uint8_t *valuep,
2760 const uint8_t *maskp, struct ds *s)
2762 unsigned long long int integer;
2765 ovs_assert(mf->n_bytes <= 8);
2768 for (i = 0; i < mf->n_bytes; i++) {
2769 integer = (integer << 8) | valuep[i];
2771 if (mf->string == MFS_HEXADECIMAL) {
2772 ds_put_format(s, "%#llx", integer);
2774 ds_put_format(s, "%lld", integer);
2778 unsigned long long int mask;
2781 for (i = 0; i < mf->n_bytes; i++) {
2782 mask = (mask << 8) | maskp[i];
2785 /* I guess we could write the mask in decimal for MFS_DECIMAL but I'm
2786 * not sure that that a bit-mask written in decimal is ever easier to
2787 * understand than the same bit-mask written in hexadecimal. */
2788 ds_put_format(s, "/%#llx", mask);
2793 mf_format_frag_string(uint8_t value, uint8_t mask, struct ds *s)
2795 const struct frag_handling *h;
2797 mask &= FLOW_NW_FRAG_MASK;
2800 for (h = all_frags; h < &all_frags[ARRAY_SIZE(all_frags)]; h++) {
2801 if (value == h->value && mask == h->mask) {
2802 ds_put_cstr(s, h->name);
2806 ds_put_cstr(s, "<error>");
2810 mf_format_tnl_flags_string(const ovs_be16 *valuep, struct ds *s)
2812 format_flags(s, flow_tun_flag_to_string, ntohs(*valuep), '|');
2816 mf_format_tcp_flags_string(ovs_be16 value, ovs_be16 mask, struct ds *s)
2818 format_flags_masked(s, NULL, packet_tcp_flag_to_string, ntohs(value),
2822 /* Appends to 's' a string representation of field 'mf' whose value is in
2823 * 'value' and 'mask'. 'mask' may be NULL to indicate an exact match. */
2825 mf_format(const struct mf_field *mf,
2826 const union mf_value *value, const union mf_value *mask,
2830 if (is_all_zeros((const uint8_t *) mask, mf->n_bytes)) {
2831 ds_put_cstr(s, "ANY");
2833 } else if (is_all_ones((const uint8_t *) mask, mf->n_bytes)) {
2838 switch (mf->string) {
2839 case MFS_OFP_PORT_OXM:
2842 ofputil_port_from_ofp11(value->be32, &port);
2843 ofputil_format_port(port, s);
2849 ofputil_format_port(u16_to_ofp(ntohs(value->be16)), s);
2854 case MFS_HEXADECIMAL:
2855 mf_format_integer_string(mf, (uint8_t *) value, (uint8_t *) mask, s);
2859 eth_format_masked(value->mac, mask->mac, s);
2863 ip_format_masked(value->be32, mask ? mask->be32 : OVS_BE32_MAX, s);
2867 print_ipv6_masked(s, &value->ipv6, mask ? &mask->ipv6 : NULL);
2871 mf_format_frag_string(value->u8, mask ? mask->u8 : UINT8_MAX, s);
2875 mf_format_tnl_flags_string(&value->be16, s);
2879 mf_format_tcp_flags_string(value->be16,
2880 mask ? mask->be16 : OVS_BE16_MAX, s);
2888 /* Makes subfield 'sf' within 'flow' exactly match the 'sf->n_bits'
2889 * least-significant bits in 'x'.
2892 mf_write_subfield_flow(const struct mf_subfield *sf,
2893 const union mf_subvalue *x, struct flow *flow)
2895 const struct mf_field *field = sf->field;
2896 union mf_value value;
2898 mf_get_value(field, flow, &value);
2899 bitwise_copy(x, sizeof *x, 0, &value, field->n_bytes,
2900 sf->ofs, sf->n_bits);
2901 mf_set_flow_value(field, &value, flow);
2904 /* Makes subfield 'sf' within 'match' exactly match the 'sf->n_bits'
2905 * least-significant bits in 'x'.
2908 mf_write_subfield(const struct mf_subfield *sf, const union mf_subvalue *x,
2909 struct match *match)
2911 const struct mf_field *field = sf->field;
2912 union mf_value value, mask;
2914 mf_get(field, match, &value, &mask);
2915 bitwise_copy(x, sizeof *x, 0, &value, field->n_bytes, sf->ofs, sf->n_bits);
2916 bitwise_one ( &mask, field->n_bytes, sf->ofs, sf->n_bits);
2917 mf_set(field, &value, &mask, match);
2920 /* Initializes 'x' to the value of 'sf' within 'flow'. 'sf' must be valid for
2921 * reading 'flow', e.g. as checked by mf_check_src(). */
2923 mf_read_subfield(const struct mf_subfield *sf, const struct flow *flow,
2924 union mf_subvalue *x)
2926 union mf_value value;
2928 mf_get_value(sf->field, flow, &value);
2930 memset(x, 0, sizeof *x);
2931 bitwise_copy(&value, sf->field->n_bytes, sf->ofs,
2936 /* Returns the value of 'sf' within 'flow'. 'sf' must be valid for reading
2937 * 'flow', e.g. as checked by mf_check_src() and sf->n_bits must be 64 or
2940 mf_get_subfield(const struct mf_subfield *sf, const struct flow *flow)
2942 union mf_value value;
2944 mf_get_value(sf->field, flow, &value);
2945 return bitwise_get(&value, sf->field->n_bytes, sf->ofs, sf->n_bits);
2948 /* Formats 'sf' into 's' in a format normally acceptable to
2949 * mf_parse_subfield(). (It won't be acceptable if sf->field is NULL or if
2950 * sf->field has no NXM name.) */
2952 mf_format_subfield(const struct mf_subfield *sf, struct ds *s)
2955 ds_put_cstr(s, "<unknown>");
2956 } else if (sf->field->nxm_name) {
2957 ds_put_cstr(s, sf->field->nxm_name);
2958 } else if (sf->field->nxm_header) {
2959 uint32_t header = sf->field->nxm_header;
2960 ds_put_format(s, "%d:%d", NXM_VENDOR(header), NXM_FIELD(header));
2962 ds_put_cstr(s, sf->field->name);
2965 if (sf->field && sf->ofs == 0 && sf->n_bits == sf->field->n_bits) {
2966 ds_put_cstr(s, "[]");
2967 } else if (sf->n_bits == 1) {
2968 ds_put_format(s, "[%d]", sf->ofs);
2970 ds_put_format(s, "[%d..%d]", sf->ofs, sf->ofs + sf->n_bits - 1);
2974 static const struct mf_field *
2975 mf_parse_subfield_name(const char *name, int name_len, bool *wild)
2979 *wild = name_len > 2 && !memcmp(&name[name_len - 2], "_W", 2);
2984 for (i = 0; i < MFF_N_IDS; i++) {
2985 const struct mf_field *mf = mf_from_id(i);
2988 && !strncmp(mf->nxm_name, name, name_len)
2989 && mf->nxm_name[name_len] == '\0') {
2993 && !strncmp(mf->oxm_name, name, name_len)
2994 && mf->oxm_name[name_len] == '\0') {
3002 /* Parses a subfield from the beginning of '*sp' into 'sf'. If successful,
3003 * returns NULL and advances '*sp' to the first byte following the parsed
3004 * string. On failure, returns a malloc()'d error message, does not modify
3005 * '*sp', and does not properly initialize 'sf'.
3007 * The syntax parsed from '*sp' takes the form "header[start..end]" where
3008 * 'header' is the name of an NXM field and 'start' and 'end' are (inclusive)
3009 * bit indexes. "..end" may be omitted to indicate a single bit. "start..end"
3010 * may both be omitted (the [] are still required) to indicate an entire
3012 char * WARN_UNUSED_RESULT
3013 mf_parse_subfield__(struct mf_subfield *sf, const char **sp)
3015 const struct mf_field *field;
3024 name_len = strcspn(s, "[");
3025 if (s[name_len] != '[') {
3026 return xasprintf("%s: missing [ looking for field name", *sp);
3029 field = mf_parse_subfield_name(name, name_len, &wild);
3031 return xasprintf("%s: unknown field `%.*s'", *sp, name_len, s);
3035 if (ovs_scan(s, "[%d..%d]", &start, &end)) {
3036 /* Nothing to do. */
3037 } else if (ovs_scan(s, "[%d]", &start)) {
3039 } else if (!strncmp(s, "[]", 2)) {
3041 end = field->n_bits - 1;
3043 return xasprintf("%s: syntax error expecting [] or [<bit>] or "
3044 "[<start>..<end>]", *sp);
3046 s = strchr(s, ']') + 1;
3049 return xasprintf("%s: starting bit %d is after ending bit %d",
3051 } else if (start >= field->n_bits) {
3052 return xasprintf("%s: starting bit %d is not valid because field is "
3053 "only %d bits wide", *sp, start, field->n_bits);
3054 } else if (end >= field->n_bits){
3055 return xasprintf("%s: ending bit %d is not valid because field is "
3056 "only %d bits wide", *sp, end, field->n_bits);
3061 sf->n_bits = end - start + 1;
3067 /* Parses a subfield from the entirety of 's' into 'sf'. Returns NULL if
3068 * successful, otherwise a malloc()'d string describing the error. The caller
3069 * is responsible for freeing the returned string.
3071 * The syntax parsed from 's' takes the form "header[start..end]" where
3072 * 'header' is the name of an NXM field and 'start' and 'end' are (inclusive)
3073 * bit indexes. "..end" may be omitted to indicate a single bit. "start..end"
3074 * may both be omitted (the [] are still required) to indicate an entire
3076 char * WARN_UNUSED_RESULT
3077 mf_parse_subfield(struct mf_subfield *sf, const char *s)
3079 char *error = mf_parse_subfield__(sf, &s);
3080 if (!error && s[0]) {
3081 error = xstrdup("unexpected input following field syntax");
3087 mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s)
3091 for (i = 0; i < ARRAY_SIZE(subvalue->u8); i++) {
3092 if (subvalue->u8[i]) {
3093 ds_put_format(s, "0x%"PRIx8, subvalue->u8[i]);
3094 for (i++; i < ARRAY_SIZE(subvalue->u8); i++) {
3095 ds_put_format(s, "%02"PRIx8, subvalue->u8[i]);
3100 ds_put_char(s, '0');