2 * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 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 "openvswitch/meta-flow.h"
23 #include <netinet/icmp6.h>
24 #include <netinet/ip6.h>
26 #include "classifier.h"
27 #include "openvswitch/dynamic-string.h"
29 #include "openvswitch/ofp-util.h"
30 #include "ovs-thread.h"
33 #include "openvswitch/shash.h"
34 #include "socket-util.h"
35 #include "tun-metadata.h"
36 #include "unaligned.h"
38 #include "openvswitch/ofp-errors.h"
39 #include "openvswitch/vlog.h"
41 VLOG_DEFINE_THIS_MODULE(meta_flow
);
43 #define FLOW_U32OFS(FIELD) \
44 offsetof(struct flow, FIELD) % 4 ? -1 : offsetof(struct flow, FIELD) / 4
46 #define MF_FIELD_SIZES(MEMBER) \
47 sizeof ((union mf_value *)0)->MEMBER, \
48 8 * sizeof ((union mf_value *)0)->MEMBER
50 extern const struct mf_field mf_fields
[MFF_N_IDS
]; /* Silence a warning. */
52 const struct mf_field mf_fields
[MFF_N_IDS
] = {
53 #include "meta-flow.inc"
56 /* Maps from an mf_field's 'name' or 'extra_name' to the mf_field. */
57 static struct shash mf_by_name
;
59 /* Rate limit for parse errors. These always indicate a bug in an OpenFlow
60 * controller and so there's not much point in showing a lot of them. */
61 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
63 #define MF_VALUE_EXACT_8 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
64 #define MF_VALUE_EXACT_16 MF_VALUE_EXACT_8, MF_VALUE_EXACT_8
65 #define MF_VALUE_EXACT_32 MF_VALUE_EXACT_16, MF_VALUE_EXACT_16
66 #define MF_VALUE_EXACT_64 MF_VALUE_EXACT_32, MF_VALUE_EXACT_32
67 #define MF_VALUE_EXACT_128 MF_VALUE_EXACT_64, MF_VALUE_EXACT_64
68 #define MF_VALUE_EXACT_INITIALIZER { .tun_metadata = { MF_VALUE_EXACT_128 } }
70 const union mf_value exact_match_mask
= MF_VALUE_EXACT_INITIALIZER
;
72 static void nxm_init(void);
74 /* Returns the field with the given 'name', or a null pointer if no field has
76 const struct mf_field
*
77 mf_from_name(const char *name
)
80 return shash_find_data(&mf_by_name
, name
);
88 shash_init(&mf_by_name
);
89 for (i
= 0; i
< MFF_N_IDS
; i
++) {
90 const struct mf_field
*mf
= &mf_fields
[i
];
92 ovs_assert(mf
->id
== i
); /* Fields must be in the enum order. */
94 shash_add_once(&mf_by_name
, mf
->name
, mf
);
96 shash_add_once(&mf_by_name
, mf
->extra_name
, mf
);
104 static pthread_once_t once
= PTHREAD_ONCE_INIT
;
105 pthread_once(&once
, nxm_do_init
);
108 /* Consider the two value/mask pairs 'a_value/a_mask' and 'b_value/b_mask' as
109 * restrictions on a field's value. Then, this function initializes
110 * 'dst_value/dst_mask' such that it combines the restrictions of both pairs.
111 * This is not always possible, i.e. if one pair insists on a value of 0 in
112 * some bit and the other pair insists on a value of 1 in that bit. This
113 * function returns false in a case where the combined restriction is
114 * impossible (in which case 'dst_value/dst_mask' is not fully initialized),
117 * (As usually true for value/mask pairs in OVS, any 1-bit in a value must have
118 * a corresponding 1-bit in its mask.) */
120 mf_subvalue_intersect(const union mf_subvalue
*a_value
,
121 const union mf_subvalue
*a_mask
,
122 const union mf_subvalue
*b_value
,
123 const union mf_subvalue
*b_mask
,
124 union mf_subvalue
*dst_value
,
125 union mf_subvalue
*dst_mask
)
127 for (int i
= 0; i
< ARRAY_SIZE(a_value
->be64
); i
++) {
128 ovs_be64 av
= a_value
->be64
[i
];
129 ovs_be64 am
= a_mask
->be64
[i
];
130 ovs_be64 bv
= b_value
->be64
[i
];
131 ovs_be64 bm
= b_mask
->be64
[i
];
132 ovs_be64
*dv
= &dst_value
->be64
[i
];
133 ovs_be64
*dm
= &dst_mask
->be64
[i
];
135 if ((av
^ bv
) & (am
& bm
)) {
144 /* Returns the "number of bits" in 'v', e.g. 1 if only the lowest-order bit is
145 * set, 2 if the second-lowest-order bit is set, and so on. */
147 mf_subvalue_width(const union mf_subvalue
*v
)
149 return 1 + bitwise_rscan(v
, sizeof *v
, true, sizeof *v
* 8 - 1, -1);
152 /* For positive 'n', shifts the bits in 'value' 'n' bits to the left, and for
153 * negative 'n', shifts the bits '-n' bits to the right. */
155 mf_subvalue_shift(union mf_subvalue
*value
, int n
)
158 union mf_subvalue tmp
;
159 memset(&tmp
, 0, sizeof tmp
);
161 if (n
> 0 && n
< 8 * sizeof tmp
) {
162 bitwise_copy(value
, sizeof *value
, 0,
165 } else if (n
< 0 && n
> -8 * sizeof tmp
) {
166 bitwise_copy(value
, sizeof *value
, -n
,
174 /* Appends a formatted representation of 'sv' to 's'. */
176 mf_subvalue_format(const union mf_subvalue
*sv
, struct ds
*s
)
178 ds_put_hex(s
, sv
, sizeof *sv
);
181 /* Returns true if 'wc' wildcards all the bits in field 'mf', false if 'wc'
182 * specifies at least one bit in the field.
184 * The caller is responsible for ensuring that 'wc' corresponds to a flow that
185 * meets 'mf''s prerequisites. */
187 mf_is_all_wild(const struct mf_field
*mf
, const struct flow_wildcards
*wc
)
191 return !wc
->masks
.dp_hash
;
193 return !wc
->masks
.recirc_id
;
195 return !wc
->masks
.conj_id
;
197 return !wc
->masks
.tunnel
.ip_src
;
199 return !wc
->masks
.tunnel
.ip_dst
;
200 case MFF_TUN_IPV6_SRC
:
201 return ipv6_mask_is_any(&wc
->masks
.tunnel
.ipv6_src
);
202 case MFF_TUN_IPV6_DST
:
203 return ipv6_mask_is_any(&wc
->masks
.tunnel
.ipv6_dst
);
205 return !wc
->masks
.tunnel
.tun_id
;
207 return !wc
->masks
.tunnel
.ip_tos
;
209 return !wc
->masks
.tunnel
.ip_ttl
;
211 return !(wc
->masks
.tunnel
.flags
& FLOW_TNL_PUB_F_MASK
);
213 return !wc
->masks
.tunnel
.gbp_id
;
214 case MFF_TUN_GBP_FLAGS
:
215 return !wc
->masks
.tunnel
.gbp_flags
;
216 CASE_MFF_TUN_METADATA
:
217 return !ULLONG_GET(wc
->masks
.tunnel
.metadata
.present
.map
,
218 mf
->id
- MFF_TUN_METADATA0
);
220 return !wc
->masks
.metadata
;
222 case MFF_IN_PORT_OXM
:
223 return !wc
->masks
.in_port
.ofp_port
;
224 case MFF_SKB_PRIORITY
:
225 return !wc
->masks
.skb_priority
;
227 return !wc
->masks
.pkt_mark
;
229 return !wc
->masks
.ct_state
;
231 return !wc
->masks
.ct_zone
;
233 return !wc
->masks
.ct_mark
;
235 return ovs_u128_is_zero(wc
->masks
.ct_label
);
237 return !wc
->masks
.regs
[mf
->id
- MFF_REG0
];
239 return !flow_get_xreg(&wc
->masks
, mf
->id
- MFF_XREG0
);
241 ovs_u128 value
= flow_get_xxreg(&wc
->masks
, mf
->id
- MFF_XXREG0
);
242 return ovs_u128_is_zero(value
);
244 case MFF_ACTSET_OUTPUT
:
245 return !wc
->masks
.actset_output
;
248 return eth_addr_is_zero(wc
->masks
.dl_src
);
250 return eth_addr_is_zero(wc
->masks
.dl_dst
);
252 return !wc
->masks
.dl_type
;
256 return eth_addr_is_zero(wc
->masks
.arp_sha
);
260 return eth_addr_is_zero(wc
->masks
.arp_tha
);
263 return !wc
->masks
.vlan_tci
;
265 return !(wc
->masks
.vlan_tci
& htons(VLAN_VID_MASK
));
267 return !(wc
->masks
.vlan_tci
& htons(VLAN_VID_MASK
| VLAN_CFI
));
268 case MFF_DL_VLAN_PCP
:
270 return !(wc
->masks
.vlan_tci
& htons(VLAN_PCP_MASK
));
273 return !(wc
->masks
.mpls_lse
[0] & htonl(MPLS_LABEL_MASK
));
275 return !(wc
->masks
.mpls_lse
[0] & htonl(MPLS_TC_MASK
));
277 return !(wc
->masks
.mpls_lse
[0] & htonl(MPLS_BOS_MASK
));
279 return !(wc
->masks
.mpls_lse
[0] & htonl(MPLS_TTL_MASK
));
282 return !wc
->masks
.nw_src
;
284 return !wc
->masks
.nw_dst
;
287 return ipv6_mask_is_any(&wc
->masks
.ipv6_src
);
289 return ipv6_mask_is_any(&wc
->masks
.ipv6_dst
);
292 return !wc
->masks
.ipv6_label
;
295 return !wc
->masks
.nw_proto
;
297 case MFF_IP_DSCP_SHIFTED
:
298 return !(wc
->masks
.nw_tos
& IP_DSCP_MASK
);
300 return !(wc
->masks
.nw_tos
& IP_ECN_MASK
);
302 return !wc
->masks
.nw_ttl
;
305 return ipv6_mask_is_any(&wc
->masks
.nd_target
);
308 return !(wc
->masks
.nw_frag
& FLOW_NW_FRAG_MASK
);
311 return !wc
->masks
.nw_proto
;
313 return !wc
->masks
.nw_src
;
315 return !wc
->masks
.nw_dst
;
320 case MFF_ICMPV4_TYPE
:
321 case MFF_ICMPV6_TYPE
:
322 return !wc
->masks
.tp_src
;
326 case MFF_ICMPV4_CODE
:
327 case MFF_ICMPV6_CODE
:
328 return !wc
->masks
.tp_dst
;
330 return !wc
->masks
.tcp_flags
;
338 /* Initializes 'mask' with the wildcard bit pattern for field 'mf' within 'wc'.
339 * Each bit in 'mask' will be set to 1 if the bit is significant for matching
340 * purposes, or to 0 if it is wildcarded.
342 * The caller is responsible for ensuring that 'wc' corresponds to a flow that
343 * meets 'mf''s prerequisites. */
345 mf_get_mask(const struct mf_field
*mf
, const struct flow_wildcards
*wc
,
346 union mf_value
*mask
)
348 mf_get_value(mf
, &wc
->masks
, mask
);
351 /* Tests whether 'mask' is a valid wildcard bit pattern for 'mf'. Returns true
352 * if the mask is valid, false otherwise. */
354 mf_is_mask_valid(const struct mf_field
*mf
, const union mf_value
*mask
)
356 switch (mf
->maskable
) {
358 return (is_all_zeros(mask
, mf
->n_bytes
) ||
359 is_all_ones(mask
, mf
->n_bytes
));
368 /* Returns true if 'flow' meets the prerequisites for 'mf', false otherwise.
369 * Sets inspected bits in 'wc', if non-NULL. */
371 mf_are_prereqs_ok(const struct mf_field
*mf
, const struct flow
*flow
,
372 struct flow_wildcards
*wc
)
374 switch (mf
->prereqs
) {
378 return (flow
->dl_type
== htons(ETH_TYPE_ARP
) ||
379 flow
->dl_type
== htons(ETH_TYPE_RARP
));
381 return flow
->dl_type
== htons(ETH_TYPE_IP
);
383 return flow
->dl_type
== htons(ETH_TYPE_IPV6
);
385 return is_vlan(flow
, wc
);
387 return eth_type_mpls(flow
->dl_type
);
389 return is_ip_any(flow
);
391 return is_tcp(flow
, wc
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
);
393 return is_udp(flow
, wc
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
);
395 return is_sctp(flow
, wc
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
);
397 return is_icmpv4(flow
, wc
);
399 return is_icmpv6(flow
, wc
);
401 return is_nd(flow
, wc
);
403 return is_nd(flow
, wc
) && flow
->tp_src
== htons(ND_NEIGHBOR_SOLICIT
);
405 return is_nd(flow
, wc
) && flow
->tp_src
== htons(ND_NEIGHBOR_ADVERT
);
411 /* Returns true if 'value' may be a valid value *as part of a masked match*,
414 * A value is not rejected just because it is not valid for the field in
415 * question, but only if it doesn't make sense to test the bits in question at
416 * all. For example, the MFF_VLAN_TCI field will never have a nonzero value
417 * without the VLAN_CFI bit being set, but we can't reject those values because
418 * it is still legitimate to test just for those bits (see the documentation
419 * for NXM_OF_VLAN_TCI in meta-flow.h). On the other hand, there is never a
420 * reason to set the low bit of MFF_IP_DSCP to 1, so we reject that. */
422 mf_is_value_valid(const struct mf_field
*mf
, const union mf_value
*value
)
431 case MFF_TUN_IPV6_SRC
:
432 case MFF_TUN_IPV6_DST
:
436 case MFF_TUN_GBP_FLAGS
:
437 CASE_MFF_TUN_METADATA
:
440 case MFF_SKB_PRIORITY
:
469 case MFF_ICMPV4_TYPE
:
470 case MFF_ICMPV4_CODE
:
471 case MFF_ICMPV6_TYPE
:
472 case MFF_ICMPV6_CODE
:
478 case MFF_IN_PORT_OXM
:
479 case MFF_ACTSET_OUTPUT
: {
481 return !ofputil_port_from_ofp11(value
->be32
, &port
);
485 return !(value
->u8
& ~IP_DSCP_MASK
);
486 case MFF_IP_DSCP_SHIFTED
:
487 return !(value
->u8
& (~IP_DSCP_MASK
>> 2));
489 return !(value
->u8
& ~IP_ECN_MASK
);
491 return !(value
->u8
& ~FLOW_NW_FRAG_MASK
);
493 return !(value
->be16
& ~htons(0x0fff));
496 return !(value
->be16
& htons(0xff00));
499 return !(value
->be16
& htons(VLAN_CFI
| VLAN_PCP_MASK
));
501 return !(value
->be16
& htons(VLAN_PCP_MASK
));
503 case MFF_DL_VLAN_PCP
:
505 return !(value
->u8
& ~(VLAN_PCP_MASK
>> VLAN_PCP_SHIFT
));
508 return !(value
->be32
& ~htonl(IPV6_LABEL_MASK
));
511 return !(value
->be32
& ~htonl(MPLS_LABEL_MASK
>> MPLS_LABEL_SHIFT
));
514 return !(value
->u8
& ~(MPLS_TC_MASK
>> MPLS_TC_SHIFT
));
517 return !(value
->u8
& ~(MPLS_BOS_MASK
>> MPLS_BOS_SHIFT
));
520 return !(value
->be16
& ~htons(FLOW_TNL_PUB_F_MASK
));
523 return !(value
->be32
& ~htonl(CS_SUPPORTED_MASK
));
531 /* Copies the value of field 'mf' from 'flow' into 'value'. The caller is
532 * responsible for ensuring that 'flow' meets 'mf''s prerequisites. */
534 mf_get_value(const struct mf_field
*mf
, const struct flow
*flow
,
535 union mf_value
*value
)
539 value
->be32
= htonl(flow
->dp_hash
);
542 value
->be32
= htonl(flow
->recirc_id
);
545 value
->be32
= htonl(flow
->conj_id
);
548 value
->be64
= flow
->tunnel
.tun_id
;
551 value
->be32
= flow
->tunnel
.ip_src
;
554 value
->be32
= flow
->tunnel
.ip_dst
;
556 case MFF_TUN_IPV6_SRC
:
557 value
->ipv6
= flow
->tunnel
.ipv6_src
;
559 case MFF_TUN_IPV6_DST
:
560 value
->ipv6
= flow
->tunnel
.ipv6_dst
;
563 value
->be16
= htons(flow
->tunnel
.flags
& FLOW_TNL_PUB_F_MASK
);
566 value
->be16
= flow
->tunnel
.gbp_id
;
568 case MFF_TUN_GBP_FLAGS
:
569 value
->u8
= flow
->tunnel
.gbp_flags
;
572 value
->u8
= flow
->tunnel
.ip_ttl
;
575 value
->u8
= flow
->tunnel
.ip_tos
;
577 CASE_MFF_TUN_METADATA
:
578 tun_metadata_read(&flow
->tunnel
, mf
, value
);
582 value
->be64
= flow
->metadata
;
586 value
->be16
= htons(ofp_to_u16(flow
->in_port
.ofp_port
));
588 case MFF_IN_PORT_OXM
:
589 value
->be32
= ofputil_port_to_ofp11(flow
->in_port
.ofp_port
);
591 case MFF_ACTSET_OUTPUT
:
592 value
->be32
= ofputil_port_to_ofp11(flow
->actset_output
);
595 case MFF_SKB_PRIORITY
:
596 value
->be32
= htonl(flow
->skb_priority
);
600 value
->be32
= htonl(flow
->pkt_mark
);
604 value
->be32
= htonl(flow
->ct_state
);
608 value
->be16
= htons(flow
->ct_zone
);
612 value
->be32
= htonl(flow
->ct_mark
);
616 value
->be128
= hton128(flow
->ct_label
);
620 value
->be32
= htonl(flow
->regs
[mf
->id
- MFF_REG0
]);
624 value
->be64
= htonll(flow_get_xreg(flow
, mf
->id
- MFF_XREG0
));
628 value
->be128
= hton128(flow_get_xxreg(flow
, mf
->id
- MFF_XXREG0
));
632 value
->mac
= flow
->dl_src
;
636 value
->mac
= flow
->dl_dst
;
640 value
->be16
= flow
->dl_type
;
644 value
->be16
= flow
->vlan_tci
;
648 value
->be16
= flow
->vlan_tci
& htons(VLAN_VID_MASK
);
651 value
->be16
= flow
->vlan_tci
& htons(VLAN_VID_MASK
| VLAN_CFI
);
654 case MFF_DL_VLAN_PCP
:
656 value
->u8
= vlan_tci_to_pcp(flow
->vlan_tci
);
660 value
->be32
= htonl(mpls_lse_to_label(flow
->mpls_lse
[0]));
664 value
->u8
= mpls_lse_to_tc(flow
->mpls_lse
[0]);
668 value
->u8
= mpls_lse_to_bos(flow
->mpls_lse
[0]);
672 value
->u8
= mpls_lse_to_ttl(flow
->mpls_lse
[0]);
676 value
->be32
= flow
->nw_src
;
680 value
->be32
= flow
->nw_dst
;
684 value
->ipv6
= flow
->ipv6_src
;
688 value
->ipv6
= flow
->ipv6_dst
;
692 value
->be32
= flow
->ipv6_label
;
696 value
->u8
= flow
->nw_proto
;
700 value
->u8
= flow
->nw_tos
& IP_DSCP_MASK
;
703 case MFF_IP_DSCP_SHIFTED
:
704 value
->u8
= flow
->nw_tos
>> 2;
708 value
->u8
= flow
->nw_tos
& IP_ECN_MASK
;
712 value
->u8
= flow
->nw_ttl
;
716 value
->u8
= flow
->nw_frag
;
720 value
->be16
= htons(flow
->nw_proto
);
724 value
->be32
= flow
->nw_src
;
728 value
->be32
= flow
->nw_dst
;
733 value
->mac
= flow
->arp_sha
;
738 value
->mac
= flow
->arp_tha
;
744 value
->be16
= flow
->tp_src
;
750 value
->be16
= flow
->tp_dst
;
754 value
->be16
= flow
->tcp_flags
;
757 case MFF_ICMPV4_TYPE
:
758 case MFF_ICMPV6_TYPE
:
759 value
->u8
= ntohs(flow
->tp_src
);
762 case MFF_ICMPV4_CODE
:
763 case MFF_ICMPV6_CODE
:
764 value
->u8
= ntohs(flow
->tp_dst
);
768 value
->ipv6
= flow
->nd_target
;
777 /* Makes 'match' match field 'mf' exactly, with the value matched taken from
778 * 'value'. The caller is responsible for ensuring that 'match' meets 'mf''s
781 * If non-NULL, 'err_str' returns a malloc'ed string describing any errors
782 * with the request or NULL if there is no error. The caller is reponsible
783 * for freeing the string. */
785 mf_set_value(const struct mf_field
*mf
,
786 const union mf_value
*value
, struct match
*match
, char **err_str
)
794 match_set_dp_hash(match
, ntohl(value
->be32
));
797 match_set_recirc_id(match
, ntohl(value
->be32
));
800 match_set_conj_id(match
, ntohl(value
->be32
));
803 match_set_tun_id(match
, value
->be64
);
806 match_set_tun_src(match
, value
->be32
);
809 match_set_tun_dst(match
, value
->be32
);
811 case MFF_TUN_IPV6_SRC
:
812 match_set_tun_ipv6_src(match
, &value
->ipv6
);
814 case MFF_TUN_IPV6_DST
:
815 match_set_tun_ipv6_dst(match
, &value
->ipv6
);
818 match_set_tun_flags(match
, ntohs(value
->be16
));
821 match_set_tun_gbp_id(match
, value
->be16
);
823 case MFF_TUN_GBP_FLAGS
:
824 match_set_tun_gbp_flags(match
, value
->u8
);
827 match_set_tun_tos(match
, value
->u8
);
830 match_set_tun_ttl(match
, value
->u8
);
832 CASE_MFF_TUN_METADATA
:
833 tun_metadata_set_match(mf
, value
, NULL
, match
, err_str
);
837 match_set_metadata(match
, value
->be64
);
841 match_set_in_port(match
, u16_to_ofp(ntohs(value
->be16
)));
844 case MFF_IN_PORT_OXM
: {
846 ofputil_port_from_ofp11(value
->be32
, &port
);
847 match_set_in_port(match
, port
);
850 case MFF_ACTSET_OUTPUT
: {
852 ofputil_port_from_ofp11(value
->be32
, &port
);
853 match_set_actset_output(match
, port
);
857 case MFF_SKB_PRIORITY
:
858 match_set_skb_priority(match
, ntohl(value
->be32
));
862 match_set_pkt_mark(match
, ntohl(value
->be32
));
866 match_set_ct_state(match
, ntohl(value
->be32
));
870 match_set_ct_zone(match
, ntohs(value
->be16
));
874 match_set_ct_mark(match
, ntohl(value
->be32
));
878 match_set_ct_label(match
, ntoh128(value
->be128
));
882 match_set_reg(match
, mf
->id
- MFF_REG0
, ntohl(value
->be32
));
886 match_set_xreg(match
, mf
->id
- MFF_XREG0
, ntohll(value
->be64
));
890 match_set_xxreg(match
, mf
->id
- MFF_XXREG0
, ntoh128(value
->be128
));
894 match_set_dl_src(match
, value
->mac
);
898 match_set_dl_dst(match
, value
->mac
);
902 match_set_dl_type(match
, value
->be16
);
906 match_set_dl_tci(match
, value
->be16
);
910 match_set_dl_vlan(match
, value
->be16
);
913 match_set_vlan_vid(match
, value
->be16
);
916 case MFF_DL_VLAN_PCP
:
918 match_set_dl_vlan_pcp(match
, value
->u8
);
922 match_set_mpls_label(match
, 0, value
->be32
);
926 match_set_mpls_tc(match
, 0, value
->u8
);
930 match_set_mpls_bos(match
, 0, value
->u8
);
934 match_set_mpls_ttl(match
, 0, value
->u8
);
938 match_set_nw_src(match
, value
->be32
);
942 match_set_nw_dst(match
, value
->be32
);
946 match_set_ipv6_src(match
, &value
->ipv6
);
950 match_set_ipv6_dst(match
, &value
->ipv6
);
954 match_set_ipv6_label(match
, value
->be32
);
958 match_set_nw_proto(match
, value
->u8
);
962 match_set_nw_dscp(match
, value
->u8
);
965 case MFF_IP_DSCP_SHIFTED
:
966 match_set_nw_dscp(match
, value
->u8
<< 2);
970 match_set_nw_ecn(match
, value
->u8
);
974 match_set_nw_ttl(match
, value
->u8
);
978 match_set_nw_frag(match
, value
->u8
);
982 match_set_nw_proto(match
, ntohs(value
->be16
));
986 match_set_nw_src(match
, value
->be32
);
990 match_set_nw_dst(match
, value
->be32
);
995 match_set_arp_sha(match
, value
->mac
);
1000 match_set_arp_tha(match
, value
->mac
);
1006 match_set_tp_src(match
, value
->be16
);
1012 match_set_tp_dst(match
, value
->be16
);
1016 match_set_tcp_flags(match
, value
->be16
);
1019 case MFF_ICMPV4_TYPE
:
1020 case MFF_ICMPV6_TYPE
:
1021 match_set_icmp_type(match
, value
->u8
);
1024 case MFF_ICMPV4_CODE
:
1025 case MFF_ICMPV6_CODE
:
1026 match_set_icmp_code(match
, value
->u8
);
1030 match_set_nd_target(match
, &value
->ipv6
);
1039 /* Unwildcard the bits in 'mask' of the 'wc' member field described by 'mf'.
1040 * The caller is responsible for ensuring that 'wc' meets 'mf''s
1043 mf_mask_field_masked(const struct mf_field
*mf
, const union mf_value
*mask
,
1044 struct flow_wildcards
*wc
)
1046 union mf_value temp_mask
;
1047 /* For MFF_DL_VLAN, we cannot send a all 1's to flow_set_dl_vlan() as that
1048 * will be considered as OFP10_VLAN_NONE. So make sure the mask only has
1049 * valid bits in this case. */
1050 if (mf
->id
== MFF_DL_VLAN
) {
1051 temp_mask
.be16
= htons(VLAN_VID_MASK
) & mask
->be16
;
1055 union mf_value mask_value
;
1057 mf_get_value(mf
, &wc
->masks
, &mask_value
);
1058 for (size_t i
= 0; i
< mf
->n_bytes
; i
++) {
1059 mask_value
.b
[i
] |= mask
->b
[i
];
1061 mf_set_flow_value(mf
, &mask_value
, &wc
->masks
);
1064 /* Unwildcard 'wc' member field described by 'mf'. The caller is
1065 * responsible for ensuring that 'mask' meets 'mf''s prerequisites. */
1067 mf_mask_field(const struct mf_field
*mf
, struct flow_wildcards
*wc
)
1069 mf_mask_field_masked(mf
, &exact_match_mask
, wc
);
1073 field_len(const struct mf_field
*mf
, const union mf_value
*value_
)
1075 const uint8_t *value
= &value_
->u8
;
1078 if (!mf
->variable_len
) {
1086 for (i
= 0; i
< mf
->n_bytes
; i
++) {
1087 if (value
[i
] != 0) {
1092 return mf
->n_bytes
- i
;
1095 /* Returns the effective length of the field. For fixed length fields,
1096 * this is just the defined length. For variable length fields, it is
1097 * the minimum size encoding that retains the same meaning (i.e.
1098 * discarding leading zeros).
1100 * 'is_masked' returns (if non-NULL) whether the original contained
1101 * a mask. Otherwise, a mask that is the same length as the value
1102 * might be misinterpreted as an exact match. */
1104 mf_field_len(const struct mf_field
*mf
, const union mf_value
*value
,
1105 const union mf_value
*mask
, bool *is_masked_
)
1108 bool is_masked
= mask
&& !is_all_ones(mask
, mf
->n_bytes
);
1110 len
= field_len(mf
, value
);
1112 mask_len
= field_len(mf
, mask
);
1113 len
= MAX(len
, mask_len
);
1117 *is_masked_
= is_masked
;
1123 /* Sets 'flow' member field described by 'mf' to 'value'. The caller is
1124 * responsible for ensuring that 'flow' meets 'mf''s prerequisites.*/
1126 mf_set_flow_value(const struct mf_field
*mf
,
1127 const union mf_value
*value
, struct flow
*flow
)
1131 flow
->dp_hash
= ntohl(value
->be32
);
1134 flow
->recirc_id
= ntohl(value
->be32
);
1137 flow
->conj_id
= ntohl(value
->be32
);
1140 flow
->tunnel
.tun_id
= value
->be64
;
1143 flow
->tunnel
.ip_src
= value
->be32
;
1146 flow
->tunnel
.ip_dst
= value
->be32
;
1148 case MFF_TUN_IPV6_SRC
:
1149 flow
->tunnel
.ipv6_src
= value
->ipv6
;
1151 case MFF_TUN_IPV6_DST
:
1152 flow
->tunnel
.ipv6_dst
= value
->ipv6
;
1155 flow
->tunnel
.flags
= (flow
->tunnel
.flags
& ~FLOW_TNL_PUB_F_MASK
) |
1158 case MFF_TUN_GBP_ID
:
1159 flow
->tunnel
.gbp_id
= value
->be16
;
1161 case MFF_TUN_GBP_FLAGS
:
1162 flow
->tunnel
.gbp_flags
= value
->u8
;
1165 flow
->tunnel
.ip_tos
= value
->u8
;
1168 flow
->tunnel
.ip_ttl
= value
->u8
;
1170 CASE_MFF_TUN_METADATA
:
1171 tun_metadata_write(&flow
->tunnel
, mf
, value
);
1174 flow
->metadata
= value
->be64
;
1178 flow
->in_port
.ofp_port
= u16_to_ofp(ntohs(value
->be16
));
1181 case MFF_IN_PORT_OXM
:
1182 ofputil_port_from_ofp11(value
->be32
, &flow
->in_port
.ofp_port
);
1184 case MFF_ACTSET_OUTPUT
:
1185 ofputil_port_from_ofp11(value
->be32
, &flow
->actset_output
);
1188 case MFF_SKB_PRIORITY
:
1189 flow
->skb_priority
= ntohl(value
->be32
);
1193 flow
->pkt_mark
= ntohl(value
->be32
);
1197 flow
->ct_state
= ntohl(value
->be32
);
1201 flow
->ct_zone
= ntohs(value
->be16
);
1205 flow
->ct_mark
= ntohl(value
->be32
);
1209 flow
->ct_label
= ntoh128(value
->be128
);
1213 flow
->regs
[mf
->id
- MFF_REG0
] = ntohl(value
->be32
);
1217 flow_set_xreg(flow
, mf
->id
- MFF_XREG0
, ntohll(value
->be64
));
1221 flow_set_xxreg(flow
, mf
->id
- MFF_XXREG0
, ntoh128(value
->be128
));
1225 flow
->dl_src
= value
->mac
;
1229 flow
->dl_dst
= value
->mac
;
1233 flow
->dl_type
= value
->be16
;
1237 flow
->vlan_tci
= value
->be16
;
1241 flow_set_dl_vlan(flow
, value
->be16
);
1244 flow_set_vlan_vid(flow
, value
->be16
);
1247 case MFF_DL_VLAN_PCP
:
1249 flow_set_vlan_pcp(flow
, value
->u8
);
1252 case MFF_MPLS_LABEL
:
1253 flow_set_mpls_label(flow
, 0, value
->be32
);
1257 flow_set_mpls_tc(flow
, 0, value
->u8
);
1261 flow_set_mpls_bos(flow
, 0, value
->u8
);
1265 flow_set_mpls_ttl(flow
, 0, value
->u8
);
1269 flow
->nw_src
= value
->be32
;
1273 flow
->nw_dst
= value
->be32
;
1277 flow
->ipv6_src
= value
->ipv6
;
1281 flow
->ipv6_dst
= value
->ipv6
;
1284 case MFF_IPV6_LABEL
:
1285 flow
->ipv6_label
= value
->be32
& htonl(IPV6_LABEL_MASK
);
1289 flow
->nw_proto
= value
->u8
;
1293 flow
->nw_tos
&= ~IP_DSCP_MASK
;
1294 flow
->nw_tos
|= value
->u8
& IP_DSCP_MASK
;
1297 case MFF_IP_DSCP_SHIFTED
:
1298 flow
->nw_tos
&= ~IP_DSCP_MASK
;
1299 flow
->nw_tos
|= value
->u8
<< 2;
1303 flow
->nw_tos
&= ~IP_ECN_MASK
;
1304 flow
->nw_tos
|= value
->u8
& IP_ECN_MASK
;
1308 flow
->nw_ttl
= value
->u8
;
1312 flow
->nw_frag
= value
->u8
& FLOW_NW_FRAG_MASK
;
1316 flow
->nw_proto
= ntohs(value
->be16
);
1320 flow
->nw_src
= value
->be32
;
1324 flow
->nw_dst
= value
->be32
;
1329 flow
->arp_sha
= value
->mac
;
1334 flow
->arp_tha
= value
->mac
;
1340 flow
->tp_src
= value
->be16
;
1346 flow
->tp_dst
= value
->be16
;
1350 flow
->tcp_flags
= value
->be16
;
1353 case MFF_ICMPV4_TYPE
:
1354 case MFF_ICMPV6_TYPE
:
1355 flow
->tp_src
= htons(value
->u8
);
1358 case MFF_ICMPV4_CODE
:
1359 case MFF_ICMPV6_CODE
:
1360 flow
->tp_dst
= htons(value
->u8
);
1364 flow
->nd_target
= value
->ipv6
;
1373 /* Consider each of 'src', 'mask', and 'dst' as if they were arrays of 8*n
1374 * bits. Then, for each 0 <= i < 8 * n such that mask[i] == 1, sets dst[i] =
1377 apply_mask(const uint8_t *src
, const uint8_t *mask
, uint8_t *dst
, size_t n
)
1381 for (i
= 0; i
< n
; i
++) {
1382 dst
[i
] = (src
[i
] & mask
[i
]) | (dst
[i
] & ~mask
[i
]);
1386 /* Sets 'flow' member field described by 'field' to 'value', except that bits
1387 * for which 'mask' has a 0-bit keep their existing values. The caller is
1388 * responsible for ensuring that 'flow' meets 'field''s prerequisites.*/
1390 mf_set_flow_value_masked(const struct mf_field
*field
,
1391 const union mf_value
*value
,
1392 const union mf_value
*mask
,
1397 mf_get_value(field
, flow
, &tmp
);
1398 apply_mask((const uint8_t *) value
, (const uint8_t *) mask
,
1399 (uint8_t *) &tmp
, field
->n_bytes
);
1400 mf_set_flow_value(field
, &tmp
, flow
);
1404 mf_is_tun_metadata(const struct mf_field
*mf
)
1406 return mf
->id
>= MFF_TUN_METADATA0
&&
1407 mf
->id
< MFF_TUN_METADATA0
+ TUN_METADATA_NUM_OPTS
;
1410 /* Returns true if 'mf' has previously been set in 'flow', false if
1411 * it contains a non-default value.
1413 * The caller is responsible for ensuring that 'flow' meets 'mf''s
1416 mf_is_set(const struct mf_field
*mf
, const struct flow
*flow
)
1418 if (!mf_is_tun_metadata(mf
)) {
1419 union mf_value value
;
1421 mf_get_value(mf
, flow
, &value
);
1422 return !is_all_zeros(&value
, mf
->n_bytes
);
1424 return ULLONG_GET(flow
->tunnel
.metadata
.present
.map
,
1425 mf
->id
- MFF_TUN_METADATA0
);
1429 /* Makes 'match' wildcard field 'mf'.
1431 * The caller is responsible for ensuring that 'match' meets 'mf''s
1434 * If non-NULL, 'err_str' returns a malloc'ed string describing any errors
1435 * with the request or NULL if there is no error. The caller is reponsible
1436 * for freeing the string. */
1438 mf_set_wild(const struct mf_field
*mf
, struct match
*match
, char **err_str
)
1446 match
->flow
.dp_hash
= 0;
1447 match
->wc
.masks
.dp_hash
= 0;
1450 match
->flow
.recirc_id
= 0;
1451 match
->wc
.masks
.recirc_id
= 0;
1454 match
->flow
.conj_id
= 0;
1455 match
->wc
.masks
.conj_id
= 0;
1458 match_set_tun_id_masked(match
, htonll(0), htonll(0));
1461 match_set_tun_src_masked(match
, htonl(0), htonl(0));
1464 match_set_tun_dst_masked(match
, htonl(0), htonl(0));
1466 case MFF_TUN_IPV6_SRC
:
1467 memset(&match
->wc
.masks
.tunnel
.ipv6_src
, 0,
1468 sizeof match
->wc
.masks
.tunnel
.ipv6_src
);
1469 memset(&match
->flow
.tunnel
.ipv6_src
, 0,
1470 sizeof match
->flow
.tunnel
.ipv6_src
);
1472 case MFF_TUN_IPV6_DST
:
1473 memset(&match
->wc
.masks
.tunnel
.ipv6_dst
, 0,
1474 sizeof match
->wc
.masks
.tunnel
.ipv6_dst
);
1475 memset(&match
->flow
.tunnel
.ipv6_dst
, 0,
1476 sizeof match
->flow
.tunnel
.ipv6_dst
);
1479 match_set_tun_flags_masked(match
, 0, 0);
1481 case MFF_TUN_GBP_ID
:
1482 match_set_tun_gbp_id_masked(match
, 0, 0);
1484 case MFF_TUN_GBP_FLAGS
:
1485 match_set_tun_gbp_flags_masked(match
, 0, 0);
1488 match_set_tun_tos_masked(match
, 0, 0);
1491 match_set_tun_ttl_masked(match
, 0, 0);
1493 CASE_MFF_TUN_METADATA
:
1494 tun_metadata_set_match(mf
, NULL
, NULL
, match
, err_str
);
1498 match_set_metadata_masked(match
, htonll(0), htonll(0));
1502 case MFF_IN_PORT_OXM
:
1503 match
->flow
.in_port
.ofp_port
= 0;
1504 match
->wc
.masks
.in_port
.ofp_port
= 0;
1506 case MFF_ACTSET_OUTPUT
:
1507 match
->flow
.actset_output
= 0;
1508 match
->wc
.masks
.actset_output
= 0;
1511 case MFF_SKB_PRIORITY
:
1512 match
->flow
.skb_priority
= 0;
1513 match
->wc
.masks
.skb_priority
= 0;
1517 match
->flow
.pkt_mark
= 0;
1518 match
->wc
.masks
.pkt_mark
= 0;
1522 match
->flow
.ct_state
= 0;
1523 match
->wc
.masks
.ct_state
= 0;
1527 match
->flow
.ct_zone
= 0;
1528 match
->wc
.masks
.ct_zone
= 0;
1532 match
->flow
.ct_mark
= 0;
1533 match
->wc
.masks
.ct_mark
= 0;
1537 memset(&match
->flow
.ct_label
, 0, sizeof(match
->flow
.ct_label
));
1538 memset(&match
->wc
.masks
.ct_label
, 0, sizeof(match
->wc
.masks
.ct_label
));
1542 match_set_reg_masked(match
, mf
->id
- MFF_REG0
, 0, 0);
1546 match_set_xreg_masked(match
, mf
->id
- MFF_XREG0
, 0, 0);
1550 match_set_xxreg_masked(match
, mf
->id
- MFF_XXREG0
, OVS_U128_ZERO
,
1556 match
->flow
.dl_src
= eth_addr_zero
;
1557 match
->wc
.masks
.dl_src
= eth_addr_zero
;
1561 match
->flow
.dl_dst
= eth_addr_zero
;
1562 match
->wc
.masks
.dl_dst
= eth_addr_zero
;
1566 match
->flow
.dl_type
= htons(0);
1567 match
->wc
.masks
.dl_type
= htons(0);
1571 match_set_dl_tci_masked(match
, htons(0), htons(0));
1576 match_set_any_vid(match
);
1579 case MFF_DL_VLAN_PCP
:
1581 match_set_any_pcp(match
);
1584 case MFF_MPLS_LABEL
:
1585 match_set_any_mpls_label(match
, 0);
1589 match_set_any_mpls_tc(match
, 0);
1593 match_set_any_mpls_bos(match
, 0);
1597 match_set_any_mpls_ttl(match
, 0);
1602 match_set_nw_src_masked(match
, htonl(0), htonl(0));
1607 match_set_nw_dst_masked(match
, htonl(0), htonl(0));
1611 memset(&match
->wc
.masks
.ipv6_src
, 0, sizeof match
->wc
.masks
.ipv6_src
);
1612 memset(&match
->flow
.ipv6_src
, 0, sizeof match
->flow
.ipv6_src
);
1616 memset(&match
->wc
.masks
.ipv6_dst
, 0, sizeof match
->wc
.masks
.ipv6_dst
);
1617 memset(&match
->flow
.ipv6_dst
, 0, sizeof match
->flow
.ipv6_dst
);
1620 case MFF_IPV6_LABEL
:
1621 match
->wc
.masks
.ipv6_label
= htonl(0);
1622 match
->flow
.ipv6_label
= htonl(0);
1626 match
->wc
.masks
.nw_proto
= 0;
1627 match
->flow
.nw_proto
= 0;
1631 case MFF_IP_DSCP_SHIFTED
:
1632 match
->wc
.masks
.nw_tos
&= ~IP_DSCP_MASK
;
1633 match
->flow
.nw_tos
&= ~IP_DSCP_MASK
;
1637 match
->wc
.masks
.nw_tos
&= ~IP_ECN_MASK
;
1638 match
->flow
.nw_tos
&= ~IP_ECN_MASK
;
1642 match
->wc
.masks
.nw_ttl
= 0;
1643 match
->flow
.nw_ttl
= 0;
1647 match
->wc
.masks
.nw_frag
&= ~FLOW_NW_FRAG_MASK
;
1648 match
->flow
.nw_frag
&= ~FLOW_NW_FRAG_MASK
;
1652 match
->wc
.masks
.nw_proto
= 0;
1653 match
->flow
.nw_proto
= 0;
1658 match
->flow
.arp_sha
= eth_addr_zero
;
1659 match
->wc
.masks
.arp_sha
= eth_addr_zero
;
1664 match
->flow
.arp_tha
= eth_addr_zero
;
1665 match
->wc
.masks
.arp_tha
= eth_addr_zero
;
1671 case MFF_ICMPV4_TYPE
:
1672 case MFF_ICMPV6_TYPE
:
1673 match
->wc
.masks
.tp_src
= htons(0);
1674 match
->flow
.tp_src
= htons(0);
1680 case MFF_ICMPV4_CODE
:
1681 case MFF_ICMPV6_CODE
:
1682 match
->wc
.masks
.tp_dst
= htons(0);
1683 match
->flow
.tp_dst
= htons(0);
1687 match
->wc
.masks
.tcp_flags
= htons(0);
1688 match
->flow
.tcp_flags
= htons(0);
1692 memset(&match
->wc
.masks
.nd_target
, 0,
1693 sizeof match
->wc
.masks
.nd_target
);
1694 memset(&match
->flow
.nd_target
, 0, sizeof match
->flow
.nd_target
);
1703 /* Makes 'match' match field 'mf' with the specified 'value' and 'mask'.
1704 * 'value' specifies a value to match and 'mask' specifies a wildcard pattern,
1705 * with a 1-bit indicating that the corresponding value bit must match and a
1706 * 0-bit indicating a don't-care.
1708 * If 'mask' is NULL or points to all-1-bits, then this call is equivalent to
1709 * mf_set_value(mf, value, match). If 'mask' points to all-0-bits, then this
1710 * call is equivalent to mf_set_wild(mf, match).
1712 * 'mask' must be a valid mask for 'mf' (see mf_is_mask_valid()). The caller
1713 * is responsible for ensuring that 'match' meets 'mf''s prerequisites.
1715 * If non-NULL, 'err_str' returns a malloc'ed string describing any errors
1716 * with the request or NULL if there is no error. The caller is reponsible
1717 * for freeing the string.
1719 * Return a set of enum ofputil_protocol bits (as an uint32_t to avoid circular
1720 * dependency on enum ofputil_protocol definition) indicating which OpenFlow
1721 * protocol versions can support this functionality. */
1723 mf_set(const struct mf_field
*mf
,
1724 const union mf_value
*value
, const union mf_value
*mask
,
1725 struct match
*match
, char **err_str
)
1727 if (!mask
|| is_all_ones(mask
, mf
->n_bytes
)) {
1728 mf_set_value(mf
, value
, match
, err_str
);
1729 return mf
->usable_protocols_exact
;
1730 } else if (is_all_zeros(mask
, mf
->n_bytes
) && !mf_is_tun_metadata(mf
)) {
1731 /* Tunnel metadata matches on the existence of the field itself, so
1732 * it still needs to be encoded even if the value is wildcarded. */
1733 mf_set_wild(mf
, match
, err_str
);
1734 return OFPUTIL_P_ANY
;
1746 case MFF_IN_PORT_OXM
:
1747 case MFF_ACTSET_OUTPUT
:
1748 case MFF_SKB_PRIORITY
:
1751 case MFF_DL_VLAN_PCP
:
1753 case MFF_MPLS_LABEL
:
1760 case MFF_IP_DSCP_SHIFTED
:
1763 case MFF_ICMPV4_TYPE
:
1764 case MFF_ICMPV4_CODE
:
1765 case MFF_ICMPV6_TYPE
:
1766 case MFF_ICMPV6_CODE
:
1767 return OFPUTIL_P_NONE
;
1770 match_set_dp_hash_masked(match
, ntohl(value
->be32
), ntohl(mask
->be32
));
1773 match_set_tun_id_masked(match
, value
->be64
, mask
->be64
);
1776 match_set_tun_src_masked(match
, value
->be32
, mask
->be32
);
1779 match_set_tun_dst_masked(match
, value
->be32
, mask
->be32
);
1781 case MFF_TUN_IPV6_SRC
:
1782 match_set_tun_ipv6_src_masked(match
, &value
->ipv6
, &mask
->ipv6
);
1784 case MFF_TUN_IPV6_DST
:
1785 match_set_tun_ipv6_dst_masked(match
, &value
->ipv6
, &mask
->ipv6
);
1788 match_set_tun_flags_masked(match
, ntohs(value
->be16
), ntohs(mask
->be16
));
1790 case MFF_TUN_GBP_ID
:
1791 match_set_tun_gbp_id_masked(match
, value
->be16
, mask
->be16
);
1793 case MFF_TUN_GBP_FLAGS
:
1794 match_set_tun_gbp_flags_masked(match
, value
->u8
, mask
->u8
);
1797 match_set_tun_ttl_masked(match
, value
->u8
, mask
->u8
);
1800 match_set_tun_tos_masked(match
, value
->u8
, mask
->u8
);
1802 CASE_MFF_TUN_METADATA
:
1803 tun_metadata_set_match(mf
, value
, mask
, match
, err_str
);
1807 match_set_metadata_masked(match
, value
->be64
, mask
->be64
);
1811 match_set_reg_masked(match
, mf
->id
- MFF_REG0
,
1812 ntohl(value
->be32
), ntohl(mask
->be32
));
1816 match_set_xreg_masked(match
, mf
->id
- MFF_XREG0
,
1817 ntohll(value
->be64
), ntohll(mask
->be64
));
1821 match_set_xxreg_masked(match
, mf
->id
- MFF_XXREG0
,
1822 ntoh128(value
->be128
), ntoh128(mask
->be128
));
1827 match_set_pkt_mark_masked(match
, ntohl(value
->be32
),
1832 match_set_ct_state_masked(match
, ntohl(value
->be32
), ntohl(mask
->be32
));
1836 match_set_ct_mark_masked(match
, ntohl(value
->be32
), ntohl(mask
->be32
));
1840 match_set_ct_label_masked(match
, ntoh128(value
->be128
),
1841 mask
? ntoh128(mask
->be128
) : OVS_U128_MAX
);
1845 match_set_dl_dst_masked(match
, value
->mac
, mask
->mac
);
1849 match_set_dl_src_masked(match
, value
->mac
, mask
->mac
);
1854 match_set_arp_sha_masked(match
, value
->mac
, mask
->mac
);
1859 match_set_arp_tha_masked(match
, value
->mac
, mask
->mac
);
1863 match_set_dl_tci_masked(match
, value
->be16
, mask
->be16
);
1867 match_set_vlan_vid_masked(match
, value
->be16
, mask
->be16
);
1871 match_set_nw_src_masked(match
, value
->be32
, mask
->be32
);
1875 match_set_nw_dst_masked(match
, value
->be32
, mask
->be32
);
1879 match_set_ipv6_src_masked(match
, &value
->ipv6
, &mask
->ipv6
);
1883 match_set_ipv6_dst_masked(match
, &value
->ipv6
, &mask
->ipv6
);
1886 case MFF_IPV6_LABEL
:
1887 if ((mask
->be32
& htonl(IPV6_LABEL_MASK
)) == htonl(IPV6_LABEL_MASK
)) {
1888 mf_set_value(mf
, value
, match
, err_str
);
1890 match_set_ipv6_label_masked(match
, value
->be32
, mask
->be32
);
1895 match_set_nd_target_masked(match
, &value
->ipv6
, &mask
->ipv6
);
1899 match_set_nw_frag_masked(match
, value
->u8
, mask
->u8
);
1903 match_set_nw_src_masked(match
, value
->be32
, mask
->be32
);
1907 match_set_nw_dst_masked(match
, value
->be32
, mask
->be32
);
1913 match_set_tp_src_masked(match
, value
->be16
, mask
->be16
);
1919 match_set_tp_dst_masked(match
, value
->be16
, mask
->be16
);
1923 match_set_tcp_flags_masked(match
, value
->be16
, mask
->be16
);
1931 return ((mf
->usable_protocols_bitwise
== mf
->usable_protocols_cidr
1932 || ip_is_cidr(mask
->be32
))
1933 ? mf
->usable_protocols_cidr
1934 : mf
->usable_protocols_bitwise
);
1938 mf_check__(const struct mf_subfield
*sf
, const struct flow
*flow
,
1942 VLOG_WARN_RL(&rl
, "unknown %s field", type
);
1943 return OFPERR_OFPBAC_BAD_SET_TYPE
;
1944 } else if (!sf
->n_bits
) {
1945 VLOG_WARN_RL(&rl
, "zero bit %s field %s", type
, sf
->field
->name
);
1946 return OFPERR_OFPBAC_BAD_SET_LEN
;
1947 } else if (sf
->ofs
>= sf
->field
->n_bits
) {
1948 VLOG_WARN_RL(&rl
, "bit offset %d exceeds %d-bit width of %s field %s",
1949 sf
->ofs
, sf
->field
->n_bits
, type
, sf
->field
->name
);
1950 return OFPERR_OFPBAC_BAD_SET_LEN
;
1951 } else if (sf
->ofs
+ sf
->n_bits
> sf
->field
->n_bits
) {
1952 VLOG_WARN_RL(&rl
, "bit offset %d and width %d exceeds %d-bit width "
1953 "of %s field %s", sf
->ofs
, sf
->n_bits
,
1954 sf
->field
->n_bits
, type
, sf
->field
->name
);
1955 return OFPERR_OFPBAC_BAD_SET_LEN
;
1956 } else if (flow
&& !mf_are_prereqs_ok(sf
->field
, flow
, NULL
)) {
1957 VLOG_WARN_RL(&rl
, "%s field %s lacks correct prerequisites",
1958 type
, sf
->field
->name
);
1959 return OFPERR_OFPBAC_MATCH_INCONSISTENT
;
1965 /* Sets all the bits in 'sf' to 1 within 'wc', if 'wc' is nonnull. */
1967 unwildcard_subfield(const struct mf_subfield
*sf
, struct flow_wildcards
*wc
)
1970 union mf_value mask
;
1972 memset(&mask
, 0, sizeof mask
);
1973 bitwise_one(&mask
, sf
->field
->n_bytes
, sf
->ofs
, sf
->n_bits
);
1974 mf_mask_field_masked(sf
->field
, &mask
, wc
);
1978 /* Copies 'src' into 'dst' within 'flow', and sets all the bits in 'src' and
1979 * 'dst' to 1s in 'wc', if 'wc' is nonnull.
1981 * 'src' and 'dst' may overlap. */
1983 mf_subfield_copy(const struct mf_subfield
*src
,
1984 const struct mf_subfield
*dst
,
1985 struct flow
*flow
, struct flow_wildcards
*wc
)
1987 ovs_assert(src
->n_bits
== dst
->n_bits
);
1988 if (mf_are_prereqs_ok(dst
->field
, flow
, wc
)
1989 && mf_are_prereqs_ok(src
->field
, flow
, wc
)) {
1990 unwildcard_subfield(src
, wc
);
1991 unwildcard_subfield(dst
, wc
);
1993 union mf_value src_value
;
1994 union mf_value dst_value
;
1995 mf_get_value(dst
->field
, flow
, &dst_value
);
1996 mf_get_value(src
->field
, flow
, &src_value
);
1997 bitwise_copy(&src_value
, src
->field
->n_bytes
, src
->ofs
,
1998 &dst_value
, dst
->field
->n_bytes
, dst
->ofs
,
2000 mf_set_flow_value(dst
->field
, &dst_value
, flow
);
2004 /* Swaps the bits in 'src' and 'dst' within 'flow', and sets all the bits in
2005 * 'src' and 'dst' to 1s in 'wc', if 'wc' is nonnull.
2007 * 'src' and 'dst' may overlap. */
2009 mf_subfield_swap(const struct mf_subfield
*a
,
2010 const struct mf_subfield
*b
,
2011 struct flow
*flow
, struct flow_wildcards
*wc
)
2013 ovs_assert(a
->n_bits
== b
->n_bits
);
2014 if (mf_are_prereqs_ok(a
->field
, flow
, wc
)
2015 && mf_are_prereqs_ok(b
->field
, flow
, wc
)) {
2016 unwildcard_subfield(a
, wc
);
2017 unwildcard_subfield(b
, wc
);
2019 union mf_value a_value
;
2020 union mf_value b_value
;
2021 mf_get_value(a
->field
, flow
, &a_value
);
2022 mf_get_value(b
->field
, flow
, &b_value
);
2023 union mf_value b2_value
= b_value
;
2025 /* Copy 'a' into 'b'. */
2026 bitwise_copy(&a_value
, a
->field
->n_bytes
, a
->ofs
,
2027 &b_value
, b
->field
->n_bytes
, b
->ofs
,
2029 mf_set_flow_value(b
->field
, &b_value
, flow
);
2031 /* Copy original 'b' into 'a'. */
2032 bitwise_copy(&b2_value
, b
->field
->n_bytes
, b
->ofs
,
2033 &a_value
, a
->field
->n_bytes
, a
->ofs
,
2035 mf_set_flow_value(a
->field
, &a_value
, flow
);
2039 /* Checks whether 'sf' is valid for reading a subfield out of 'flow'. Returns
2040 * 0 if so, otherwise an OpenFlow error code (e.g. as returned by
2043 mf_check_src(const struct mf_subfield
*sf
, const struct flow
*flow
)
2045 return mf_check__(sf
, flow
, "source");
2048 /* Checks whether 'sf' is valid for writing a subfield into 'flow'. Returns 0
2049 * if so, otherwise an OpenFlow error code (e.g. as returned by
2052 mf_check_dst(const struct mf_subfield
*sf
, const struct flow
*flow
)
2054 int error
= mf_check__(sf
, flow
, "destination");
2055 if (!error
&& !sf
->field
->writable
) {
2056 VLOG_WARN_RL(&rl
, "destination field %s is not writable",
2058 return OFPERR_OFPBAC_BAD_SET_ARGUMENT
;
2063 /* Copies the value and wildcard bit pattern for 'mf' from 'match' into the
2064 * 'value' and 'mask', respectively. */
2066 mf_get(const struct mf_field
*mf
, const struct match
*match
,
2067 union mf_value
*value
, union mf_value
*mask
)
2069 mf_get_value(mf
, &match
->flow
, value
);
2070 mf_get_mask(mf
, &match
->wc
, mask
);
2074 mf_from_integer_string(const struct mf_field
*mf
, const char *s
,
2075 uint8_t *valuep
, uint8_t *maskp
)
2078 const char *err_str
= "";
2081 err
= parse_int_string(s
, valuep
, mf
->n_bytes
, &tail
);
2082 if (err
|| (*tail
!= '\0' && *tail
!= '/')) {
2088 err
= parse_int_string(tail
+ 1, maskp
, mf
->n_bytes
, &tail
);
2089 if (err
|| *tail
!= '\0') {
2094 memset(maskp
, 0xff, mf
->n_bytes
);
2100 if (err
== ERANGE
) {
2101 return xasprintf("%s: %s too large for %u-byte field %s",
2102 s
, err_str
, mf
->n_bytes
, mf
->name
);
2104 return xasprintf("%s: bad syntax for %s %s", s
, mf
->name
, err_str
);
2109 mf_from_ethernet_string(const struct mf_field
*mf
, const char *s
,
2110 struct eth_addr
*mac
, struct eth_addr
*mask
)
2114 ovs_assert(mf
->n_bytes
== ETH_ADDR_LEN
);
2117 if (ovs_scan(s
, ETH_ADDR_SCAN_FMT
"%n", ETH_ADDR_SCAN_ARGS(*mac
), &n
)
2118 && n
== strlen(s
)) {
2119 *mask
= eth_addr_exact
;
2124 if (ovs_scan(s
, ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
"%n",
2125 ETH_ADDR_SCAN_ARGS(*mac
), ETH_ADDR_SCAN_ARGS(*mask
), &n
)
2126 && n
== strlen(s
)) {
2130 return xasprintf("%s: invalid Ethernet address", s
);
2134 mf_from_ipv4_string(const struct mf_field
*mf
, const char *s
,
2135 ovs_be32
*ip
, ovs_be32
*mask
)
2137 ovs_assert(mf
->n_bytes
== sizeof *ip
);
2138 return ip_parse_masked(s
, ip
, mask
);
2142 mf_from_ipv6_string(const struct mf_field
*mf
, const char *s
,
2143 struct in6_addr
*ipv6
, struct in6_addr
*mask
)
2145 ovs_assert(mf
->n_bytes
== sizeof *ipv6
);
2146 return ipv6_parse_masked(s
, ipv6
, mask
);
2150 mf_from_ofp_port_string(const struct mf_field
*mf
, const char *s
,
2151 ovs_be16
*valuep
, ovs_be16
*maskp
)
2155 ovs_assert(mf
->n_bytes
== sizeof(ovs_be16
));
2157 if (ofputil_port_from_string(s
, &port
)) {
2158 *valuep
= htons(ofp_to_u16(port
));
2159 *maskp
= OVS_BE16_MAX
;
2162 return xasprintf("%s: port value out of range for %s", s
, mf
->name
);
2166 mf_from_ofp_port_string32(const struct mf_field
*mf
, const char *s
,
2167 ovs_be32
*valuep
, ovs_be32
*maskp
)
2171 ovs_assert(mf
->n_bytes
== sizeof(ovs_be32
));
2172 if (ofputil_port_from_string(s
, &port
)) {
2173 *valuep
= ofputil_port_to_ofp11(port
);
2174 *maskp
= OVS_BE32_MAX
;
2177 return xasprintf("%s: port value out of range for %s", s
, mf
->name
);
2180 struct frag_handling
{
2186 static const struct frag_handling all_frags
[] = {
2187 #define A FLOW_NW_FRAG_ANY
2188 #define L FLOW_NW_FRAG_LATER
2189 /* name mask value */
2192 { "first", A
|L
, A
},
2193 { "later", A
|L
, A
|L
},
2198 { "not_later", L
, 0 },
2205 mf_from_frag_string(const char *s
, uint8_t *valuep
, uint8_t *maskp
)
2207 const struct frag_handling
*h
;
2209 for (h
= all_frags
; h
< &all_frags
[ARRAY_SIZE(all_frags
)]; h
++) {
2210 if (!strcasecmp(s
, h
->name
)) {
2211 /* We force the upper bits of the mask on to make mf_parse_value()
2212 * happy (otherwise it will never think it's an exact match.) */
2213 *maskp
= h
->mask
| ~FLOW_NW_FRAG_MASK
;
2219 return xasprintf("%s: unknown fragment type (valid types are \"no\", "
2220 "\"yes\", \"first\", \"later\", \"not_first\"", s
);
2224 parse_mf_flags(const char *s
, const char *(*bit_to_string
)(uint32_t),
2225 const char *field_name
, ovs_be16
*flagsp
, ovs_be16 allowed
,
2230 uint32_t flags
, mask
;
2232 err
= parse_flags(s
, bit_to_string
, '\0', field_name
, &err_str
,
2233 &flags
, ntohs(allowed
), maskp
? &mask
: NULL
);
2238 *flagsp
= htons(flags
);
2240 *maskp
= htons(mask
);
2247 mf_from_tcp_flags_string(const char *s
, ovs_be16
*flagsp
, ovs_be16
*maskp
)
2249 return parse_mf_flags(s
, packet_tcp_flag_to_string
, "TCP", flagsp
,
2250 TCP_FLAGS_BE16(OVS_BE16_MAX
), maskp
);
2254 mf_from_tun_flags_string(const char *s
, ovs_be16
*flagsp
, ovs_be16
*maskp
)
2256 return parse_mf_flags(s
, flow_tun_flag_to_string
, "tunnel", flagsp
,
2257 htons(FLOW_TNL_PUB_F_MASK
), maskp
);
2261 mf_from_ct_state_string(const char *s
, ovs_be32
*flagsp
, ovs_be32
*maskp
)
2265 uint32_t flags
, mask
;
2267 err
= parse_flags(s
, ct_state_to_string
, '\0', "ct_state", &err_str
,
2268 &flags
, CS_SUPPORTED_MASK
, maskp
? &mask
: NULL
);
2273 *flagsp
= htonl(flags
);
2275 *maskp
= htonl(mask
);
2281 /* Parses 's', a string value for field 'mf', into 'value' and 'mask'. Returns
2282 * NULL if successful, otherwise a malloc()'d string describing the error. */
2284 mf_parse(const struct mf_field
*mf
, const char *s
,
2285 union mf_value
*value
, union mf_value
*mask
)
2289 if (!strcmp(s
, "*")) {
2290 memset(value
, 0, mf
->n_bytes
);
2291 memset(mask
, 0, mf
->n_bytes
);
2295 switch (mf
->string
) {
2297 case MFS_HEXADECIMAL
:
2298 error
= mf_from_integer_string(mf
, s
,
2299 (uint8_t *) value
, (uint8_t *) mask
);
2303 ovs_assert(mf
->n_bytes
== sizeof(ovs_be32
));
2304 error
= mf_from_ct_state_string(s
, &value
->be32
, &mask
->be32
);
2308 error
= mf_from_ethernet_string(mf
, s
, &value
->mac
, &mask
->mac
);
2312 error
= mf_from_ipv4_string(mf
, s
, &value
->be32
, &mask
->be32
);
2316 error
= mf_from_ipv6_string(mf
, s
, &value
->ipv6
, &mask
->ipv6
);
2320 error
= mf_from_ofp_port_string(mf
, s
, &value
->be16
, &mask
->be16
);
2323 case MFS_OFP_PORT_OXM
:
2324 error
= mf_from_ofp_port_string32(mf
, s
, &value
->be32
, &mask
->be32
);
2328 error
= mf_from_frag_string(s
, &value
->u8
, &mask
->u8
);
2332 ovs_assert(mf
->n_bytes
== sizeof(ovs_be16
));
2333 error
= mf_from_tun_flags_string(s
, &value
->be16
, &mask
->be16
);
2337 ovs_assert(mf
->n_bytes
== sizeof(ovs_be16
));
2338 error
= mf_from_tcp_flags_string(s
, &value
->be16
, &mask
->be16
);
2345 if (!error
&& !mf_is_mask_valid(mf
, mask
)) {
2346 error
= xasprintf("%s: invalid mask for field %s", s
, mf
->name
);
2351 /* Parses 's', a string value for field 'mf', into 'value'. Returns NULL if
2352 * successful, otherwise a malloc()'d string describing the error. */
2354 mf_parse_value(const struct mf_field
*mf
, const char *s
, union mf_value
*value
)
2356 union mf_value mask
;
2359 error
= mf_parse(mf
, s
, value
, &mask
);
2364 if (!is_all_ones((const uint8_t *) &mask
, mf
->n_bytes
)) {
2365 return xasprintf("%s: wildcards not allowed here", s
);
2371 mf_format_integer_string(const struct mf_field
*mf
, const uint8_t *valuep
,
2372 const uint8_t *maskp
, struct ds
*s
)
2374 if (mf
->string
== MFS_HEXADECIMAL
) {
2375 ds_put_hex(s
, valuep
, mf
->n_bytes
);
2377 unsigned long long int integer
= 0;
2380 ovs_assert(mf
->n_bytes
<= 8);
2381 for (i
= 0; i
< mf
->n_bytes
; i
++) {
2382 integer
= (integer
<< 8) | valuep
[i
];
2384 ds_put_format(s
, "%lld", integer
);
2388 /* I guess we could write the mask in decimal for MFS_DECIMAL but I'm
2389 * not sure that that a bit-mask written in decimal is ever easier to
2390 * understand than the same bit-mask written in hexadecimal. */
2391 ds_put_char(s
, '/');
2392 ds_put_hex(s
, maskp
, mf
->n_bytes
);
2397 mf_format_frag_string(uint8_t value
, uint8_t mask
, struct ds
*s
)
2399 const struct frag_handling
*h
;
2401 mask
&= FLOW_NW_FRAG_MASK
;
2404 for (h
= all_frags
; h
< &all_frags
[ARRAY_SIZE(all_frags
)]; h
++) {
2405 if (value
== h
->value
&& mask
== h
->mask
) {
2406 ds_put_cstr(s
, h
->name
);
2410 ds_put_cstr(s
, "<error>");
2414 mf_format_tnl_flags_string(ovs_be16 value
, ovs_be16 mask
, struct ds
*s
)
2416 format_flags_masked(s
, NULL
, flow_tun_flag_to_string
, ntohs(value
),
2417 ntohs(mask
) & FLOW_TNL_PUB_F_MASK
, FLOW_TNL_PUB_F_MASK
);
2421 mf_format_tcp_flags_string(ovs_be16 value
, ovs_be16 mask
, struct ds
*s
)
2423 format_flags_masked(s
, NULL
, packet_tcp_flag_to_string
, ntohs(value
),
2424 TCP_FLAGS(mask
), TCP_FLAGS(OVS_BE16_MAX
));
2428 mf_format_ct_state_string(ovs_be32 value
, ovs_be32 mask
, struct ds
*s
)
2430 format_flags_masked(s
, NULL
, ct_state_to_string
, ntohl(value
),
2431 ntohl(mask
), UINT16_MAX
);
2434 /* Appends to 's' a string representation of field 'mf' whose value is in
2435 * 'value' and 'mask'. 'mask' may be NULL to indicate an exact match. */
2437 mf_format(const struct mf_field
*mf
,
2438 const union mf_value
*value
, const union mf_value
*mask
,
2442 if (is_all_zeros(mask
, mf
->n_bytes
)) {
2443 ds_put_cstr(s
, "ANY");
2445 } else if (is_all_ones(mask
, mf
->n_bytes
)) {
2450 switch (mf
->string
) {
2451 case MFS_OFP_PORT_OXM
:
2454 ofputil_port_from_ofp11(value
->be32
, &port
);
2455 ofputil_format_port(port
, s
);
2461 ofputil_format_port(u16_to_ofp(ntohs(value
->be16
)), s
);
2466 case MFS_HEXADECIMAL
:
2467 mf_format_integer_string(mf
, (uint8_t *) value
, (uint8_t *) mask
, s
);
2471 mf_format_ct_state_string(value
->be32
,
2472 mask
? mask
->be32
: OVS_BE32_MAX
, s
);
2476 eth_format_masked(value
->mac
, mask
? &mask
->mac
: NULL
, s
);
2480 ip_format_masked(value
->be32
, mask
? mask
->be32
: OVS_BE32_MAX
, s
);
2484 ipv6_format_masked(&value
->ipv6
, mask
? &mask
->ipv6
: NULL
, s
);
2488 mf_format_frag_string(value
->u8
, mask
? mask
->u8
: UINT8_MAX
, s
);
2492 mf_format_tnl_flags_string(value
->be16
,
2493 mask
? mask
->be16
: OVS_BE16_MAX
, s
);
2497 mf_format_tcp_flags_string(value
->be16
,
2498 mask
? mask
->be16
: OVS_BE16_MAX
, s
);
2506 /* Makes subfield 'sf' within 'flow' exactly match the 'sf->n_bits'
2507 * least-significant bits in 'x'.
2510 mf_write_subfield_flow(const struct mf_subfield
*sf
,
2511 const union mf_subvalue
*x
, struct flow
*flow
)
2513 const struct mf_field
*field
= sf
->field
;
2514 union mf_value value
;
2516 mf_get_value(field
, flow
, &value
);
2517 bitwise_copy(x
, sizeof *x
, 0, &value
, field
->n_bytes
,
2518 sf
->ofs
, sf
->n_bits
);
2519 mf_set_flow_value(field
, &value
, flow
);
2522 /* Makes subfield 'sf' within 'match' exactly match the 'sf->n_bits'
2523 * least-significant bits in 'x'.
2526 mf_write_subfield(const struct mf_subfield
*sf
, const union mf_subvalue
*x
,
2527 struct match
*match
)
2529 const struct mf_field
*field
= sf
->field
;
2530 union mf_value value
, mask
;
2532 mf_get(field
, match
, &value
, &mask
);
2533 bitwise_copy(x
, sizeof *x
, 0, &value
, field
->n_bytes
, sf
->ofs
, sf
->n_bits
);
2534 bitwise_one ( &mask
, field
->n_bytes
, sf
->ofs
, sf
->n_bits
);
2535 mf_set(field
, &value
, &mask
, match
, NULL
);
2539 mf_write_subfield_value(const struct mf_subfield
*sf
, const void *src
,
2540 struct match
*match
)
2542 const struct mf_field
*field
= sf
->field
;
2543 union mf_value value
, mask
;
2544 unsigned int size
= DIV_ROUND_UP(sf
->n_bits
, 8);
2546 mf_get(field
, match
, &value
, &mask
);
2547 bitwise_copy(src
, size
, 0, &value
, field
->n_bytes
, sf
->ofs
, sf
->n_bits
);
2548 bitwise_one ( &mask
, field
->n_bytes
, sf
->ofs
, sf
->n_bits
);
2549 mf_set(field
, &value
, &mask
, match
, NULL
);
2552 /* 'v' and 'm' correspond to values of 'field'. This function copies them into
2553 * 'match' in the correspond positions. */
2555 mf_mask_subfield(const struct mf_field
*field
,
2556 const union mf_subvalue
*v
,
2557 const union mf_subvalue
*m
,
2558 struct match
*match
)
2560 union mf_value value
, mask
;
2562 mf_get(field
, match
, &value
, &mask
);
2563 bitwise_copy(v
, sizeof *v
, 0, &value
, field
->n_bytes
, 0, field
->n_bits
);
2564 bitwise_copy(m
, sizeof *m
, 0, &mask
, field
->n_bytes
, 0, field
->n_bits
);
2565 mf_set(field
, &value
, &mask
, match
, NULL
);
2568 /* Initializes 'x' to the value of 'sf' within 'flow'. 'sf' must be valid for
2569 * reading 'flow', e.g. as checked by mf_check_src(). */
2571 mf_read_subfield(const struct mf_subfield
*sf
, const struct flow
*flow
,
2572 union mf_subvalue
*x
)
2574 union mf_value value
;
2576 mf_get_value(sf
->field
, flow
, &value
);
2578 memset(x
, 0, sizeof *x
);
2579 bitwise_copy(&value
, sf
->field
->n_bytes
, sf
->ofs
,
2584 /* Returns the value of 'sf' within 'flow'. 'sf' must be valid for reading
2585 * 'flow', e.g. as checked by mf_check_src() and sf->n_bits must be 64 or
2588 mf_get_subfield(const struct mf_subfield
*sf
, const struct flow
*flow
)
2590 union mf_value value
;
2592 mf_get_value(sf
->field
, flow
, &value
);
2593 return bitwise_get(&value
, sf
->field
->n_bytes
, sf
->ofs
, sf
->n_bits
);
2597 mf_format_subvalue(const union mf_subvalue
*subvalue
, struct ds
*s
)
2599 ds_put_hex(s
, subvalue
->u8
, sizeof subvalue
->u8
);
2603 field_array_set(enum mf_field_id id
, const union mf_value
*value
,
2604 struct field_array
*fa
)
2606 size_t i
, offset
= 0;
2608 ovs_assert(id
< MFF_N_IDS
);
2610 /* Find the spot for 'id'. */
2611 BITMAP_FOR_EACH_1 (i
, id
, fa
->used
.bm
) {
2612 offset
+= mf_from_id(i
)->n_bytes
;
2615 size_t value_size
= mf_from_id(id
)->n_bytes
;
2617 /* make room if necessary. */
2618 if (!bitmap_is_set(fa
->used
.bm
, id
)) {
2619 fa
->values
= xrealloc(fa
->values
, fa
->values_size
+ value_size
);
2620 /* Move remainder forward, if any. */
2621 if (offset
< fa
->values_size
) {
2622 memmove(fa
->values
+ offset
+ value_size
, fa
->values
+ offset
,
2623 fa
->values_size
- offset
);
2625 fa
->values_size
+= value_size
;
2627 bitmap_set1(fa
->used
.bm
, id
);
2629 memcpy(fa
->values
+ offset
, value
, value_size
);