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"
29 #include "ofp-errors.h"
31 #include "ovs-thread.h"
35 #include "socket-util.h"
36 #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] = {
51 #include "meta-flow.inc"
54 /* Maps from an mf_field's 'name' or 'extra_name' to the mf_field. */
55 static struct shash mf_by_name;
57 /* Rate limit for parse errors. These always indicate a bug in an OpenFlow
58 * controller and so there's not much point in showing a lot of them. */
59 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
61 static void nxm_init(void);
63 /* Returns the field with the given 'name', or a null pointer if no field has
65 const struct mf_field *
66 mf_from_name(const char *name)
69 return shash_find_data(&mf_by_name, name);
77 shash_init(&mf_by_name);
78 for (i = 0; i < MFF_N_IDS; i++) {
79 const struct mf_field *mf = &mf_fields[i];
81 ovs_assert(mf->id == i); /* Fields must be in the enum order. */
83 shash_add_once(&mf_by_name, mf->name, mf);
85 shash_add_once(&mf_by_name, mf->extra_name, mf);
93 static pthread_once_t once = PTHREAD_ONCE_INIT;
94 pthread_once(&once, nxm_do_init);
97 /* Returns true if 'wc' wildcards all the bits in field 'mf', false if 'wc'
98 * specifies at least one bit in the field.
100 * The caller is responsible for ensuring that 'wc' corresponds to a flow that
101 * meets 'mf''s prerequisites. */
103 mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
107 return !wc->masks.dp_hash;
109 return !wc->masks.recirc_id;
111 return !wc->masks.tunnel.ip_src;
113 return !wc->masks.tunnel.ip_dst;
118 return !wc->masks.tunnel.tun_id;
120 return !wc->masks.metadata;
122 case MFF_IN_PORT_OXM:
123 return !wc->masks.in_port.ofp_port;
124 case MFF_SKB_PRIORITY:
125 return !wc->masks.skb_priority;
127 return !wc->masks.pkt_mark;
129 return !wc->masks.regs[mf->id - MFF_REG0];
131 return !flow_get_xreg(&wc->masks, mf->id - MFF_XREG0);
134 return eth_addr_is_zero(wc->masks.dl_src);
136 return eth_addr_is_zero(wc->masks.dl_dst);
138 return !wc->masks.dl_type;
142 return eth_addr_is_zero(wc->masks.arp_sha);
146 return eth_addr_is_zero(wc->masks.arp_tha);
149 return !wc->masks.vlan_tci;
151 return !(wc->masks.vlan_tci & htons(VLAN_VID_MASK));
153 return !(wc->masks.vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI));
154 case MFF_DL_VLAN_PCP:
156 return !(wc->masks.vlan_tci & htons(VLAN_PCP_MASK));
159 return !(wc->masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK));
161 return !(wc->masks.mpls_lse[0] & htonl(MPLS_TC_MASK));
163 return !(wc->masks.mpls_lse[0] & htonl(MPLS_BOS_MASK));
166 return !wc->masks.nw_src;
168 return !wc->masks.nw_dst;
171 return ipv6_mask_is_any(&wc->masks.ipv6_src);
173 return ipv6_mask_is_any(&wc->masks.ipv6_dst);
176 return !wc->masks.ipv6_label;
179 return !wc->masks.nw_proto;
181 case MFF_IP_DSCP_SHIFTED:
182 return !(wc->masks.nw_tos & IP_DSCP_MASK);
184 return !(wc->masks.nw_tos & IP_ECN_MASK);
186 return !wc->masks.nw_ttl;
189 return ipv6_mask_is_any(&wc->masks.nd_target);
192 return !(wc->masks.nw_frag & FLOW_NW_FRAG_MASK);
195 return !wc->masks.nw_proto;
197 return !wc->masks.nw_src;
199 return !wc->masks.nw_dst;
204 case MFF_ICMPV4_TYPE:
205 case MFF_ICMPV6_TYPE:
206 return !wc->masks.tp_src;
210 case MFF_ICMPV4_CODE:
211 case MFF_ICMPV6_CODE:
212 return !wc->masks.tp_dst;
214 return !wc->masks.tcp_flags;
222 /* Initializes 'mask' with the wildcard bit pattern for field 'mf' within 'wc'.
223 * Each bit in 'mask' will be set to 1 if the bit is significant for matching
224 * purposes, or to 0 if it is wildcarded.
226 * The caller is responsible for ensuring that 'wc' corresponds to a flow that
227 * meets 'mf''s prerequisites. */
229 mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc,
230 union mf_value *mask)
232 mf_get_value(mf, &wc->masks, mask);
235 /* Tests whether 'mask' is a valid wildcard bit pattern for 'mf'. Returns true
236 * if the mask is valid, false otherwise. */
238 mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask)
240 switch (mf->maskable) {
242 return (is_all_zeros(mask, mf->n_bytes) ||
243 is_all_ones(mask, mf->n_bytes));
252 /* Returns true if 'flow' meets the prerequisites for 'mf', false otherwise. */
254 mf_are_prereqs_ok(const struct mf_field *mf, const struct flow *flow)
256 switch (mf->prereqs) {
261 return (flow->dl_type == htons(ETH_TYPE_ARP) ||
262 flow->dl_type == htons(ETH_TYPE_RARP));
264 return flow->dl_type == htons(ETH_TYPE_IP);
266 return flow->dl_type == htons(ETH_TYPE_IPV6);
268 return (flow->vlan_tci & htons(VLAN_CFI)) != 0;
270 return eth_type_mpls(flow->dl_type);
272 return is_ip_any(flow);
275 return is_ip_any(flow) && flow->nw_proto == IPPROTO_TCP;
277 return is_ip_any(flow) && flow->nw_proto == IPPROTO_UDP;
279 return is_ip_any(flow) && flow->nw_proto == IPPROTO_SCTP;
281 return is_icmpv4(flow);
283 return is_icmpv6(flow);
286 return (is_icmpv6(flow)
287 && flow->tp_dst == htons(0)
288 && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
289 flow->tp_src == htons(ND_NEIGHBOR_ADVERT)));
291 return (is_icmpv6(flow)
292 && flow->tp_dst == htons(0)
293 && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)));
295 return (is_icmpv6(flow)
296 && flow->tp_dst == htons(0)
297 && (flow->tp_src == htons(ND_NEIGHBOR_ADVERT)));
303 /* Set field and it's prerequisities in the mask.
304 * This is only ever called for writeable 'mf's, but we do not make the
305 * distinction here. */
307 mf_mask_field_and_prereqs(const struct mf_field *mf, struct flow *mask)
309 static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
311 mf_set_flow_value(mf, &exact_match_mask, mask);
313 switch (mf->prereqs) {
317 mask->tp_src = OVS_BE16_MAX;
318 mask->tp_dst = OVS_BE16_MAX;
325 mask->nw_proto = 0xff;
332 mask->dl_type = OVS_BE16_MAX;
335 mask->vlan_tci |= htons(VLAN_CFI);
343 /* Returns true if 'value' may be a valid value *as part of a masked match*,
346 * A value is not rejected just because it is not valid for the field in
347 * question, but only if it doesn't make sense to test the bits in question at
348 * all. For example, the MFF_VLAN_TCI field will never have a nonzero value
349 * without the VLAN_CFI bit being set, but we can't reject those values because
350 * it is still legitimate to test just for those bits (see the documentation
351 * for NXM_OF_VLAN_TCI in nicira-ext.h). On the other hand, there is never a
352 * reason to set the low bit of MFF_IP_DSCP to 1, so we reject that. */
354 mf_is_value_valid(const struct mf_field *mf, const union mf_value *value)
367 case MFF_SKB_PRIORITY:
391 case MFF_ICMPV4_TYPE:
392 case MFF_ICMPV4_CODE:
393 case MFF_ICMPV6_TYPE:
394 case MFF_ICMPV6_CODE:
400 case MFF_IN_PORT_OXM: {
402 return !ofputil_port_from_ofp11(value->be32, &port);
406 return !(value->u8 & ~IP_DSCP_MASK);
407 case MFF_IP_DSCP_SHIFTED:
408 return !(value->u8 & (~IP_DSCP_MASK >> 2));
410 return !(value->u8 & ~IP_ECN_MASK);
412 return !(value->u8 & ~FLOW_NW_FRAG_MASK);
414 return !(value->be16 & ~htons(0x0fff));
417 return !(value->be16 & htons(0xff00));
420 return !(value->be16 & htons(VLAN_CFI | VLAN_PCP_MASK));
422 return !(value->be16 & htons(VLAN_PCP_MASK));
424 case MFF_DL_VLAN_PCP:
426 return !(value->u8 & ~(VLAN_PCP_MASK >> VLAN_PCP_SHIFT));
429 return !(value->be32 & ~htonl(IPV6_LABEL_MASK));
432 return !(value->be32 & ~htonl(MPLS_LABEL_MASK >> MPLS_LABEL_SHIFT));
435 return !(value->u8 & ~(MPLS_TC_MASK >> MPLS_TC_SHIFT));
438 return !(value->u8 & ~(MPLS_BOS_MASK >> MPLS_BOS_SHIFT));
446 /* Copies the value of field 'mf' from 'flow' into 'value'. The caller is
447 * responsible for ensuring that 'flow' meets 'mf''s prerequisites. */
449 mf_get_value(const struct mf_field *mf, const struct flow *flow,
450 union mf_value *value)
454 value->be32 = htonl(flow->dp_hash);
457 value->be32 = htonl(flow->recirc_id);
460 value->be64 = flow->tunnel.tun_id;
463 value->be32 = flow->tunnel.ip_src;
466 value->be32 = flow->tunnel.ip_dst;
469 value->be16 = htons(flow->tunnel.flags);
472 value->u8 = flow->tunnel.ip_ttl;
475 value->u8 = flow->tunnel.ip_tos;
479 value->be64 = flow->metadata;
483 value->be16 = htons(ofp_to_u16(flow->in_port.ofp_port));
485 case MFF_IN_PORT_OXM:
486 value->be32 = ofputil_port_to_ofp11(flow->in_port.ofp_port);
489 case MFF_SKB_PRIORITY:
490 value->be32 = htonl(flow->skb_priority);
494 value->be32 = htonl(flow->pkt_mark);
498 value->be32 = htonl(flow->regs[mf->id - MFF_REG0]);
502 value->be64 = htonll(flow_get_xreg(flow, mf->id - MFF_XREG0));
506 memcpy(value->mac, flow->dl_src, ETH_ADDR_LEN);
510 memcpy(value->mac, flow->dl_dst, ETH_ADDR_LEN);
514 value->be16 = flow->dl_type;
518 value->be16 = flow->vlan_tci;
522 value->be16 = flow->vlan_tci & htons(VLAN_VID_MASK);
525 value->be16 = flow->vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI);
528 case MFF_DL_VLAN_PCP:
530 value->u8 = vlan_tci_to_pcp(flow->vlan_tci);
534 value->be32 = htonl(mpls_lse_to_label(flow->mpls_lse[0]));
538 value->u8 = mpls_lse_to_tc(flow->mpls_lse[0]);
542 value->u8 = mpls_lse_to_bos(flow->mpls_lse[0]);
546 value->be32 = flow->nw_src;
550 value->be32 = flow->nw_dst;
554 value->ipv6 = flow->ipv6_src;
558 value->ipv6 = flow->ipv6_dst;
562 value->be32 = flow->ipv6_label;
566 value->u8 = flow->nw_proto;
570 value->u8 = flow->nw_tos & IP_DSCP_MASK;
573 case MFF_IP_DSCP_SHIFTED:
574 value->u8 = flow->nw_tos >> 2;
578 value->u8 = flow->nw_tos & IP_ECN_MASK;
582 value->u8 = flow->nw_ttl;
586 value->u8 = flow->nw_frag;
590 value->be16 = htons(flow->nw_proto);
594 value->be32 = flow->nw_src;
598 value->be32 = flow->nw_dst;
603 memcpy(value->mac, flow->arp_sha, ETH_ADDR_LEN);
608 memcpy(value->mac, flow->arp_tha, ETH_ADDR_LEN);
614 value->be16 = flow->tp_src;
620 value->be16 = flow->tp_dst;
624 value->be16 = flow->tcp_flags;
627 case MFF_ICMPV4_TYPE:
628 case MFF_ICMPV6_TYPE:
629 value->u8 = ntohs(flow->tp_src);
632 case MFF_ICMPV4_CODE:
633 case MFF_ICMPV6_CODE:
634 value->u8 = ntohs(flow->tp_dst);
638 value->ipv6 = flow->nd_target;
647 /* Makes 'match' match field 'mf' exactly, with the value matched taken from
648 * 'value'. The caller is responsible for ensuring that 'match' meets 'mf''s
651 mf_set_value(const struct mf_field *mf,
652 const union mf_value *value, struct match *match)
656 match_set_dp_hash(match, ntohl(value->be32));
659 match_set_recirc_id(match, ntohl(value->be32));
662 match_set_tun_id(match, value->be64);
665 match_set_tun_src(match, value->be32);
668 match_set_tun_dst(match, value->be32);
671 match_set_tun_flags(match, ntohs(value->be16));
674 match_set_tun_tos(match, value->u8);
677 match_set_tun_ttl(match, value->u8);
681 match_set_metadata(match, value->be64);
685 match_set_in_port(match, u16_to_ofp(ntohs(value->be16)));
688 case MFF_IN_PORT_OXM: {
690 ofputil_port_from_ofp11(value->be32, &port);
691 match_set_in_port(match, port);
695 case MFF_SKB_PRIORITY:
696 match_set_skb_priority(match, ntohl(value->be32));
700 match_set_pkt_mark(match, ntohl(value->be32));
704 match_set_reg(match, mf->id - MFF_REG0, ntohl(value->be32));
708 match_set_xreg(match, mf->id - MFF_XREG0, ntohll(value->be64));
712 match_set_dl_src(match, value->mac);
716 match_set_dl_dst(match, value->mac);
720 match_set_dl_type(match, value->be16);
724 match_set_dl_tci(match, value->be16);
728 match_set_dl_vlan(match, value->be16);
731 match_set_vlan_vid(match, value->be16);
734 case MFF_DL_VLAN_PCP:
736 match_set_dl_vlan_pcp(match, value->u8);
740 match_set_mpls_label(match, 0, value->be32);
744 match_set_mpls_tc(match, 0, value->u8);
748 match_set_mpls_bos(match, 0, value->u8);
752 match_set_nw_src(match, value->be32);
756 match_set_nw_dst(match, value->be32);
760 match_set_ipv6_src(match, &value->ipv6);
764 match_set_ipv6_dst(match, &value->ipv6);
768 match_set_ipv6_label(match, value->be32);
772 match_set_nw_proto(match, value->u8);
776 match_set_nw_dscp(match, value->u8);
779 case MFF_IP_DSCP_SHIFTED:
780 match_set_nw_dscp(match, value->u8 << 2);
784 match_set_nw_ecn(match, value->u8);
788 match_set_nw_ttl(match, value->u8);
792 match_set_nw_frag(match, value->u8);
796 match_set_nw_proto(match, ntohs(value->be16));
800 match_set_nw_src(match, value->be32);
804 match_set_nw_dst(match, value->be32);
809 match_set_arp_sha(match, value->mac);
814 match_set_arp_tha(match, value->mac);
820 match_set_tp_src(match, value->be16);
826 match_set_tp_dst(match, value->be16);
830 match_set_tcp_flags(match, value->be16);
833 case MFF_ICMPV4_TYPE:
834 case MFF_ICMPV6_TYPE:
835 match_set_icmp_type(match, value->u8);
838 case MFF_ICMPV4_CODE:
839 case MFF_ICMPV6_CODE:
840 match_set_icmp_code(match, value->u8);
844 match_set_nd_target(match, &value->ipv6);
853 /* Unwildcard 'mask' member field described by 'mf'. The caller is
854 * responsible for ensuring that 'mask' meets 'mf''s prerequisites. */
856 mf_mask_field(const struct mf_field *mf, struct flow *mask)
858 static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
860 /* For MFF_DL_VLAN, we cannot send a all 1's to flow_set_dl_vlan()
861 * as that will be considered as OFP10_VLAN_NONE. So consider it as a
862 * special case. For the rest, calling mf_set_flow_value() is good
864 if (mf->id == MFF_DL_VLAN) {
865 flow_set_dl_vlan(mask, htons(VLAN_VID_MASK));
867 mf_set_flow_value(mf, &exact_match_mask, mask);
871 /* Sets 'flow' member field described by 'mf' to 'value'. The caller is
872 * responsible for ensuring that 'flow' meets 'mf''s prerequisites.*/
874 mf_set_flow_value(const struct mf_field *mf,
875 const union mf_value *value, struct flow *flow)
879 flow->dp_hash = ntohl(value->be32);
882 flow->recirc_id = ntohl(value->be32);
885 flow->tunnel.tun_id = value->be64;
888 flow->tunnel.ip_src = value->be32;
891 flow->tunnel.ip_dst = value->be32;
894 flow->tunnel.flags = ntohs(value->be16);
897 flow->tunnel.ip_tos = value->u8;
900 flow->tunnel.ip_ttl = value->u8;
904 flow->metadata = value->be64;
908 flow->in_port.ofp_port = u16_to_ofp(ntohs(value->be16));
911 case MFF_IN_PORT_OXM: {
913 ofputil_port_from_ofp11(value->be32, &port);
914 flow->in_port.ofp_port = port;
918 case MFF_SKB_PRIORITY:
919 flow->skb_priority = ntohl(value->be32);
923 flow->pkt_mark = ntohl(value->be32);
927 flow->regs[mf->id - MFF_REG0] = ntohl(value->be32);
931 flow_set_xreg(flow, mf->id - MFF_XREG0, ntohll(value->be64));
935 memcpy(flow->dl_src, value->mac, ETH_ADDR_LEN);
939 memcpy(flow->dl_dst, value->mac, ETH_ADDR_LEN);
943 flow->dl_type = value->be16;
947 flow->vlan_tci = value->be16;
951 flow_set_dl_vlan(flow, value->be16);
954 flow_set_vlan_vid(flow, value->be16);
957 case MFF_DL_VLAN_PCP:
959 flow_set_vlan_pcp(flow, value->u8);
963 flow_set_mpls_label(flow, 0, value->be32);
967 flow_set_mpls_tc(flow, 0, value->u8);
971 flow_set_mpls_bos(flow, 0, value->u8);
975 flow->nw_src = value->be32;
979 flow->nw_dst = value->be32;
983 flow->ipv6_src = value->ipv6;
987 flow->ipv6_dst = value->ipv6;
991 flow->ipv6_label = value->be32 & ~htonl(IPV6_LABEL_MASK);
995 flow->nw_proto = value->u8;
999 flow->nw_tos &= ~IP_DSCP_MASK;
1000 flow->nw_tos |= value->u8 & IP_DSCP_MASK;
1003 case MFF_IP_DSCP_SHIFTED:
1004 flow->nw_tos &= ~IP_DSCP_MASK;
1005 flow->nw_tos |= value->u8 << 2;
1009 flow->nw_tos &= ~IP_ECN_MASK;
1010 flow->nw_tos |= value->u8 & IP_ECN_MASK;
1014 flow->nw_ttl = value->u8;
1018 flow->nw_frag = value->u8 & FLOW_NW_FRAG_MASK;
1022 flow->nw_proto = ntohs(value->be16);
1026 flow->nw_src = value->be32;
1030 flow->nw_dst = value->be32;
1035 memcpy(flow->arp_sha, value->mac, ETH_ADDR_LEN);
1040 memcpy(flow->arp_tha, value->mac, ETH_ADDR_LEN);
1046 flow->tp_src = value->be16;
1052 flow->tp_dst = value->be16;
1056 flow->tcp_flags = value->be16;
1059 case MFF_ICMPV4_TYPE:
1060 case MFF_ICMPV6_TYPE:
1061 flow->tp_src = htons(value->u8);
1064 case MFF_ICMPV4_CODE:
1065 case MFF_ICMPV6_CODE:
1066 flow->tp_dst = htons(value->u8);
1070 flow->nd_target = value->ipv6;
1079 /* Returns true if 'mf' has a zero value in 'flow', false if it is nonzero.
1081 * The caller is responsible for ensuring that 'flow' meets 'mf''s
1084 mf_is_zero(const struct mf_field *mf, const struct flow *flow)
1086 union mf_value value;
1088 mf_get_value(mf, flow, &value);
1089 return is_all_zeros(&value, mf->n_bytes);
1092 /* Makes 'match' wildcard field 'mf'.
1094 * The caller is responsible for ensuring that 'match' meets 'mf''s
1097 mf_set_wild(const struct mf_field *mf, struct match *match)
1101 match->flow.dp_hash = 0;
1102 match->wc.masks.dp_hash = 0;
1105 match->flow.recirc_id = 0;
1106 match->wc.masks.recirc_id = 0;
1109 match_set_tun_id_masked(match, htonll(0), htonll(0));
1112 match_set_tun_src_masked(match, htonl(0), htonl(0));
1115 match_set_tun_dst_masked(match, htonl(0), htonl(0));
1118 match_set_tun_flags_masked(match, 0, 0);
1121 match_set_tun_tos_masked(match, 0, 0);
1124 match_set_tun_ttl_masked(match, 0, 0);
1128 match_set_metadata_masked(match, htonll(0), htonll(0));
1132 case MFF_IN_PORT_OXM:
1133 match->flow.in_port.ofp_port = 0;
1134 match->wc.masks.in_port.ofp_port = 0;
1137 case MFF_SKB_PRIORITY:
1138 match->flow.skb_priority = 0;
1139 match->wc.masks.skb_priority = 0;
1143 match->flow.pkt_mark = 0;
1144 match->wc.masks.pkt_mark = 0;
1148 match_set_reg_masked(match, mf->id - MFF_REG0, 0, 0);
1152 match_set_xreg_masked(match, mf->id - MFF_XREG0, 0, 0);
1156 memset(match->flow.dl_src, 0, ETH_ADDR_LEN);
1157 memset(match->wc.masks.dl_src, 0, ETH_ADDR_LEN);
1161 memset(match->flow.dl_dst, 0, ETH_ADDR_LEN);
1162 memset(match->wc.masks.dl_dst, 0, ETH_ADDR_LEN);
1166 match->flow.dl_type = htons(0);
1167 match->wc.masks.dl_type = htons(0);
1171 match_set_dl_tci_masked(match, htons(0), htons(0));
1176 match_set_any_vid(match);
1179 case MFF_DL_VLAN_PCP:
1181 match_set_any_pcp(match);
1184 case MFF_MPLS_LABEL:
1185 match_set_any_mpls_label(match, 0);
1189 match_set_any_mpls_tc(match, 0);
1193 match_set_any_mpls_bos(match, 0);
1198 match_set_nw_src_masked(match, htonl(0), htonl(0));
1203 match_set_nw_dst_masked(match, htonl(0), htonl(0));
1207 memset(&match->wc.masks.ipv6_src, 0, sizeof match->wc.masks.ipv6_src);
1208 memset(&match->flow.ipv6_src, 0, sizeof match->flow.ipv6_src);
1212 memset(&match->wc.masks.ipv6_dst, 0, sizeof match->wc.masks.ipv6_dst);
1213 memset(&match->flow.ipv6_dst, 0, sizeof match->flow.ipv6_dst);
1216 case MFF_IPV6_LABEL:
1217 match->wc.masks.ipv6_label = htonl(0);
1218 match->flow.ipv6_label = htonl(0);
1222 match->wc.masks.nw_proto = 0;
1223 match->flow.nw_proto = 0;
1227 case MFF_IP_DSCP_SHIFTED:
1228 match->wc.masks.nw_tos &= ~IP_DSCP_MASK;
1229 match->flow.nw_tos &= ~IP_DSCP_MASK;
1233 match->wc.masks.nw_tos &= ~IP_ECN_MASK;
1234 match->flow.nw_tos &= ~IP_ECN_MASK;
1238 match->wc.masks.nw_ttl = 0;
1239 match->flow.nw_ttl = 0;
1243 match->wc.masks.nw_frag |= FLOW_NW_FRAG_MASK;
1244 match->flow.nw_frag &= ~FLOW_NW_FRAG_MASK;
1248 match->wc.masks.nw_proto = 0;
1249 match->flow.nw_proto = 0;
1254 memset(match->flow.arp_sha, 0, ETH_ADDR_LEN);
1255 memset(match->wc.masks.arp_sha, 0, ETH_ADDR_LEN);
1260 memset(match->flow.arp_tha, 0, ETH_ADDR_LEN);
1261 memset(match->wc.masks.arp_tha, 0, ETH_ADDR_LEN);
1267 case MFF_ICMPV4_TYPE:
1268 case MFF_ICMPV6_TYPE:
1269 match->wc.masks.tp_src = htons(0);
1270 match->flow.tp_src = htons(0);
1276 case MFF_ICMPV4_CODE:
1277 case MFF_ICMPV6_CODE:
1278 match->wc.masks.tp_dst = htons(0);
1279 match->flow.tp_dst = htons(0);
1283 match->wc.masks.tcp_flags = htons(0);
1284 match->flow.tcp_flags = htons(0);
1288 memset(&match->wc.masks.nd_target, 0,
1289 sizeof match->wc.masks.nd_target);
1290 memset(&match->flow.nd_target, 0, sizeof match->flow.nd_target);
1299 /* Makes 'match' match field 'mf' with the specified 'value' and 'mask'.
1300 * 'value' specifies a value to match and 'mask' specifies a wildcard pattern,
1301 * with a 1-bit indicating that the corresponding value bit must match and a
1302 * 0-bit indicating a don't-care.
1304 * If 'mask' is NULL or points to all-1-bits, then this call is equivalent to
1305 * mf_set_value(mf, value, match). If 'mask' points to all-0-bits, then this
1306 * call is equivalent to mf_set_wild(mf, match).
1308 * 'mask' must be a valid mask for 'mf' (see mf_is_mask_valid()). The caller
1309 * is responsible for ensuring that 'match' meets 'mf''s prerequisites. */
1310 enum ofputil_protocol
1311 mf_set(const struct mf_field *mf,
1312 const union mf_value *value, const union mf_value *mask,
1313 struct match *match)
1315 if (!mask || is_all_ones(mask, mf->n_bytes)) {
1316 mf_set_value(mf, value, match);
1317 return mf->usable_protocols_exact;
1318 } else if (is_all_zeros(mask, mf->n_bytes)) {
1319 mf_set_wild(mf, match);
1320 return OFPUTIL_P_ANY;
1326 case MFF_IN_PORT_OXM:
1327 case MFF_SKB_PRIORITY:
1330 case MFF_DL_VLAN_PCP:
1332 case MFF_MPLS_LABEL:
1338 case MFF_IP_DSCP_SHIFTED:
1341 case MFF_ICMPV4_TYPE:
1342 case MFF_ICMPV4_CODE:
1343 case MFF_ICMPV6_TYPE:
1344 case MFF_ICMPV6_CODE:
1345 return OFPUTIL_P_NONE;
1348 match_set_dp_hash_masked(match, ntohl(value->be32), ntohl(mask->be32));
1351 match_set_tun_id_masked(match, value->be64, mask->be64);
1354 match_set_tun_src_masked(match, value->be32, mask->be32);
1357 match_set_tun_dst_masked(match, value->be32, mask->be32);
1360 match_set_tun_flags_masked(match, ntohs(value->be16), ntohs(mask->be16));
1363 match_set_tun_ttl_masked(match, value->u8, mask->u8);
1366 match_set_tun_tos_masked(match, value->u8, mask->u8);
1370 match_set_metadata_masked(match, value->be64, mask->be64);
1374 match_set_reg_masked(match, mf->id - MFF_REG0,
1375 ntohl(value->be32), ntohl(mask->be32));
1379 match_set_xreg_masked(match, mf->id - MFF_XREG0,
1380 ntohll(value->be64), ntohll(mask->be64));
1384 match_set_pkt_mark_masked(match, ntohl(value->be32),
1389 match_set_dl_dst_masked(match, value->mac, mask->mac);
1393 match_set_dl_src_masked(match, value->mac, mask->mac);
1398 match_set_arp_sha_masked(match, value->mac, mask->mac);
1403 match_set_arp_tha_masked(match, value->mac, mask->mac);
1407 match_set_dl_tci_masked(match, value->be16, mask->be16);
1411 match_set_vlan_vid_masked(match, value->be16, mask->be16);
1415 match_set_nw_src_masked(match, value->be32, mask->be32);
1419 match_set_nw_dst_masked(match, value->be32, mask->be32);
1423 match_set_ipv6_src_masked(match, &value->ipv6, &mask->ipv6);
1427 match_set_ipv6_dst_masked(match, &value->ipv6, &mask->ipv6);
1430 case MFF_IPV6_LABEL:
1431 if ((mask->be32 & htonl(IPV6_LABEL_MASK)) == htonl(IPV6_LABEL_MASK)) {
1432 mf_set_value(mf, value, match);
1434 match_set_ipv6_label_masked(match, value->be32, mask->be32);
1439 match_set_nd_target_masked(match, &value->ipv6, &mask->ipv6);
1443 match_set_nw_frag_masked(match, value->u8, mask->u8);
1447 match_set_nw_src_masked(match, value->be32, mask->be32);
1451 match_set_nw_dst_masked(match, value->be32, mask->be32);
1457 match_set_tp_src_masked(match, value->be16, mask->be16);
1463 match_set_tp_dst_masked(match, value->be16, mask->be16);
1467 match_set_tcp_flags_masked(match, value->be16, mask->be16);
1475 return ((mf->usable_protocols_bitwise == mf->usable_protocols_cidr
1476 || ip_is_cidr(mask->be32))
1477 ? mf->usable_protocols_cidr
1478 : mf->usable_protocols_bitwise);
1482 mf_check__(const struct mf_subfield *sf, const struct flow *flow,
1486 VLOG_WARN_RL(&rl, "unknown %s field", type);
1487 return OFPERR_OFPBAC_BAD_SET_TYPE;
1488 } else if (!sf->n_bits) {
1489 VLOG_WARN_RL(&rl, "zero bit %s field %s", type, sf->field->name);
1490 return OFPERR_OFPBAC_BAD_SET_LEN;
1491 } else if (sf->ofs >= sf->field->n_bits) {
1492 VLOG_WARN_RL(&rl, "bit offset %d exceeds %d-bit width of %s field %s",
1493 sf->ofs, sf->field->n_bits, type, sf->field->name);
1494 return OFPERR_OFPBAC_BAD_SET_LEN;
1495 } else if (sf->ofs + sf->n_bits > sf->field->n_bits) {
1496 VLOG_WARN_RL(&rl, "bit offset %d and width %d exceeds %d-bit width "
1497 "of %s field %s", sf->ofs, sf->n_bits,
1498 sf->field->n_bits, type, sf->field->name);
1499 return OFPERR_OFPBAC_BAD_SET_LEN;
1500 } else if (flow && !mf_are_prereqs_ok(sf->field, flow)) {
1501 VLOG_WARN_RL(&rl, "%s field %s lacks correct prerequisites",
1502 type, sf->field->name);
1503 return OFPERR_OFPBAC_MATCH_INCONSISTENT;
1509 /* Checks whether 'sf' is valid for reading a subfield out of 'flow'. Returns
1510 * 0 if so, otherwise an OpenFlow error code (e.g. as returned by
1513 mf_check_src(const struct mf_subfield *sf, const struct flow *flow)
1515 return mf_check__(sf, flow, "source");
1518 /* Checks whether 'sf' is valid for writing a subfield into 'flow'. Returns 0
1519 * if so, otherwise an OpenFlow error code (e.g. as returned by
1522 mf_check_dst(const struct mf_subfield *sf, const struct flow *flow)
1524 int error = mf_check__(sf, flow, "destination");
1525 if (!error && !sf->field->writable) {
1526 VLOG_WARN_RL(&rl, "destination field %s is not writable",
1528 return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
1533 /* Copies the value and wildcard bit pattern for 'mf' from 'match' into the
1534 * 'value' and 'mask', respectively. */
1536 mf_get(const struct mf_field *mf, const struct match *match,
1537 union mf_value *value, union mf_value *mask)
1539 mf_get_value(mf, &match->flow, value);
1540 mf_get_mask(mf, &match->wc, mask);
1544 mf_from_integer_string(const struct mf_field *mf, const char *s,
1545 uint8_t *valuep, uint8_t *maskp)
1547 unsigned long long int integer, mask;
1552 integer = strtoull(s, &tail, 0);
1553 if (errno || (*tail != '\0' && *tail != '/')) {
1558 mask = strtoull(tail + 1, &tail, 0);
1559 if (errno || *tail != '\0') {
1566 for (i = mf->n_bytes - 1; i >= 0; i--) {
1567 valuep[i] = integer;
1573 return xasprintf("%s: value too large for %u-byte field %s",
1574 s, mf->n_bytes, mf->name);
1579 return xasprintf("%s: bad syntax for %s", s, mf->name);
1583 mf_from_ethernet_string(const struct mf_field *mf, const char *s,
1584 uint8_t mac[ETH_ADDR_LEN],
1585 uint8_t mask[ETH_ADDR_LEN])
1589 ovs_assert(mf->n_bytes == ETH_ADDR_LEN);
1592 if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(mac), &n)
1593 && n == strlen(s)) {
1594 memset(mask, 0xff, ETH_ADDR_LEN);
1599 if (ovs_scan(s, ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT"%n",
1600 ETH_ADDR_SCAN_ARGS(mac), ETH_ADDR_SCAN_ARGS(mask), &n)
1601 && n == strlen(s)) {
1605 return xasprintf("%s: invalid Ethernet address", s);
1609 mf_from_ipv4_string(const struct mf_field *mf, const char *s,
1610 ovs_be32 *ip, ovs_be32 *mask)
1614 ovs_assert(mf->n_bytes == sizeof *ip);
1616 if (ovs_scan(s, IP_SCAN_FMT"/"IP_SCAN_FMT,
1617 IP_SCAN_ARGS(ip), IP_SCAN_ARGS(mask))) {
1619 } else if (ovs_scan(s, IP_SCAN_FMT"/%d", IP_SCAN_ARGS(ip), &prefix)) {
1620 if (prefix <= 0 || prefix > 32) {
1621 return xasprintf("%s: network prefix bits not between 1 and "
1623 } else if (prefix == 32) {
1624 *mask = OVS_BE32_MAX;
1626 *mask = htonl(((1u << prefix) - 1) << (32 - prefix));
1628 } else if (ovs_scan(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip))) {
1629 *mask = OVS_BE32_MAX;
1631 return xasprintf("%s: invalid IP address", s);
1637 mf_from_ipv6_string(const struct mf_field *mf, const char *s,
1638 struct in6_addr *value, struct in6_addr *mask)
1640 char *str = xstrdup(s);
1641 char *save_ptr = NULL;
1642 const char *name, *netmask;
1645 ovs_assert(mf->n_bytes == sizeof *value);
1647 name = strtok_r(str, "/", &save_ptr);
1648 retval = name ? lookup_ipv6(name, value) : EINVAL;
1652 err = xasprintf("%s: could not convert to IPv6 address", str);
1658 netmask = strtok_r(NULL, "/", &save_ptr);
1660 if (inet_pton(AF_INET6, netmask, mask) != 1) {
1661 int prefix = atoi(netmask);
1662 if (prefix <= 0 || prefix > 128) {
1664 return xasprintf("%s: prefix bits not between 1 and 128", s);
1666 *mask = ipv6_create_mask(prefix);
1670 *mask = in6addr_exact;
1678 mf_from_ofp_port_string(const struct mf_field *mf, const char *s,
1679 ovs_be16 *valuep, ovs_be16 *maskp)
1683 ovs_assert(mf->n_bytes == sizeof(ovs_be16));
1685 if (ofputil_port_from_string(s, &port)) {
1686 *valuep = htons(ofp_to_u16(port));
1687 *maskp = OVS_BE16_MAX;
1690 return xasprintf("%s: port value out of range for %s", s, mf->name);
1694 mf_from_ofp_port_string32(const struct mf_field *mf, const char *s,
1695 ovs_be32 *valuep, ovs_be32 *maskp)
1699 ovs_assert(mf->n_bytes == sizeof(ovs_be32));
1700 if (ofputil_port_from_string(s, &port)) {
1701 *valuep = ofputil_port_to_ofp11(port);
1702 *maskp = OVS_BE32_MAX;
1705 return xasprintf("%s: port value out of range for %s", s, mf->name);
1708 struct frag_handling {
1714 static const struct frag_handling all_frags[] = {
1715 #define A FLOW_NW_FRAG_ANY
1716 #define L FLOW_NW_FRAG_LATER
1717 /* name mask value */
1720 { "first", A|L, A },
1721 { "later", A|L, A|L },
1726 { "not_later", L, 0 },
1733 mf_from_frag_string(const char *s, uint8_t *valuep, uint8_t *maskp)
1735 const struct frag_handling *h;
1737 for (h = all_frags; h < &all_frags[ARRAY_SIZE(all_frags)]; h++) {
1738 if (!strcasecmp(s, h->name)) {
1739 /* We force the upper bits of the mask on to make mf_parse_value()
1740 * happy (otherwise it will never think it's an exact match.) */
1741 *maskp = h->mask | ~FLOW_NW_FRAG_MASK;
1747 return xasprintf("%s: unknown fragment type (valid types are \"no\", "
1748 "\"yes\", \"first\", \"later\", \"not_first\"", s);
1752 parse_flow_tun_flags(const char *s_, const char *(*bit_to_string)(uint32_t),
1755 uint32_t result = 0;
1756 char *save_ptr = NULL;
1759 char *s = xstrdup(s_);
1761 for (name = strtok_r((char *)s, " |", &save_ptr); name;
1762 name = strtok_r(NULL, " |", &save_ptr)) {
1764 unsigned long long int flags;
1767 if (ovs_scan(name, "%lli", &flags)) {
1771 name_len = strlen(name);
1772 for (bit = 1; bit; bit <<= 1) {
1773 const char *fname = bit_to_string(bit);
1780 len = strlen(fname);
1781 if (len != name_len) {
1784 if (!strncmp(name, fname, len)) {
1796 *res = htons(result);
1803 mf_from_tun_flags_string(const char *s, ovs_be16 *valuep, ovs_be16 *maskp)
1805 if (!parse_flow_tun_flags(s, flow_tun_flag_to_string, valuep)) {
1806 *maskp = OVS_BE16_MAX;
1810 return xasprintf("%s: unknown tunnel flags (valid flags are \"df\", "
1811 "\"csum\", \"key\")", s);
1815 mf_from_tcp_flags_string(const char *s, ovs_be16 *flagsp, ovs_be16 *maskp)
1822 if (ovs_scan(s, "%"SCNi16"/%"SCNi16"%n", &flags, &mask, &n) && !s[n]) {
1823 *flagsp = htons(flags);
1824 *maskp = htons(mask);
1827 if (ovs_scan(s, "%"SCNi16"%n", &flags, &n) && !s[n]) {
1828 *flagsp = htons(flags);
1829 *maskp = OVS_BE16_MAX;
1833 while (*s != '\0') {
1845 return xasprintf("%s: TCP flag must be preceded by '+' (for SET) "
1846 "or '-' (NOT SET)", s);
1850 name_len = strcspn(s,"+-");
1852 for (bit = 1; bit; bit <<= 1) {
1853 const char *fname = packet_tcp_flag_to_string(bit);
1860 len = strlen(fname);
1861 if (len != name_len) {
1864 if (!strncmp(s, fname, len)) {
1866 return xasprintf("%s: Each TCP flag can be specified only "
1878 return xasprintf("%s: unknown TCP flag(s)", s);
1883 *flagsp = htons(flags);
1884 *maskp = htons(mask);
1889 /* Parses 's', a string value for field 'mf', into 'value' and 'mask'. Returns
1890 * NULL if successful, otherwise a malloc()'d string describing the error. */
1892 mf_parse(const struct mf_field *mf, const char *s,
1893 union mf_value *value, union mf_value *mask)
1897 if (!strcmp(s, "*")) {
1898 memset(value, 0, mf->n_bytes);
1899 memset(mask, 0, mf->n_bytes);
1903 switch (mf->string) {
1905 case MFS_HEXADECIMAL:
1906 error = mf_from_integer_string(mf, s,
1907 (uint8_t *) value, (uint8_t *) mask);
1911 error = mf_from_ethernet_string(mf, s, value->mac, mask->mac);
1915 error = mf_from_ipv4_string(mf, s, &value->be32, &mask->be32);
1919 error = mf_from_ipv6_string(mf, s, &value->ipv6, &mask->ipv6);
1923 error = mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16);
1926 case MFS_OFP_PORT_OXM:
1927 error = mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32);
1931 error = mf_from_frag_string(s, &value->u8, &mask->u8);
1935 ovs_assert(mf->n_bytes == sizeof(ovs_be16));
1936 error = mf_from_tun_flags_string(s, &value->be16, &mask->be16);
1940 ovs_assert(mf->n_bytes == sizeof(ovs_be16));
1941 error = mf_from_tcp_flags_string(s, &value->be16, &mask->be16);
1948 if (!error && !mf_is_mask_valid(mf, mask)) {
1949 error = xasprintf("%s: invalid mask for field %s", s, mf->name);
1954 /* Parses 's', a string value for field 'mf', into 'value'. Returns NULL if
1955 * successful, otherwise a malloc()'d string describing the error. */
1957 mf_parse_value(const struct mf_field *mf, const char *s, union mf_value *value)
1959 union mf_value mask;
1962 error = mf_parse(mf, s, value, &mask);
1967 if (!is_all_ones((const uint8_t *) &mask, mf->n_bytes)) {
1968 return xasprintf("%s: wildcards not allowed here", s);
1974 mf_format_integer_string(const struct mf_field *mf, const uint8_t *valuep,
1975 const uint8_t *maskp, struct ds *s)
1977 unsigned long long int integer;
1980 ovs_assert(mf->n_bytes <= 8);
1983 for (i = 0; i < mf->n_bytes; i++) {
1984 integer = (integer << 8) | valuep[i];
1986 if (mf->string == MFS_HEXADECIMAL) {
1987 ds_put_format(s, "%#llx", integer);
1989 ds_put_format(s, "%lld", integer);
1993 unsigned long long int mask;
1996 for (i = 0; i < mf->n_bytes; i++) {
1997 mask = (mask << 8) | maskp[i];
2000 /* I guess we could write the mask in decimal for MFS_DECIMAL but I'm
2001 * not sure that that a bit-mask written in decimal is ever easier to
2002 * understand than the same bit-mask written in hexadecimal. */
2003 ds_put_format(s, "/%#llx", mask);
2008 mf_format_frag_string(uint8_t value, uint8_t mask, struct ds *s)
2010 const struct frag_handling *h;
2012 mask &= FLOW_NW_FRAG_MASK;
2015 for (h = all_frags; h < &all_frags[ARRAY_SIZE(all_frags)]; h++) {
2016 if (value == h->value && mask == h->mask) {
2017 ds_put_cstr(s, h->name);
2021 ds_put_cstr(s, "<error>");
2025 mf_format_tnl_flags_string(const ovs_be16 *valuep, struct ds *s)
2027 format_flags(s, flow_tun_flag_to_string, ntohs(*valuep), '|');
2031 mf_format_tcp_flags_string(ovs_be16 value, ovs_be16 mask, struct ds *s)
2033 format_flags_masked(s, NULL, packet_tcp_flag_to_string, ntohs(value),
2037 /* Appends to 's' a string representation of field 'mf' whose value is in
2038 * 'value' and 'mask'. 'mask' may be NULL to indicate an exact match. */
2040 mf_format(const struct mf_field *mf,
2041 const union mf_value *value, const union mf_value *mask,
2045 if (is_all_zeros(mask, mf->n_bytes)) {
2046 ds_put_cstr(s, "ANY");
2048 } else if (is_all_ones(mask, mf->n_bytes)) {
2053 switch (mf->string) {
2054 case MFS_OFP_PORT_OXM:
2057 ofputil_port_from_ofp11(value->be32, &port);
2058 ofputil_format_port(port, s);
2064 ofputil_format_port(u16_to_ofp(ntohs(value->be16)), s);
2069 case MFS_HEXADECIMAL:
2070 mf_format_integer_string(mf, (uint8_t *) value, (uint8_t *) mask, s);
2074 eth_format_masked(value->mac, mask->mac, s);
2078 ip_format_masked(value->be32, mask ? mask->be32 : OVS_BE32_MAX, s);
2082 print_ipv6_masked(s, &value->ipv6, mask ? &mask->ipv6 : NULL);
2086 mf_format_frag_string(value->u8, mask ? mask->u8 : UINT8_MAX, s);
2090 mf_format_tnl_flags_string(&value->be16, s);
2094 mf_format_tcp_flags_string(value->be16,
2095 mask ? mask->be16 : OVS_BE16_MAX, s);
2103 /* Makes subfield 'sf' within 'flow' exactly match the 'sf->n_bits'
2104 * least-significant bits in 'x'.
2107 mf_write_subfield_flow(const struct mf_subfield *sf,
2108 const union mf_subvalue *x, struct flow *flow)
2110 const struct mf_field *field = sf->field;
2111 union mf_value value;
2113 mf_get_value(field, flow, &value);
2114 bitwise_copy(x, sizeof *x, 0, &value, field->n_bytes,
2115 sf->ofs, sf->n_bits);
2116 mf_set_flow_value(field, &value, flow);
2119 /* Makes subfield 'sf' within 'match' exactly match the 'sf->n_bits'
2120 * least-significant bits in 'x'.
2123 mf_write_subfield(const struct mf_subfield *sf, const union mf_subvalue *x,
2124 struct match *match)
2126 const struct mf_field *field = sf->field;
2127 union mf_value value, mask;
2129 mf_get(field, match, &value, &mask);
2130 bitwise_copy(x, sizeof *x, 0, &value, field->n_bytes, sf->ofs, sf->n_bits);
2131 bitwise_one ( &mask, field->n_bytes, sf->ofs, sf->n_bits);
2132 mf_set(field, &value, &mask, match);
2135 /* Initializes 'x' to the value of 'sf' within 'flow'. 'sf' must be valid for
2136 * reading 'flow', e.g. as checked by mf_check_src(). */
2138 mf_read_subfield(const struct mf_subfield *sf, const struct flow *flow,
2139 union mf_subvalue *x)
2141 union mf_value value;
2143 mf_get_value(sf->field, flow, &value);
2145 memset(x, 0, sizeof *x);
2146 bitwise_copy(&value, sf->field->n_bytes, sf->ofs,
2151 /* Returns the value of 'sf' within 'flow'. 'sf' must be valid for reading
2152 * 'flow', e.g. as checked by mf_check_src() and sf->n_bits must be 64 or
2155 mf_get_subfield(const struct mf_subfield *sf, const struct flow *flow)
2157 union mf_value value;
2159 mf_get_value(sf->field, flow, &value);
2160 return bitwise_get(&value, sf->field->n_bytes, sf->ofs, sf->n_bits);
2164 mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s)
2168 for (i = 0; i < ARRAY_SIZE(subvalue->u8); i++) {
2169 if (subvalue->u8[i]) {
2170 ds_put_format(s, "0x%"PRIx8, subvalue->u8[i]);
2171 for (i++; i < ARRAY_SIZE(subvalue->u8); i++) {
2172 ds_put_format(s, "%02"PRIx8, subvalue->u8[i]);
2177 ds_put_char(s, '0');