2 * Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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.
143 * Either "bitwise", if OVS supports matching any subset of bits in the
144 * field, or "no", if OVS only supports matching or wildcarding the entire
149 * Explains how a field's value is formatted and parsed for human
150 * consumption. Some of the options are fairly generally useful:
152 * decimal: Formats the value as a decimal number. On parsing, accepts
153 * decimal (with no prefix), hexadecimal with 0x prefix, or octal
156 * hexadecimal: Same as decimal except nonzero values are formatted in
157 * hex with 0x prefix. The default for parsing is *not* hexadecimal:
158 * only with a 0x prefix is the input in hexadecimal.
160 * Ethernet: Formats and accepts the common format xx:xx:xx:xx:xx:xx.
161 * 6-byte fields only.
163 * IPv4: Formats and accepts the common format w.x.y.z. 4-byte fields
166 * IPv6: Formats and accepts the common IPv6 formats. 16-byte fields
169 * OpenFlow 1.0 port: Accepts an OpenFlow well-known port name
170 * (e.g. "IN_PORT") in uppercase or lowercase, or a 16-bit port
171 * number in decimal. Formats ports using their well-known names in
172 * uppercase, or in decimal otherwise. 2-byte fields only.
174 * OpenFlow 1.1+ port: Same syntax as for OpenFlow 1.0 ports but for
175 * 4-byte OpenFlow 1.1+ port number fields.
177 * Others are very specific to particular fields:
179 * frag: One of the strings "no", "first", "later", "yes", "not_later"
180 * describing which IPv4/v6 fragments are matched.
182 * tunnel flags: Any number of the strings "df", "csum", "key", or
183 * "oam" separated by "|".
185 * TCP flags: See the description of tcp_flags in ovs-ofctl(8).
189 * The field's prerequisites. The values should be straightfoward.
193 * Either "read-only", for a field that cannot be changed via OpenFlow, or
194 * "read/write" for a modifiable field.
198 * If the field has an NXM field assignment, then this specifies the NXM
199 * name of the field (e.g. "NXM_OF_ETH_SRC"), followed by its nxm_type in
200 * parentheses, followed by "since v<x>.<y>" specifying the version of Open
201 * vSwitch that first supported this field in NXM (e.g. "since v1.1" if it
202 * was introduced in Open vSwitch 1.1).
204 * The NXM name must begin with NXM_OF_ or NXM_NX_. This allows OVS to
205 * determine the correct NXM class.
207 * If the field does not have an NXM field assignment, specify "none".
211 * If the field has an OXM field assignment, then this specifies the OXM
212 * name of the field (e.g. "OXM_OF_ETH_SRC"), followed by its nxm_type in
213 * parentheses, followed by "since OF<a>.<b> v<x>.<y>" specifying the
214 * versions of OpenFlow and Open vSwitch that first supported this field in
215 * OXM (e.g. "since OF1.3 and v1.10" if it was introduced in OpenFlow 1.3
216 * and first supported by Open vSwitch in version 1.10).
218 * OVS uses the start of the OXM field name to determine the correct OXM
219 * class. To support a new OXM class, edit the mapping table in
220 * build-aux/extract-ofp-fields.
222 * If the field does not have an OXM field assignment, specify "none".
224 * The following key-value pairs are optional. Open vSwitch already supports
225 * all the fields to which they apply, so new fields should probably not
226 * include these pairs:
230 * Specify this as "exact match" if OpenFlow 1.0 can match or wildcard the
231 * entire field, or as "CIDR mask" if OpenFlow 1.0 can match any CIDR
232 * prefix of the field. (OpenFlow 1.0 did not support bitwise matching.)
233 * Omit, if OpenFlow 1.0 did not support this field.
237 * Specify this as "exact match" if OpenFlow 1.1 can match or wildcard the
238 * entire field, or as "bitwise" if OpenFlow 1.1 can match any subset of
239 * bits in the field. Omit, if OpenFlow 1.1 did not support this field.
241 * The following key-value pair is optional:
243 * Prefix lookup member:
245 * If this field makes sense for use with classifier_set_prefix_fields(),
246 * specify the name of the "struct flow" member that corresponds to the
249 * Finally, a few "register" fields have very similar names and purposes,
250 * e.g. MFF_REG0 through MFF_REG7. For these, the comments may be merged
251 * together using <N> as a metasyntactic variable for the numeric suffix.
252 * Lines in the comment that are specific to one of the particular fields by
253 * writing, e.g. <1>, to consider that line only for e.g. MFF_REG1.
256 enum OVS_PACKED_ENUM mf_field_id {
263 * Flow hash computed in the datapath. Internal use only, not programmable
266 * The OXM code point for this is an attempt to test OXM experimenter
267 * support, which is otherwise difficult to test due to the dearth of use
268 * out in the wild. Because controllers can't add flows that match on
269 * dp_hash, this doesn't commit OVS to supporting this OXM experimenter
270 * code point in the future.
274 * Formatting: hexadecimal.
275 * Prerequisites: none.
277 * NXM: NXM_NX_DP_HASH(35) since v2.2.
278 * OXM: NXOXM_ET_DP_HASH(0) since OF1.5 and v2.4.
284 * ID for recirculation. The value 0 is reserved for initially received
285 * packets. Internal use only, not programmable from controller.
289 * Formatting: decimal.
290 * Prerequisites: none.
292 * NXM: NXM_NX_RECIRC_ID(36) since v2.2.
297 /* "tun_id" (aka "tunnel_id").
299 * The "key" or "tunnel ID" or "VNI" in a packet received via a keyed
300 * tunnel. For protocols in which the key is shorter than 64 bits, the key
301 * is stored in the low bits and the high bits are zeroed. For non-keyed
302 * tunnels and packets not received via a tunnel, the value is 0.
306 * Formatting: hexadecimal.
307 * Prerequisites: none.
308 * Access: read/write.
309 * NXM: NXM_NX_TUN_ID(16) since v1.1.
310 * OXM: OXM_OF_TUNNEL_ID(38) since OF1.3 and v1.10.
311 * Prefix lookup member: tunnel.tun_id.
317 * The IPv4 source address in the outer IP header of a tunneled packet.
319 * For non-tunneled packets, the value is 0.
324 * Prerequisites: none.
325 * Access: read/write.
326 * NXM: NXM_NX_TUN_IPV4_SRC(31) since v2.0.
328 * Prefix lookup member: tunnel.ip_src.
334 * The IPv4 destination address in the outer IP header of a tunneled
337 * For non-tunneled packets, the value is 0.
342 * Prerequisites: none.
343 * Access: read/write.
344 * NXM: NXM_NX_TUN_IPV4_DST(32) since v2.0.
346 * Prefix lookup member: tunnel.ip_dst.
352 * Combination of FLOW_TNL_F_* bitmapped flags that indicate properties of
353 * a tunneled packet. Internal use only, not programmable from controller.
355 * For non-tunneled packets, the value is 0.
359 * Formatting: tunnel flags.
360 * Prerequisites: none.
369 * The TTL in the outer IP header of a tunneled packet. Internal use only,
370 * not programmable from controller.
372 * For non-tunneled packets, the value is 0.
376 * Formatting: decimal.
377 * Prerequisites: none.
386 * The ToS value in the outer IP header of a tunneled packet. Internal use
387 * only, not programmable from controller.
391 * Formatting: decimal.
392 * Prerequisites: none.
401 * A scratch pad value standardized in OpenFlow 1.1+. Initially zero, at
402 * the beginning of the pipeline.
406 * Formatting: hexadecimal.
407 * Prerequisites: none.
408 * Access: read/write.
410 * OXM: OXM_OF_METADATA(2) since OF1.2 and v1.8.
411 * OF1.1: bitwise mask.
417 * 16-bit (OpenFlow 1.0) view of the physical or virtual port on which the
418 * packet was received.
422 * Formatting: OpenFlow 1.0 port.
423 * Prerequisites: none.
424 * Access: read/write.
425 * NXM: NXM_OF_IN_PORT(0) since v1.1.
427 * OF1.0: exact match.
428 * OF1.1: exact match.
434 * 32-bit (OpenFlow 1.1+) view of the physical or virtual port on which the
435 * packet was received.
439 * Formatting: OpenFlow 1.1+ port.
440 * Prerequisites: none.
441 * Access: read/write.
443 * OXM: OXM_OF_IN_PORT(0) since OF1.2 and v1.7.
444 * OF1.1: exact match.
450 * Designates the queue to which output will be directed. The value in
451 * this field is not necessarily the OpenFlow queue number; with the Linux
452 * kernel switch, it instead has a pair of subfields designating the
453 * "major" and "minor" numbers of a Linux kernel qdisc handle.
455 * This field is "semi-internal" in that it can be set with the "set_queue"
456 * action but not matched or read or written other ways.
460 * Formatting: hexadecimal.
461 * Prerequisites: none.
470 * Packet metadata mark. The mark may be passed into other system
471 * components in order to facilitate interaction between subsystems. On
472 * Linux this corresponds to struct sk_buff's "skb_mark" member but the
473 * exact implementation is platform-dependent.
477 * Formatting: hexadecimal.
478 * Prerequisites: none.
479 * Access: read/write.
480 * NXM: NXM_NX_PKT_MARK(33) since v2.0.
488 * Nicira extension scratch pad register with initial value 0.
492 * Formatting: hexadecimal.
493 * Prerequisites: none.
494 * Access: read/write.
495 * NXM: NXM_NX_REG0(0) since v1.1. <0>
496 * NXM: NXM_NX_REG1(1) since v1.1. <1>
497 * NXM: NXM_NX_REG2(2) since v1.1. <2>
498 * NXM: NXM_NX_REG3(3) since v1.1. <3>
499 * NXM: NXM_NX_REG4(4) since v1.3. <4>
500 * NXM: NXM_NX_REG5(5) since v1.7. <5>
501 * NXM: NXM_NX_REG6(6) since v1.7. <6>
502 * NXM: NXM_NX_REG7(7) since v1.7. <7>
514 #error "Need to update MFF_REG* to match FLOW_N_REGS"
517 #if FLOW_N_XREGS == 4
520 * OpenFlow 1.5 (draft) ``extended register". Each extended register
521 * overlays two of the Nicira extension 32-bit registers: xreg0 overlays
522 * reg0 and reg1, with reg0 supplying the most-significant bits of xreg0
523 * and reg1 the least-significant. xreg1 similarly overlays reg2 and reg3,
528 * Formatting: hexadecimal.
529 * Prerequisites: none.
530 * Access: read/write.
532 * OXM: OXM_OF_PKT_REG<N>(<N>) since OF1.5 and v2.4.
539 #error "Need to update MFF_REG* to match FLOW_N_XREGS"
546 /* "eth_src" (aka "dl_src").
548 * Source address in Ethernet header.
550 * This field was not maskable before Open vSwitch 1.8.
554 * Formatting: Ethernet.
555 * Prerequisites: none.
556 * Access: read/write.
557 * NXM: NXM_OF_ETH_SRC(2) since v1.1.
558 * OXM: OXM_OF_ETH_SRC(4) since OF1.2 and v1.7.
559 * OF1.0: exact match.
560 * OF1.1: bitwise mask.
564 /* "eth_dst" (aka "dl_dst").
566 * Destination address in Ethernet header.
568 * Before Open vSwitch 1.8, the allowed masks were restricted to
569 * 00:00:00:00:00:00, fe:ff:ff:ff:ff:ff, 01:00:00:00:00:00,
574 * Formatting: Ethernet.
575 * Prerequisites: none.
576 * Access: read/write.
577 * NXM: NXM_OF_ETH_DST(1) since v1.1.
578 * OXM: OXM_OF_ETH_DST(3) since OF1.2 and v1.7.
579 * OF1.0: exact match.
580 * OF1.1: bitwise mask.
584 /* "eth_type" (aka "dl_type").
586 * Packet's Ethernet type.
588 * For an Ethernet II packet this is taken from the Ethernet header. For
589 * an 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP
590 * header. A packet that has neither format has value 0x05ff
591 * (OFP_DL_TYPE_NOT_ETH_TYPE).
593 * For a packet with an 802.1Q header, this is the type of the encapsulated
598 * Formatting: hexadecimal.
599 * Prerequisites: none.
601 * NXM: NXM_OF_ETH_TYPE(3) since v1.1.
602 * OXM: OXM_OF_ETH_TYPE(5) since OF1.2 and v1.7.
603 * OF1.0: exact match.
604 * OF1.1: exact match.
612 /* It looks odd for vlan_tci, vlan_vid, and vlan_pcp to say that they are
613 * supported in OF1.0 and OF1.1, since the detailed semantics of these fields
614 * only apply to NXM or OXM. They are marked as supported for exact matches in
615 * OF1.0 and OF1.1 because exact matches on those fields can be successfully
616 * translated into the OF1.0 and OF1.1 flow formats. */
622 * For a packet with an 802.1Q header, this is the Tag Control Information
623 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
624 * header, this has value 0.
626 * This field can be used in various ways:
628 * - If it is not constrained at all, the nx_match matches packets
629 * without an 802.1Q header or with an 802.1Q header that has any TCI
632 * - Testing for an exact match with 0 matches only packets without an
635 * - Testing for an exact match with a TCI value with CFI=1 matches
636 * packets that have an 802.1Q header with a specified VID and PCP.
638 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
639 * not make sense. The switch may reject this combination.
641 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
642 * packets that have an 802.1Q header with that VID (and any PCP).
644 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
645 * packets that have an 802.1Q header with that PCP (and any VID).
647 * - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no
648 * 802.1Q header or with an 802.1Q header with a VID of 0.
650 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no
651 * 802.1Q header or with an 802.1Q header with a PCP of 0.
653 * - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no
654 * 802.1Q header or with an 802.1Q header with both VID and PCP of 0.
658 * Formatting: hexadecimal.
659 * Prerequisites: none.
660 * Access: read/write.
661 * NXM: NXM_OF_VLAN_TCI(4) since v1.1.
663 * OF1.0: exact match.
664 * OF1.1: exact match.
668 /* "dl_vlan" (OpenFlow 1.0).
670 * VLAN ID field. Zero if no 802.1Q header is present.
672 * Type: be16 (low 12 bits).
674 * Formatting: decimal.
675 * Prerequisites: none.
676 * Access: read/write.
679 * OF1.0: exact match.
680 * OF1.1: exact match.
684 /* "vlan_vid" (OpenFlow 1.2+).
686 * If an 802.1Q header is present, this field's value is 0x1000
687 * bitwise-or'd with the VLAN ID. If no 802.1Q is present, this field's
690 * Type: be16 (low 12 bits).
692 * Formatting: decimal.
693 * Prerequisites: none.
694 * Access: read/write.
696 * OXM: OXM_OF_VLAN_VID(6) since OF1.2 and v1.7.
697 * OF1.0: exact match.
698 * OF1.1: exact match.
702 /* "dl_vlan_pcp" (OpenFlow 1.0).
704 * VLAN priority (PCP) field. Zero if no 802.1Q header is present.
706 * Type: u8 (low 3 bits).
708 * Formatting: decimal.
709 * Prerequisites: none.
710 * Access: read/write.
713 * OF1.0: exact match.
714 * OF1.1: exact match.
718 /* "vlan_pcp" (OpenFlow 1.2+).
720 * VLAN priority (PCP) field. Zero if no 802.1Q header is present.
722 * Type: u8 (low 3 bits).
724 * Formatting: decimal.
725 * Prerequisites: VLAN VID.
726 * Access: read/write.
728 * OXM: OXM_OF_VLAN_PCP(7) since OF1.2 and v1.7.
729 * OF1.0: exact match.
730 * OF1.1: exact match.
740 * The outermost MPLS label, or 0 if no MPLS labels are present.
742 * Type: be32 (low 20 bits).
744 * Formatting: decimal.
745 * Prerequisites: MPLS.
746 * Access: read/write.
748 * OXM: OXM_OF_MPLS_LABEL(34) since OF1.2 and v1.11.
749 * OF1.1: exact match.
755 * The outermost MPLS label's traffic control (TC) field, or 0 if no MPLS
756 * labels are present.
758 * Type: u8 (low 3 bits).
760 * Formatting: decimal.
761 * Prerequisites: MPLS.
762 * Access: read/write.
764 * OXM: OXM_OF_MPLS_TC(35) since OF1.2 and v1.11.
765 * OF1.1: exact match.
771 * The outermost MPLS label's bottom of stack (BoS) field, or 0 if no MPLS
772 * labels are present.
774 * Type: u8 (low 1 bits).
776 * Formatting: decimal.
777 * Prerequisites: MPLS.
780 * OXM: OXM_OF_MPLS_BOS(36) since OF1.3 and v1.11.
788 /* Update mf_is_l3_or_higher() if MFF_IPV4_SRC is no longer the first element
789 * for a field of layer 3 or higher */
791 /* "ip_src" (aka "nw_src").
793 * The source address in the IPv4 header.
795 * Before Open vSwitch 1.8, only CIDR masks were supported.
800 * Prerequisites: IPv4.
801 * Access: read/write.
802 * NXM: NXM_OF_IP_SRC(7) since v1.1.
803 * OXM: OXM_OF_IPV4_SRC(11) since OF1.2 and v1.7.
805 * OF1.1: bitwise mask.
806 * Prefix lookup member: nw_src.
810 /* "ip_dst" (aka "nw_dst").
812 * The destination address in the IPv4 header.
814 * Before Open vSwitch 1.8, only CIDR masks were supported.
819 * Prerequisites: IPv4.
820 * Access: read/write.
821 * NXM: NXM_OF_IP_DST(8) since v1.1.
822 * OXM: OXM_OF_IPV4_DST(12) since OF1.2 and v1.7.
824 * OF1.1: bitwise mask.
825 * Prefix lookup member: nw_dst.
835 * The source address in the IPv6 header.
840 * Prerequisites: IPv6.
841 * Access: read/write.
842 * NXM: NXM_NX_IPV6_SRC(19) since v1.1.
843 * OXM: OXM_OF_IPV6_SRC(26) since OF1.2 and v1.1.
844 * Prefix lookup member: ipv6_src.
850 * The destination address in the IPv6 header.
855 * Prerequisites: IPv6.
856 * Access: read/write.
857 * NXM: NXM_NX_IPV6_DST(20) since v1.1.
858 * OXM: OXM_OF_IPV6_DST(27) since OF1.2 and v1.1.
859 * Prefix lookup member: ipv6_dst.
865 * The flow label in the IPv6 header.
867 * Type: be32 (low 20 bits).
869 * Formatting: hexadecimal.
870 * Prerequisites: IPv6.
872 * NXM: NXM_NX_IPV6_LABEL(27) since v1.4.
873 * OXM: OXM_OF_IPV6_FLABEL(28) since OF1.2 and v1.7.
877 /* ## ----------------------- ## */
878 /* ## IPv4/IPv6 common fields ## */
879 /* ## ----------------------- ## */
881 /* "nw_proto" (aka "ip_proto").
883 * The "protocol" byte in the IPv4 or IPv6 header.
887 * Formatting: decimal.
888 * Prerequisites: IPv4/IPv6.
890 * NXM: NXM_OF_IP_PROTO(6) since v1.1.
891 * OXM: OXM_OF_IP_PROTO(10) since OF1.2 and v1.7.
892 * OF1.0: exact match.
893 * OF1.1: exact match.
897 /* Both views of the DSCP below are marked as supported in all of the versions
898 * of OpenFlow because a match on either view can be successfully translated
899 * into every OpenFlow flow format. */
901 /* "nw_tos" (OpenFlow 1.0/1.1).
903 * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
904 * header, with the ECN bits forced to 0. (That is, bits 2-7 contain the
905 * type of service and bits 0-1 are zero.)
909 * Formatting: decimal.
910 * Prerequisites: IPv4/IPv6.
911 * Access: read/write.
912 * NXM: NXM_OF_IP_TOS(5) since v1.1.
914 * OF1.0: exact match.
915 * OF1.1: exact match.
919 /* "ip_dscp" (OpenFlow 1.2+).
921 * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
922 * header, shifted right 2 bits. (That is, bits 0-5 contain the type of
923 * service and bits 6-7 are zero.)
925 * Type: u8 (low 6 bits).
927 * Formatting: decimal.
928 * Prerequisites: IPv4/IPv6.
929 * Access: read/write.
931 * OXM: OXM_OF_IP_DSCP(8) since OF1.2 and v1.7.
932 * OF1.0: exact match.
933 * OF1.1: exact match.
937 /* "nw_ecn" (aka "ip_ecn").
939 * The ECN bits in the IPv4 or IPv6 header.
941 * Type: u8 (low 2 bits).
943 * Formatting: decimal.
944 * Prerequisites: IPv4/IPv6.
945 * Access: read/write.
946 * NXM: NXM_NX_IP_ECN(28) since v1.4.
947 * OXM: OXM_OF_IP_ECN(9) since OF1.2 and v1.7.
953 * The time-to-live (TTL) in the IPv4 header or hop limit in the IPv6
958 * Formatting: decimal.
959 * Prerequisites: IPv4/IPv6.
960 * Access: read/write.
961 * NXM: NXM_NX_IP_TTL(29) since v1.4.
968 * IP fragment information.
970 * This field has three possible values:
972 * - A packet that is not an IP fragment has value 0.
974 * - A packet that is an IP fragment with offset 0 (the first fragment)
975 * has bit 0 set and thus value 1.
977 * - A packet that is an IP fragment with nonzero offset has bits 0 and 1
978 * set and thus value 3.
980 * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically
981 * represent the meanings of bits 0 and 1.
983 * The switch may reject matches against values that can never appear.
985 * It is important to understand how this field interacts with the OpenFlow
986 * IP fragment handling mode:
988 * - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
989 * before they reach the flow table, so every packet that is available
990 * for matching will have value 0 in this field.
992 * - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did
993 * then IP fragments would be reassembled before they reached the flow
994 * table and again every packet available for matching would always
997 * - In OFPC_FRAG_NORMAL mode, all three values are possible, but
998 * OpenFlow 1.0 says that fragments' transport ports are always 0, even
999 * for the first fragment, so this does not provide much extra
1002 * - In OFPC_FRAG_NX_MATCH mode, all three values are possible. For
1003 * fragments with offset 0, Open vSwitch makes L4 header information
1006 * Type: u8 (low 2 bits).
1007 * Maskable: bitwise.
1009 * Prerequisites: IPv4/IPv6.
1010 * Access: read-only.
1011 * NXM: NXM_NX_IP_FRAG(26) since v1.3.
1024 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
1025 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
1030 * Formatting: decimal.
1031 * Prerequisites: ARP.
1032 * Access: read/write.
1033 * NXM: NXM_OF_ARP_OP(15) since v1.1.
1034 * OXM: OXM_OF_ARP_OP(21) since OF1.2 and v1.7.
1035 * OF1.0: exact match.
1036 * OF1.1: exact match.
1042 * For an Ethernet+IP ARP packet, the source protocol (IPv4) address in the
1043 * ARP header. Always 0 otherwise.
1045 * Before Open vSwitch 1.8, only CIDR masks were supported.
1048 * Maskable: bitwise.
1050 * Prerequisites: ARP.
1051 * Access: read/write.
1052 * NXM: NXM_OF_ARP_SPA(16) since v1.1.
1053 * OXM: OXM_OF_ARP_SPA(22) since OF1.2 and v1.7.
1055 * OF1.1: bitwise mask.
1061 * For an Ethernet+IP ARP packet, the target protocol (IPv4) address in the
1062 * ARP header. Always 0 otherwise.
1064 * Before Open vSwitch 1.8, only CIDR masks were supported.
1067 * Maskable: bitwise.
1069 * Prerequisites: ARP.
1070 * Access: read/write.
1071 * NXM: NXM_OF_ARP_TPA(17) since v1.1.
1072 * OXM: OXM_OF_ARP_TPA(23) since OF1.2 and v1.7.
1074 * OF1.1: bitwise mask.
1080 * For an Ethernet+IP ARP packet, the source hardware (Ethernet) address in
1081 * the ARP header. Always 0 otherwise.
1084 * Maskable: bitwise.
1085 * Formatting: Ethernet.
1086 * Prerequisites: ARP.
1087 * Access: read/write.
1088 * NXM: NXM_NX_ARP_SHA(17) since v1.1.
1089 * OXM: OXM_OF_ARP_SHA(24) since OF1.2 and v1.7.
1095 * For an Ethernet+IP ARP packet, the target hardware (Ethernet) address in
1096 * the ARP header. Always 0 otherwise.
1099 * Maskable: bitwise.
1100 * Formatting: Ethernet.
1101 * Prerequisites: ARP.
1102 * Access: read/write.
1103 * NXM: NXM_NX_ARP_THA(18) since v1.1.
1104 * OXM: OXM_OF_ARP_THA(25) since OF1.2 and v1.7.
1112 /* "tcp_src" (aka "tp_src").
1117 * Maskable: bitwise.
1118 * Formatting: decimal.
1119 * Prerequisites: TCP.
1120 * Access: read/write.
1121 * NXM: NXM_OF_TCP_SRC(9) since v1.1.
1122 * OXM: OXM_OF_TCP_SRC(13) since OF1.2 and v1.7.
1123 * OF1.0: exact match.
1124 * OF1.1: exact match.
1128 /* "tcp_dst" (aka "tp_dst").
1130 * TCP destination port.
1133 * Maskable: bitwise.
1134 * Formatting: decimal.
1135 * Prerequisites: TCP.
1136 * Access: read/write.
1137 * NXM: NXM_OF_TCP_DST(10) since v1.1.
1138 * OXM: OXM_OF_TCP_DST(14) since OF1.2 and v1.7.
1139 * OF1.0: exact match.
1140 * OF1.1: exact match.
1146 * Flags in the TCP header.
1148 * TCP currently defines 9 flag bits, and additional 3 bits are reserved
1149 * (must be transmitted as zero). See RFCs 793, 3168, and 3540.
1151 * Type: be16 (low 12 bits).
1152 * Maskable: bitwise.
1153 * Formatting: TCP flags.
1154 * Prerequisites: TCP.
1155 * Access: read-only.
1156 * NXM: NXM_NX_TCP_FLAGS(34) since v2.1.
1157 * OXM: OXM_OF_TCP_FLAGS(42) since OF1.5 and v2.3.
1170 * Maskable: bitwise.
1171 * Formatting: decimal.
1172 * Prerequisites: UDP.
1173 * Access: read/write.
1174 * NXM: NXM_OF_UDP_SRC(11) since v1.1.
1175 * OXM: OXM_OF_UDP_SRC(15) since OF1.2 and v1.7.
1176 * OF1.0: exact match.
1177 * OF1.1: exact match.
1183 * UDP destination port
1186 * Maskable: bitwise.
1187 * Formatting: decimal.
1188 * Prerequisites: UDP.
1189 * Access: read/write.
1190 * NXM: NXM_OF_UDP_DST(12) since v1.1.
1191 * OXM: OXM_OF_UDP_DST(16) since OF1.2 and v1.7.
1192 * OF1.0: exact match.
1193 * OF1.1: exact match.
1206 * Maskable: bitwise.
1207 * Formatting: decimal.
1208 * Prerequisites: SCTP.
1209 * Access: read/write.
1211 * OXM: OXM_OF_SCTP_SRC(17) since OF1.2 and v2.0.
1212 * OF1.1: exact match.
1218 * SCTP destination port.
1221 * Maskable: bitwise.
1222 * Formatting: decimal.
1223 * Prerequisites: SCTP.
1224 * Access: read/write.
1226 * OXM: OXM_OF_SCTP_DST(18) since OF1.2 and v2.0.
1227 * OF1.1: exact match.
1241 * Formatting: decimal.
1242 * Prerequisites: ICMPv4.
1243 * Access: read-only.
1244 * NXM: NXM_OF_ICMP_TYPE(13) since v1.1.
1245 * OXM: OXM_OF_ICMPV4_TYPE(19) since OF1.2 and v1.7.
1246 * OF1.0: exact match.
1247 * OF1.1: exact match.
1257 * Formatting: decimal.
1258 * Prerequisites: ICMPv4.
1259 * Access: read-only.
1260 * NXM: NXM_OF_ICMP_CODE(14) since v1.1.
1261 * OXM: OXM_OF_ICMPV4_CODE(20) since OF1.2 and v1.7.
1262 * OF1.0: exact match.
1263 * OF1.1: exact match.
1273 * Formatting: decimal.
1274 * Prerequisites: ICMPv6.
1275 * Access: read-only.
1276 * NXM: NXM_NX_ICMPV6_TYPE(21) since v1.1.
1277 * OXM: OXM_OF_ICMPV6_TYPE(29) since OF1.2 and v1.7.
1287 * Formatting: decimal.
1288 * Prerequisites: ICMPv6.
1289 * Access: read-only.
1290 * NXM: NXM_NX_ICMPV6_CODE(22) since v1.1.
1291 * OXM: OXM_OF_ICMPV6_CODE(30) since OF1.2 and v1.7.
1295 /* ## ------------------------- ## */
1296 /* ## ICMPv6 Neighbor Discovery ## */
1297 /* ## ------------------------- ## */
1301 * The target address in an IPv6 Neighbor Discovery message.
1303 * Before Open vSwitch 1.8, only CIDR masks were supported.
1306 * Maskable: bitwise.
1308 * Prerequisites: ND.
1309 * Access: read-only.
1310 * NXM: NXM_NX_ND_TARGET(23) since v1.1.
1311 * OXM: OXM_OF_IPV6_ND_TARGET(31) since OF1.2 and v1.7.
1317 * The source link layer address in an IPv6 Neighbor Discovery message.
1320 * Maskable: bitwise.
1321 * Formatting: Ethernet.
1322 * Prerequisites: ND solicit.
1323 * Access: read-only.
1324 * NXM: NXM_NX_ND_SLL(24) since v1.1.
1325 * OXM: OXM_OF_IPV6_ND_SLL(32) since OF1.2 and v1.7.
1331 * The target link layer address in an IPv6 Neighbor Discovery message.
1334 * Maskable: bitwise.
1335 * Formatting: Ethernet.
1336 * Prerequisites: ND advert.
1337 * Access: read-only.
1338 * NXM: NXM_NX_ND_TLL(25) since v1.1.
1339 * OXM: OXM_OF_IPV6_ND_TLL(33) since OF1.2 and v1.7.
1346 /* A set of mf_field_ids. */
1348 unsigned long bm[BITMAP_N_LONGS(MFF_N_IDS)];
1350 #define MF_BITMAP_INITIALIZER { { [0] = 0 } }
1352 /* Use this macro as CASE_MFF_REGS: in a switch statement to choose all of the
1353 * MFF_REGn cases. */
1354 #if FLOW_N_REGS == 8
1355 #define CASE_MFF_REGS \
1356 case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
1357 case MFF_REG4: case MFF_REG5: case MFF_REG6: case MFF_REG7
1359 #error "Need to update CASE_MFF_REGS to match FLOW_N_REGS"
1362 /* Use this macro as CASE_MFF_XREGS: in a switch statement to choose all of the
1363 * MFF_REGn cases. */
1364 #if FLOW_N_XREGS == 4
1365 #define CASE_MFF_XREGS \
1366 case MFF_XREG0: case MFF_XREG1: case MFF_XREG2: case MFF_XREG3
1368 #error "Need to update CASE_MFF_XREGS to match FLOW_N_XREGS"
1371 /* Prerequisites for matching a field.
1373 * A field may only be matched if the correct lower-level protocols are also
1374 * matched. For example, the TCP port may be matched only if the Ethernet type
1375 * matches ETH_TYPE_IP and the IP protocol matches IPPROTO_TCP. */
1376 enum OVS_PACKED_ENUM mf_prereqs {
1379 /* L2 requirements. */
1386 /* L2.5 requirements. */
1389 /* L2+L3 requirements. */
1390 MFP_TCP, /* On IPv4 or IPv6. */
1391 MFP_UDP, /* On IPv4 or IPv6. */
1392 MFP_SCTP, /* On IPv4 or IPv6. */
1396 /* L2+L3+L4 requirements. */
1402 /* Forms of partial-field masking allowed for a field.
1404 * Every field may be masked as a whole. */
1405 enum OVS_PACKED_ENUM mf_maskable {
1406 MFM_NONE, /* No sub-field masking. */
1407 MFM_FULLY, /* Every bit is individually maskable. */
1410 /* How to format or parse a field's value. */
1411 enum OVS_PACKED_ENUM mf_string {
1414 * The particular MFS_* constant sets the output format. On input, either
1415 * decimal or hexadecimal (prefixed with 0x) is accepted. */
1419 /* Other formats. */
1423 MFS_OFP_PORT, /* 16-bit OpenFlow 1.0 port number or name. */
1424 MFS_OFP_PORT_OXM, /* 32-bit OpenFlow 1.1+ port number or name. */
1425 MFS_FRAG, /* no, yes, first, later, not_later */
1426 MFS_TNL_FLAGS, /* FLOW_TNL_F_* flags */
1427 MFS_TCP_FLAGS, /* TCP_* flags */
1431 /* Identification. */
1432 enum mf_field_id id; /* MFF_*. */
1433 const char *name; /* Name of this field, e.g. "eth_type". */
1434 const char *extra_name; /* Alternate name, e.g. "dl_type", or NULL. */
1438 * Most fields have n_bytes * 8 == n_bits. There are a few exceptions:
1440 * - "dl_vlan" is 2 bytes but only 12 bits.
1441 * - "dl_vlan_pcp" is 1 byte but only 3 bits.
1442 * - "is_frag" is 1 byte but only 2 bits.
1443 * - "ipv6_label" is 4 bytes but only 20 bits.
1444 * - "mpls_label" is 4 bytes but only 20 bits.
1445 * - "mpls_tc" is 1 byte but only 3 bits.
1446 * - "mpls_bos" is 1 byte but only 1 bit.
1448 unsigned int n_bytes; /* Width of the field in bytes. */
1449 unsigned int n_bits; /* Number of significant bits in field. */
1452 enum mf_maskable maskable;
1453 enum mf_string string;
1454 enum mf_prereqs prereqs;
1455 bool writable; /* May be written by actions? */
1457 /* Usable protocols.
1459 * NXM and OXM are extensible, allowing later extensions to be sent in
1460 * earlier protocol versions, so this does not necessarily correspond to
1461 * the OpenFlow protocol version the field was introduced in.
1462 * Also, some field types are tranparently mapped to each other via the
1463 * struct flow (like vlan and dscp/tos fields), so each variant supports
1466 * These are combinations of OFPUTIL_P_*. (They are not declared as type
1467 * enum ofputil_protocol because that would give meta-flow.h and ofp-util.h
1468 * a circular dependency.) */
1469 uint32_t usable_protocols_exact; /* Matching or setting whole field. */
1470 uint32_t usable_protocols_cidr; /* Matching a CIDR mask in field. */
1471 uint32_t usable_protocols_bitwise; /* Matching arbitrary bits in field. */
1473 int flow_be32ofs; /* Field's be32 offset in "struct flow", if prefix tree
1474 * lookup is supported for the field, or -1. */
1477 /* The representation of a field's value. */
1479 struct in6_addr ipv6;
1480 uint8_t mac[ETH_ADDR_LEN];
1486 BUILD_ASSERT_DECL(sizeof(union mf_value) == 16);
1488 #define MF_EXACT_MASK_INITIALIZER { IN6ADDR_EXACT_INIT }
1490 /* Part of a field. */
1491 struct mf_subfield {
1492 const struct mf_field *field;
1493 unsigned int ofs; /* Bit offset. */
1494 unsigned int n_bits; /* Number of bits. */
1497 /* Data for some part of an mf_field.
1499 * The data is stored "right-justified". For example, if "union mf_subvalue
1500 * value" contains NXM_OF_VLAN_TCI[0..11], then one could access the
1501 * corresponding data in value.be16[7] as the bits in the mask htons(0xfff). */
1508 BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof (union mf_subvalue));
1510 /* Finding mf_fields. */
1511 const struct mf_field *mf_from_name(const char *name);
1513 static inline const struct mf_field *
1514 mf_from_id(enum mf_field_id id)
1516 extern const struct mf_field mf_fields[MFF_N_IDS];
1517 ovs_assert((unsigned int) id < MFF_N_IDS);
1518 return &mf_fields[id];
1521 /* Inspecting wildcarded bits. */
1522 bool mf_is_all_wild(const struct mf_field *, const struct flow_wildcards *);
1524 bool mf_is_mask_valid(const struct mf_field *, const union mf_value *mask);
1525 void mf_get_mask(const struct mf_field *, const struct flow_wildcards *,
1526 union mf_value *mask);
1528 /* Prerequisites. */
1529 bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
1530 void mf_mask_field_and_prereqs(const struct mf_field *, struct flow *mask);
1533 mf_is_l3_or_higher(const struct mf_field *mf)
1535 return mf->id >= MFF_IPV4_SRC;
1539 bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
1541 void mf_get_value(const struct mf_field *, const struct flow *,
1542 union mf_value *value);
1543 void mf_set_value(const struct mf_field *, const union mf_value *value,
1545 void mf_set_flow_value(const struct mf_field *, const union mf_value *value,
1547 void mf_set_flow_value_masked(const struct mf_field *,
1548 const union mf_value *value,
1549 const union mf_value *mask,
1551 bool mf_is_zero(const struct mf_field *, const struct flow *);
1552 void mf_mask_field(const struct mf_field *, struct flow *);
1554 void mf_get(const struct mf_field *, const struct match *,
1555 union mf_value *value, union mf_value *mask);
1557 /* Returns the set of usable protocols. */
1558 enum ofputil_protocol mf_set(const struct mf_field *,
1559 const union mf_value *value,
1560 const union mf_value *mask,
1563 void mf_set_wild(const struct mf_field *, struct match *);
1566 void mf_write_subfield_flow(const struct mf_subfield *,
1567 const union mf_subvalue *, struct flow *);
1568 void mf_write_subfield(const struct mf_subfield *, const union mf_subvalue *,
1571 void mf_read_subfield(const struct mf_subfield *, const struct flow *,
1572 union mf_subvalue *);
1573 uint64_t mf_get_subfield(const struct mf_subfield *, const struct flow *);
1576 enum ofperr mf_check_src(const struct mf_subfield *, const struct flow *);
1577 enum ofperr mf_check_dst(const struct mf_subfield *, const struct flow *);
1579 /* Parsing and formatting. */
1580 char *mf_parse(const struct mf_field *, const char *,
1581 union mf_value *value, union mf_value *mask);
1582 char *mf_parse_value(const struct mf_field *, const char *, union mf_value *);
1583 void mf_format(const struct mf_field *,
1584 const union mf_value *value, const union mf_value *mask,
1586 void mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s);
1588 #endif /* meta-flow.h */