2 * Copyright (c) 2010, 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.
21 #include <netinet/icmp6.h>
23 #include "classifier.h"
26 #include "openflow/nicira-ext.h"
27 #include "openvswitch/dynamic-string.h"
28 #include "openvswitch/meta-flow.h"
29 #include "openvswitch/ofp-actions.h"
30 #include "openvswitch/ofp-errors.h"
31 #include "openvswitch/ofp-util.h"
32 #include "openvswitch/ofpbuf.h"
33 #include "openvswitch/vlog.h"
36 #include "tun-metadata.h"
37 #include "unaligned.h"
40 VLOG_DEFINE_THIS_MODULE(nx_match
);
48 * The header is 32 bits long. It looks like this:
51 * +----------------------------------+---------------+--+------------------+
52 * | oxm_class | oxm_field |hm| oxm_length |
53 * +----------------------------------+---------------+--+------------------+
55 * where hm stands for oxm_hasmask. It is followed by oxm_length bytes of
56 * payload. When oxm_hasmask is 0, the payload is the value of the field
57 * identified by the header; when oxm_hasmask is 1, the payload is a value for
58 * the field followed by a mask of equal length.
60 * Internally, we represent a standard OXM header as a 64-bit integer with the
61 * above information in the most-significant bits.
67 * The header is 64 bits long. It looks like the diagram above except that a
68 * 32-bit experimenter ID, which we call oxm_vendor and which identifies a
69 * vendor, is inserted just before the payload. Experimenter OXMs are
70 * identified by an all-1-bits oxm_class (OFPXMC12_EXPERIMENTER). The
71 * oxm_length value *includes* the experimenter ID, so that the real payload is
72 * only oxm_length - 4 bytes long.
74 * Internally, we represent an experimenter OXM header as a 64-bit integer with
75 * the standard header in the upper 32 bits and the experimenter ID in the
76 * lower 32 bits. (It would be more convenient to swap the positions of the
77 * two 32-bit words, but this would be more error-prone because experimenter
78 * OXMs are very rarely used, so accidentally passing one through a 32-bit type
79 * somewhere in the OVS code would be hard to find.)
84 * The high order bit differentiate reserved classes from member classes.
85 * Classes 0x0000 to 0x7FFF are member classes, allocated by ONF.
86 * Classes 0x8000 to 0xFFFE are reserved classes, reserved for standardisation.
88 enum ofp12_oxm_class
{
89 OFPXMC12_NXM_0
= 0x0000, /* Backward compatibility with NXM */
90 OFPXMC12_NXM_1
= 0x0001, /* Backward compatibility with NXM */
91 OFPXMC12_OPENFLOW_BASIC
= 0x8000, /* Basic class for OpenFlow */
92 OFPXMC15_PACKET_REGS
= 0x8001, /* Packet registers (pipeline fields). */
93 OFPXMC12_EXPERIMENTER
= 0xffff, /* Experimenter class */
96 /* Functions for extracting raw field values from OXM/NXM headers. */
97 static uint32_t nxm_vendor(uint64_t header
) { return header
; }
98 static int nxm_class(uint64_t header
) { return header
>> 48; }
99 static int nxm_field(uint64_t header
) { return (header
>> 41) & 0x7f; }
100 static bool nxm_hasmask(uint64_t header
) { return (header
>> 40) & 1; }
101 static int nxm_length(uint64_t header
) { return (header
>> 32) & 0xff; }
102 static uint64_t nxm_no_len(uint64_t header
) { return header
& 0xffffff80ffffffffULL
; }
105 is_experimenter_oxm(uint64_t header
)
107 return nxm_class(header
) == OFPXMC12_EXPERIMENTER
;
110 /* The OXM header "length" field is somewhat tricky:
112 * - For a standard OXM header, the length is the number of bytes of the
113 * payload, and the payload consists of just the value (and mask, if
116 * - For an experimenter OXM header, the length is the number of bytes in
117 * the payload plus 4 (the length of the experimenter ID). That is, the
118 * experimenter ID is included in oxm_length.
120 * This function returns the length of the experimenter ID field in 'header'.
121 * That is, for an experimenter OXM (when an experimenter ID is present), it
122 * returns 4, and for a standard OXM (when no experimenter ID is present), it
125 nxm_experimenter_len(uint64_t header
)
127 return is_experimenter_oxm(header
) ? 4 : 0;
130 /* Returns the number of bytes that follow the header for an NXM/OXM entry
131 * with the given 'header'. */
133 nxm_payload_len(uint64_t header
)
135 return nxm_length(header
) - nxm_experimenter_len(header
);
138 /* Returns the number of bytes in the header for an NXM/OXM entry with the
141 nxm_header_len(uint64_t header
)
143 return 4 + nxm_experimenter_len(header
);
146 #define NXM_HEADER(VENDOR, CLASS, FIELD, HASMASK, LENGTH) \
147 (((uint64_t) (CLASS) << 48) | \
148 ((uint64_t) (FIELD) << 41) | \
149 ((uint64_t) (HASMASK) << 40) | \
150 ((uint64_t) (LENGTH) << 32) | \
153 #define NXM_HEADER_FMT "%#"PRIx32":%d:%d:%d:%d"
154 #define NXM_HEADER_ARGS(HEADER) \
155 nxm_vendor(HEADER), nxm_class(HEADER), nxm_field(HEADER), \
156 nxm_hasmask(HEADER), nxm_length(HEADER)
158 /* Functions for turning the "hasmask" bit on or off. (This also requires
159 * adjusting the length.) */
161 nxm_make_exact_header(uint64_t header
)
163 int new_len
= nxm_payload_len(header
) / 2 + nxm_experimenter_len(header
);
164 return NXM_HEADER(nxm_vendor(header
), nxm_class(header
),
165 nxm_field(header
), 0, new_len
);
168 nxm_make_wild_header(uint64_t header
)
170 int new_len
= nxm_payload_len(header
) * 2 + nxm_experimenter_len(header
);
171 return NXM_HEADER(nxm_vendor(header
), nxm_class(header
),
172 nxm_field(header
), 1, new_len
);
177 * This may be used to gain the OpenFlow 1.1-like ability to restrict
178 * certain NXM-based Flow Mod and Flow Stats Request messages to flows
179 * with specific cookies. See the "nx_flow_mod" and "nx_flow_stats_request"
180 * structure definitions for more details. This match is otherwise not
182 #define NXM_NX_COOKIE NXM_HEADER (0, 0x0001, 30, 0, 8)
183 #define NXM_NX_COOKIE_W nxm_make_wild_header(NXM_NX_COOKIE)
187 enum ofp_version version
;
188 const char *name
; /* e.g. "NXM_OF_IN_PORT". */
193 static const struct nxm_field
*nxm_field_by_header(uint64_t header
);
194 static const struct nxm_field
*nxm_field_by_name(const char *name
, size_t len
);
195 static const struct nxm_field
*nxm_field_by_mf_id(enum mf_field_id
,
198 static void nx_put_header__(struct ofpbuf
*, uint64_t header
, bool masked
);
199 static void nx_put_header_len(struct ofpbuf
*, enum mf_field_id field
,
200 enum ofp_version version
, bool masked
,
203 /* Rate limit for nx_match parse errors. These always indicate a bug in the
204 * peer and so there's not much point in showing a lot of them. */
205 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
207 static const struct nxm_field
*
208 mf_parse_subfield_name(const char *name
, int name_len
, bool *wild
);
210 /* Returns the preferred OXM header to use for field 'id' in OpenFlow version
211 * 'version'. Specify 0 for 'version' if an NXM legacy header should be
212 * preferred over any standardized OXM header. Returns 0 if field 'id' cannot
213 * be expressed in NXM or OXM. */
215 mf_oxm_header(enum mf_field_id id
, enum ofp_version version
)
217 const struct nxm_field
*f
= nxm_field_by_mf_id(id
, version
);
218 return f
? f
->header
: 0;
221 /* Returns the 32-bit OXM or NXM header to use for field 'id', preferring an
222 * NXM legacy header over any standardized OXM header. Returns 0 if field 'id'
223 * cannot be expressed with a 32-bit NXM or OXM header.
225 * Whenever possible, use nx_pull_header() instead of this function, because
226 * this function cannot support 64-bit experimenter OXM headers. */
228 mf_nxm_header(enum mf_field_id id
)
230 uint64_t oxm
= mf_oxm_header(id
, 0);
231 return is_experimenter_oxm(oxm
) ? 0 : oxm
>> 32;
234 static const struct mf_field
*
235 mf_from_oxm_header(uint64_t header
)
237 const struct nxm_field
*f
= nxm_field_by_header(header
);
238 return f
? mf_from_id(f
->id
) : NULL
;
241 /* Returns the "struct mf_field" that corresponds to NXM or OXM header
242 * 'header', or NULL if 'header' doesn't correspond to any known field. */
243 const struct mf_field
*
244 mf_from_nxm_header(uint32_t header
)
246 return mf_from_oxm_header((uint64_t) header
<< 32);
249 /* Returns the width of the data for a field with the given 'header', in
252 nxm_field_bytes(uint64_t header
)
254 unsigned int length
= nxm_payload_len(header
);
255 return nxm_hasmask(header
) ? length
/ 2 : length
;
258 /* nx_pull_match() and helpers. */
260 /* Given NXM/OXM value 'value' and mask 'mask' associated with 'header', checks
261 * for any 1-bit in the value where there is a 0-bit in the mask. Returns 0 if
262 * none, otherwise an error code. */
264 is_mask_consistent(uint64_t header
, const uint8_t *value
, const uint8_t *mask
)
266 unsigned int width
= nxm_field_bytes(header
);
269 for (i
= 0; i
< width
; i
++) {
270 if (value
[i
] & ~mask
[i
]) {
271 if (!VLOG_DROP_WARN(&rl
)) {
272 VLOG_WARN_RL(&rl
, "Rejecting NXM/OXM entry "NXM_HEADER_FMT
" "
273 "with 1-bits in value for bits wildcarded by the "
274 "mask.", NXM_HEADER_ARGS(header
));
283 is_cookie_pseudoheader(uint64_t header
)
285 return header
== NXM_NX_COOKIE
|| header
== NXM_NX_COOKIE_W
;
289 nx_pull_header__(struct ofpbuf
*b
, bool allow_cookie
, uint64_t *header
,
290 const struct mf_field
**field
)
296 *header
= ((uint64_t) ntohl(get_unaligned_be32(b
->data
))) << 32;
297 if (is_experimenter_oxm(*header
)) {
301 *header
= ntohll(get_unaligned_be64(b
->data
));
303 if (nxm_length(*header
) < nxm_experimenter_len(*header
)) {
304 VLOG_WARN_RL(&rl
, "OXM header "NXM_HEADER_FMT
" has invalid length %d "
306 NXM_HEADER_ARGS(*header
), nxm_length(*header
),
307 nxm_header_len(*header
));
310 ofpbuf_pull(b
, nxm_header_len(*header
));
313 *field
= mf_from_oxm_header(*header
);
314 if (!*field
&& !(allow_cookie
&& is_cookie_pseudoheader(*header
))) {
315 VLOG_DBG_RL(&rl
, "OXM header "NXM_HEADER_FMT
" is unknown",
316 NXM_HEADER_ARGS(*header
));
317 return OFPERR_OFPBMC_BAD_FIELD
;
324 VLOG_DBG_RL(&rl
, "encountered partial (%"PRIu32
"-byte) OXM entry",
331 return OFPERR_OFPBMC_BAD_LEN
;
335 copy_entry_value(const struct mf_field
*field
, union mf_value
*value
,
336 const uint8_t *payload
, int width
)
342 copy_len
= MIN(width
, field
? field
->n_bytes
: sizeof *value
);
344 if (field
&& field
->variable_len
) {
345 memset(value
, 0, field
->n_bytes
);
346 copy_dst
= &value
->u8
+ field
->n_bytes
- copy_len
;
349 memcpy(copy_dst
, payload
, copy_len
);
353 nx_pull_entry__(struct ofpbuf
*b
, bool allow_cookie
, uint64_t *header
,
354 const struct mf_field
**field_
,
355 union mf_value
*value
, union mf_value
*mask
)
357 const struct mf_field
*field
;
358 enum ofperr header_error
;
359 unsigned int payload_len
;
360 const uint8_t *payload
;
363 header_error
= nx_pull_header__(b
, allow_cookie
, header
, &field
);
364 if (header_error
&& header_error
!= OFPERR_OFPBMC_BAD_FIELD
) {
368 payload_len
= nxm_payload_len(*header
);
369 payload
= ofpbuf_try_pull(b
, payload_len
);
371 VLOG_DBG_RL(&rl
, "OXM header "NXM_HEADER_FMT
" calls for %u-byte "
372 "payload but only %"PRIu32
" bytes follow OXM header",
373 NXM_HEADER_ARGS(*header
), payload_len
, b
->size
);
374 return OFPERR_OFPBMC_BAD_LEN
;
377 width
= nxm_field_bytes(*header
);
378 if (nxm_hasmask(*header
)
379 && !is_mask_consistent(*header
, payload
, payload
+ width
)) {
380 return OFPERR_OFPBMC_BAD_WILDCARDS
;
383 copy_entry_value(field
, value
, payload
, width
);
386 if (nxm_hasmask(*header
)) {
387 copy_entry_value(field
, mask
, payload
+ width
, width
);
389 memset(mask
, 0xff, sizeof *mask
);
391 } else if (nxm_hasmask(*header
)) {
392 VLOG_DBG_RL(&rl
, "OXM header "NXM_HEADER_FMT
" includes mask but "
393 "masked OXMs are not allowed here",
394 NXM_HEADER_ARGS(*header
));
395 return OFPERR_OFPBMC_BAD_MASK
;
406 /* Attempts to pull an NXM or OXM header, value, and mask (if present) from the
407 * beginning of 'b'. If successful, stores a pointer to the "struct mf_field"
408 * corresponding to the pulled header in '*field', the value into '*value',
409 * and the mask into '*mask', and returns 0. On error, returns an OpenFlow
410 * error; in this case, some bytes might have been pulled off 'b' anyhow, and
411 * the output parameters might have been modified.
413 * If a NULL 'mask' is supplied, masked OXM or NXM entries are treated as
414 * errors (with OFPERR_OFPBMC_BAD_MASK).
417 nx_pull_entry(struct ofpbuf
*b
, const struct mf_field
**field
,
418 union mf_value
*value
, union mf_value
*mask
)
422 return nx_pull_entry__(b
, false, &header
, field
, value
, mask
);
425 /* Attempts to pull an NXM or OXM header from the beginning of 'b'. If
426 * successful, stores a pointer to the "struct mf_field" corresponding to the
427 * pulled header in '*field', stores the header's hasmask bit in '*masked'
428 * (true if hasmask=1, false if hasmask=0), and returns 0. On error, returns
429 * an OpenFlow error; in this case, some bytes might have been pulled off 'b'
430 * anyhow, and the output parameters might have been modified.
432 * If NULL 'masked' is supplied, masked OXM or NXM headers are treated as
433 * errors (with OFPERR_OFPBMC_BAD_MASK).
436 nx_pull_header(struct ofpbuf
*b
, const struct mf_field
**field
, bool *masked
)
441 error
= nx_pull_header__(b
, false, &header
, field
);
443 *masked
= !error
&& nxm_hasmask(header
);
444 } else if (!error
&& nxm_hasmask(header
)) {
445 error
= OFPERR_OFPBMC_BAD_MASK
;
451 nx_pull_match_entry(struct ofpbuf
*b
, bool allow_cookie
,
452 const struct mf_field
**field
,
453 union mf_value
*value
, union mf_value
*mask
)
458 error
= nx_pull_entry__(b
, allow_cookie
, &header
, field
, value
, mask
);
462 if (field
&& *field
) {
463 if (!mf_is_mask_valid(*field
, mask
)) {
464 VLOG_DBG_RL(&rl
, "bad mask for field %s", (*field
)->name
);
465 return OFPERR_OFPBMC_BAD_MASK
;
467 if (!mf_is_value_valid(*field
, value
)) {
468 VLOG_DBG_RL(&rl
, "bad value for field %s", (*field
)->name
);
469 return OFPERR_OFPBMC_BAD_VALUE
;
476 nx_pull_raw(const uint8_t *p
, unsigned int match_len
, bool strict
,
477 struct match
*match
, ovs_be64
*cookie
, ovs_be64
*cookie_mask
)
479 ovs_assert((cookie
!= NULL
) == (cookie_mask
!= NULL
));
481 match_init_catchall(match
);
483 *cookie
= *cookie_mask
= htonll(0);
486 struct ofpbuf b
= ofpbuf_const_initializer(p
, match_len
);
488 const uint8_t *pos
= b
.data
;
489 const struct mf_field
*field
;
490 union mf_value value
;
494 error
= nx_pull_match_entry(&b
, cookie
!= NULL
, &field
, &value
, &mask
);
496 if (error
== OFPERR_OFPBMC_BAD_FIELD
&& !strict
) {
501 error
= OFPERR_OFPBMC_BAD_FIELD
;
502 } else if (*cookie_mask
) {
503 error
= OFPERR_OFPBMC_DUP_FIELD
;
505 *cookie
= value
.be64
;
506 *cookie_mask
= mask
.be64
;
508 } else if (!mf_are_prereqs_ok(field
, &match
->flow
)) {
509 error
= OFPERR_OFPBMC_BAD_PREREQ
;
510 } else if (!mf_is_all_wild(field
, &match
->wc
)) {
511 error
= OFPERR_OFPBMC_DUP_FIELD
;
515 mf_set(field
, &value
, &mask
, match
, &err_str
);
517 VLOG_DBG_RL(&rl
, "error parsing OXM at offset %"PRIdPTR
" "
518 "within match (%s)", pos
- p
, err_str
);
520 return OFPERR_OFPBMC_BAD_VALUE
;
525 VLOG_DBG_RL(&rl
, "error parsing OXM at offset %"PRIdPTR
" "
526 "within match (%s)", pos
-
527 p
, ofperr_to_string(error
));
536 nx_pull_match__(struct ofpbuf
*b
, unsigned int match_len
, bool strict
,
538 ovs_be64
*cookie
, ovs_be64
*cookie_mask
)
543 p
= ofpbuf_try_pull(b
, ROUND_UP(match_len
, 8));
545 VLOG_DBG_RL(&rl
, "nx_match length %u, rounded up to a "
546 "multiple of 8, is longer than space in message (max "
547 "length %"PRIu32
")", match_len
, b
->size
);
548 return OFPERR_OFPBMC_BAD_LEN
;
552 return nx_pull_raw(p
, match_len
, strict
, match
, cookie
, cookie_mask
);
555 /* Parses the nx_match formatted match description in 'b' with length
556 * 'match_len'. Stores the results in 'match'. If 'cookie' and 'cookie_mask'
557 * are valid pointers, then stores the cookie and mask in them if 'b' contains
558 * a "NXM_NX_COOKIE*" match. Otherwise, stores 0 in both.
560 * Fails with an error upon encountering an unknown NXM header.
562 * Returns 0 if successful, otherwise an OpenFlow error code. */
564 nx_pull_match(struct ofpbuf
*b
, unsigned int match_len
, struct match
*match
,
565 ovs_be64
*cookie
, ovs_be64
*cookie_mask
)
567 return nx_pull_match__(b
, match_len
, true, match
, cookie
, cookie_mask
);
570 /* Behaves the same as nx_pull_match(), but skips over unknown NXM headers,
571 * instead of failing with an error. */
573 nx_pull_match_loose(struct ofpbuf
*b
, unsigned int match_len
,
575 ovs_be64
*cookie
, ovs_be64
*cookie_mask
)
577 return nx_pull_match__(b
, match_len
, false, match
, cookie
, cookie_mask
);
581 oxm_pull_match__(struct ofpbuf
*b
, bool strict
, struct match
*match
)
583 struct ofp11_match_header
*omh
= b
->data
;
587 if (b
->size
< sizeof *omh
) {
588 return OFPERR_OFPBMC_BAD_LEN
;
591 match_len
= ntohs(omh
->length
);
592 if (match_len
< sizeof *omh
) {
593 return OFPERR_OFPBMC_BAD_LEN
;
596 if (omh
->type
!= htons(OFPMT_OXM
)) {
597 return OFPERR_OFPBMC_BAD_TYPE
;
600 p
= ofpbuf_try_pull(b
, ROUND_UP(match_len
, 8));
602 VLOG_DBG_RL(&rl
, "oxm length %u, rounded up to a "
603 "multiple of 8, is longer than space in message (max "
604 "length %"PRIu32
")", match_len
, b
->size
);
605 return OFPERR_OFPBMC_BAD_LEN
;
608 return nx_pull_raw(p
+ sizeof *omh
, match_len
- sizeof *omh
,
609 strict
, match
, NULL
, NULL
);
612 /* Parses the oxm formatted match description preceded by a struct
613 * ofp11_match_header in 'b'. Stores the result in 'match'.
615 * Fails with an error when encountering unknown OXM headers.
617 * Returns 0 if successful, otherwise an OpenFlow error code. */
619 oxm_pull_match(struct ofpbuf
*b
, struct match
*match
)
621 return oxm_pull_match__(b
, true, match
);
624 /* Behaves the same as oxm_pull_match() with one exception. Skips over unknown
625 * OXM headers instead of failing with an error when they are encountered. */
627 oxm_pull_match_loose(struct ofpbuf
*b
, struct match
*match
)
629 return oxm_pull_match__(b
, false, match
);
632 /* Parses the OXM match description in the 'oxm_len' bytes in 'oxm'. Stores
633 * the result in 'match'.
635 * Fails with an error when encountering unknown OXM headers.
637 * Returns 0 if successful, otherwise an OpenFlow error code. */
639 oxm_decode_match(const void *oxm
, size_t oxm_len
, struct match
*match
)
641 return nx_pull_raw(oxm
, oxm_len
, true, match
, NULL
, NULL
);
644 /* Verify an array of OXM TLVs treating value of each TLV as a mask,
645 * disallowing masks in each TLV and ignoring pre-requisites. */
647 oxm_pull_field_array(const void *fields_data
, size_t fields_len
,
648 struct field_array
*fa
)
650 struct ofpbuf b
= ofpbuf_const_initializer(fields_data
, fields_len
);
652 const uint8_t *pos
= b
.data
;
653 const struct mf_field
*field
;
654 union mf_value value
;
658 error
= nx_pull_entry__(&b
, false, &header
, &field
, &value
, NULL
);
660 VLOG_DBG_RL(&rl
, "error pulling field array field");
663 VLOG_DBG_RL(&rl
, "unknown field array field");
664 error
= OFPERR_OFPBMC_BAD_FIELD
;
665 } else if (bitmap_is_set(fa
->used
.bm
, field
->id
)) {
666 VLOG_DBG_RL(&rl
, "duplicate field array field '%s'", field
->name
);
667 error
= OFPERR_OFPBMC_DUP_FIELD
;
668 } else if (!mf_is_mask_valid(field
, &value
)) {
669 VLOG_DBG_RL(&rl
, "bad mask in field array field '%s'", field
->name
);
670 return OFPERR_OFPBMC_BAD_MASK
;
672 field_array_set(field
->id
, &value
, fa
);
676 const uint8_t *start
= fields_data
;
678 VLOG_DBG_RL(&rl
, "error parsing OXM at offset %"PRIdPTR
" "
679 "within field array (%s)", pos
- start
,
680 ofperr_to_string(error
));
688 /* nx_put_match() and helpers.
690 * 'put' functions whose names end in 'w' add a wildcarded field.
691 * 'put' functions whose names end in 'm' add a field that might be wildcarded.
692 * Other 'put' functions add exact-match fields.
695 nxm_put__(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
696 const void *value
, const void *mask
, size_t n_bytes
)
698 nx_put_header_len(b
, field
, version
, !!mask
, n_bytes
);
699 ofpbuf_put(b
, value
, n_bytes
);
701 ofpbuf_put(b
, mask
, n_bytes
);
707 nxm_put(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
708 const void *value
, const void *mask
, size_t n_bytes
)
710 if (!is_all_zeros(mask
, n_bytes
)) {
711 bool masked
= !is_all_ones(mask
, n_bytes
);
712 nxm_put__(b
, field
, version
, value
, masked
? mask
: NULL
, n_bytes
);
717 nxm_put_8m(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
718 uint8_t value
, uint8_t mask
)
720 nxm_put(b
, field
, version
, &value
, &mask
, sizeof value
);
724 nxm_put_8(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
727 nxm_put__(b
, field
, version
, &value
, NULL
, sizeof value
);
731 nxm_put_16m(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
732 ovs_be16 value
, ovs_be16 mask
)
734 nxm_put(b
, field
, version
, &value
, &mask
, sizeof value
);
738 nxm_put_16(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
741 nxm_put__(b
, field
, version
, &value
, NULL
, sizeof value
);
745 nxm_put_32m(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
746 ovs_be32 value
, ovs_be32 mask
)
748 nxm_put(b
, field
, version
, &value
, &mask
, sizeof value
);
752 nxm_put_32(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
755 nxm_put__(b
, field
, version
, &value
, NULL
, sizeof value
);
759 nxm_put_64m(struct ofpbuf
*b
, enum mf_field_id field
, enum ofp_version version
,
760 ovs_be64 value
, ovs_be64 mask
)
762 nxm_put(b
, field
, version
, &value
, &mask
, sizeof value
);
766 nxm_put_128m(struct ofpbuf
*b
,
767 enum mf_field_id field
, enum ofp_version version
,
768 const ovs_be128 value
, const ovs_be128 mask
)
770 nxm_put(b
, field
, version
, &value
, &mask
, sizeof(value
));
774 nxm_put_eth_masked(struct ofpbuf
*b
,
775 enum mf_field_id field
, enum ofp_version version
,
776 const struct eth_addr value
, const struct eth_addr mask
)
778 nxm_put(b
, field
, version
, value
.ea
, mask
.ea
, ETH_ADDR_LEN
);
782 nxm_put_ipv6(struct ofpbuf
*b
,
783 enum mf_field_id field
, enum ofp_version version
,
784 const struct in6_addr
*value
, const struct in6_addr
*mask
)
786 nxm_put(b
, field
, version
, value
->s6_addr
, mask
->s6_addr
,
787 sizeof value
->s6_addr
);
791 nxm_put_frag(struct ofpbuf
*b
, const struct match
*match
,
792 enum ofp_version version
)
794 uint8_t nw_frag
= match
->flow
.nw_frag
& FLOW_NW_FRAG_MASK
;
795 uint8_t nw_frag_mask
= match
->wc
.masks
.nw_frag
& FLOW_NW_FRAG_MASK
;
797 nxm_put_8m(b
, MFF_IP_FRAG
, version
, nw_frag
,
798 nw_frag_mask
== FLOW_NW_FRAG_MASK
? UINT8_MAX
: nw_frag_mask
);
801 /* Appends to 'b' a set of OXM or NXM matches for the IPv4 or IPv6 fields in
804 nxm_put_ip(struct ofpbuf
*b
, const struct match
*match
, enum ofp_version oxm
)
806 const struct flow
*flow
= &match
->flow
;
808 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
809 nxm_put_32m(b
, MFF_IPV4_SRC
, oxm
,
810 flow
->nw_src
, match
->wc
.masks
.nw_src
);
811 nxm_put_32m(b
, MFF_IPV4_DST
, oxm
,
812 flow
->nw_dst
, match
->wc
.masks
.nw_dst
);
814 nxm_put_ipv6(b
, MFF_IPV6_SRC
, oxm
,
815 &flow
->ipv6_src
, &match
->wc
.masks
.ipv6_src
);
816 nxm_put_ipv6(b
, MFF_IPV6_DST
, oxm
,
817 &flow
->ipv6_dst
, &match
->wc
.masks
.ipv6_dst
);
820 nxm_put_frag(b
, match
, oxm
);
822 if (match
->wc
.masks
.nw_tos
& IP_DSCP_MASK
) {
824 nxm_put_8(b
, MFF_IP_DSCP_SHIFTED
, oxm
,
827 nxm_put_8(b
, MFF_IP_DSCP
, oxm
,
828 flow
->nw_tos
& IP_DSCP_MASK
);
832 if (match
->wc
.masks
.nw_tos
& IP_ECN_MASK
) {
833 nxm_put_8(b
, MFF_IP_ECN
, oxm
,
834 flow
->nw_tos
& IP_ECN_MASK
);
837 if (match
->wc
.masks
.nw_ttl
) {
838 nxm_put_8(b
, MFF_IP_TTL
, oxm
, flow
->nw_ttl
);
841 nxm_put_32m(b
, MFF_IPV6_LABEL
, oxm
,
842 flow
->ipv6_label
, match
->wc
.masks
.ipv6_label
);
844 if (match
->wc
.masks
.nw_proto
) {
845 nxm_put_8(b
, MFF_IP_PROTO
, oxm
, flow
->nw_proto
);
847 if (flow
->nw_proto
== IPPROTO_TCP
) {
848 nxm_put_16m(b
, MFF_TCP_SRC
, oxm
,
849 flow
->tp_src
, match
->wc
.masks
.tp_src
);
850 nxm_put_16m(b
, MFF_TCP_DST
, oxm
,
851 flow
->tp_dst
, match
->wc
.masks
.tp_dst
);
852 nxm_put_16m(b
, MFF_TCP_FLAGS
, oxm
,
853 flow
->tcp_flags
, match
->wc
.masks
.tcp_flags
);
854 } else if (flow
->nw_proto
== IPPROTO_UDP
) {
855 nxm_put_16m(b
, MFF_UDP_SRC
, oxm
,
856 flow
->tp_src
, match
->wc
.masks
.tp_src
);
857 nxm_put_16m(b
, MFF_UDP_DST
, oxm
,
858 flow
->tp_dst
, match
->wc
.masks
.tp_dst
);
859 } else if (flow
->nw_proto
== IPPROTO_SCTP
) {
860 nxm_put_16m(b
, MFF_SCTP_SRC
, oxm
, flow
->tp_src
,
861 match
->wc
.masks
.tp_src
);
862 nxm_put_16m(b
, MFF_SCTP_DST
, oxm
, flow
->tp_dst
,
863 match
->wc
.masks
.tp_dst
);
864 } else if (is_icmpv4(flow
)) {
865 if (match
->wc
.masks
.tp_src
) {
866 nxm_put_8(b
, MFF_ICMPV4_TYPE
, oxm
,
867 ntohs(flow
->tp_src
));
869 if (match
->wc
.masks
.tp_dst
) {
870 nxm_put_8(b
, MFF_ICMPV4_CODE
, oxm
,
871 ntohs(flow
->tp_dst
));
873 } else if (is_icmpv6(flow
)) {
874 if (match
->wc
.masks
.tp_src
) {
875 nxm_put_8(b
, MFF_ICMPV6_TYPE
, oxm
,
876 ntohs(flow
->tp_src
));
878 if (match
->wc
.masks
.tp_dst
) {
879 nxm_put_8(b
, MFF_ICMPV6_CODE
, oxm
,
880 ntohs(flow
->tp_dst
));
882 if (flow
->tp_src
== htons(ND_NEIGHBOR_SOLICIT
) ||
883 flow
->tp_src
== htons(ND_NEIGHBOR_ADVERT
)) {
884 nxm_put_ipv6(b
, MFF_ND_TARGET
, oxm
,
885 &flow
->nd_target
, &match
->wc
.masks
.nd_target
);
886 if (flow
->tp_src
== htons(ND_NEIGHBOR_SOLICIT
)) {
887 nxm_put_eth_masked(b
, MFF_ND_SLL
, oxm
,
888 flow
->arp_sha
, match
->wc
.masks
.arp_sha
);
890 if (flow
->tp_src
== htons(ND_NEIGHBOR_ADVERT
)) {
891 nxm_put_eth_masked(b
, MFF_ND_TLL
, oxm
,
892 flow
->arp_tha
, match
->wc
.masks
.arp_tha
);
899 /* Appends to 'b' the nx_match format that expresses 'match'. For Flow Mod and
900 * Flow Stats Requests messages, a 'cookie' and 'cookie_mask' may be supplied.
901 * Otherwise, 'cookie_mask' should be zero.
903 * Specify 'oxm' as 0 to express the match in NXM format; otherwise, specify
904 * 'oxm' as the OpenFlow version number for the OXM format to use.
906 * This function can cause 'b''s data to be reallocated.
908 * Returns the number of bytes appended to 'b', excluding padding.
910 * If 'match' is a catch-all rule that matches every packet, then this function
911 * appends nothing to 'b' and returns 0. */
913 nx_put_raw(struct ofpbuf
*b
, enum ofp_version oxm
, const struct match
*match
,
914 ovs_be64 cookie
, ovs_be64 cookie_mask
)
916 const struct flow
*flow
= &match
->flow
;
917 const size_t start_len
= b
->size
;
921 BUILD_ASSERT_DECL(FLOW_WC_SEQ
== 35);
924 if (match
->wc
.masks
.dp_hash
) {
925 nxm_put_32m(b
, MFF_DP_HASH
, oxm
,
926 htonl(flow
->dp_hash
), htonl(match
->wc
.masks
.dp_hash
));
929 if (match
->wc
.masks
.recirc_id
) {
930 nxm_put_32(b
, MFF_RECIRC_ID
, oxm
, htonl(flow
->recirc_id
));
933 if (match
->wc
.masks
.conj_id
) {
934 nxm_put_32(b
, MFF_CONJ_ID
, oxm
, htonl(flow
->conj_id
));
937 if (match
->wc
.masks
.in_port
.ofp_port
) {
938 ofp_port_t in_port
= flow
->in_port
.ofp_port
;
940 nxm_put_32(b
, MFF_IN_PORT_OXM
, oxm
,
941 ofputil_port_to_ofp11(in_port
));
943 nxm_put_16(b
, MFF_IN_PORT
, oxm
,
944 htons(ofp_to_u16(in_port
)));
947 if (match
->wc
.masks
.actset_output
) {
948 nxm_put_32(b
, MFF_ACTSET_OUTPUT
, oxm
,
949 ofputil_port_to_ofp11(flow
->actset_output
));
953 nxm_put_eth_masked(b
, MFF_ETH_SRC
, oxm
,
954 flow
->dl_src
, match
->wc
.masks
.dl_src
);
955 nxm_put_eth_masked(b
, MFF_ETH_DST
, oxm
,
956 flow
->dl_dst
, match
->wc
.masks
.dl_dst
);
957 nxm_put_16m(b
, MFF_ETH_TYPE
, oxm
,
958 ofputil_dl_type_to_openflow(flow
->dl_type
),
959 match
->wc
.masks
.dl_type
);
963 ovs_be16 VID_CFI_MASK
= htons(VLAN_VID_MASK
| VLAN_CFI
);
964 ovs_be16 vid
= flow
->vlan_tci
& VID_CFI_MASK
;
965 ovs_be16 mask
= match
->wc
.masks
.vlan_tci
& VID_CFI_MASK
;
967 if (mask
== htons(VLAN_VID_MASK
| VLAN_CFI
)) {
968 nxm_put_16(b
, MFF_VLAN_VID
, oxm
, vid
);
970 nxm_put_16m(b
, MFF_VLAN_VID
, oxm
, vid
, mask
);
973 if (vid
&& vlan_tci_to_pcp(match
->wc
.masks
.vlan_tci
)) {
974 nxm_put_8(b
, MFF_VLAN_PCP
, oxm
,
975 vlan_tci_to_pcp(flow
->vlan_tci
));
979 nxm_put_16m(b
, MFF_VLAN_TCI
, oxm
, flow
->vlan_tci
,
980 match
->wc
.masks
.vlan_tci
);
984 if (eth_type_mpls(flow
->dl_type
)) {
985 if (match
->wc
.masks
.mpls_lse
[0] & htonl(MPLS_TC_MASK
)) {
986 nxm_put_8(b
, MFF_MPLS_TC
, oxm
,
987 mpls_lse_to_tc(flow
->mpls_lse
[0]));
990 if (match
->wc
.masks
.mpls_lse
[0] & htonl(MPLS_BOS_MASK
)) {
991 nxm_put_8(b
, MFF_MPLS_BOS
, oxm
,
992 mpls_lse_to_bos(flow
->mpls_lse
[0]));
995 if (match
->wc
.masks
.mpls_lse
[0] & htonl(MPLS_LABEL_MASK
)) {
996 nxm_put_32(b
, MFF_MPLS_LABEL
, oxm
,
997 htonl(mpls_lse_to_label(flow
->mpls_lse
[0])));
1002 if (is_ip_any(flow
)) {
1003 nxm_put_ip(b
, match
, oxm
);
1004 } else if (flow
->dl_type
== htons(ETH_TYPE_ARP
) ||
1005 flow
->dl_type
== htons(ETH_TYPE_RARP
)) {
1007 if (match
->wc
.masks
.nw_proto
) {
1008 nxm_put_16(b
, MFF_ARP_OP
, oxm
,
1009 htons(flow
->nw_proto
));
1011 nxm_put_32m(b
, MFF_ARP_SPA
, oxm
,
1012 flow
->nw_src
, match
->wc
.masks
.nw_src
);
1013 nxm_put_32m(b
, MFF_ARP_TPA
, oxm
,
1014 flow
->nw_dst
, match
->wc
.masks
.nw_dst
);
1015 nxm_put_eth_masked(b
, MFF_ARP_SHA
, oxm
,
1016 flow
->arp_sha
, match
->wc
.masks
.arp_sha
);
1017 nxm_put_eth_masked(b
, MFF_ARP_THA
, oxm
,
1018 flow
->arp_tha
, match
->wc
.masks
.arp_tha
);
1022 nxm_put_64m(b
, MFF_TUN_ID
, oxm
,
1023 flow
->tunnel
.tun_id
, match
->wc
.masks
.tunnel
.tun_id
);
1025 /* Other tunnel metadata. */
1026 nxm_put_16m(b
, MFF_TUN_FLAGS
, oxm
,
1027 htons(flow
->tunnel
.flags
), htons(match
->wc
.masks
.tunnel
.flags
));
1028 nxm_put_32m(b
, MFF_TUN_SRC
, oxm
,
1029 flow
->tunnel
.ip_src
, match
->wc
.masks
.tunnel
.ip_src
);
1030 nxm_put_32m(b
, MFF_TUN_DST
, oxm
,
1031 flow
->tunnel
.ip_dst
, match
->wc
.masks
.tunnel
.ip_dst
);
1032 nxm_put_ipv6(b
, MFF_TUN_IPV6_SRC
, oxm
,
1033 &flow
->tunnel
.ipv6_src
, &match
->wc
.masks
.tunnel
.ipv6_src
);
1034 nxm_put_ipv6(b
, MFF_TUN_IPV6_DST
, oxm
,
1035 &flow
->tunnel
.ipv6_dst
, &match
->wc
.masks
.tunnel
.ipv6_dst
);
1036 nxm_put_16m(b
, MFF_TUN_GBP_ID
, oxm
,
1037 flow
->tunnel
.gbp_id
, match
->wc
.masks
.tunnel
.gbp_id
);
1038 nxm_put_8m(b
, MFF_TUN_GBP_FLAGS
, oxm
,
1039 flow
->tunnel
.gbp_flags
, match
->wc
.masks
.tunnel
.gbp_flags
);
1040 tun_metadata_to_nx_match(b
, oxm
, match
);
1043 if (oxm
< OFP15_VERSION
) {
1044 for (i
= 0; i
< FLOW_N_REGS
; i
++) {
1045 nxm_put_32m(b
, MFF_REG0
+ i
, oxm
,
1046 htonl(flow
->regs
[i
]), htonl(match
->wc
.masks
.regs
[i
]));
1049 for (i
= 0; i
< FLOW_N_XREGS
; i
++) {
1050 nxm_put_64m(b
, MFF_XREG0
+ i
, oxm
,
1051 htonll(flow_get_xreg(flow
, i
)),
1052 htonll(flow_get_xreg(&match
->wc
.masks
, i
)));
1057 nxm_put_32m(b
, MFF_PKT_MARK
, oxm
, htonl(flow
->pkt_mark
),
1058 htonl(match
->wc
.masks
.pkt_mark
));
1060 /* Connection tracking. */
1061 nxm_put_32m(b
, MFF_CT_STATE
, oxm
, htonl(flow
->ct_state
),
1062 htonl(match
->wc
.masks
.ct_state
));
1063 nxm_put_16m(b
, MFF_CT_ZONE
, oxm
, htons(flow
->ct_zone
),
1064 htons(match
->wc
.masks
.ct_zone
));
1065 nxm_put_32m(b
, MFF_CT_MARK
, oxm
, htonl(flow
->ct_mark
),
1066 htonl(match
->wc
.masks
.ct_mark
));
1067 nxm_put_128m(b
, MFF_CT_LABEL
, oxm
, hton128(flow
->ct_label
),
1068 hton128(match
->wc
.masks
.ct_label
));
1070 /* OpenFlow 1.1+ Metadata. */
1071 nxm_put_64m(b
, MFF_METADATA
, oxm
,
1072 flow
->metadata
, match
->wc
.masks
.metadata
);
1076 bool masked
= cookie_mask
!= OVS_BE64_MAX
;
1078 cookie
&= cookie_mask
;
1079 nx_put_header__(b
, NXM_NX_COOKIE
, masked
);
1080 ofpbuf_put(b
, &cookie
, sizeof cookie
);
1082 ofpbuf_put(b
, &cookie_mask
, sizeof cookie_mask
);
1086 match_len
= b
->size
- start_len
;
1090 /* Appends to 'b' the nx_match format that expresses 'match', plus enough zero
1091 * bytes to pad the nx_match out to a multiple of 8. For Flow Mod and Flow
1092 * Stats Requests messages, a 'cookie' and 'cookie_mask' may be supplied.
1093 * Otherwise, 'cookie_mask' should be zero.
1095 * This function can cause 'b''s data to be reallocated.
1097 * Returns the number of bytes appended to 'b', excluding padding. The return
1098 * value can be zero if it appended nothing at all to 'b' (which happens if
1099 * 'cr' is a catch-all rule that matches every packet). */
1101 nx_put_match(struct ofpbuf
*b
, const struct match
*match
,
1102 ovs_be64 cookie
, ovs_be64 cookie_mask
)
1104 int match_len
= nx_put_raw(b
, 0, match
, cookie
, cookie_mask
);
1106 ofpbuf_put_zeros(b
, PAD_SIZE(match_len
, 8));
1110 /* Appends to 'b' an struct ofp11_match_header followed by the OXM format that
1111 * expresses 'match', plus enough zero bytes to pad the data appended out to a
1114 * OXM differs slightly among versions of OpenFlow. Specify the OpenFlow
1115 * version in use as 'version'.
1117 * This function can cause 'b''s data to be reallocated.
1119 * Returns the number of bytes appended to 'b', excluding the padding. Never
1122 oxm_put_match(struct ofpbuf
*b
, const struct match
*match
,
1123 enum ofp_version version
)
1126 struct ofp11_match_header
*omh
;
1127 size_t start_len
= b
->size
;
1128 ovs_be64 cookie
= htonll(0), cookie_mask
= htonll(0);
1130 ofpbuf_put_uninit(b
, sizeof *omh
);
1131 match_len
= (nx_put_raw(b
, version
, match
, cookie
, cookie_mask
)
1133 ofpbuf_put_zeros(b
, PAD_SIZE(match_len
, 8));
1135 omh
= ofpbuf_at(b
, start_len
, sizeof *omh
);
1136 omh
->type
= htons(OFPMT_OXM
);
1137 omh
->length
= htons(match_len
);
1142 /* Appends to 'b' the OXM formats that expresses 'match', without header or
1145 * OXM differs slightly among versions of OpenFlow. Specify the OpenFlow
1146 * version in use as 'version'.
1148 * This function can cause 'b''s data to be reallocated. */
1150 oxm_put_raw(struct ofpbuf
*b
, const struct match
*match
,
1151 enum ofp_version version
)
1153 nx_put_raw(b
, version
, match
, 0, 0);
1156 /* Appends to 'b' the nx_match format that expresses the tlv corresponding
1157 * to 'id'. If mask is not all-ones then it is also formated as the value
1160 nx_format_mask_tlv(struct ds
*ds
, enum mf_field_id id
,
1161 const union mf_value
*mask
)
1163 const struct mf_field
*mf
= mf_from_id(id
);
1165 ds_put_format(ds
, "%s", mf
->name
);
1167 if (!is_all_ones(mask
, mf
->n_bytes
)) {
1168 ds_put_char(ds
, '=');
1169 mf_format(mf
, mask
, NULL
, ds
);
1172 ds_put_char(ds
, ',');
1175 /* Appends a string representation of 'fa_' to 'ds'.
1176 * The TLVS value of 'fa_' is treated as a mask and
1177 * only the name of fields is formated if it is all ones. */
1179 oxm_format_field_array(struct ds
*ds
, const struct field_array
*fa
)
1181 size_t start_len
= ds
->length
;
1184 for (i
= 0; i
< MFF_N_IDS
; i
++) {
1185 if (bitmap_is_set(fa
->used
.bm
, i
)) {
1186 nx_format_mask_tlv(ds
, i
, &fa
->value
[i
]);
1190 if (ds
->length
> start_len
) {
1195 /* Appends to 'b' a series of OXM TLVs corresponding to the series
1196 * of enum mf_field_id and value tuples in 'fa_'.
1198 * OXM differs slightly among versions of OpenFlow. Specify the OpenFlow
1199 * version in use as 'version'.
1201 * This function can cause 'b''s data to be reallocated.
1203 * Returns the number of bytes appended to 'b'. May return zero. */
1205 oxm_put_field_array(struct ofpbuf
*b
, const struct field_array
*fa
,
1206 enum ofp_version version
)
1208 size_t start_len
= b
->size
;
1211 /* Field arrays are only used with the group selection method
1212 * property and group properties are only available in OpenFlow 1.5+.
1213 * So the following assertion should never fail.
1215 * If support for older OpenFlow versions is desired then some care
1216 * will need to be taken of different TLVs that handle the same
1217 * flow fields. In particular:
1218 * - VLAN_TCI, VLAN_VID and MFF_VLAN_PCP
1219 * - IP_DSCP_MASK and DSCP_SHIFTED
1222 ovs_assert(version
>= OFP15_VERSION
);
1224 for (i
= 0; i
< MFF_N_IDS
; i
++) {
1225 if (bitmap_is_set(fa
->used
.bm
, i
)) {
1226 int len
= mf_field_len(mf_from_id(i
), &fa
->value
[i
], NULL
, NULL
);
1227 nxm_put__(b
, i
, version
,
1228 &fa
->value
[i
].u8
+ mf_from_id(i
)->n_bytes
- len
, NULL
,
1233 return b
->size
- start_len
;
1237 nx_put_header__(struct ofpbuf
*b
, uint64_t header
, bool masked
)
1239 uint64_t masked_header
= masked
? nxm_make_wild_header(header
) : header
;
1240 ovs_be64 network_header
= htonll(masked_header
);
1242 ofpbuf_put(b
, &network_header
, nxm_header_len(header
));
1246 nx_put_header(struct ofpbuf
*b
, enum mf_field_id field
,
1247 enum ofp_version version
, bool masked
)
1249 nx_put_header__(b
, mf_oxm_header(field
, version
), masked
);
1253 nx_put_header_len(struct ofpbuf
*b
, enum mf_field_id field
,
1254 enum ofp_version version
, bool masked
, size_t n_bytes
)
1256 uint64_t header
= mf_oxm_header(field
, version
);
1258 header
= NXM_HEADER(nxm_vendor(header
), nxm_class(header
),
1259 nxm_field(header
), false,
1260 nxm_experimenter_len(header
) + n_bytes
);
1262 nx_put_header__(b
, header
, masked
);
1266 nx_put_entry(struct ofpbuf
*b
,
1267 enum mf_field_id field
, enum ofp_version version
,
1268 const union mf_value
*value
, const union mf_value
*mask
)
1270 const struct mf_field
*mf
= mf_from_id(field
);
1274 len
= mf_field_len(mf
, value
, mask
, &masked
);
1275 offset
= mf
->n_bytes
- len
;
1277 nx_put_header_len(b
, field
, version
, masked
, len
);
1278 ofpbuf_put(b
, &value
->u8
+ offset
, len
);
1280 ofpbuf_put(b
, &mask
->u8
+ offset
, len
);
1284 /* nx_match_to_string() and helpers. */
1286 static void format_nxm_field_name(struct ds
*, uint64_t header
);
1289 nx_match_to_string(const uint8_t *p
, unsigned int match_len
)
1292 return xstrdup("<any>");
1295 struct ofpbuf b
= ofpbuf_const_initializer(p
, match_len
);
1296 struct ds s
= DS_EMPTY_INITIALIZER
;
1298 union mf_value value
;
1299 union mf_value mask
;
1304 error
= nx_pull_entry__(&b
, true, &header
, NULL
, &value
, &mask
);
1308 value_len
= MIN(sizeof value
, nxm_field_bytes(header
));
1311 ds_put_cstr(&s
, ", ");
1314 format_nxm_field_name(&s
, header
);
1315 ds_put_char(&s
, '(');
1317 for (int i
= 0; i
< value_len
; i
++) {
1318 ds_put_format(&s
, "%02x", ((const uint8_t *) &value
)[i
]);
1320 if (nxm_hasmask(header
)) {
1321 ds_put_char(&s
, '/');
1322 for (int i
= 0; i
< value_len
; i
++) {
1323 ds_put_format(&s
, "%02x", ((const uint8_t *) &mask
)[i
]);
1326 ds_put_char(&s
, ')');
1331 ds_put_cstr(&s
, ", ");
1334 ds_put_format(&s
, "<%u invalid bytes>", b
.size
);
1337 return ds_steal_cstr(&s
);
1341 oxm_match_to_string(const struct ofpbuf
*p
, unsigned int match_len
)
1343 const struct ofp11_match_header
*omh
= p
->data
;
1344 uint16_t match_len_
;
1349 if (match_len
< sizeof *omh
) {
1350 ds_put_format(&s
, "<match too short: %u>", match_len
);
1354 if (omh
->type
!= htons(OFPMT_OXM
)) {
1355 ds_put_format(&s
, "<bad match type field: %u>", ntohs(omh
->type
));
1359 match_len_
= ntohs(omh
->length
);
1360 if (match_len_
< sizeof *omh
) {
1361 ds_put_format(&s
, "<match length field too short: %u>", match_len_
);
1365 if (match_len_
!= match_len
) {
1366 ds_put_format(&s
, "<match length field incorrect: %u != %u>",
1367 match_len_
, match_len
);
1371 return nx_match_to_string(ofpbuf_at(p
, sizeof *omh
, 0),
1372 match_len
- sizeof *omh
);
1375 return ds_steal_cstr(&s
);
1379 nx_format_field_name(enum mf_field_id id
, enum ofp_version version
,
1382 format_nxm_field_name(s
, mf_oxm_header(id
, version
));
1386 format_nxm_field_name(struct ds
*s
, uint64_t header
)
1388 const struct nxm_field
*f
= nxm_field_by_header(header
);
1390 ds_put_cstr(s
, f
->name
);
1391 if (nxm_hasmask(header
)) {
1392 ds_put_cstr(s
, "_W");
1394 } else if (header
== NXM_NX_COOKIE
) {
1395 ds_put_cstr(s
, "NXM_NX_COOKIE");
1396 } else if (header
== NXM_NX_COOKIE_W
) {
1397 ds_put_cstr(s
, "NXM_NX_COOKIE_W");
1399 ds_put_format(s
, "%d:%d", nxm_class(header
), nxm_field(header
));
1404 streq_len(const char *a
, size_t a_len
, const char *b
)
1406 return strlen(b
) == a_len
&& !memcmp(a
, b
, a_len
);
1410 parse_nxm_field_name(const char *name
, int name_len
)
1412 const struct nxm_field
*f
;
1415 f
= mf_parse_subfield_name(name
, name_len
, &wild
);
1419 } else if (mf_from_id(f
->id
)->maskable
!= MFM_NONE
) {
1420 return nxm_make_wild_header(f
->header
);
1424 if (streq_len(name
, name_len
, "NXM_NX_COOKIE")) {
1425 return NXM_NX_COOKIE
;
1426 } else if (streq_len(name
, name_len
, "NXM_NX_COOKIE_W")) {
1427 return NXM_NX_COOKIE_W
;
1430 /* Check whether it's a field header value as hex.
1431 * (This isn't ordinarily useful except for testing error behavior.) */
1432 if (name_len
== 8) {
1436 header
= hexits_value(name
, name_len
, &ok
) << 32;
1440 } else if (name_len
== 16) {
1444 header
= hexits_value(name
, name_len
, &ok
);
1445 if (ok
&& is_experimenter_oxm(header
)) {
1453 /* nx_match_from_string(). */
1456 nx_match_from_string_raw(const char *s
, struct ofpbuf
*b
)
1458 const char *full_s
= s
;
1459 const size_t start_len
= b
->size
;
1461 if (!strcmp(s
, "<any>")) {
1462 /* Ensure that 'b->data' isn't actually null. */
1463 ofpbuf_prealloc_tailroom(b
, 1);
1467 for (s
+= strspn(s
, ", "); *s
; s
+= strspn(s
, ", ")) {
1475 name_len
= strcspn(s
, "(");
1476 if (s
[name_len
] != '(') {
1477 ovs_fatal(0, "%s: missing ( at end of nx_match", full_s
);
1480 header
= parse_nxm_field_name(name
, name_len
);
1482 ovs_fatal(0, "%s: unknown field `%.*s'", full_s
, name_len
, s
);
1487 b
->header
= ofpbuf_put_uninit(b
, nxm_header_len(header
));
1488 s
= ofpbuf_put_hex(b
, s
, &n
);
1489 if (n
!= nxm_field_bytes(header
)) {
1490 const struct mf_field
*field
= mf_from_oxm_header(header
);
1492 if (field
&& field
->variable_len
) {
1493 if (n
<= field
->n_bytes
) {
1494 int len
= (nxm_hasmask(header
) ? n
* 2 : n
) +
1495 nxm_experimenter_len(header
);
1497 header
= NXM_HEADER(nxm_vendor(header
), nxm_class(header
),
1499 nxm_hasmask(header
) ? 1 : 0, len
);
1501 ovs_fatal(0, "expected to read at most %d bytes but got "
1502 "%"PRIuSIZE
, field
->n_bytes
, n
);
1505 ovs_fatal(0, "expected to read %d bytes but got %"PRIuSIZE
,
1506 nxm_field_bytes(header
), n
);
1509 nw_header
= htonll(header
);
1510 memcpy(b
->header
, &nw_header
, nxm_header_len(header
));
1512 if (nxm_hasmask(header
)) {
1513 s
+= strspn(s
, " ");
1515 ovs_fatal(0, "%s: missing / in masked field %.*s",
1516 full_s
, name_len
, name
);
1518 s
= ofpbuf_put_hex(b
, s
+ 1, &n
);
1519 if (n
!= nxm_field_bytes(header
)) {
1520 ovs_fatal(0, "%.2s: hex digits expected", s
);
1524 s
+= strspn(s
, " ");
1526 ovs_fatal(0, "%s: missing ) following field %.*s",
1527 full_s
, name_len
, name
);
1532 return b
->size
- start_len
;
1536 nx_match_from_string(const char *s
, struct ofpbuf
*b
)
1538 int match_len
= nx_match_from_string_raw(s
, b
);
1539 ofpbuf_put_zeros(b
, PAD_SIZE(match_len
, 8));
1544 oxm_match_from_string(const char *s
, struct ofpbuf
*b
)
1547 struct ofp11_match_header
*omh
;
1548 size_t start_len
= b
->size
;
1550 ofpbuf_put_uninit(b
, sizeof *omh
);
1551 match_len
= nx_match_from_string_raw(s
, b
) + sizeof *omh
;
1552 ofpbuf_put_zeros(b
, PAD_SIZE(match_len
, 8));
1554 omh
= ofpbuf_at(b
, start_len
, sizeof *omh
);
1555 omh
->type
= htons(OFPMT_OXM
);
1556 omh
->length
= htons(match_len
);
1561 /* Parses 's' as a "move" action, in the form described in ovs-ofctl(8), into
1564 * Returns NULL if successful, otherwise a malloc()'d string describing the
1565 * error. The caller is responsible for freeing the returned string. */
1566 char * OVS_WARN_UNUSED_RESULT
1567 nxm_parse_reg_move(struct ofpact_reg_move
*move
, const char *s
)
1569 const char *full_s
= s
;
1572 error
= mf_parse_subfield__(&move
->src
, &s
);
1576 if (strncmp(s
, "->", 2)) {
1577 return xasprintf("%s: missing `->' following source", full_s
);
1580 error
= mf_parse_subfield(&move
->dst
, s
);
1585 if (move
->src
.n_bits
!= move
->dst
.n_bits
) {
1586 return xasprintf("%s: source field is %d bits wide but destination is "
1587 "%d bits wide", full_s
,
1588 move
->src
.n_bits
, move
->dst
.n_bits
);
1593 /* nxm_format_reg_move(). */
1596 nxm_format_reg_move(const struct ofpact_reg_move
*move
, struct ds
*s
)
1598 ds_put_format(s
, "%smove:%s", colors
.special
, colors
.end
);
1599 mf_format_subfield(&move
->src
, s
);
1600 ds_put_format(s
, "%s->%s", colors
.special
, colors
.end
);
1601 mf_format_subfield(&move
->dst
, s
);
1606 nxm_reg_move_check(const struct ofpact_reg_move
*move
, const struct flow
*flow
)
1610 error
= mf_check_src(&move
->src
, flow
);
1615 return mf_check_dst(&move
->dst
, flow
);
1618 /* nxm_execute_reg_move(). */
1621 nxm_execute_reg_move(const struct ofpact_reg_move
*move
,
1622 struct flow
*flow
, struct flow_wildcards
*wc
)
1624 union mf_value src_value
;
1625 union mf_value dst_value
;
1627 mf_mask_field_and_prereqs(move
->dst
.field
, wc
);
1628 mf_mask_field_and_prereqs(move
->src
.field
, wc
);
1630 /* A flow may wildcard nw_frag. Do nothing if setting a transport
1631 * header field on a packet that does not have them. */
1632 if (mf_are_prereqs_ok(move
->dst
.field
, flow
)
1633 && mf_are_prereqs_ok(move
->src
.field
, flow
)) {
1635 mf_get_value(move
->dst
.field
, flow
, &dst_value
);
1636 mf_get_value(move
->src
.field
, flow
, &src_value
);
1637 bitwise_copy(&src_value
, move
->src
.field
->n_bytes
, move
->src
.ofs
,
1638 &dst_value
, move
->dst
.field
->n_bytes
, move
->dst
.ofs
,
1640 mf_set_flow_value(move
->dst
.field
, &dst_value
, flow
);
1645 nxm_reg_load(const struct mf_subfield
*dst
, uint64_t src_data
,
1646 struct flow
*flow
, struct flow_wildcards
*wc
)
1648 union mf_subvalue src_subvalue
;
1649 union mf_subvalue mask_value
;
1650 ovs_be64 src_data_be
= htonll(src_data
);
1652 memset(&mask_value
, 0xff, sizeof mask_value
);
1653 mf_write_subfield_flow(dst
, &mask_value
, &wc
->masks
);
1655 bitwise_copy(&src_data_be
, sizeof src_data_be
, 0,
1656 &src_subvalue
, sizeof src_subvalue
, 0,
1657 sizeof src_data_be
* 8);
1658 mf_write_subfield_flow(dst
, &src_subvalue
, flow
);
1661 /* nxm_parse_stack_action, works for both push() and pop(). */
1663 /* Parses 's' as a "push" or "pop" action, in the form described in
1664 * ovs-ofctl(8), into '*stack_action'.
1666 * Returns NULL if successful, otherwise a malloc()'d string describing the
1667 * error. The caller is responsible for freeing the returned string. */
1668 char * OVS_WARN_UNUSED_RESULT
1669 nxm_parse_stack_action(struct ofpact_stack
*stack_action
, const char *s
)
1673 error
= mf_parse_subfield__(&stack_action
->subfield
, &s
);
1679 return xasprintf("%s: trailing garbage following push or pop", s
);
1686 nxm_format_stack_push(const struct ofpact_stack
*push
, struct ds
*s
)
1688 ds_put_format(s
, "%spush:%s", colors
.param
, colors
.end
);
1689 mf_format_subfield(&push
->subfield
, s
);
1693 nxm_format_stack_pop(const struct ofpact_stack
*pop
, struct ds
*s
)
1695 ds_put_format(s
, "%spop:%s", colors
.param
, colors
.end
);
1696 mf_format_subfield(&pop
->subfield
, s
);
1700 nxm_stack_push_check(const struct ofpact_stack
*push
,
1701 const struct flow
*flow
)
1703 return mf_check_src(&push
->subfield
, flow
);
1707 nxm_stack_pop_check(const struct ofpact_stack
*pop
,
1708 const struct flow
*flow
)
1710 return mf_check_dst(&pop
->subfield
, flow
);
1713 /* nxm_execute_stack_push(), nxm_execute_stack_pop(). */
1715 nx_stack_push(struct ofpbuf
*stack
, union mf_subvalue
*v
)
1717 ofpbuf_put(stack
, v
, sizeof *v
);
1720 static union mf_subvalue
*
1721 nx_stack_pop(struct ofpbuf
*stack
)
1723 union mf_subvalue
*v
= NULL
;
1727 stack
->size
-= sizeof *v
;
1728 v
= (union mf_subvalue
*) ofpbuf_tail(stack
);
1735 nxm_execute_stack_push(const struct ofpact_stack
*push
,
1736 const struct flow
*flow
, struct flow_wildcards
*wc
,
1737 struct ofpbuf
*stack
)
1739 union mf_subvalue mask_value
;
1740 union mf_subvalue dst_value
;
1742 memset(&mask_value
, 0xff, sizeof mask_value
);
1743 mf_write_subfield_flow(&push
->subfield
, &mask_value
, &wc
->masks
);
1745 mf_read_subfield(&push
->subfield
, flow
, &dst_value
);
1746 nx_stack_push(stack
, &dst_value
);
1750 nxm_execute_stack_pop(const struct ofpact_stack
*pop
,
1751 struct flow
*flow
, struct flow_wildcards
*wc
,
1752 struct ofpbuf
*stack
)
1754 union mf_subvalue
*src_value
;
1756 src_value
= nx_stack_pop(stack
);
1758 /* Only pop if stack is not empty. Otherwise, give warning. */
1760 union mf_subvalue mask_value
;
1762 memset(&mask_value
, 0xff, sizeof mask_value
);
1763 mf_write_subfield_flow(&pop
->subfield
, &mask_value
, &wc
->masks
);
1764 mf_write_subfield_flow(&pop
->subfield
, src_value
, flow
);
1766 if (!VLOG_DROP_WARN(&rl
)) {
1767 char *flow_str
= flow_to_string(flow
);
1768 VLOG_WARN_RL(&rl
, "Failed to pop from an empty stack. On flow\n"
1775 /* Formats 'sf' into 's' in a format normally acceptable to
1776 * mf_parse_subfield(). (It won't be acceptable if sf->field is NULL or if
1777 * sf->field has no NXM name.) */
1779 mf_format_subfield(const struct mf_subfield
*sf
, struct ds
*s
)
1782 ds_put_cstr(s
, "<unknown>");
1784 const struct nxm_field
*f
= nxm_field_by_mf_id(sf
->field
->id
, 0);
1785 ds_put_cstr(s
, f
? f
->name
: sf
->field
->name
);
1788 if (sf
->field
&& sf
->ofs
== 0 && sf
->n_bits
== sf
->field
->n_bits
) {
1789 ds_put_cstr(s
, "[]");
1790 } else if (sf
->n_bits
== 1) {
1791 ds_put_format(s
, "[%d]", sf
->ofs
);
1793 ds_put_format(s
, "[%d..%d]", sf
->ofs
, sf
->ofs
+ sf
->n_bits
- 1);
1797 static const struct nxm_field
*
1798 mf_parse_subfield_name(const char *name
, int name_len
, bool *wild
)
1800 *wild
= name_len
> 2 && !memcmp(&name
[name_len
- 2], "_W", 2);
1805 return nxm_field_by_name(name
, name_len
);
1808 /* Parses a subfield from the beginning of '*sp' into 'sf'. If successful,
1809 * returns NULL and advances '*sp' to the first byte following the parsed
1810 * string. On failure, returns a malloc()'d error message, does not modify
1811 * '*sp', and does not properly initialize 'sf'.
1813 * The syntax parsed from '*sp' takes the form "header[start..end]" where
1814 * 'header' is the name of an NXM field and 'start' and 'end' are (inclusive)
1815 * bit indexes. "..end" may be omitted to indicate a single bit. "start..end"
1816 * may both be omitted (the [] are still required) to indicate an entire
1818 char * OVS_WARN_UNUSED_RESULT
1819 mf_parse_subfield__(struct mf_subfield
*sf
, const char **sp
)
1821 const struct mf_field
*field
;
1822 const struct nxm_field
*f
;
1831 name_len
= strcspn(s
, "[");
1832 if (s
[name_len
] != '[') {
1833 return xasprintf("%s: missing [ looking for field name", *sp
);
1836 f
= mf_parse_subfield_name(name
, name_len
, &wild
);
1838 return xasprintf("%s: unknown field `%.*s'", *sp
, name_len
, s
);
1840 field
= mf_from_id(f
->id
);
1843 if (ovs_scan(s
, "[%d..%d]", &start
, &end
)) {
1844 /* Nothing to do. */
1845 } else if (ovs_scan(s
, "[%d]", &start
)) {
1847 } else if (!strncmp(s
, "[]", 2)) {
1849 end
= field
->n_bits
- 1;
1851 return xasprintf("%s: syntax error expecting [] or [<bit>] or "
1852 "[<start>..<end>]", *sp
);
1854 s
= strchr(s
, ']') + 1;
1857 return xasprintf("%s: starting bit %d is after ending bit %d",
1859 } else if (start
>= field
->n_bits
) {
1860 return xasprintf("%s: starting bit %d is not valid because field is "
1861 "only %d bits wide", *sp
, start
, field
->n_bits
);
1862 } else if (end
>= field
->n_bits
){
1863 return xasprintf("%s: ending bit %d is not valid because field is "
1864 "only %d bits wide", *sp
, end
, field
->n_bits
);
1869 sf
->n_bits
= end
- start
+ 1;
1875 /* Parses a subfield from the entirety of 's' into 'sf'. Returns NULL if
1876 * successful, otherwise a malloc()'d string describing the error. The caller
1877 * is responsible for freeing the returned string.
1879 * The syntax parsed from 's' takes the form "header[start..end]" where
1880 * 'header' is the name of an NXM field and 'start' and 'end' are (inclusive)
1881 * bit indexes. "..end" may be omitted to indicate a single bit. "start..end"
1882 * may both be omitted (the [] are still required) to indicate an entire
1884 char * OVS_WARN_UNUSED_RESULT
1885 mf_parse_subfield(struct mf_subfield
*sf
, const char *s
)
1887 char *error
= mf_parse_subfield__(sf
, &s
);
1888 if (!error
&& s
[0]) {
1889 error
= xstrdup("unexpected input following field syntax");
1894 /* Returns an bitmap in which each bit corresponds to the like-numbered field
1895 * in the OFPXMC12_OPENFLOW_BASIC OXM class, in which the bit values are taken
1896 * from the 'fields' bitmap. Only fields defined in OpenFlow 'version' are
1899 * This is useful for encoding OpenFlow 1.2 table stats messages. */
1901 oxm_bitmap_from_mf_bitmap(const struct mf_bitmap
*fields
,
1902 enum ofp_version version
)
1904 uint64_t oxm_bitmap
= 0;
1907 BITMAP_FOR_EACH_1 (i
, MFF_N_IDS
, fields
->bm
) {
1908 uint64_t oxm
= mf_oxm_header(i
, version
);
1909 uint32_t class = nxm_class(oxm
);
1910 int field
= nxm_field(oxm
);
1912 if (class == OFPXMC12_OPENFLOW_BASIC
&& field
< 64) {
1913 oxm_bitmap
|= UINT64_C(1) << field
;
1916 return htonll(oxm_bitmap
);
1919 /* Opposite conversion from oxm_bitmap_from_mf_bitmap().
1921 * This is useful for decoding OpenFlow 1.2 table stats messages. */
1923 oxm_bitmap_to_mf_bitmap(ovs_be64 oxm_bitmap
, enum ofp_version version
)
1925 struct mf_bitmap fields
= MF_BITMAP_INITIALIZER
;
1927 for (enum mf_field_id id
= 0; id
< MFF_N_IDS
; id
++) {
1928 uint64_t oxm
= mf_oxm_header(id
, version
);
1929 if (oxm
&& version
>= nxm_field_by_header(oxm
)->version
) {
1930 uint32_t class = nxm_class(oxm
);
1931 int field
= nxm_field(oxm
);
1933 if (class == OFPXMC12_OPENFLOW_BASIC
1935 && oxm_bitmap
& htonll(UINT64_C(1) << field
)) {
1936 bitmap_set1(fields
.bm
, id
);
1943 /* Returns a bitmap of fields that can be encoded in OXM and that can be
1944 * modified with a "set_field" action. */
1946 oxm_writable_fields(void)
1948 struct mf_bitmap b
= MF_BITMAP_INITIALIZER
;
1951 for (i
= 0; i
< MFF_N_IDS
; i
++) {
1952 if (mf_oxm_header(i
, 0) && mf_from_id(i
)->writable
) {
1953 bitmap_set1(b
.bm
, i
);
1959 /* Returns a bitmap of fields that can be encoded in OXM and that can be
1960 * matched in a flow table. */
1962 oxm_matchable_fields(void)
1964 struct mf_bitmap b
= MF_BITMAP_INITIALIZER
;
1967 for (i
= 0; i
< MFF_N_IDS
; i
++) {
1968 if (mf_oxm_header(i
, 0)) {
1969 bitmap_set1(b
.bm
, i
);
1975 /* Returns a bitmap of fields that can be encoded in OXM and that can be
1976 * matched in a flow table with an arbitrary bitmask. */
1978 oxm_maskable_fields(void)
1980 struct mf_bitmap b
= MF_BITMAP_INITIALIZER
;
1983 for (i
= 0; i
< MFF_N_IDS
; i
++) {
1984 if (mf_oxm_header(i
, 0) && mf_from_id(i
)->maskable
== MFM_FULLY
) {
1985 bitmap_set1(b
.bm
, i
);
1991 struct nxm_field_index
{
1992 struct hmap_node header_node
; /* In nxm_header_map. */
1993 struct hmap_node name_node
; /* In nxm_name_map. */
1994 struct ovs_list mf_node
; /* In mf_mf_map[nf.id]. */
1995 const struct nxm_field nf
;
1998 #include "nx-match.inc"
2000 static struct hmap nxm_header_map
;
2001 static struct hmap nxm_name_map
;
2002 static struct ovs_list nxm_mf_map
[MFF_N_IDS
];
2007 static struct ovsthread_once once
= OVSTHREAD_ONCE_INITIALIZER
;
2008 if (ovsthread_once_start(&once
)) {
2009 hmap_init(&nxm_header_map
);
2010 hmap_init(&nxm_name_map
);
2011 for (int i
= 0; i
< MFF_N_IDS
; i
++) {
2012 ovs_list_init(&nxm_mf_map
[i
]);
2014 for (struct nxm_field_index
*nfi
= all_nxm_fields
;
2015 nfi
< &all_nxm_fields
[ARRAY_SIZE(all_nxm_fields
)]; nfi
++) {
2016 hmap_insert(&nxm_header_map
, &nfi
->header_node
,
2017 hash_uint64(nxm_no_len(nfi
->nf
.header
)));
2018 hmap_insert(&nxm_name_map
, &nfi
->name_node
,
2019 hash_string(nfi
->nf
.name
, 0));
2020 ovs_list_push_back(&nxm_mf_map
[nfi
->nf
.id
], &nfi
->mf_node
);
2022 ovsthread_once_done(&once
);
2026 static const struct nxm_field
*
2027 nxm_field_by_header(uint64_t header
)
2029 const struct nxm_field_index
*nfi
;
2030 uint64_t header_no_len
;
2033 if (nxm_hasmask(header
)) {
2034 header
= nxm_make_exact_header(header
);
2037 header_no_len
= nxm_no_len(header
);
2039 HMAP_FOR_EACH_IN_BUCKET (nfi
, header_node
, hash_uint64(header_no_len
),
2041 if (header_no_len
== nxm_no_len(nfi
->nf
.header
)) {
2042 if (nxm_length(header
) == nxm_length(nfi
->nf
.header
) ||
2043 mf_from_id(nfi
->nf
.id
)->variable_len
) {
2053 static const struct nxm_field
*
2054 nxm_field_by_name(const char *name
, size_t len
)
2056 const struct nxm_field_index
*nfi
;
2059 HMAP_FOR_EACH_WITH_HASH (nfi
, name_node
, hash_bytes(name
, len
, 0),
2061 if (strlen(nfi
->nf
.name
) == len
&& !memcmp(nfi
->nf
.name
, name
, len
)) {
2068 static const struct nxm_field
*
2069 nxm_field_by_mf_id(enum mf_field_id id
, enum ofp_version version
)
2071 const struct nxm_field_index
*nfi
;
2072 const struct nxm_field
*f
;
2077 LIST_FOR_EACH (nfi
, mf_node
, &nxm_mf_map
[id
]) {
2078 if (!f
|| version
>= nfi
->nf
.version
) {