2 * Copyright (c) 2011, 2012, 2013, 2014, 2015 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.
20 #include <sys/types.h>
21 #include <netinet/in.h>
22 #include <netinet/ip6.h>
25 #include "ofp-errors.h"
32 /* Open vSwitch fields
35 * A "field" is a property of a packet. Most familiarly, "data fields" are
36 * fields that can be extracted from a packet.
38 * Some data fields are always present as a consequence of the basic networking
39 * technology in use. Ethernet is the assumed base technology for current
40 * versions of OpenFlow and Open vSwitch, so Ethernet header fields are always
43 * Other data fields are not always present. A packet contains ARP fields, for
44 * example, only when its Ethernet header indicates the Ethertype for ARP,
45 * 0x0806. We say that a field is "applicable" when it is it present in a
46 * packet, and "inapplicable" when it is not, and refer to the conditions that
47 * determine whether a field is applicable as "prerequisites". Some
48 * VLAN-related fields are a special case: these fields are always applicable,
49 * but have a designated value or bit that indicates whether a VLAN header is
50 * present, with the remaining values or bits indicating the VLAN header's
51 * content (if it is present). See MFF_VLAN_TCI for an example.
53 * Conceptually, an inapplicable field does not have a value, not even a
54 * nominal ``value'' such as all-zero-bits. In many circumstances, OpenFlow
55 * and Open vSwitch allow references only to applicable fields. For example,
56 * one may match a given field only if the match includes the field's
57 * prerequisite, e.g. matching an ARP field is only allowed if one also matches
58 * on Ethertype 0x0806.
60 * (Practically, however, OVS represents a field's value as some fixed member
61 * in its "struct flow", so accessing that member will obtain some value. Some
62 * members are used for more than one purpose, e.g. the "tp_src" member
63 * represents the TCP, UDP, and SCTP source port, so the value read may not
64 * even make sense. For this reason, it is important to know whether a field's
65 * prerequisites are satisfied before attempting to read it.)
67 * Sometimes a packet may contain multiple instances of a header. For example,
68 * a packet may contain multiple VLAN or MPLS headers, and tunnels can cause
69 * any data field to recur. OpenFlow and Open vSwitch do not address these
70 * cases uniformly. For VLAN and MPLS headers, only the outermost header is
71 * accessible, so that inner headers may be accessed only by ``popping''
72 * (removing) the outer header. (Open vSwitch supports only a single VLAN
73 * header in any case.) For tunnels, e.g. GRE or VXLAN, the outer header and
74 * inner headers are treated as different data fields.
76 * OpenFlow and Open vSwitch support some fields other than data fields.
77 * "Metadata fields" relate to the origin or treatment of a packet, but they
78 * are not extracted from the packet data itself. One example is the physical
79 * port on which a packet arrived at the switch. "Register fields" act like
80 * variables: they give an OpenFlow switch space for temporary storage while
81 * processing a packet. Existing metadata and register fields have no
84 * A field's value consists of an integral number of bytes. Most data fields
85 * are copied directly from protocol headers, e.g. at layer 2, MFF_ETH_SRC is
86 * copied from the Ethernet source address and MFF_ETH_DST from the destination
87 * address. Other data fields are copied from a packet with padding, usually
88 * with zeros and in the most significant positions (see e.g. MFF_MPLS_LABEL)
89 * but not always (see e.g. MFF_IP_DSCP). A final category of data fields is
90 * transformed in other ways as they are copied from the packets, to make them
91 * more useful for matching, e.g. MFF_IP_FRAG describes whether a packet is a
92 * fragment but it is not copied directly from the IP header.
95 * Field specifications
96 * ====================
98 * Each of the enumeration values below represents a field. The comments
99 * preceding each enum must be in a stylized form that is parsed at compile
100 * time by the extract-ofp-fields program. The comment itself consists of a
101 * series of paragraphs separate by blank lines. The paragraphs consist of:
103 * - The first paragraph gives the user-visible name of the field as a
104 * quoted string. This is the name used for parsing and formatting the
107 * For historical reasons, some fields have an additional name that is
108 * accepted as an alternative in parsing. This name, when there is one,
109 * is given as a quoted string in parentheses along with "aka". For
112 * "tun_id" (aka "tunnel_id").
114 * New fields should have only one name.
116 * - Any number of paragraphs of free text that describe the field. This
117 * is meant for human readers, so extract-ofp-fields ignores it.
119 * - A final paragraph that consists of a series of key-value pairs, one
120 * per line, in the form "key: value." where the period at the end of the
121 * line is a mandatory part of the syntax.
123 * Every field must specify the following key-value pairs:
127 * The format and size of the field's value. Some possible values are
130 * u8: A one-byte field.
131 * be16: A two-byte field.
132 * be32: A four-byte field.
133 * be64: An eight-byte field.
135 * The remaining values imply more about the value's semantics, though OVS
136 * does not currently take advantage of this additional information:
138 * MAC: A six-byte field whose value is an Ethernet address.
139 * IPv6: A 16-byte field whose value is an IPv6 address.
140 * tunnelMD: A variable length field, up to 124 bytes, that carries
145 * Either "bitwise", if OVS supports matching any subset of bits in the
146 * field, or "no", if OVS only supports matching or wildcarding the entire
151 * Explains how a field's value is formatted and parsed for human
152 * consumption. Some of the options are fairly generally useful:
154 * decimal: Formats the value as a decimal number. On parsing, accepts
155 * decimal (with no prefix), hexadecimal with 0x prefix, or octal
158 * hexadecimal: Same as decimal except nonzero values are formatted in
159 * hex with 0x prefix. The default for parsing is *not* hexadecimal:
160 * only with a 0x prefix is the input in hexadecimal.
162 * Ethernet: Formats and accepts the common format xx:xx:xx:xx:xx:xx.
163 * 6-byte fields only.
165 * IPv4: Formats and accepts the common format w.x.y.z. 4-byte fields
168 * IPv6: Formats and accepts the common IPv6 formats. 16-byte fields
171 * OpenFlow 1.0 port: Accepts an OpenFlow well-known port name
172 * (e.g. "IN_PORT") in uppercase or lowercase, or a 16-bit port
173 * number in decimal. Formats ports using their well-known names in
174 * uppercase, or in decimal otherwise. 2-byte fields only.
176 * OpenFlow 1.1+ port: Same syntax as for OpenFlow 1.0 ports but for
177 * 4-byte OpenFlow 1.1+ port number fields.
179 * Others are very specific to particular fields:
181 * frag: One of the strings "no", "first", "later", "yes", "not_later"
182 * describing which IPv4/v6 fragments are matched.
184 * tunnel flags: Any number of the strings "df", "csum", "key", or
185 * "oam" separated by "|".
187 * TCP flags: See the description of tcp_flags in ovs-ofctl(8).
191 * The field's prerequisites. The values should be straightfoward.
195 * Either "read-only", for a field that cannot be changed via OpenFlow, or
196 * "read/write" for a modifiable field.
200 * If the field has an NXM field assignment, then this specifies the NXM
201 * name of the field (e.g. "NXM_OF_ETH_SRC"), followed by its nxm_type in
202 * parentheses, followed by "since v<x>.<y>" specifying the version of Open
203 * vSwitch that first supported this field in NXM (e.g. "since v1.1" if it
204 * was introduced in Open vSwitch 1.1).
206 * The NXM name must begin with NXM_OF_ or NXM_NX_. This allows OVS to
207 * determine the correct NXM class.
209 * If the field does not have an NXM field assignment, specify "none".
213 * If the field has an OXM field assignment, then this specifies the OXM
214 * name of the field (e.g. "OXM_OF_ETH_SRC"), followed by its nxm_type in
215 * parentheses, followed by "since OF<a>.<b> v<x>.<y>" specifying the
216 * versions of OpenFlow and Open vSwitch that first supported this field in
217 * OXM (e.g. "since OF1.3 and v1.10" if it was introduced in OpenFlow 1.3
218 * and first supported by Open vSwitch in version 1.10).
220 * Some fields have more than one OXM field assignment. For example,
221 * actset_output has an experimenter OXM assignment in OpenFlow 1.3 and a
222 * standard OXM assignment in OpenFlow 1.5. In such a case, specify both,
223 * separated by commas.
225 * OVS uses the start of the OXM field name to determine the correct OXM
226 * class. To support a new OXM class, edit the mapping table in
227 * build-aux/extract-ofp-fields.
229 * If the field does not have an OXM field assignment, specify "none".
231 * The following key-value pairs are optional. Open vSwitch already supports
232 * all the fields to which they apply, so new fields should probably not
233 * include these pairs:
237 * Specify this as "exact match" if OpenFlow 1.0 can match or wildcard the
238 * entire field, or as "CIDR mask" if OpenFlow 1.0 can match any CIDR
239 * prefix of the field. (OpenFlow 1.0 did not support bitwise matching.)
240 * Omit, if OpenFlow 1.0 did not support this field.
244 * Specify this as "exact match" if OpenFlow 1.1 can match or wildcard the
245 * entire field, or as "bitwise" if OpenFlow 1.1 can match any subset of
246 * bits in the field. Omit, if OpenFlow 1.1 did not support this field.
248 * The following key-value pair is optional:
250 * Prefix lookup member:
252 * If this field makes sense for use with classifier_set_prefix_fields(),
253 * specify the name of the "struct flow" member that corresponds to the
256 * Finally, a few "register" fields have very similar names and purposes,
257 * e.g. MFF_REG0 through MFF_REG7. For these, the comments may be merged
258 * together using <N> as a metasyntactic variable for the numeric suffix.
259 * Lines in the comment that are specific to one of the particular fields by
260 * writing, e.g. <1>, to consider that line only for e.g. MFF_REG1.
263 enum OVS_PACKED_ENUM mf_field_id {
270 * Flow hash computed in the datapath. Internal use only, not programmable
273 * The OXM code point for this is an attempt to test OXM experimenter
274 * support, which is otherwise difficult to test due to the dearth of use
275 * out in the wild. Because controllers can't add flows that match on
276 * dp_hash, this doesn't commit OVS to supporting this OXM experimenter
277 * code point in the future.
281 * Formatting: hexadecimal.
282 * Prerequisites: none.
284 * NXM: NXM_NX_DP_HASH(35) since v2.2.
285 * OXM: NXOXM_ET_DP_HASH(0) since OF1.5 and v2.4.
291 * ID for recirculation. The value 0 is reserved for initially received
292 * packets. Internal use only, not programmable from controller.
296 * Formatting: decimal.
297 * Prerequisites: none.
299 * NXM: NXM_NX_RECIRC_ID(36) since v2.2.
306 * ID for "conjunction" actions. Please refer to ovs-ofctl(8)
307 * documentation of "conjunction" for details.
311 * Formatting: decimal.
312 * Prerequisites: none.
314 * NXM: NXM_NX_CONJ_ID(37) since v2.4.
318 /* "tun_id" (aka "tunnel_id").
320 * The "key" or "tunnel ID" or "VNI" in a packet received via a keyed
321 * tunnel. For protocols in which the key is shorter than 64 bits, the key
322 * is stored in the low bits and the high bits are zeroed. For non-keyed
323 * tunnels and packets not received via a tunnel, the value is 0.
327 * Formatting: hexadecimal.
328 * Prerequisites: none.
329 * Access: read/write.
330 * NXM: NXM_NX_TUN_ID(16) since v1.1.
331 * OXM: OXM_OF_TUNNEL_ID(38) since OF1.3 and v1.10.
332 * Prefix lookup member: tunnel.tun_id.
338 * The IPv4 source address in the outer IP header of a tunneled packet.
340 * For non-tunneled packets, the value is 0.
345 * Prerequisites: none.
346 * Access: read/write.
347 * NXM: NXM_NX_TUN_IPV4_SRC(31) since v2.0.
349 * Prefix lookup member: tunnel.ip_src.
355 * The IPv4 destination address in the outer IP header of a tunneled
358 * For non-tunneled packets, the value is 0.
363 * Prerequisites: none.
364 * Access: read/write.
365 * NXM: NXM_NX_TUN_IPV4_DST(32) since v2.0.
367 * Prefix lookup member: tunnel.ip_dst.
373 * Flags representing aspects of tunnel behavior.
375 * This field currently only has a single flag defined:
377 * - NX_TUN_FLAG_OAM: The tunnel protocol indicated that this is an
378 * OAM control packet.
380 * The switch may reject matches against values that it is not aware of.
382 * Note that it is possible for newer version of Open vSwitch to
383 * introduce additional flags with varying meaning. It is therefore not
384 * recommended to use an exact match on this field since the behavior of
385 * these new flags is unknown and should be ignored.
387 * For non-tunneled packets, the value is 0.
389 * Type: be16 (low 1 bits).
391 * Formatting: tunnel flags.
392 * Prerequisites: none.
393 * Access: read/write.
394 * NXM: NXM_NX_TUN_FLAGS(104) since v2.5.
401 * The TTL in the outer IP header of a tunneled packet. Internal use only,
402 * not programmable from controller.
404 * For non-tunneled packets, the value is 0.
408 * Formatting: decimal.
409 * Prerequisites: none.
418 * The ToS value in the outer IP header of a tunneled packet. Internal use
419 * only, not programmable from controller.
423 * Formatting: decimal.
424 * Prerequisites: none.
433 * VXLAN Group Policy ID
437 * Formatting: decimal.
438 * Prerequisites: none.
439 * Access: read/write.
440 * NXM: NXM_NX_TUN_GBP_ID(38) since v2.4.
447 * VXLAN Group Policy flags
451 * Formatting: hexadecimal.
452 * Prerequisites: none.
453 * Access: read/write.
454 * NXM: NXM_NX_TUN_GBP_FLAGS(39) since v2.4.
459 #if TUN_METADATA_NUM_OPTS == 64
460 /* "tun_metadata<N>".
462 * Encapsulation metadata for tunnels.
464 * Each NXM can be dynamically mapped onto a particular tunnel field using
465 * OpenFlow commands. The individual NXMs can each carry up to 124 bytes
466 * of data and a combined total of 256 across all allocated fields.
470 * Formatting: hexadecimal.
471 * Prerequisites: none.
472 * Access: read/write.
473 * NXM: NXM_NX_TUN_METADATA0(40) since v2.5. <0>
474 * NXM: NXM_NX_TUN_METADATA1(41) since v2.5. <1>
475 * NXM: NXM_NX_TUN_METADATA2(42) since v2.5. <2>
476 * NXM: NXM_NX_TUN_METADATA3(43) since v2.5. <3>
477 * NXM: NXM_NX_TUN_METADATA4(44) since v2.5. <4>
478 * NXM: NXM_NX_TUN_METADATA5(45) since v2.5. <5>
479 * NXM: NXM_NX_TUN_METADATA6(46) since v2.5. <6>
480 * NXM: NXM_NX_TUN_METADATA7(47) since v2.5. <7>
481 * NXM: NXM_NX_TUN_METADATA8(48) since v2.5. <8>
482 * NXM: NXM_NX_TUN_METADATA9(49) since v2.5. <9>
483 * NXM: NXM_NX_TUN_METADATA10(50) since v2.5. <10>
484 * NXM: NXM_NX_TUN_METADATA11(51) since v2.5. <11>
485 * NXM: NXM_NX_TUN_METADATA12(52) since v2.5. <12>
486 * NXM: NXM_NX_TUN_METADATA13(53) since v2.5. <13>
487 * NXM: NXM_NX_TUN_METADATA14(54) since v2.5. <14>
488 * NXM: NXM_NX_TUN_METADATA15(55) since v2.5. <15>
489 * NXM: NXM_NX_TUN_METADATA16(56) since v2.5. <16>
490 * NXM: NXM_NX_TUN_METADATA17(57) since v2.5. <17>
491 * NXM: NXM_NX_TUN_METADATA18(58) since v2.5. <18>
492 * NXM: NXM_NX_TUN_METADATA19(59) since v2.5. <19>
493 * NXM: NXM_NX_TUN_METADATA20(60) since v2.5. <20>
494 * NXM: NXM_NX_TUN_METADATA21(61) since v2.5. <21>
495 * NXM: NXM_NX_TUN_METADATA22(62) since v2.5. <22>
496 * NXM: NXM_NX_TUN_METADATA23(63) since v2.5. <23>
497 * NXM: NXM_NX_TUN_METADATA24(64) since v2.5. <24>
498 * NXM: NXM_NX_TUN_METADATA25(65) since v2.5. <25>
499 * NXM: NXM_NX_TUN_METADATA26(66) since v2.5. <26>
500 * NXM: NXM_NX_TUN_METADATA27(67) since v2.5. <27>
501 * NXM: NXM_NX_TUN_METADATA28(68) since v2.5. <28>
502 * NXM: NXM_NX_TUN_METADATA29(69) since v2.5. <29>
503 * NXM: NXM_NX_TUN_METADATA30(70) since v2.5. <30>
504 * NXM: NXM_NX_TUN_METADATA31(71) since v2.5. <31>
505 * NXM: NXM_NX_TUN_METADATA32(72) since v2.5. <32>
506 * NXM: NXM_NX_TUN_METADATA33(73) since v2.5. <33>
507 * NXM: NXM_NX_TUN_METADATA34(74) since v2.5. <34>
508 * NXM: NXM_NX_TUN_METADATA35(75) since v2.5. <35>
509 * NXM: NXM_NX_TUN_METADATA36(76) since v2.5. <36>
510 * NXM: NXM_NX_TUN_METADATA37(77) since v2.5. <37>
511 * NXM: NXM_NX_TUN_METADATA38(78) since v2.5. <38>
512 * NXM: NXM_NX_TUN_METADATA39(79) since v2.5. <39>
513 * NXM: NXM_NX_TUN_METADATA40(80) since v2.5. <40>
514 * NXM: NXM_NX_TUN_METADATA41(81) since v2.5. <41>
515 * NXM: NXM_NX_TUN_METADATA42(82) since v2.5. <42>
516 * NXM: NXM_NX_TUN_METADATA43(83) since v2.5. <43>
517 * NXM: NXM_NX_TUN_METADATA44(84) since v2.5. <44>
518 * NXM: NXM_NX_TUN_METADATA45(85) since v2.5. <45>
519 * NXM: NXM_NX_TUN_METADATA46(86) since v2.5. <46>
520 * NXM: NXM_NX_TUN_METADATA47(87) since v2.5. <47>
521 * NXM: NXM_NX_TUN_METADATA48(88) since v2.5. <48>
522 * NXM: NXM_NX_TUN_METADATA49(89) since v2.5. <49>
523 * NXM: NXM_NX_TUN_METADATA50(90) since v2.5. <50>
524 * NXM: NXM_NX_TUN_METADATA51(91) since v2.5. <51>
525 * NXM: NXM_NX_TUN_METADATA52(92) since v2.5. <52>
526 * NXM: NXM_NX_TUN_METADATA53(93) since v2.5. <53>
527 * NXM: NXM_NX_TUN_METADATA54(94) since v2.5. <54>
528 * NXM: NXM_NX_TUN_METADATA55(95) since v2.5. <55>
529 * NXM: NXM_NX_TUN_METADATA56(96) since v2.5. <56>
530 * NXM: NXM_NX_TUN_METADATA57(97) since v2.5. <57>
531 * NXM: NXM_NX_TUN_METADATA58(98) since v2.5. <58>
532 * NXM: NXM_NX_TUN_METADATA59(99) since v2.5. <59>
533 * NXM: NXM_NX_TUN_METADATA60(100) since v2.5. <60>
534 * NXM: NXM_NX_TUN_METADATA61(101) since v2.5. <61>
535 * NXM: NXM_NX_TUN_METADATA62(102) since v2.5. <62>
536 * NXM: NXM_NX_TUN_METADATA63(103) since v2.5. <63>
604 #error "Need to update MFF_TUN_METADATA* to match TUN_METADATA_NUM_OPTS"
609 * A scratch pad value standardized in OpenFlow 1.1+. Initially zero, at
610 * the beginning of the pipeline.
614 * Formatting: hexadecimal.
615 * Prerequisites: none.
616 * Access: read/write.
618 * OXM: OXM_OF_METADATA(2) since OF1.2 and v1.8.
619 * OF1.1: bitwise mask.
625 * 16-bit (OpenFlow 1.0) view of the physical or virtual port on which the
626 * packet was received.
630 * Formatting: OpenFlow 1.0 port.
631 * Prerequisites: none.
632 * Access: read/write.
633 * NXM: NXM_OF_IN_PORT(0) since v1.1.
635 * OF1.0: exact match.
636 * OF1.1: exact match.
642 * 32-bit (OpenFlow 1.1+) view of the physical or virtual port on which the
643 * packet was received.
647 * Formatting: OpenFlow 1.1+ port.
648 * Prerequisites: none.
649 * Access: read/write.
651 * OXM: OXM_OF_IN_PORT(0) since OF1.2 and v1.7.
652 * OF1.1: exact match.
660 * Formatting: OpenFlow 1.1+ port.
661 * Prerequisites: none.
664 * OXM: ONFOXM_ET_ACTSET_OUTPUT(43) since OF1.3 and v2.4,
665 * OXM_OF_ACTSET_OUTPUT(43) since OF1.5 and v2.4.
671 * Designates the queue to which output will be directed. The value in
672 * this field is not necessarily the OpenFlow queue number; with the Linux
673 * kernel switch, it instead has a pair of subfields designating the
674 * "major" and "minor" numbers of a Linux kernel qdisc handle.
676 * This field is "semi-internal" in that it can be set with the "set_queue"
677 * action but not matched or read or written other ways.
681 * Formatting: hexadecimal.
682 * Prerequisites: none.
691 * Packet metadata mark. The mark may be passed into other system
692 * components in order to facilitate interaction between subsystems. On
693 * Linux this corresponds to struct sk_buff's "skb_mark" member but the
694 * exact implementation is platform-dependent.
698 * Formatting: hexadecimal.
699 * Prerequisites: none.
700 * Access: read/write.
701 * NXM: NXM_NX_PKT_MARK(33) since v2.0.
709 * Nicira extension scratch pad register with initial value 0.
713 * Formatting: hexadecimal.
714 * Prerequisites: none.
715 * Access: read/write.
716 * NXM: NXM_NX_REG0(0) since v1.1. <0>
717 * NXM: NXM_NX_REG1(1) since v1.1. <1>
718 * NXM: NXM_NX_REG2(2) since v1.1. <2>
719 * NXM: NXM_NX_REG3(3) since v1.1. <3>
720 * NXM: NXM_NX_REG4(4) since v1.3. <4>
721 * NXM: NXM_NX_REG5(5) since v1.7. <5>
722 * NXM: NXM_NX_REG6(6) since v1.7. <6>
723 * NXM: NXM_NX_REG7(7) since v1.7. <7>
735 #error "Need to update MFF_REG* to match FLOW_N_REGS"
738 #if FLOW_N_XREGS == 4
741 * OpenFlow 1.5 ``extended register". Each extended register
742 * overlays two of the Nicira extension 32-bit registers: xreg0 overlays
743 * reg0 and reg1, with reg0 supplying the most-significant bits of xreg0
744 * and reg1 the least-significant. xreg1 similarly overlays reg2 and reg3,
747 * These registers were introduced in OpenFlow 1.5, but EXT-244 in the ONF
748 * JIRA also publishes them as a (draft) OpenFlow extension to OpenFlow
753 * Formatting: hexadecimal.
754 * Prerequisites: none.
755 * Access: read/write.
757 * OXM: OXM_OF_PKT_REG<N>(<N>) since OF1.3 and v2.4.
764 #error "Need to update MFF_REG* to match FLOW_N_XREGS"
771 /* "eth_src" (aka "dl_src").
773 * Source address in Ethernet header.
775 * This field was not maskable before Open vSwitch 1.8.
779 * Formatting: Ethernet.
780 * Prerequisites: none.
781 * Access: read/write.
782 * NXM: NXM_OF_ETH_SRC(2) since v1.1.
783 * OXM: OXM_OF_ETH_SRC(4) since OF1.2 and v1.7.
784 * OF1.0: exact match.
785 * OF1.1: bitwise mask.
789 /* "eth_dst" (aka "dl_dst").
791 * Destination address in Ethernet header.
793 * Before Open vSwitch 1.8, the allowed masks were restricted to
794 * 00:00:00:00:00:00, fe:ff:ff:ff:ff:ff, 01:00:00:00:00:00,
799 * Formatting: Ethernet.
800 * Prerequisites: none.
801 * Access: read/write.
802 * NXM: NXM_OF_ETH_DST(1) since v1.1.
803 * OXM: OXM_OF_ETH_DST(3) since OF1.2 and v1.7.
804 * OF1.0: exact match.
805 * OF1.1: bitwise mask.
809 /* "eth_type" (aka "dl_type").
811 * Packet's Ethernet type.
813 * For an Ethernet II packet this is taken from the Ethernet header. For
814 * an 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP
815 * header. A packet that has neither format has value 0x05ff
816 * (OFP_DL_TYPE_NOT_ETH_TYPE).
818 * For a packet with an 802.1Q header, this is the type of the encapsulated
823 * Formatting: hexadecimal.
824 * Prerequisites: none.
826 * NXM: NXM_OF_ETH_TYPE(3) since v1.1.
827 * OXM: OXM_OF_ETH_TYPE(5) since OF1.2 and v1.7.
828 * OF1.0: exact match.
829 * OF1.1: exact match.
837 /* It looks odd for vlan_tci, vlan_vid, and vlan_pcp to say that they are
838 * supported in OF1.0 and OF1.1, since the detailed semantics of these fields
839 * only apply to NXM or OXM. They are marked as supported for exact matches in
840 * OF1.0 and OF1.1 because exact matches on those fields can be successfully
841 * translated into the OF1.0 and OF1.1 flow formats. */
847 * For a packet with an 802.1Q header, this is the Tag Control Information
848 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
849 * header, this has value 0.
851 * This field can be used in various ways:
853 * - If it is not constrained at all, the nx_match matches packets
854 * without an 802.1Q header or with an 802.1Q header that has any TCI
857 * - Testing for an exact match with 0 matches only packets without an
860 * - Testing for an exact match with a TCI value with CFI=1 matches
861 * packets that have an 802.1Q header with a specified VID and PCP.
863 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
864 * not make sense. The switch may reject this combination.
866 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
867 * packets that have an 802.1Q header with that VID (and any PCP).
869 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
870 * packets that have an 802.1Q header with that PCP (and any VID).
872 * - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no
873 * 802.1Q header or with an 802.1Q header with a VID of 0.
875 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no
876 * 802.1Q header or with an 802.1Q header with a PCP of 0.
878 * - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no
879 * 802.1Q header or with an 802.1Q header with both VID and PCP of 0.
883 * Formatting: hexadecimal.
884 * Prerequisites: none.
885 * Access: read/write.
886 * NXM: NXM_OF_VLAN_TCI(4) since v1.1.
888 * OF1.0: exact match.
889 * OF1.1: exact match.
893 /* "dl_vlan" (OpenFlow 1.0).
895 * VLAN ID field. Zero if no 802.1Q header is present.
897 * Type: be16 (low 12 bits).
899 * Formatting: decimal.
900 * Prerequisites: none.
901 * Access: read/write.
904 * OF1.0: exact match.
905 * OF1.1: exact match.
909 /* "vlan_vid" (OpenFlow 1.2+).
911 * If an 802.1Q header is present, this field's value is 0x1000
912 * bitwise-or'd with the VLAN ID. If no 802.1Q is present, this field's
915 * Type: be16 (low 12 bits).
917 * Formatting: decimal.
918 * Prerequisites: none.
919 * Access: read/write.
921 * OXM: OXM_OF_VLAN_VID(6) since OF1.2 and v1.7.
922 * OF1.0: exact match.
923 * OF1.1: exact match.
927 /* "dl_vlan_pcp" (OpenFlow 1.0).
929 * VLAN priority (PCP) field. Zero if no 802.1Q header is present.
931 * Type: u8 (low 3 bits).
933 * Formatting: decimal.
934 * Prerequisites: none.
935 * Access: read/write.
938 * OF1.0: exact match.
939 * OF1.1: exact match.
943 /* "vlan_pcp" (OpenFlow 1.2+).
945 * VLAN priority (PCP) field. Zero if no 802.1Q header is present.
947 * Type: u8 (low 3 bits).
949 * Formatting: decimal.
950 * Prerequisites: VLAN VID.
951 * Access: read/write.
953 * OXM: OXM_OF_VLAN_PCP(7) since OF1.2 and v1.7.
954 * OF1.0: exact match.
955 * OF1.1: exact match.
965 * The outermost MPLS label, or 0 if no MPLS labels are present.
967 * Type: be32 (low 20 bits).
969 * Formatting: decimal.
970 * Prerequisites: MPLS.
971 * Access: read/write.
973 * OXM: OXM_OF_MPLS_LABEL(34) since OF1.2 and v1.11.
974 * OF1.1: exact match.
980 * The outermost MPLS label's traffic control (TC) field, or 0 if no MPLS
981 * labels are present.
983 * Type: u8 (low 3 bits).
985 * Formatting: decimal.
986 * Prerequisites: MPLS.
987 * Access: read/write.
989 * OXM: OXM_OF_MPLS_TC(35) since OF1.2 and v1.11.
990 * OF1.1: exact match.
996 * The outermost MPLS label's bottom of stack (BoS) field, or 0 if no MPLS
997 * labels are present.
999 * Type: u8 (low 1 bits).
1001 * Formatting: decimal.
1002 * Prerequisites: MPLS.
1003 * Access: read-only.
1005 * OXM: OXM_OF_MPLS_BOS(36) since OF1.3 and v1.11.
1013 /* Update mf_is_l3_or_higher() if MFF_IPV4_SRC is no longer the first element
1014 * for a field of layer 3 or higher */
1016 /* "ip_src" (aka "nw_src").
1018 * The source address in the IPv4 header.
1020 * Before Open vSwitch 1.8, only CIDR masks were supported.
1023 * Maskable: bitwise.
1025 * Prerequisites: IPv4.
1026 * Access: read/write.
1027 * NXM: NXM_OF_IP_SRC(7) since v1.1.
1028 * OXM: OXM_OF_IPV4_SRC(11) since OF1.2 and v1.7.
1030 * OF1.1: bitwise mask.
1031 * Prefix lookup member: nw_src.
1035 /* "ip_dst" (aka "nw_dst").
1037 * The destination address in the IPv4 header.
1039 * Before Open vSwitch 1.8, only CIDR masks were supported.
1042 * Maskable: bitwise.
1044 * Prerequisites: IPv4.
1045 * Access: read/write.
1046 * NXM: NXM_OF_IP_DST(8) since v1.1.
1047 * OXM: OXM_OF_IPV4_DST(12) since OF1.2 and v1.7.
1049 * OF1.1: bitwise mask.
1050 * Prefix lookup member: nw_dst.
1060 * The source address in the IPv6 header.
1063 * Maskable: bitwise.
1065 * Prerequisites: IPv6.
1066 * Access: read/write.
1067 * NXM: NXM_NX_IPV6_SRC(19) since v1.1.
1068 * OXM: OXM_OF_IPV6_SRC(26) since OF1.2 and v1.1.
1069 * Prefix lookup member: ipv6_src.
1075 * The destination address in the IPv6 header.
1078 * Maskable: bitwise.
1080 * Prerequisites: IPv6.
1081 * Access: read/write.
1082 * NXM: NXM_NX_IPV6_DST(20) since v1.1.
1083 * OXM: OXM_OF_IPV6_DST(27) since OF1.2 and v1.1.
1084 * Prefix lookup member: ipv6_dst.
1090 * The flow label in the IPv6 header.
1092 * Type: be32 (low 20 bits).
1093 * Maskable: bitwise.
1094 * Formatting: hexadecimal.
1095 * Prerequisites: IPv6.
1096 * Access: read/write.
1097 * NXM: NXM_NX_IPV6_LABEL(27) since v1.4.
1098 * OXM: OXM_OF_IPV6_FLABEL(28) since OF1.2 and v1.7.
1102 /* ## ----------------------- ## */
1103 /* ## IPv4/IPv6 common fields ## */
1104 /* ## ----------------------- ## */
1106 /* "nw_proto" (aka "ip_proto").
1108 * The "protocol" byte in the IPv4 or IPv6 header.
1112 * Formatting: decimal.
1113 * Prerequisites: IPv4/IPv6.
1114 * Access: read-only.
1115 * NXM: NXM_OF_IP_PROTO(6) since v1.1.
1116 * OXM: OXM_OF_IP_PROTO(10) since OF1.2 and v1.7.
1117 * OF1.0: exact match.
1118 * OF1.1: exact match.
1122 /* Both views of the DSCP below are marked as supported in all of the versions
1123 * of OpenFlow because a match on either view can be successfully translated
1124 * into every OpenFlow flow format. */
1126 /* "nw_tos" (OpenFlow 1.0/1.1).
1128 * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
1129 * header, with the ECN bits forced to 0. (That is, bits 2-7 contain the
1130 * type of service and bits 0-1 are zero.)
1134 * Formatting: decimal.
1135 * Prerequisites: IPv4/IPv6.
1136 * Access: read/write.
1137 * NXM: NXM_OF_IP_TOS(5) since v1.1.
1139 * OF1.0: exact match.
1140 * OF1.1: exact match.
1144 /* "ip_dscp" (OpenFlow 1.2+).
1146 * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
1147 * header, shifted right 2 bits. (That is, bits 0-5 contain the type of
1148 * service and bits 6-7 are zero.)
1150 * Type: u8 (low 6 bits).
1152 * Formatting: decimal.
1153 * Prerequisites: IPv4/IPv6.
1154 * Access: read/write.
1156 * OXM: OXM_OF_IP_DSCP(8) since OF1.2 and v1.7.
1157 * OF1.0: exact match.
1158 * OF1.1: exact match.
1160 MFF_IP_DSCP_SHIFTED,
1162 /* "nw_ecn" (aka "ip_ecn").
1164 * The ECN bits in the IPv4 or IPv6 header.
1166 * Type: u8 (low 2 bits).
1168 * Formatting: decimal.
1169 * Prerequisites: IPv4/IPv6.
1170 * Access: read/write.
1171 * NXM: NXM_NX_IP_ECN(28) since v1.4.
1172 * OXM: OXM_OF_IP_ECN(9) since OF1.2 and v1.7.
1178 * The time-to-live (TTL) in the IPv4 header or hop limit in the IPv6
1183 * Formatting: decimal.
1184 * Prerequisites: IPv4/IPv6.
1185 * Access: read/write.
1186 * NXM: NXM_NX_IP_TTL(29) since v1.4.
1193 * IP fragment information.
1195 * This field has three possible values:
1197 * - A packet that is not an IP fragment has value 0.
1199 * - A packet that is an IP fragment with offset 0 (the first fragment)
1200 * has bit 0 set and thus value 1.
1202 * - A packet that is an IP fragment with nonzero offset has bits 0 and 1
1203 * set and thus value 3.
1205 * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically
1206 * represent the meanings of bits 0 and 1.
1208 * The switch may reject matches against values that can never appear.
1210 * It is important to understand how this field interacts with the OpenFlow
1211 * IP fragment handling mode:
1213 * - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
1214 * before they reach the flow table, so every packet that is available
1215 * for matching will have value 0 in this field.
1217 * - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did
1218 * then IP fragments would be reassembled before they reached the flow
1219 * table and again every packet available for matching would always
1222 * - In OFPC_FRAG_NORMAL mode, all three values are possible, but
1223 * OpenFlow 1.0 says that fragments' transport ports are always 0, even
1224 * for the first fragment, so this does not provide much extra
1227 * - In OFPC_FRAG_NX_MATCH mode, all three values are possible. For
1228 * fragments with offset 0, Open vSwitch makes L4 header information
1231 * Type: u8 (low 2 bits).
1232 * Maskable: bitwise.
1234 * Prerequisites: IPv4/IPv6.
1235 * Access: read-only.
1236 * NXM: NXM_NX_IP_FRAG(26) since v1.3.
1249 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
1250 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
1255 * Formatting: decimal.
1256 * Prerequisites: ARP.
1257 * Access: read/write.
1258 * NXM: NXM_OF_ARP_OP(15) since v1.1.
1259 * OXM: OXM_OF_ARP_OP(21) since OF1.2 and v1.7.
1260 * OF1.0: exact match.
1261 * OF1.1: exact match.
1267 * For an Ethernet+IP ARP packet, the source protocol (IPv4) address in the
1268 * ARP header. Always 0 otherwise.
1270 * Before Open vSwitch 1.8, only CIDR masks were supported.
1273 * Maskable: bitwise.
1275 * Prerequisites: ARP.
1276 * Access: read/write.
1277 * NXM: NXM_OF_ARP_SPA(16) since v1.1.
1278 * OXM: OXM_OF_ARP_SPA(22) since OF1.2 and v1.7.
1280 * OF1.1: bitwise mask.
1286 * For an Ethernet+IP ARP packet, the target protocol (IPv4) address in the
1287 * ARP header. Always 0 otherwise.
1289 * Before Open vSwitch 1.8, only CIDR masks were supported.
1292 * Maskable: bitwise.
1294 * Prerequisites: ARP.
1295 * Access: read/write.
1296 * NXM: NXM_OF_ARP_TPA(17) since v1.1.
1297 * OXM: OXM_OF_ARP_TPA(23) since OF1.2 and v1.7.
1299 * OF1.1: bitwise mask.
1305 * For an Ethernet+IP ARP packet, the source hardware (Ethernet) address in
1306 * the ARP header. Always 0 otherwise.
1309 * Maskable: bitwise.
1310 * Formatting: Ethernet.
1311 * Prerequisites: ARP.
1312 * Access: read/write.
1313 * NXM: NXM_NX_ARP_SHA(17) since v1.1.
1314 * OXM: OXM_OF_ARP_SHA(24) since OF1.2 and v1.7.
1320 * For an Ethernet+IP ARP packet, the target hardware (Ethernet) address in
1321 * the ARP header. Always 0 otherwise.
1324 * Maskable: bitwise.
1325 * Formatting: Ethernet.
1326 * Prerequisites: ARP.
1327 * Access: read/write.
1328 * NXM: NXM_NX_ARP_THA(18) since v1.1.
1329 * OXM: OXM_OF_ARP_THA(25) since OF1.2 and v1.7.
1337 /* "tcp_src" (aka "tp_src").
1342 * Maskable: bitwise.
1343 * Formatting: decimal.
1344 * Prerequisites: TCP.
1345 * Access: read/write.
1346 * NXM: NXM_OF_TCP_SRC(9) since v1.1.
1347 * OXM: OXM_OF_TCP_SRC(13) since OF1.2 and v1.7.
1348 * OF1.0: exact match.
1349 * OF1.1: exact match.
1353 /* "tcp_dst" (aka "tp_dst").
1355 * TCP destination port.
1358 * Maskable: bitwise.
1359 * Formatting: decimal.
1360 * Prerequisites: TCP.
1361 * Access: read/write.
1362 * NXM: NXM_OF_TCP_DST(10) since v1.1.
1363 * OXM: OXM_OF_TCP_DST(14) since OF1.2 and v1.7.
1364 * OF1.0: exact match.
1365 * OF1.1: exact match.
1371 * Flags in the TCP header.
1373 * TCP currently defines 9 flag bits, and additional 3 bits are reserved
1374 * (must be transmitted as zero). See RFCs 793, 3168, and 3540.
1376 * Type: be16 (low 12 bits).
1377 * Maskable: bitwise.
1378 * Formatting: TCP flags.
1379 * Prerequisites: TCP.
1380 * Access: read-only.
1381 * NXM: NXM_NX_TCP_FLAGS(34) since v2.1.
1382 * OXM: ONFOXM_ET_TCP_FLAGS(42) since OF1.3 and v2.4,
1383 * OXM_OF_TCP_FLAGS(42) since OF1.5 and v2.3.
1396 * Maskable: bitwise.
1397 * Formatting: decimal.
1398 * Prerequisites: UDP.
1399 * Access: read/write.
1400 * NXM: NXM_OF_UDP_SRC(11) since v1.1.
1401 * OXM: OXM_OF_UDP_SRC(15) since OF1.2 and v1.7.
1402 * OF1.0: exact match.
1403 * OF1.1: exact match.
1409 * UDP destination port
1412 * Maskable: bitwise.
1413 * Formatting: decimal.
1414 * Prerequisites: UDP.
1415 * Access: read/write.
1416 * NXM: NXM_OF_UDP_DST(12) since v1.1.
1417 * OXM: OXM_OF_UDP_DST(16) since OF1.2 and v1.7.
1418 * OF1.0: exact match.
1419 * OF1.1: exact match.
1432 * Maskable: bitwise.
1433 * Formatting: decimal.
1434 * Prerequisites: SCTP.
1435 * Access: read/write.
1437 * OXM: OXM_OF_SCTP_SRC(17) since OF1.2 and v2.0.
1438 * OF1.1: exact match.
1444 * SCTP destination port.
1447 * Maskable: bitwise.
1448 * Formatting: decimal.
1449 * Prerequisites: SCTP.
1450 * Access: read/write.
1452 * OXM: OXM_OF_SCTP_DST(18) since OF1.2 and v2.0.
1453 * OF1.1: exact match.
1467 * Formatting: decimal.
1468 * Prerequisites: ICMPv4.
1469 * Access: read-only.
1470 * NXM: NXM_OF_ICMP_TYPE(13) since v1.1.
1471 * OXM: OXM_OF_ICMPV4_TYPE(19) since OF1.2 and v1.7.
1472 * OF1.0: exact match.
1473 * OF1.1: exact match.
1483 * Formatting: decimal.
1484 * Prerequisites: ICMPv4.
1485 * Access: read-only.
1486 * NXM: NXM_OF_ICMP_CODE(14) since v1.1.
1487 * OXM: OXM_OF_ICMPV4_CODE(20) since OF1.2 and v1.7.
1488 * OF1.0: exact match.
1489 * OF1.1: exact match.
1499 * Formatting: decimal.
1500 * Prerequisites: ICMPv6.
1501 * Access: read-only.
1502 * NXM: NXM_NX_ICMPV6_TYPE(21) since v1.1.
1503 * OXM: OXM_OF_ICMPV6_TYPE(29) since OF1.2 and v1.7.
1513 * Formatting: decimal.
1514 * Prerequisites: ICMPv6.
1515 * Access: read-only.
1516 * NXM: NXM_NX_ICMPV6_CODE(22) since v1.1.
1517 * OXM: OXM_OF_ICMPV6_CODE(30) since OF1.2 and v1.7.
1521 /* ## ------------------------- ## */
1522 /* ## ICMPv6 Neighbor Discovery ## */
1523 /* ## ------------------------- ## */
1527 * The target address in an IPv6 Neighbor Discovery message.
1529 * Before Open vSwitch 1.8, only CIDR masks were supported.
1532 * Maskable: bitwise.
1534 * Prerequisites: ND.
1535 * Access: read/write.
1536 * NXM: NXM_NX_ND_TARGET(23) since v1.1.
1537 * OXM: OXM_OF_IPV6_ND_TARGET(31) since OF1.2 and v1.7.
1543 * The source link layer address in an IPv6 Neighbor Discovery message.
1546 * Maskable: bitwise.
1547 * Formatting: Ethernet.
1548 * Prerequisites: ND solicit.
1549 * Access: read/write.
1550 * NXM: NXM_NX_ND_SLL(24) since v1.1.
1551 * OXM: OXM_OF_IPV6_ND_SLL(32) since OF1.2 and v1.7.
1557 * The target link layer address in an IPv6 Neighbor Discovery message.
1560 * Maskable: bitwise.
1561 * Formatting: Ethernet.
1562 * Prerequisites: ND advert.
1563 * Access: read/write.
1564 * NXM: NXM_NX_ND_TLL(25) since v1.1.
1565 * OXM: OXM_OF_IPV6_ND_TLL(33) since OF1.2 and v1.7.
1572 /* A set of mf_field_ids. */
1574 unsigned long bm[BITMAP_N_LONGS(MFF_N_IDS)];
1576 #define MF_BITMAP_INITIALIZER { { [0] = 0 } }
1578 /* Use this macro as CASE_MFF_REGS: in a switch statement to choose all of the
1579 * MFF_REGn cases. */
1580 #if FLOW_N_REGS == 8
1581 #define CASE_MFF_REGS \
1582 case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
1583 case MFF_REG4: case MFF_REG5: case MFF_REG6: case MFF_REG7
1585 #error "Need to update CASE_MFF_REGS to match FLOW_N_REGS"
1588 /* Use this macro as CASE_MFF_XREGS: in a switch statement to choose all of the
1589 * MFF_REGn cases. */
1590 #if FLOW_N_XREGS == 4
1591 #define CASE_MFF_XREGS \
1592 case MFF_XREG0: case MFF_XREG1: case MFF_XREG2: case MFF_XREG3
1594 #error "Need to update CASE_MFF_XREGS to match FLOW_N_XREGS"
1597 /* Use this macro as CASE_MFF_TUN_METADATA: in a switch statement to choose
1598 * all of the MFF_TUN_METADATAn cases. */
1599 #define CASE_MFF_TUN_METADATA \
1600 case MFF_TUN_METADATA0: case MFF_TUN_METADATA1: \
1601 case MFF_TUN_METADATA2: case MFF_TUN_METADATA3: \
1602 case MFF_TUN_METADATA4: case MFF_TUN_METADATA5: \
1603 case MFF_TUN_METADATA6: case MFF_TUN_METADATA7: \
1604 case MFF_TUN_METADATA8: case MFF_TUN_METADATA9: \
1605 case MFF_TUN_METADATA10: case MFF_TUN_METADATA11: \
1606 case MFF_TUN_METADATA12: case MFF_TUN_METADATA13: \
1607 case MFF_TUN_METADATA14: case MFF_TUN_METADATA15: \
1608 case MFF_TUN_METADATA16: case MFF_TUN_METADATA17: \
1609 case MFF_TUN_METADATA18: case MFF_TUN_METADATA19: \
1610 case MFF_TUN_METADATA20: case MFF_TUN_METADATA21: \
1611 case MFF_TUN_METADATA22: case MFF_TUN_METADATA23: \
1612 case MFF_TUN_METADATA24: case MFF_TUN_METADATA25: \
1613 case MFF_TUN_METADATA26: case MFF_TUN_METADATA27: \
1614 case MFF_TUN_METADATA28: case MFF_TUN_METADATA29: \
1615 case MFF_TUN_METADATA30: case MFF_TUN_METADATA31: \
1616 case MFF_TUN_METADATA32: case MFF_TUN_METADATA33: \
1617 case MFF_TUN_METADATA34: case MFF_TUN_METADATA35: \
1618 case MFF_TUN_METADATA36: case MFF_TUN_METADATA37: \
1619 case MFF_TUN_METADATA38: case MFF_TUN_METADATA39: \
1620 case MFF_TUN_METADATA40: case MFF_TUN_METADATA41: \
1621 case MFF_TUN_METADATA42: case MFF_TUN_METADATA43: \
1622 case MFF_TUN_METADATA44: case MFF_TUN_METADATA45: \
1623 case MFF_TUN_METADATA46: case MFF_TUN_METADATA47: \
1624 case MFF_TUN_METADATA48: case MFF_TUN_METADATA49: \
1625 case MFF_TUN_METADATA50: case MFF_TUN_METADATA51: \
1626 case MFF_TUN_METADATA52: case MFF_TUN_METADATA53: \
1627 case MFF_TUN_METADATA54: case MFF_TUN_METADATA55: \
1628 case MFF_TUN_METADATA56: case MFF_TUN_METADATA57: \
1629 case MFF_TUN_METADATA58: case MFF_TUN_METADATA59: \
1630 case MFF_TUN_METADATA60: case MFF_TUN_METADATA61: \
1631 case MFF_TUN_METADATA62: case MFF_TUN_METADATA63
1633 /* Prerequisites for matching a field.
1635 * A field may only be matched if the correct lower-level protocols are also
1636 * matched. For example, the TCP port may be matched only if the Ethernet type
1637 * matches ETH_TYPE_IP and the IP protocol matches IPPROTO_TCP. */
1638 enum OVS_PACKED_ENUM mf_prereqs {
1641 /* L2 requirements. */
1648 /* L2.5 requirements. */
1651 /* L2+L3 requirements. */
1652 MFP_TCP, /* On IPv4 or IPv6. */
1653 MFP_UDP, /* On IPv4 or IPv6. */
1654 MFP_SCTP, /* On IPv4 or IPv6. */
1658 /* L2+L3+L4 requirements. */
1664 /* Forms of partial-field masking allowed for a field.
1666 * Every field may be masked as a whole. */
1667 enum OVS_PACKED_ENUM mf_maskable {
1668 MFM_NONE, /* No sub-field masking. */
1669 MFM_FULLY, /* Every bit is individually maskable. */
1672 /* How to format or parse a field's value. */
1673 enum OVS_PACKED_ENUM mf_string {
1676 * The particular MFS_* constant sets the output format. On input, either
1677 * decimal or hexadecimal (prefixed with 0x) is accepted. */
1681 /* Other formats. */
1685 MFS_OFP_PORT, /* 16-bit OpenFlow 1.0 port number or name. */
1686 MFS_OFP_PORT_OXM, /* 32-bit OpenFlow 1.1+ port number or name. */
1687 MFS_FRAG, /* no, yes, first, later, not_later */
1688 MFS_TNL_FLAGS, /* FLOW_TNL_F_* flags */
1689 MFS_TCP_FLAGS, /* TCP_* flags */
1693 /* Identification. */
1694 enum mf_field_id id; /* MFF_*. */
1695 const char *name; /* Name of this field, e.g. "eth_type". */
1696 const char *extra_name; /* Alternate name, e.g. "dl_type", or NULL. */
1700 * Most fields have n_bytes * 8 == n_bits. There are a few exceptions:
1702 * - "dl_vlan" is 2 bytes but only 12 bits.
1703 * - "dl_vlan_pcp" is 1 byte but only 3 bits.
1704 * - "is_frag" is 1 byte but only 2 bits.
1705 * - "ipv6_label" is 4 bytes but only 20 bits.
1706 * - "mpls_label" is 4 bytes but only 20 bits.
1707 * - "mpls_tc" is 1 byte but only 3 bits.
1708 * - "mpls_bos" is 1 byte but only 1 bit.
1710 unsigned int n_bytes; /* Width of the field in bytes. */
1711 unsigned int n_bits; /* Number of significant bits in field. */
1712 bool variable_len; /* Length is variable, if so width is max. */
1715 enum mf_maskable maskable;
1716 enum mf_string string;
1717 enum mf_prereqs prereqs;
1718 bool writable; /* May be written by actions? */
1720 /* Usable protocols.
1722 * NXM and OXM are extensible, allowing later extensions to be sent in
1723 * earlier protocol versions, so this does not necessarily correspond to
1724 * the OpenFlow protocol version the field was introduced in.
1725 * Also, some field types are tranparently mapped to each other via the
1726 * struct flow (like vlan and dscp/tos fields), so each variant supports
1729 * These are combinations of OFPUTIL_P_*. (They are not declared as type
1730 * enum ofputil_protocol because that would give meta-flow.h and ofp-util.h
1731 * a circular dependency.) */
1732 uint32_t usable_protocols_exact; /* Matching or setting whole field. */
1733 uint32_t usable_protocols_cidr; /* Matching a CIDR mask in field. */
1734 uint32_t usable_protocols_bitwise; /* Matching arbitrary bits in field. */
1736 int flow_be32ofs; /* Field's be32 offset in "struct flow", if prefix tree
1737 * lookup is supported for the field, or -1. */
1740 /* The representation of a field's value. */
1742 uint8_t tun_metadata[128];
1743 struct in6_addr ipv6;
1744 struct eth_addr mac;
1751 BUILD_ASSERT_DECL(sizeof(union mf_value) == 128);
1752 BUILD_ASSERT_DECL(sizeof(union mf_value) >= GENEVE_MAX_OPT_SIZE);
1754 /* A const mf_value with all bits initialized to ones. */
1755 extern const union mf_value exact_match_mask;
1757 /* Part of a field. */
1758 struct mf_subfield {
1759 const struct mf_field *field;
1760 unsigned int ofs; /* Bit offset. */
1761 unsigned int n_bits; /* Number of bits. */
1764 /* Data for some part of an mf_field.
1766 * The data is stored "right-justified". For example, if "union mf_subvalue
1767 * value" contains NXM_OF_VLAN_TCI[0..11], then one could access the
1768 * corresponding data in value.be16[7] as the bits in the mask htons(0xfff). */
1770 /* Access to full data. */
1776 /* Convenient access to just least-significant bits in various forms. */
1778 ovs_be64 dummy_integer[15];
1782 uint8_t dummy_mac[122];
1783 struct eth_addr mac;
1786 ovs_be32 dummy_ipv4[31];
1790 struct in6_addr dummy_ipv6[7];
1791 struct in6_addr ipv6;
1794 BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof (union mf_subvalue));
1796 bool mf_subvalue_intersect(const union mf_subvalue *a_value,
1797 const union mf_subvalue *a_mask,
1798 const union mf_subvalue *b_value,
1799 const union mf_subvalue *b_mask,
1800 union mf_subvalue *dst_value,
1801 union mf_subvalue *dst_mask);
1802 int mf_subvalue_width(const union mf_subvalue *);
1803 void mf_subvalue_shift(union mf_subvalue *, int n);
1805 /* An array of fields with values */
1806 struct field_array {
1807 struct mf_bitmap used;
1808 union mf_value value[MFF_N_IDS];
1811 /* Finding mf_fields. */
1812 const struct mf_field *mf_from_name(const char *name);
1814 static inline const struct mf_field *
1815 mf_from_id(enum mf_field_id id)
1817 extern const struct mf_field mf_fields[MFF_N_IDS];
1818 ovs_assert((unsigned int) id < MFF_N_IDS);
1819 return &mf_fields[id];
1822 /* Inspecting wildcarded bits. */
1823 bool mf_is_all_wild(const struct mf_field *, const struct flow_wildcards *);
1825 bool mf_is_mask_valid(const struct mf_field *, const union mf_value *mask);
1826 void mf_get_mask(const struct mf_field *, const struct flow_wildcards *,
1827 union mf_value *mask);
1829 /* Prerequisites. */
1830 bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
1831 void mf_mask_field_and_prereqs(const struct mf_field *,
1832 struct flow_wildcards *);
1833 void mf_bitmap_set_field_and_prereqs(const struct mf_field *mf, struct
1837 mf_is_l3_or_higher(const struct mf_field *mf)
1839 return mf->id >= MFF_IPV4_SRC;
1843 bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
1845 void mf_get_value(const struct mf_field *, const struct flow *,
1846 union mf_value *value);
1847 void mf_set_value(const struct mf_field *, const union mf_value *value,
1848 struct match *, char **err_str);
1849 void mf_set_flow_value(const struct mf_field *, const union mf_value *value,
1851 void mf_set_flow_value_masked(const struct mf_field *,
1852 const union mf_value *value,
1853 const union mf_value *mask,
1855 bool mf_is_tun_metadata(const struct mf_field *);
1856 bool mf_is_set(const struct mf_field *, const struct flow *);
1857 void mf_mask_field(const struct mf_field *, struct flow *);
1858 int mf_field_len(const struct mf_field *, const union mf_value *value,
1859 const union mf_value *mask, bool *is_masked);
1861 void mf_get(const struct mf_field *, const struct match *,
1862 union mf_value *value, union mf_value *mask);
1864 /* Returns the set of usable protocols. */
1865 uint32_t mf_set(const struct mf_field *, const union mf_value *value,
1866 const union mf_value *mask, struct match *, char **err_str);
1868 void mf_set_wild(const struct mf_field *, struct match *, char **err_str);
1871 void mf_write_subfield_flow(const struct mf_subfield *,
1872 const union mf_subvalue *, struct flow *);
1873 void mf_write_subfield(const struct mf_subfield *, const union mf_subvalue *,
1875 void mf_mask_subfield(const struct mf_field *,
1876 const union mf_subvalue *value,
1877 const union mf_subvalue *mask,
1880 void mf_read_subfield(const struct mf_subfield *, const struct flow *,
1881 union mf_subvalue *);
1882 uint64_t mf_get_subfield(const struct mf_subfield *, const struct flow *);
1885 enum ofperr mf_check_src(const struct mf_subfield *, const struct flow *);
1886 enum ofperr mf_check_dst(const struct mf_subfield *, const struct flow *);
1888 /* Parsing and formatting. */
1889 char *mf_parse(const struct mf_field *, const char *,
1890 union mf_value *value, union mf_value *mask);
1891 char *mf_parse_value(const struct mf_field *, const char *, union mf_value *);
1892 void mf_format(const struct mf_field *,
1893 const union mf_value *value, const union mf_value *mask,
1895 void mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s);
1898 void field_array_set(enum mf_field_id id, const union mf_value *,
1899 struct field_array *);
1901 #endif /* meta-flow.h */