cb4e22d33e5a090a5071988c5881fc389c353fe9
[cascardo/ovs.git] / lib / meta-flow.h
1 /*
2  * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef META_FLOW_H
18 #define META_FLOW_H 1
19
20 #include <sys/types.h>
21 #include <netinet/in.h>
22 #include <netinet/ip6.h>
23 #include "bitmap.h"
24 #include "flow.h"
25 #include "ofp-errors.h"
26 #include "packets.h"
27 #include "util.h"
28
29 struct ds;
30 struct match;
31
32 /* Open vSwitch fields
33  * ===================
34  *
35  * A "field" is a property of a packet.  Most familiarly, "data fields" are
36  * fields that can be extracted from a packet.
37  *
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
41  * available.
42  *
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.
52  *
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.
59  *
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.)
66  *
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.
75  *
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
82  * prerequisites.
83  *
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.
93  *
94  *
95  * Field specifications
96  * ====================
97  *
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:
102  *
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
105  *       field.
106  *
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
110  *       example:
111  *
112  *           "tun_id" (aka "tunnel_id").
113  *
114  *       New fields should have only one name.
115  *
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.
118  *
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.
122  *
123  * Every field must specify the following key-value pairs:
124  *
125  *   Type:
126  *
127  *     The format and size of the field's value.  Some possible values are
128  *     generic:
129  *
130  *         u8: A one-byte field.
131  *         be16: A two-byte field.
132  *         be32: A four-byte field.
133  *         be64: An eight-byte field.
134  *
135  *     The remaining values imply more about the value's semantics, though OVS
136  *     does not currently take advantage of this additional information:
137  *
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
141  *                   tunnel metadata.
142  *
143  *   Maskable:
144  *
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
147  *     field.
148  *
149  *   Formatting:
150  *
151  *     Explains how a field's value is formatted and parsed for human
152  *     consumption.  Some of the options are fairly generally useful:
153  *
154  *       decimal: Formats the value as a decimal number.  On parsing, accepts
155  *         decimal (with no prefix), hexadecimal with 0x prefix, or octal
156  *         with 0 prefix.
157  *
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.
161  *
162  *       Ethernet: Formats and accepts the common format xx:xx:xx:xx:xx:xx.
163  *         6-byte fields only.
164  *
165  *       IPv4: Formats and accepts the common format w.x.y.z.  4-byte fields
166  *         only.
167  *
168  *       IPv6: Formats and accepts the common IPv6 formats.  16-byte fields
169  *         only.
170  *
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.
175  *
176  *       OpenFlow 1.1+ port: Same syntax as for OpenFlow 1.0 ports but for
177  *         4-byte OpenFlow 1.1+ port number fields.
178  *
179  *     Others are very specific to particular fields:
180  *
181  *       frag: One of the strings "no", "first", "later", "yes", "not_later"
182  *         describing which IPv4/v6 fragments are matched.
183  *
184  *       tunnel flags: Any number of the strings "df", "csum", "key", or
185  *         "oam" separated by "|".
186  *
187  *       TCP flags: See the description of tcp_flags in ovs-ofctl(8).
188  *
189  *   Prerequisites:
190  *
191  *     The field's prerequisites.  The values should be straightfoward.
192  *
193  *   Access:
194  *
195  *     Either "read-only", for a field that cannot be changed via OpenFlow, or
196  *     "read/write" for a modifiable field.
197  *
198  *   NXM:
199  *
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).
205  *
206  *     The NXM name must begin with NXM_OF_ or NXM_NX_.  This allows OVS to
207  *     determine the correct NXM class.
208  *
209  *     If the field does not have an NXM field assignment, specify "none".
210  *
211  *   OXM:
212  *
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).
219  *
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.
224  *
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.
228  *
229  *     If the field does not have an OXM field assignment, specify "none".
230  *
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:
234  *
235  *   OF1.0:
236  *
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.
241  *
242  *   OF1.1:
243  *
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.
247  *
248  * The following key-value pair is optional:
249  *
250  *   Prefix lookup member:
251  *
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
254  *     field.
255  *
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.
261  */
262
263 enum OVS_PACKED_ENUM mf_field_id {
264 /* ## -------- ## */
265 /* ## Metadata ## */
266 /* ## -------- ## */
267
268     /* "dp_hash".
269      *
270      * Flow hash computed in the datapath.  Internal use only, not programmable
271      * from controller.
272      *
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.
278      *
279      * Type: be32.
280      * Maskable: bitwise.
281      * Formatting: hexadecimal.
282      * Prerequisites: none.
283      * Access: read-only.
284      * NXM: NXM_NX_DP_HASH(35) since v2.2.
285      * OXM: NXOXM_ET_DP_HASH(0) since OF1.5 and v2.4.
286      */
287     MFF_DP_HASH,
288
289     /* "recirc_id".
290      *
291      * ID for recirculation.  The value 0 is reserved for initially received
292      * packets.  Internal use only, not programmable from controller.
293      *
294      * Type: be32.
295      * Maskable: no.
296      * Formatting: decimal.
297      * Prerequisites: none.
298      * Access: read-only.
299      * NXM: NXM_NX_RECIRC_ID(36) since v2.2.
300      * OXM: none.
301      */
302     MFF_RECIRC_ID,
303
304     /* "conj_id".
305      *
306      * ID for "conjunction" actions.  Please refer to ovs-ofctl(8)
307      * documentation of "conjunction" for details.
308      *
309      * Type: be32.
310      * Maskable: no.
311      * Formatting: decimal.
312      * Prerequisites: none.
313      * Access: read-only.
314      * NXM: NXM_NX_CONJ_ID(37) since v2.4.
315      * OXM: none. */
316     MFF_CONJ_ID,
317
318     /* "tun_id" (aka "tunnel_id").
319      *
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.
324      *
325      * Type: be64.
326      * Maskable: bitwise.
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.
333      */
334     MFF_TUN_ID,
335
336     /* "tun_src".
337      *
338      * The IPv4 source address in the outer IP header of a tunneled packet.
339      *
340      * For non-tunneled packets, the value is 0.
341      *
342      * Type: be32.
343      * Maskable: bitwise.
344      * Formatting: IPv4.
345      * Prerequisites: none.
346      * Access: read/write.
347      * NXM: NXM_NX_TUN_IPV4_SRC(31) since v2.0.
348      * OXM: none.
349      * Prefix lookup member: tunnel.ip_src.
350      */
351     MFF_TUN_SRC,
352
353     /* "tun_dst".
354      *
355      * The IPv4 destination address in the outer IP header of a tunneled
356      * packet.
357      *
358      * For non-tunneled packets, the value is 0.
359      *
360      * Type: be32.
361      * Maskable: bitwise.
362      * Formatting: IPv4.
363      * Prerequisites: none.
364      * Access: read/write.
365      * NXM: NXM_NX_TUN_IPV4_DST(32) since v2.0.
366      * OXM: none.
367      * Prefix lookup member: tunnel.ip_dst.
368      */
369     MFF_TUN_DST,
370
371     /* "tun_ipv6_src".
372      *
373      * The IPv6 source address in the outer IP header of a tunneled packet.
374      *
375      * For non-tunneled packets, the value is 0.
376      *
377      * Type: be128.
378      * Maskable: bitwise.
379      * Formatting: IPv6.
380      * Prerequisites: none.
381      * Access: read/write.
382      * NXM: NXM_NX_TUN_IPV6_SRC(109) since v2.5.
383      * OXM: none.
384      * Prefix lookup member: tunnel.ipv6_src.
385      */
386     MFF_TUN_IPV6_SRC,
387
388     /* "tun_ipv6_dst".
389      *
390      * The IPv6 destination address in the outer IP header of a tunneled
391      * packet.
392      *
393      * For non-tunneled packets, the value is 0.
394      *
395      * Type: be128.
396      * Maskable: bitwise.
397      * Formatting: IPv6.
398      * Prerequisites: none.
399      * Access: read/write.
400      * NXM: NXM_NX_TUN_IPV6_DST(110) since v2.5.
401      * OXM: none.
402      * Prefix lookup member: tunnel.ipv6_dst.
403      */
404     MFF_TUN_IPV6_DST,
405
406     /* "tun_flags".
407      *
408      * Flags representing aspects of tunnel behavior.
409      *
410      * This field currently only has a single flag defined:
411      *
412      *   - NX_TUN_FLAG_OAM: The tunnel protocol indicated that this is an
413      *                      OAM control packet.
414      *
415      * The switch may reject matches against values that it is not aware of.
416      *
417      * Note that it is possible for newer version of Open vSwitch to
418      * introduce additional flags with varying meaning. It is therefore not
419      * recommended to use an exact match on this field since the behavior of
420      * these new flags is unknown and should be ignored.
421      *
422      * For non-tunneled packets, the value is 0.
423      *
424      * Type: be16 (low 1 bits).
425      * Maskable: bitwise.
426      * Formatting: tunnel flags.
427      * Prerequisites: none.
428      * Access: read/write.
429      * NXM: NXM_NX_TUN_FLAGS(104) since v2.5.
430      * OXM: none.
431      */
432     MFF_TUN_FLAGS,
433
434     /* "tun_ttl".
435      *
436      * The TTL in the outer IP header of a tunneled packet.  Internal use only,
437      * not programmable from controller.
438      *
439      * For non-tunneled packets, the value is 0.
440      *
441      * Type: u8.
442      * Maskable: no.
443      * Formatting: decimal.
444      * Prerequisites: none.
445      * Access: read-only.
446      * NXM: none.
447      * OXM: none.
448      */
449     MFF_TUN_TTL,
450
451     /* "tun_tos".
452      *
453      * The ToS value in the outer IP header of a tunneled packet.  Internal use
454      * only, not programmable from controller.
455      *
456      * Type: u8.
457      * Maskable: no.
458      * Formatting: decimal.
459      * Prerequisites: none.
460      * Access: read-only.
461      * NXM: none.
462      * OXM: none.
463      */
464     MFF_TUN_TOS,
465
466     /* "tun_gbp_id".
467      *
468      * VXLAN Group Policy ID
469      *
470      * Type: be16.
471      * Maskable: bitwise.
472      * Formatting: decimal.
473      * Prerequisites: none.
474      * Access: read/write.
475      * NXM: NXM_NX_TUN_GBP_ID(38) since v2.4.
476      * OXM: none.
477      */
478     MFF_TUN_GBP_ID,
479
480     /* "tun_gbp_flags".
481      *
482      * VXLAN Group Policy flags
483      *
484      * Type: u8.
485      * Maskable: bitwise.
486      * Formatting: hexadecimal.
487      * Prerequisites: none.
488      * Access: read/write.
489      * NXM: NXM_NX_TUN_GBP_FLAGS(39) since v2.4.
490      * OXM: none.
491      */
492     MFF_TUN_GBP_FLAGS,
493
494 #if TUN_METADATA_NUM_OPTS == 64
495     /* "tun_metadata<N>".
496      *
497      * Encapsulation metadata for tunnels.
498      *
499      * Each NXM can be dynamically mapped onto a particular tunnel field using
500      * OpenFlow commands. The individual NXMs can each carry up to 124 bytes
501      * of data and a combined total of 256 across all allocated fields.
502      *
503      * Type: tunnelMD.
504      * Maskable: bitwise.
505      * Formatting: hexadecimal.
506      * Prerequisites: none.
507      * Access: read/write.
508      * NXM: NXM_NX_TUN_METADATA0(40) since v2.5.        <0>
509      * NXM: NXM_NX_TUN_METADATA1(41) since v2.5.        <1>
510      * NXM: NXM_NX_TUN_METADATA2(42) since v2.5.        <2>
511      * NXM: NXM_NX_TUN_METADATA3(43) since v2.5.        <3>
512      * NXM: NXM_NX_TUN_METADATA4(44) since v2.5.        <4>
513      * NXM: NXM_NX_TUN_METADATA5(45) since v2.5.        <5>
514      * NXM: NXM_NX_TUN_METADATA6(46) since v2.5.        <6>
515      * NXM: NXM_NX_TUN_METADATA7(47) since v2.5.        <7>
516      * NXM: NXM_NX_TUN_METADATA8(48) since v2.5.        <8>
517      * NXM: NXM_NX_TUN_METADATA9(49) since v2.5.        <9>
518      * NXM: NXM_NX_TUN_METADATA10(50) since v2.5.       <10>
519      * NXM: NXM_NX_TUN_METADATA11(51) since v2.5.       <11>
520      * NXM: NXM_NX_TUN_METADATA12(52) since v2.5.       <12>
521      * NXM: NXM_NX_TUN_METADATA13(53) since v2.5.       <13>
522      * NXM: NXM_NX_TUN_METADATA14(54) since v2.5.       <14>
523      * NXM: NXM_NX_TUN_METADATA15(55) since v2.5.       <15>
524      * NXM: NXM_NX_TUN_METADATA16(56) since v2.5.       <16>
525      * NXM: NXM_NX_TUN_METADATA17(57) since v2.5.       <17>
526      * NXM: NXM_NX_TUN_METADATA18(58) since v2.5.       <18>
527      * NXM: NXM_NX_TUN_METADATA19(59) since v2.5.       <19>
528      * NXM: NXM_NX_TUN_METADATA20(60) since v2.5.       <20>
529      * NXM: NXM_NX_TUN_METADATA21(61) since v2.5.       <21>
530      * NXM: NXM_NX_TUN_METADATA22(62) since v2.5.       <22>
531      * NXM: NXM_NX_TUN_METADATA23(63) since v2.5.       <23>
532      * NXM: NXM_NX_TUN_METADATA24(64) since v2.5.       <24>
533      * NXM: NXM_NX_TUN_METADATA25(65) since v2.5.       <25>
534      * NXM: NXM_NX_TUN_METADATA26(66) since v2.5.       <26>
535      * NXM: NXM_NX_TUN_METADATA27(67) since v2.5.       <27>
536      * NXM: NXM_NX_TUN_METADATA28(68) since v2.5.       <28>
537      * NXM: NXM_NX_TUN_METADATA29(69) since v2.5.       <29>
538      * NXM: NXM_NX_TUN_METADATA30(70) since v2.5.       <30>
539      * NXM: NXM_NX_TUN_METADATA31(71) since v2.5.       <31>
540      * NXM: NXM_NX_TUN_METADATA32(72) since v2.5.       <32>
541      * NXM: NXM_NX_TUN_METADATA33(73) since v2.5.       <33>
542      * NXM: NXM_NX_TUN_METADATA34(74) since v2.5.       <34>
543      * NXM: NXM_NX_TUN_METADATA35(75) since v2.5.       <35>
544      * NXM: NXM_NX_TUN_METADATA36(76) since v2.5.       <36>
545      * NXM: NXM_NX_TUN_METADATA37(77) since v2.5.       <37>
546      * NXM: NXM_NX_TUN_METADATA38(78) since v2.5.       <38>
547      * NXM: NXM_NX_TUN_METADATA39(79) since v2.5.       <39>
548      * NXM: NXM_NX_TUN_METADATA40(80) since v2.5.       <40>
549      * NXM: NXM_NX_TUN_METADATA41(81) since v2.5.       <41>
550      * NXM: NXM_NX_TUN_METADATA42(82) since v2.5.       <42>
551      * NXM: NXM_NX_TUN_METADATA43(83) since v2.5.       <43>
552      * NXM: NXM_NX_TUN_METADATA44(84) since v2.5.       <44>
553      * NXM: NXM_NX_TUN_METADATA45(85) since v2.5.       <45>
554      * NXM: NXM_NX_TUN_METADATA46(86) since v2.5.       <46>
555      * NXM: NXM_NX_TUN_METADATA47(87) since v2.5.       <47>
556      * NXM: NXM_NX_TUN_METADATA48(88) since v2.5.       <48>
557      * NXM: NXM_NX_TUN_METADATA49(89) since v2.5.       <49>
558      * NXM: NXM_NX_TUN_METADATA50(90) since v2.5.       <50>
559      * NXM: NXM_NX_TUN_METADATA51(91) since v2.5.       <51>
560      * NXM: NXM_NX_TUN_METADATA52(92) since v2.5.       <52>
561      * NXM: NXM_NX_TUN_METADATA53(93) since v2.5.       <53>
562      * NXM: NXM_NX_TUN_METADATA54(94) since v2.5.       <54>
563      * NXM: NXM_NX_TUN_METADATA55(95) since v2.5.       <55>
564      * NXM: NXM_NX_TUN_METADATA56(96) since v2.5.       <56>
565      * NXM: NXM_NX_TUN_METADATA57(97) since v2.5.       <57>
566      * NXM: NXM_NX_TUN_METADATA58(98) since v2.5.       <58>
567      * NXM: NXM_NX_TUN_METADATA59(99) since v2.5.       <59>
568      * NXM: NXM_NX_TUN_METADATA60(100) since v2.5.      <60>
569      * NXM: NXM_NX_TUN_METADATA61(101) since v2.5.      <61>
570      * NXM: NXM_NX_TUN_METADATA62(102) since v2.5.      <62>
571      * NXM: NXM_NX_TUN_METADATA63(103) since v2.5.      <63>
572      * OXM: none.
573      */
574     MFF_TUN_METADATA0,
575     MFF_TUN_METADATA1,
576     MFF_TUN_METADATA2,
577     MFF_TUN_METADATA3,
578     MFF_TUN_METADATA4,
579     MFF_TUN_METADATA5,
580     MFF_TUN_METADATA6,
581     MFF_TUN_METADATA7,
582     MFF_TUN_METADATA8,
583     MFF_TUN_METADATA9,
584     MFF_TUN_METADATA10,
585     MFF_TUN_METADATA11,
586     MFF_TUN_METADATA12,
587     MFF_TUN_METADATA13,
588     MFF_TUN_METADATA14,
589     MFF_TUN_METADATA15,
590     MFF_TUN_METADATA16,
591     MFF_TUN_METADATA17,
592     MFF_TUN_METADATA18,
593     MFF_TUN_METADATA19,
594     MFF_TUN_METADATA20,
595     MFF_TUN_METADATA21,
596     MFF_TUN_METADATA22,
597     MFF_TUN_METADATA23,
598     MFF_TUN_METADATA24,
599     MFF_TUN_METADATA25,
600     MFF_TUN_METADATA26,
601     MFF_TUN_METADATA27,
602     MFF_TUN_METADATA28,
603     MFF_TUN_METADATA29,
604     MFF_TUN_METADATA30,
605     MFF_TUN_METADATA31,
606     MFF_TUN_METADATA32,
607     MFF_TUN_METADATA33,
608     MFF_TUN_METADATA34,
609     MFF_TUN_METADATA35,
610     MFF_TUN_METADATA36,
611     MFF_TUN_METADATA37,
612     MFF_TUN_METADATA38,
613     MFF_TUN_METADATA39,
614     MFF_TUN_METADATA40,
615     MFF_TUN_METADATA41,
616     MFF_TUN_METADATA42,
617     MFF_TUN_METADATA43,
618     MFF_TUN_METADATA44,
619     MFF_TUN_METADATA45,
620     MFF_TUN_METADATA46,
621     MFF_TUN_METADATA47,
622     MFF_TUN_METADATA48,
623     MFF_TUN_METADATA49,
624     MFF_TUN_METADATA50,
625     MFF_TUN_METADATA51,
626     MFF_TUN_METADATA52,
627     MFF_TUN_METADATA53,
628     MFF_TUN_METADATA54,
629     MFF_TUN_METADATA55,
630     MFF_TUN_METADATA56,
631     MFF_TUN_METADATA57,
632     MFF_TUN_METADATA58,
633     MFF_TUN_METADATA59,
634     MFF_TUN_METADATA60,
635     MFF_TUN_METADATA61,
636     MFF_TUN_METADATA62,
637     MFF_TUN_METADATA63,
638 #else
639 #error "Need to update MFF_TUN_METADATA* to match TUN_METADATA_NUM_OPTS"
640 #endif
641
642     /* "metadata".
643      *
644      * A scratch pad value standardized in OpenFlow 1.1+.  Initially zero, at
645      * the beginning of the pipeline.
646      *
647      * Type: be64.
648      * Maskable: bitwise.
649      * Formatting: hexadecimal.
650      * Prerequisites: none.
651      * Access: read/write.
652      * NXM: none.
653      * OXM: OXM_OF_METADATA(2) since OF1.2 and v1.8.
654      * OF1.1: bitwise mask.
655      */
656     MFF_METADATA,
657
658     /* "in_port".
659      *
660      * 16-bit (OpenFlow 1.0) view of the physical or virtual port on which the
661      * packet was received.
662      *
663      * Type: be16.
664      * Maskable: no.
665      * Formatting: OpenFlow 1.0 port.
666      * Prerequisites: none.
667      * Access: read/write.
668      * NXM: NXM_OF_IN_PORT(0) since v1.1.
669      * OXM: none.
670      * OF1.0: exact match.
671      * OF1.1: exact match.
672      */
673     MFF_IN_PORT,
674
675     /* "in_port_oxm".
676      *
677      * 32-bit (OpenFlow 1.1+) view of the physical or virtual port on which the
678      * packet was received.
679      *
680      * Type: be32.
681      * Maskable: no.
682      * Formatting: OpenFlow 1.1+ port.
683      * Prerequisites: none.
684      * Access: read/write.
685      * NXM: none.
686      * OXM: OXM_OF_IN_PORT(0) since OF1.2 and v1.7.
687      * OF1.1: exact match.
688      */
689     MFF_IN_PORT_OXM,
690
691     /* "actset_output".
692      *
693      * Type: be32.
694      * Maskable: no.
695      * Formatting: OpenFlow 1.1+ port.
696      * Prerequisites: none.
697      * Access: read-only.
698      * NXM: none.
699      * OXM: ONFOXM_ET_ACTSET_OUTPUT(43) since OF1.3 and v2.4,
700      *      OXM_OF_ACTSET_OUTPUT(43) since OF1.5 and v2.4.
701      */
702     MFF_ACTSET_OUTPUT,
703
704     /* "skb_priority".
705      *
706      * Designates the queue to which output will be directed.  The value in
707      * this field is not necessarily the OpenFlow queue number; with the Linux
708      * kernel switch, it instead has a pair of subfields designating the
709      * "major" and "minor" numbers of a Linux kernel qdisc handle.
710      *
711      * This field is "semi-internal" in that it can be set with the "set_queue"
712      * action but not matched or read or written other ways.
713      *
714      * Type: be32.
715      * Maskable: no.
716      * Formatting: hexadecimal.
717      * Prerequisites: none.
718      * Access: read-only.
719      * NXM: none.
720      * OXM: none.
721      */
722     MFF_SKB_PRIORITY,
723
724     /* "pkt_mark".
725      *
726      * Packet metadata mark.  The mark may be passed into other system
727      * components in order to facilitate interaction between subsystems.  On
728      * Linux this corresponds to struct sk_buff's "skb_mark" member but the
729      * exact implementation is platform-dependent.
730      *
731      * Type: be32.
732      * Maskable: bitwise.
733      * Formatting: hexadecimal.
734      * Prerequisites: none.
735      * Access: read/write.
736      * NXM: NXM_NX_PKT_MARK(33) since v2.0.
737      * OXM: none.
738      */
739     MFF_PKT_MARK,
740
741     /* "ct_state".
742      *
743      * Connection tracking state.  The field is populated by the NXAST_CT
744      * action. The following bit values describe the state of the connection:
745      *
746      *   - New (0x01): This is the beginning of a new connection.
747      *   - Established (0x02): This is part of an already existing connection.
748      *   - Related (0x04): This is a separate connection that is related to an
749      *                     existing connection.
750      *   - Reply (0x08): This flow is in the reply direction, ie it did not
751      *                   initiate the connection.
752      *   - Invalid (0x10): This flow could not be associated with a connection.
753      *                     This could be set for a variety of reasons,
754      *                     including (but not limited to):
755      *                     - L3/L4 protocol handler is not loaded/unavailable.
756      *                     - L3/L4 protocol handler determines that the packet
757      *                       is malformed or invalid for the current FSM stage.
758      *                     - Packets are unexpected length for protocol.
759      *   - Tracked (0x20): Connection tracking has occurred.
760      *
761      * The "Tracked" bit corresponds to the packet_state as described in the
762      * description of NXAST_CT action. The remaining bits correspond to
763      * connection state. The "New" bit implies that the connection state
764      * is uncommitted, while "Established" implies that it has previously been
765      * committed.
766      *
767      * There are additional constraints on the ct_state bits, listed in order
768      * of precedence below:
769      *
770      *   - If "Tracked" is unset, no other bits may be set.
771      *   - If "Tracked" is set, one or more other bits may be set.
772      *   - If "Invalid" is set, only the "Tracked" bit is also set.
773      *   - The "New" and "Established" bits are mutually exclusive.
774      *   - The "New" and "Reply" bits are mutually exclusive.
775      *   - The "Related" bit may be set in conjunction with any other bits.
776      *     Connections that are identified as "Related" are separate
777      *     connections from the originating connection, so must be committed
778      *     separately. All packets for a related connection will have the
779      *     "Related" bit set (not just the initial packet).
780      *
781      * Type: be32.
782      * Maskable: bitwise.
783      * Formatting: ct state.
784      * Prerequisites: none.
785      * Access: read-only.
786      * NXM: NXM_NX_CT_STATE(105) since v2.5.
787      * OXM: none.
788      */
789     MFF_CT_STATE,
790
791     /* "ct_zone".
792      *
793      * Connection tracking zone.  The field is populated by the
794      * NXAST_CT action.
795      *
796      * Type: be16.
797      * Maskable: no.
798      * Formatting: hexadecimal.
799      * Prerequisites: none.
800      * Access: read-only.
801      * NXM: NXM_NX_CT_ZONE(106) since v2.5.
802      * OXM: none.
803      */
804     MFF_CT_ZONE,
805
806     /* "ct_mark".
807      *
808      * Connection tracking mark.  The mark is carried with the
809      * connection tracking state.  On Linux this corresponds to the
810      * nf_conn's "mark" member but the exact implementation is
811      * platform-dependent.
812      *
813      * Writable only from nested actions within the NXAST_CT action.
814      *
815      * Type: be32.
816      * Maskable: bitwise.
817      * Formatting: hexadecimal.
818      * Prerequisites: none.
819      * Access: read/write.
820      * NXM: NXM_NX_CT_MARK(107) since v2.5.
821      * OXM: none.
822      */
823     MFF_CT_MARK,
824
825     /* "ct_label".
826      *
827      * Connection tracking label.  The label is carried with the
828      * connection tracking state.  On Linux this is held in the
829      * conntrack label extension but the exact implementation is
830      * platform-dependent.
831      *
832      * Writable only from nested actions within the NXAST_CT action.
833      *
834      * Type: be128.
835      * Maskable: bitwise.
836      * Formatting: hexadecimal.
837      * Prerequisites: none.
838      * Access: read/write.
839      * NXM: NXM_NX_CT_LABEL(108) since v2.5.
840      * OXM: none.
841      */
842     MFF_CT_LABEL,
843
844 #if FLOW_N_REGS == 8
845     /* "reg<N>".
846      *
847      * Nicira extension scratch pad register with initial value 0.
848      *
849      * Type: be32.
850      * Maskable: bitwise.
851      * Formatting: hexadecimal.
852      * Prerequisites: none.
853      * Access: read/write.
854      * NXM: NXM_NX_REG0(0) since v1.1.        <0>
855      * NXM: NXM_NX_REG1(1) since v1.1.        <1>
856      * NXM: NXM_NX_REG2(2) since v1.1.        <2>
857      * NXM: NXM_NX_REG3(3) since v1.1.        <3>
858      * NXM: NXM_NX_REG4(4) since v1.3.        <4>
859      * NXM: NXM_NX_REG5(5) since v1.7.        <5>
860      * NXM: NXM_NX_REG6(6) since v1.7.        <6>
861      * NXM: NXM_NX_REG7(7) since v1.7.        <7>
862      * OXM: none.
863      */
864     MFF_REG0,
865     MFF_REG1,
866     MFF_REG2,
867     MFF_REG3,
868     MFF_REG4,
869     MFF_REG5,
870     MFF_REG6,
871     MFF_REG7,
872 #else
873 #error "Need to update MFF_REG* to match FLOW_N_REGS"
874 #endif
875
876 #if FLOW_N_XREGS == 4
877     /* "xreg<N>".
878      *
879      * OpenFlow 1.5 ``extended register".  Each extended register
880      * overlays two of the Nicira extension 32-bit registers: xreg0 overlays
881      * reg0 and reg1, with reg0 supplying the most-significant bits of xreg0
882      * and reg1 the least-significant.  xreg1 similarly overlays reg2 and reg3,
883      * and so on.
884      *
885      * These registers were introduced in OpenFlow 1.5, but EXT-244 in the ONF
886      * JIRA also publishes them as a (draft) OpenFlow extension to OpenFlow
887      * 1.3.
888      *
889      * Type: be64.
890      * Maskable: bitwise.
891      * Formatting: hexadecimal.
892      * Prerequisites: none.
893      * Access: read/write.
894      * NXM: none.
895      * OXM: OXM_OF_PKT_REG<N>(<N>) since OF1.3 and v2.4.
896      */
897     MFF_XREG0,
898     MFF_XREG1,
899     MFF_XREG2,
900     MFF_XREG3,
901 #else
902 #error "Need to update MFF_REG* to match FLOW_N_XREGS"
903 #endif
904
905 /* ## -------- ## */
906 /* ## Ethernet ## */
907 /* ## -------- ## */
908
909     /* "eth_src" (aka "dl_src").
910      *
911      * Source address in Ethernet header.
912      *
913      * This field was not maskable before Open vSwitch 1.8.
914      *
915      * Type: MAC.
916      * Maskable: bitwise.
917      * Formatting: Ethernet.
918      * Prerequisites: none.
919      * Access: read/write.
920      * NXM: NXM_OF_ETH_SRC(2) since v1.1.
921      * OXM: OXM_OF_ETH_SRC(4) since OF1.2 and v1.7.
922      * OF1.0: exact match.
923      * OF1.1: bitwise mask.
924      */
925     MFF_ETH_SRC,
926
927     /* "eth_dst" (aka "dl_dst").
928      *
929      * Destination address in Ethernet header.
930      *
931      * Before Open vSwitch 1.8, the allowed masks were restricted to
932      * 00:00:00:00:00:00, fe:ff:ff:ff:ff:ff, 01:00:00:00:00:00,
933      * ff:ff:ff:ff:ff:ff.
934      *
935      * Type: MAC.
936      * Maskable: bitwise.
937      * Formatting: Ethernet.
938      * Prerequisites: none.
939      * Access: read/write.
940      * NXM: NXM_OF_ETH_DST(1) since v1.1.
941      * OXM: OXM_OF_ETH_DST(3) since OF1.2 and v1.7.
942      * OF1.0: exact match.
943      * OF1.1: bitwise mask.
944      */
945     MFF_ETH_DST,
946
947     /* "eth_type" (aka "dl_type").
948      *
949      * Packet's Ethernet type.
950      *
951      * For an Ethernet II packet this is taken from the Ethernet header.  For
952      * an 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP
953      * header.  A packet that has neither format has value 0x05ff
954      * (OFP_DL_TYPE_NOT_ETH_TYPE).
955      *
956      * For a packet with an 802.1Q header, this is the type of the encapsulated
957      * frame.
958      *
959      * Type: be16.
960      * Maskable: no.
961      * Formatting: hexadecimal.
962      * Prerequisites: none.
963      * Access: read-only.
964      * NXM: NXM_OF_ETH_TYPE(3) since v1.1.
965      * OXM: OXM_OF_ETH_TYPE(5) since OF1.2 and v1.7.
966      * OF1.0: exact match.
967      * OF1.1: exact match.
968      */
969     MFF_ETH_TYPE,
970
971 /* ## ---- ## */
972 /* ## VLAN ## */
973 /* ## ---- ## */
974
975 /* It looks odd for vlan_tci, vlan_vid, and vlan_pcp to say that they are
976  * supported in OF1.0 and OF1.1, since the detailed semantics of these fields
977  * only apply to NXM or OXM.  They are marked as supported for exact matches in
978  * OF1.0 and OF1.1 because exact matches on those fields can be successfully
979  * translated into the OF1.0 and OF1.1 flow formats. */
980
981     /* "vlan_tci".
982      *
983      * 802.1Q TCI.
984      *
985      * For a packet with an 802.1Q header, this is the Tag Control Information
986      * (TCI) field, with the CFI bit forced to 1.  For a packet with no 802.1Q
987      * header, this has value 0.
988      *
989      * This field can be used in various ways:
990      *
991      *   - If it is not constrained at all, the nx_match matches packets
992      *     without an 802.1Q header or with an 802.1Q header that has any TCI
993      *     value.
994      *
995      *   - Testing for an exact match with 0 matches only packets without an
996      *     802.1Q header.
997      *
998      *   - Testing for an exact match with a TCI value with CFI=1 matches
999      *     packets that have an 802.1Q header with a specified VID and PCP.
1000      *
1001      *   - Testing for an exact match with a nonzero TCI value with CFI=0 does
1002      *     not make sense.  The switch may reject this combination.
1003      *
1004      *   - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
1005      *     packets that have an 802.1Q header with that VID (and any PCP).
1006      *
1007      *   - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
1008      *     packets that have an 802.1Q header with that PCP (and any VID).
1009      *
1010      *   - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no
1011      *     802.1Q header or with an 802.1Q header with a VID of 0.
1012      *
1013      *   - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no
1014      *     802.1Q header or with an 802.1Q header with a PCP of 0.
1015      *
1016      *   - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no
1017      *     802.1Q header or with an 802.1Q header with both VID and PCP of 0.
1018      *
1019      * Type: be16.
1020      * Maskable: bitwise.
1021      * Formatting: hexadecimal.
1022      * Prerequisites: none.
1023      * Access: read/write.
1024      * NXM: NXM_OF_VLAN_TCI(4) since v1.1.
1025      * OXM: none.
1026      * OF1.0: exact match.
1027      * OF1.1: exact match.
1028      */
1029     MFF_VLAN_TCI,
1030
1031     /* "dl_vlan" (OpenFlow 1.0).
1032      *
1033      * VLAN ID field.  Zero if no 802.1Q header is present.
1034      *
1035      * Type: be16 (low 12 bits).
1036      * Maskable: no.
1037      * Formatting: decimal.
1038      * Prerequisites: none.
1039      * Access: read/write.
1040      * NXM: none.
1041      * OXM: none.
1042      * OF1.0: exact match.
1043      * OF1.1: exact match.
1044      */
1045     MFF_DL_VLAN,
1046
1047     /* "vlan_vid" (OpenFlow 1.2+).
1048      *
1049      * If an 802.1Q header is present, this field's value is 0x1000
1050      * bitwise-or'd with the VLAN ID.  If no 802.1Q is present, this field's
1051      * value is 0.
1052      *
1053      * Type: be16 (low 12 bits).
1054      * Maskable: bitwise.
1055      * Formatting: decimal.
1056      * Prerequisites: none.
1057      * Access: read/write.
1058      * NXM: none.
1059      * OXM: OXM_OF_VLAN_VID(6) since OF1.2 and v1.7.
1060      * OF1.0: exact match.
1061      * OF1.1: exact match.
1062      */
1063     MFF_VLAN_VID,
1064
1065     /* "dl_vlan_pcp" (OpenFlow 1.0).
1066      *
1067      * VLAN priority (PCP) field.  Zero if no 802.1Q header is present.
1068      *
1069      * Type: u8 (low 3 bits).
1070      * Maskable: no.
1071      * Formatting: decimal.
1072      * Prerequisites: none.
1073      * Access: read/write.
1074      * NXM: none.
1075      * OXM: none.
1076      * OF1.0: exact match.
1077      * OF1.1: exact match.
1078      */
1079     MFF_DL_VLAN_PCP,
1080
1081     /* "vlan_pcp" (OpenFlow 1.2+).
1082      *
1083      * VLAN priority (PCP) field.  Zero if no 802.1Q header is present.
1084      *
1085      * Type: u8 (low 3 bits).
1086      * Maskable: no.
1087      * Formatting: decimal.
1088      * Prerequisites: VLAN VID.
1089      * Access: read/write.
1090      * NXM: none.
1091      * OXM: OXM_OF_VLAN_PCP(7) since OF1.2 and v1.7.
1092      * OF1.0: exact match.
1093      * OF1.1: exact match.
1094      */
1095     MFF_VLAN_PCP,
1096
1097 /* ## ---- ## */
1098 /* ## MPLS ## */
1099 /* ## ---- ## */
1100
1101     /* "mpls_label".
1102      *
1103      * The outermost MPLS label, or 0 if no MPLS labels are present.
1104      *
1105      * Type: be32 (low 20 bits).
1106      * Maskable: no.
1107      * Formatting: decimal.
1108      * Prerequisites: MPLS.
1109      * Access: read/write.
1110      * NXM: none.
1111      * OXM: OXM_OF_MPLS_LABEL(34) since OF1.2 and v1.11.
1112      * OF1.1: exact match.
1113      */
1114     MFF_MPLS_LABEL,
1115
1116     /* "mpls_tc".
1117      *
1118      * The outermost MPLS label's traffic control (TC) field, or 0 if no MPLS
1119      * labels are present.
1120      *
1121      * Type: u8 (low 3 bits).
1122      * Maskable: no.
1123      * Formatting: decimal.
1124      * Prerequisites: MPLS.
1125      * Access: read/write.
1126      * NXM: none.
1127      * OXM: OXM_OF_MPLS_TC(35) since OF1.2 and v1.11.
1128      * OF1.1: exact match.
1129      */
1130     MFF_MPLS_TC,
1131
1132     /* "mpls_bos".
1133      *
1134      * The outermost MPLS label's bottom of stack (BoS) field, or 0 if no MPLS
1135      * labels are present.
1136      *
1137      * Type: u8 (low 1 bits).
1138      * Maskable: no.
1139      * Formatting: decimal.
1140      * Prerequisites: MPLS.
1141      * Access: read-only.
1142      * NXM: none.
1143      * OXM: OXM_OF_MPLS_BOS(36) since OF1.3 and v1.11.
1144      */
1145     MFF_MPLS_BOS,
1146
1147 /* ## ---- ## */
1148 /* ## IPv4 ## */
1149 /* ## ---- ## */
1150
1151 /* Update mf_is_l3_or_higher() if MFF_IPV4_SRC is no longer the first element
1152  * for a field of layer 3 or higher */
1153
1154     /* "ip_src" (aka "nw_src").
1155      *
1156      * The source address in the IPv4 header.
1157      *
1158      * Before Open vSwitch 1.8, only CIDR masks were supported.
1159      *
1160      * Type: be32.
1161      * Maskable: bitwise.
1162      * Formatting: IPv4.
1163      * Prerequisites: IPv4.
1164      * Access: read/write.
1165      * NXM: NXM_OF_IP_SRC(7) since v1.1.
1166      * OXM: OXM_OF_IPV4_SRC(11) since OF1.2 and v1.7.
1167      * OF1.0: CIDR mask.
1168      * OF1.1: bitwise mask.
1169      * Prefix lookup member: nw_src.
1170      */
1171     MFF_IPV4_SRC,
1172
1173     /* "ip_dst" (aka "nw_dst").
1174      *
1175      * The destination address in the IPv4 header.
1176      *
1177      * Before Open vSwitch 1.8, only CIDR masks were supported.
1178      *
1179      * Type: be32.
1180      * Maskable: bitwise.
1181      * Formatting: IPv4.
1182      * Prerequisites: IPv4.
1183      * Access: read/write.
1184      * NXM: NXM_OF_IP_DST(8) since v1.1.
1185      * OXM: OXM_OF_IPV4_DST(12) since OF1.2 and v1.7.
1186      * OF1.0: CIDR mask.
1187      * OF1.1: bitwise mask.
1188      * Prefix lookup member: nw_dst.
1189      */
1190     MFF_IPV4_DST,
1191
1192 /* ## ---- ## */
1193 /* ## IPv6 ## */
1194 /* ## ---- ## */
1195
1196     /* "ipv6_src".
1197      *
1198      * The source address in the IPv6 header.
1199      *
1200      * Type: be128.
1201      * Maskable: bitwise.
1202      * Formatting: IPv6.
1203      * Prerequisites: IPv6.
1204      * Access: read/write.
1205      * NXM: NXM_NX_IPV6_SRC(19) since v1.1.
1206      * OXM: OXM_OF_IPV6_SRC(26) since OF1.2 and v1.1.
1207      * Prefix lookup member: ipv6_src.
1208      */
1209     MFF_IPV6_SRC,
1210
1211     /* "ipv6_dst".
1212      *
1213      * The destination address in the IPv6 header.
1214      *
1215      * Type: be128.
1216      * Maskable: bitwise.
1217      * Formatting: IPv6.
1218      * Prerequisites: IPv6.
1219      * Access: read/write.
1220      * NXM: NXM_NX_IPV6_DST(20) since v1.1.
1221      * OXM: OXM_OF_IPV6_DST(27) since OF1.2 and v1.1.
1222      * Prefix lookup member: ipv6_dst.
1223      */
1224     MFF_IPV6_DST,
1225
1226     /* "ipv6_label".
1227      *
1228      * The flow label in the IPv6 header.
1229      *
1230      * Type: be32 (low 20 bits).
1231      * Maskable: bitwise.
1232      * Formatting: hexadecimal.
1233      * Prerequisites: IPv6.
1234      * Access: read/write.
1235      * NXM: NXM_NX_IPV6_LABEL(27) since v1.4.
1236      * OXM: OXM_OF_IPV6_FLABEL(28) since OF1.2 and v1.7.
1237      */
1238     MFF_IPV6_LABEL,
1239
1240 /* ## ----------------------- ## */
1241 /* ## IPv4/IPv6 common fields ## */
1242 /* ## ----------------------- ## */
1243
1244     /* "nw_proto" (aka "ip_proto").
1245      *
1246      * The "protocol" byte in the IPv4 or IPv6 header.
1247      *
1248      * Type: u8.
1249      * Maskable: no.
1250      * Formatting: decimal.
1251      * Prerequisites: IPv4/IPv6.
1252      * Access: read-only.
1253      * NXM: NXM_OF_IP_PROTO(6) since v1.1.
1254      * OXM: OXM_OF_IP_PROTO(10) since OF1.2 and v1.7.
1255      * OF1.0: exact match.
1256      * OF1.1: exact match.
1257      */
1258     MFF_IP_PROTO,
1259
1260 /* Both views of the DSCP below are marked as supported in all of the versions
1261  * of OpenFlow because a match on either view can be successfully translated
1262  * into every OpenFlow flow format. */
1263
1264     /* "nw_tos" (OpenFlow 1.0/1.1).
1265      *
1266      * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
1267      * header, with the ECN bits forced to 0.  (That is, bits 2-7 contain the
1268      * type of service and bits 0-1 are zero.)
1269      *
1270      * Type: u8.
1271      * Maskable: no.
1272      * Formatting: decimal.
1273      * Prerequisites: IPv4/IPv6.
1274      * Access: read/write.
1275      * NXM: NXM_OF_IP_TOS(5) since v1.1.
1276      * OXM: none.
1277      * OF1.0: exact match.
1278      * OF1.1: exact match.
1279      */
1280     MFF_IP_DSCP,
1281
1282     /* "ip_dscp" (OpenFlow 1.2+).
1283      *
1284      * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
1285      * header, shifted right 2 bits.  (That is, bits 0-5 contain the type of
1286      * service and bits 6-7 are zero.)
1287      *
1288      * Type: u8 (low 6 bits).
1289      * Maskable: no.
1290      * Formatting: decimal.
1291      * Prerequisites: IPv4/IPv6.
1292      * Access: read/write.
1293      * NXM: none.
1294      * OXM: OXM_OF_IP_DSCP(8) since OF1.2 and v1.7.
1295      * OF1.0: exact match.
1296      * OF1.1: exact match.
1297      */
1298     MFF_IP_DSCP_SHIFTED,
1299
1300     /* "nw_ecn" (aka "ip_ecn").
1301      *
1302      * The ECN bits in the IPv4 or IPv6 header.
1303      *
1304      * Type: u8 (low 2 bits).
1305      * Maskable: no.
1306      * Formatting: decimal.
1307      * Prerequisites: IPv4/IPv6.
1308      * Access: read/write.
1309      * NXM: NXM_NX_IP_ECN(28) since v1.4.
1310      * OXM: OXM_OF_IP_ECN(9) since OF1.2 and v1.7.
1311      */
1312     MFF_IP_ECN,
1313
1314     /* "nw_ttl".
1315      *
1316      * The time-to-live (TTL) in the IPv4 header or hop limit in the IPv6
1317      * header.
1318      *
1319      * Type: u8.
1320      * Maskable: no.
1321      * Formatting: decimal.
1322      * Prerequisites: IPv4/IPv6.
1323      * Access: read/write.
1324      * NXM: NXM_NX_IP_TTL(29) since v1.4.
1325      * OXM: none.
1326      */
1327     MFF_IP_TTL,
1328
1329     /* "ip_frag".
1330      *
1331      * IP fragment information.
1332      *
1333      * This field has three possible values:
1334      *
1335      *   - A packet that is not an IP fragment has value 0.
1336      *
1337      *   - A packet that is an IP fragment with offset 0 (the first fragment)
1338      *     has bit 0 set and thus value 1.
1339      *
1340      *   - A packet that is an IP fragment with nonzero offset has bits 0 and 1
1341      *     set and thus value 3.
1342      *
1343      * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically
1344      * represent the meanings of bits 0 and 1.
1345      *
1346      * The switch may reject matches against values that can never appear.
1347      *
1348      * It is important to understand how this field interacts with the OpenFlow
1349      * IP fragment handling mode:
1350      *
1351      *   - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
1352      *     before they reach the flow table, so every packet that is available
1353      *     for matching will have value 0 in this field.
1354      *
1355      *   - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did
1356      *     then IP fragments would be reassembled before they reached the flow
1357      *     table and again every packet available for matching would always
1358      *     have value 0.
1359      *
1360      *   - In OFPC_FRAG_NORMAL mode, all three values are possible, but
1361      *     OpenFlow 1.0 says that fragments' transport ports are always 0, even
1362      *     for the first fragment, so this does not provide much extra
1363      *     information.
1364      *
1365      *   - In OFPC_FRAG_NX_MATCH mode, all three values are possible.  For
1366      *     fragments with offset 0, Open vSwitch makes L4 header information
1367      *     available.
1368      *
1369      * Type: u8 (low 2 bits).
1370      * Maskable: bitwise.
1371      * Formatting: frag.
1372      * Prerequisites: IPv4/IPv6.
1373      * Access: read-only.
1374      * NXM: NXM_NX_IP_FRAG(26) since v1.3.
1375      * OXM: none.
1376      */
1377     MFF_IP_FRAG,
1378
1379 /* ## --- ## */
1380 /* ## ARP ## */
1381 /* ## --- ## */
1382
1383     /* "arp_op".
1384      *
1385      * ARP opcode.
1386      *
1387      * For an Ethernet+IP ARP packet, the opcode in the ARP header.  Always 0
1388      * otherwise.  Only ARP opcodes between 1 and 255 should be specified for
1389      * matching.
1390      *
1391      * Type: be16.
1392      * Maskable: no.
1393      * Formatting: decimal.
1394      * Prerequisites: ARP.
1395      * Access: read/write.
1396      * NXM: NXM_OF_ARP_OP(15) since v1.1.
1397      * OXM: OXM_OF_ARP_OP(21) since OF1.2 and v1.7.
1398      * OF1.0: exact match.
1399      * OF1.1: exact match.
1400      */
1401     MFF_ARP_OP,
1402
1403     /* "arp_spa".
1404      *
1405      * For an Ethernet+IP ARP packet, the source protocol (IPv4) address in the
1406      * ARP header.  Always 0 otherwise.
1407      *
1408      * Before Open vSwitch 1.8, only CIDR masks were supported.
1409      *
1410      * Type: be32.
1411      * Maskable: bitwise.
1412      * Formatting: IPv4.
1413      * Prerequisites: ARP.
1414      * Access: read/write.
1415      * NXM: NXM_OF_ARP_SPA(16) since v1.1.
1416      * OXM: OXM_OF_ARP_SPA(22) since OF1.2 and v1.7.
1417      * OF1.0: CIDR mask.
1418      * OF1.1: bitwise mask.
1419      */
1420     MFF_ARP_SPA,
1421
1422     /* "arp_tpa".
1423      *
1424      * For an Ethernet+IP ARP packet, the target protocol (IPv4) address in the
1425      * ARP header.  Always 0 otherwise.
1426      *
1427      * Before Open vSwitch 1.8, only CIDR masks were supported.
1428      *
1429      * Type: be32.
1430      * Maskable: bitwise.
1431      * Formatting: IPv4.
1432      * Prerequisites: ARP.
1433      * Access: read/write.
1434      * NXM: NXM_OF_ARP_TPA(17) since v1.1.
1435      * OXM: OXM_OF_ARP_TPA(23) since OF1.2 and v1.7.
1436      * OF1.0: CIDR mask.
1437      * OF1.1: bitwise mask.
1438      */
1439     MFF_ARP_TPA,
1440
1441     /* "arp_sha".
1442      *
1443      * For an Ethernet+IP ARP packet, the source hardware (Ethernet) address in
1444      * the ARP header.  Always 0 otherwise.
1445      *
1446      * Type: MAC.
1447      * Maskable: bitwise.
1448      * Formatting: Ethernet.
1449      * Prerequisites: ARP.
1450      * Access: read/write.
1451      * NXM: NXM_NX_ARP_SHA(17) since v1.1.
1452      * OXM: OXM_OF_ARP_SHA(24) since OF1.2 and v1.7.
1453      */
1454     MFF_ARP_SHA,
1455
1456     /* "arp_tha".
1457      *
1458      * For an Ethernet+IP ARP packet, the target hardware (Ethernet) address in
1459      * the ARP header.  Always 0 otherwise.
1460      *
1461      * Type: MAC.
1462      * Maskable: bitwise.
1463      * Formatting: Ethernet.
1464      * Prerequisites: ARP.
1465      * Access: read/write.
1466      * NXM: NXM_NX_ARP_THA(18) since v1.1.
1467      * OXM: OXM_OF_ARP_THA(25) since OF1.2 and v1.7.
1468      */
1469     MFF_ARP_THA,
1470
1471 /* ## --- ## */
1472 /* ## TCP ## */
1473 /* ## --- ## */
1474
1475     /* "tcp_src" (aka "tp_src").
1476      *
1477      * TCP source port.
1478      *
1479      * Type: be16.
1480      * Maskable: bitwise.
1481      * Formatting: decimal.
1482      * Prerequisites: TCP.
1483      * Access: read/write.
1484      * NXM: NXM_OF_TCP_SRC(9) since v1.1.
1485      * OXM: OXM_OF_TCP_SRC(13) since OF1.2 and v1.7.
1486      * OF1.0: exact match.
1487      * OF1.1: exact match.
1488      */
1489     MFF_TCP_SRC,
1490
1491     /* "tcp_dst" (aka "tp_dst").
1492      *
1493      * TCP destination port.
1494      *
1495      * Type: be16.
1496      * Maskable: bitwise.
1497      * Formatting: decimal.
1498      * Prerequisites: TCP.
1499      * Access: read/write.
1500      * NXM: NXM_OF_TCP_DST(10) since v1.1.
1501      * OXM: OXM_OF_TCP_DST(14) since OF1.2 and v1.7.
1502      * OF1.0: exact match.
1503      * OF1.1: exact match.
1504      */
1505     MFF_TCP_DST,
1506
1507     /* "tcp_flags".
1508      *
1509      * Flags in the TCP header.
1510      *
1511      * TCP currently defines 9 flag bits, and additional 3 bits are reserved
1512      * (must be transmitted as zero).  See RFCs 793, 3168, and 3540.
1513      *
1514      * Type: be16 (low 12 bits).
1515      * Maskable: bitwise.
1516      * Formatting: TCP flags.
1517      * Prerequisites: TCP.
1518      * Access: read-only.
1519      * NXM: NXM_NX_TCP_FLAGS(34) since v2.1.
1520      * OXM: ONFOXM_ET_TCP_FLAGS(42) since OF1.3 and v2.4,
1521      *      OXM_OF_TCP_FLAGS(42) since OF1.5 and v2.3.
1522      */
1523     MFF_TCP_FLAGS,
1524
1525 /* ## --- ## */
1526 /* ## UDP ## */
1527 /* ## --- ## */
1528
1529     /* "udp_src".
1530      *
1531      * UDP source port.
1532      *
1533      * Type: be16.
1534      * Maskable: bitwise.
1535      * Formatting: decimal.
1536      * Prerequisites: UDP.
1537      * Access: read/write.
1538      * NXM: NXM_OF_UDP_SRC(11) since v1.1.
1539      * OXM: OXM_OF_UDP_SRC(15) since OF1.2 and v1.7.
1540      * OF1.0: exact match.
1541      * OF1.1: exact match.
1542      */
1543     MFF_UDP_SRC,
1544
1545     /* "udp_dst".
1546      *
1547      * UDP destination port
1548      *
1549      * Type: be16.
1550      * Maskable: bitwise.
1551      * Formatting: decimal.
1552      * Prerequisites: UDP.
1553      * Access: read/write.
1554      * NXM: NXM_OF_UDP_DST(12) since v1.1.
1555      * OXM: OXM_OF_UDP_DST(16) since OF1.2 and v1.7.
1556      * OF1.0: exact match.
1557      * OF1.1: exact match.
1558      */
1559     MFF_UDP_DST,
1560
1561 /* ## ---- ## */
1562 /* ## SCTP ## */
1563 /* ## ---- ## */
1564
1565     /* "sctp_src".
1566      *
1567      * SCTP source port.
1568      *
1569      * Type: be16.
1570      * Maskable: bitwise.
1571      * Formatting: decimal.
1572      * Prerequisites: SCTP.
1573      * Access: read/write.
1574      * NXM: none.
1575      * OXM: OXM_OF_SCTP_SRC(17) since OF1.2 and v2.0.
1576      * OF1.1: exact match.
1577      */
1578     MFF_SCTP_SRC,
1579
1580     /* "sctp_dst".
1581      *
1582      * SCTP destination port.
1583      *
1584      * Type: be16.
1585      * Maskable: bitwise.
1586      * Formatting: decimal.
1587      * Prerequisites: SCTP.
1588      * Access: read/write.
1589      * NXM: none.
1590      * OXM: OXM_OF_SCTP_DST(18) since OF1.2 and v2.0.
1591      * OF1.1: exact match.
1592      */
1593     MFF_SCTP_DST,
1594
1595 /* ## ---- ## */
1596 /* ## ICMP ## */
1597 /* ## ---- ## */
1598
1599     /* "icmp_type".
1600      *
1601      * ICMPv4 type.
1602      *
1603      * Type: u8.
1604      * Maskable: no.
1605      * Formatting: decimal.
1606      * Prerequisites: ICMPv4.
1607      * Access: read/write.
1608      * NXM: NXM_OF_ICMP_TYPE(13) since v1.1.
1609      * OXM: OXM_OF_ICMPV4_TYPE(19) since OF1.2 and v1.7.
1610      * OF1.0: exact match.
1611      * OF1.1: exact match.
1612      */
1613     MFF_ICMPV4_TYPE,
1614
1615     /* "icmp_code".
1616      *
1617      * ICMPv4 code.
1618      *
1619      * Type: u8.
1620      * Maskable: no.
1621      * Formatting: decimal.
1622      * Prerequisites: ICMPv4.
1623      * Access: read/write.
1624      * NXM: NXM_OF_ICMP_CODE(14) since v1.1.
1625      * OXM: OXM_OF_ICMPV4_CODE(20) since OF1.2 and v1.7.
1626      * OF1.0: exact match.
1627      * OF1.1: exact match.
1628      */
1629     MFF_ICMPV4_CODE,
1630
1631     /* "icmpv6_type".
1632      *
1633      * ICMPv6 type.
1634      *
1635      * Type: u8.
1636      * Maskable: no.
1637      * Formatting: decimal.
1638      * Prerequisites: ICMPv6.
1639      * Access: read/write.
1640      * NXM: NXM_NX_ICMPV6_TYPE(21) since v1.1.
1641      * OXM: OXM_OF_ICMPV6_TYPE(29) since OF1.2 and v1.7.
1642      */
1643     MFF_ICMPV6_TYPE,
1644
1645     /* "icmpv6_code".
1646      *
1647      * ICMPv6 code.
1648      *
1649      * Type: u8.
1650      * Maskable: no.
1651      * Formatting: decimal.
1652      * Prerequisites: ICMPv6.
1653      * Access: read/write.
1654      * NXM: NXM_NX_ICMPV6_CODE(22) since v1.1.
1655      * OXM: OXM_OF_ICMPV6_CODE(30) since OF1.2 and v1.7.
1656      */
1657     MFF_ICMPV6_CODE,
1658
1659 /* ## ------------------------- ## */
1660 /* ## ICMPv6 Neighbor Discovery ## */
1661 /* ## ------------------------- ## */
1662
1663     /* "nd_target".
1664      *
1665      * The target address in an IPv6 Neighbor Discovery message.
1666      *
1667      * Before Open vSwitch 1.8, only CIDR masks were supported.
1668      *
1669      * Type: be128.
1670      * Maskable: bitwise.
1671      * Formatting: IPv6.
1672      * Prerequisites: ND.
1673      * Access: read/write.
1674      * NXM: NXM_NX_ND_TARGET(23) since v1.1.
1675      * OXM: OXM_OF_IPV6_ND_TARGET(31) since OF1.2 and v1.7.
1676      */
1677     MFF_ND_TARGET,
1678
1679     /* "nd_sll".
1680      *
1681      * The source link layer address in an IPv6 Neighbor Discovery message.
1682      *
1683      * Type: MAC.
1684      * Maskable: bitwise.
1685      * Formatting: Ethernet.
1686      * Prerequisites: ND solicit.
1687      * Access: read/write.
1688      * NXM: NXM_NX_ND_SLL(24) since v1.1.
1689      * OXM: OXM_OF_IPV6_ND_SLL(32) since OF1.2 and v1.7.
1690      */
1691     MFF_ND_SLL,
1692
1693     /* "nd_tll".
1694      *
1695      * The target link layer address in an IPv6 Neighbor Discovery message.
1696      *
1697      * Type: MAC.
1698      * Maskable: bitwise.
1699      * Formatting: Ethernet.
1700      * Prerequisites: ND advert.
1701      * Access: read/write.
1702      * NXM: NXM_NX_ND_TLL(25) since v1.1.
1703      * OXM: OXM_OF_IPV6_ND_TLL(33) since OF1.2 and v1.7.
1704      */
1705     MFF_ND_TLL,
1706
1707     MFF_N_IDS
1708 };
1709
1710 /* A set of mf_field_ids. */
1711 struct mf_bitmap {
1712     unsigned long bm[BITMAP_N_LONGS(MFF_N_IDS)];
1713 };
1714 #define MF_BITMAP_INITIALIZER { { [0] = 0 } }
1715
1716 /* Use this macro as CASE_MFF_REGS: in a switch statement to choose all of the
1717  * MFF_REGn cases. */
1718 #if FLOW_N_REGS == 8
1719 #define CASE_MFF_REGS                                           \
1720     case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
1721     case MFF_REG4: case MFF_REG5: case MFF_REG6: case MFF_REG7
1722 #else
1723 #error "Need to update CASE_MFF_REGS to match FLOW_N_REGS"
1724 #endif
1725
1726 /* Use this macro as CASE_MFF_XREGS: in a switch statement to choose all of the
1727  * MFF_REGn cases. */
1728 #if FLOW_N_XREGS == 4
1729 #define CASE_MFF_XREGS                                              \
1730     case MFF_XREG0: case MFF_XREG1: case MFF_XREG2: case MFF_XREG3
1731 #else
1732 #error "Need to update CASE_MFF_XREGS to match FLOW_N_XREGS"
1733 #endif
1734
1735 /* Use this macro as CASE_MFF_TUN_METADATA: in a switch statement to choose
1736  * all of the MFF_TUN_METADATAn cases. */
1737 #define CASE_MFF_TUN_METADATA                         \
1738     case MFF_TUN_METADATA0: case MFF_TUN_METADATA1:   \
1739     case MFF_TUN_METADATA2: case MFF_TUN_METADATA3:   \
1740     case MFF_TUN_METADATA4: case MFF_TUN_METADATA5:   \
1741     case MFF_TUN_METADATA6: case MFF_TUN_METADATA7:   \
1742     case MFF_TUN_METADATA8: case MFF_TUN_METADATA9:   \
1743     case MFF_TUN_METADATA10: case MFF_TUN_METADATA11: \
1744     case MFF_TUN_METADATA12: case MFF_TUN_METADATA13: \
1745     case MFF_TUN_METADATA14: case MFF_TUN_METADATA15: \
1746     case MFF_TUN_METADATA16: case MFF_TUN_METADATA17: \
1747     case MFF_TUN_METADATA18: case MFF_TUN_METADATA19: \
1748     case MFF_TUN_METADATA20: case MFF_TUN_METADATA21: \
1749     case MFF_TUN_METADATA22: case MFF_TUN_METADATA23: \
1750     case MFF_TUN_METADATA24: case MFF_TUN_METADATA25: \
1751     case MFF_TUN_METADATA26: case MFF_TUN_METADATA27: \
1752     case MFF_TUN_METADATA28: case MFF_TUN_METADATA29: \
1753     case MFF_TUN_METADATA30: case MFF_TUN_METADATA31: \
1754     case MFF_TUN_METADATA32: case MFF_TUN_METADATA33: \
1755     case MFF_TUN_METADATA34: case MFF_TUN_METADATA35: \
1756     case MFF_TUN_METADATA36: case MFF_TUN_METADATA37: \
1757     case MFF_TUN_METADATA38: case MFF_TUN_METADATA39: \
1758     case MFF_TUN_METADATA40: case MFF_TUN_METADATA41: \
1759     case MFF_TUN_METADATA42: case MFF_TUN_METADATA43: \
1760     case MFF_TUN_METADATA44: case MFF_TUN_METADATA45: \
1761     case MFF_TUN_METADATA46: case MFF_TUN_METADATA47: \
1762     case MFF_TUN_METADATA48: case MFF_TUN_METADATA49: \
1763     case MFF_TUN_METADATA50: case MFF_TUN_METADATA51: \
1764     case MFF_TUN_METADATA52: case MFF_TUN_METADATA53: \
1765     case MFF_TUN_METADATA54: case MFF_TUN_METADATA55: \
1766     case MFF_TUN_METADATA56: case MFF_TUN_METADATA57: \
1767     case MFF_TUN_METADATA58: case MFF_TUN_METADATA59: \
1768     case MFF_TUN_METADATA60: case MFF_TUN_METADATA61: \
1769     case MFF_TUN_METADATA62: case MFF_TUN_METADATA63
1770
1771 /* Prerequisites for matching a field.
1772  *
1773  * A field may only be matched if the correct lower-level protocols are also
1774  * matched.  For example, the TCP port may be matched only if the Ethernet type
1775  * matches ETH_TYPE_IP and the IP protocol matches IPPROTO_TCP. */
1776 enum OVS_PACKED_ENUM mf_prereqs {
1777     MFP_NONE,
1778
1779     /* L2 requirements. */
1780     MFP_ARP,
1781     MFP_VLAN_VID,
1782     MFP_IPV4,
1783     MFP_IPV6,
1784     MFP_IP_ANY,
1785
1786     /* L2.5 requirements. */
1787     MFP_MPLS,
1788
1789     /* L2+L3 requirements. */
1790     MFP_TCP,                    /* On IPv4 or IPv6. */
1791     MFP_UDP,                    /* On IPv4 or IPv6. */
1792     MFP_SCTP,                   /* On IPv4 or IPv6. */
1793     MFP_ICMPV4,
1794     MFP_ICMPV6,
1795
1796     /* L2+L3+L4 requirements. */
1797     MFP_ND,
1798     MFP_ND_SOLICIT,
1799     MFP_ND_ADVERT
1800 };
1801
1802 /* Forms of partial-field masking allowed for a field.
1803  *
1804  * Every field may be masked as a whole. */
1805 enum OVS_PACKED_ENUM mf_maskable {
1806     MFM_NONE,                   /* No sub-field masking. */
1807     MFM_FULLY,                  /* Every bit is individually maskable. */
1808 };
1809
1810 /* How to format or parse a field's value. */
1811 enum OVS_PACKED_ENUM mf_string {
1812     /* Integer formats.
1813      *
1814      * The particular MFS_* constant sets the output format.  On input, either
1815      * decimal or hexadecimal (prefixed with 0x) is accepted. */
1816     MFS_DECIMAL,
1817     MFS_HEXADECIMAL,
1818
1819     /* Other formats. */
1820     MFS_CT_STATE,               /* Connection tracking state */
1821     MFS_ETHERNET,
1822     MFS_IPV4,
1823     MFS_IPV6,
1824     MFS_OFP_PORT,               /* 16-bit OpenFlow 1.0 port number or name. */
1825     MFS_OFP_PORT_OXM,           /* 32-bit OpenFlow 1.1+ port number or name. */
1826     MFS_FRAG,                   /* no, yes, first, later, not_later */
1827     MFS_TNL_FLAGS,              /* FLOW_TNL_F_* flags */
1828     MFS_TCP_FLAGS,              /* TCP_* flags */
1829 };
1830
1831 struct mf_field {
1832     /* Identification. */
1833     enum mf_field_id id;        /* MFF_*. */
1834     const char *name;           /* Name of this field, e.g. "eth_type". */
1835     const char *extra_name;     /* Alternate name, e.g. "dl_type", or NULL. */
1836
1837     /* Size.
1838      *
1839      * Most fields have n_bytes * 8 == n_bits.  There are a few exceptions:
1840      *
1841      *     - "dl_vlan" is 2 bytes but only 12 bits.
1842      *     - "dl_vlan_pcp" is 1 byte but only 3 bits.
1843      *     - "is_frag" is 1 byte but only 2 bits.
1844      *     - "ipv6_label" is 4 bytes but only 20 bits.
1845      *     - "mpls_label" is 4 bytes but only 20 bits.
1846      *     - "mpls_tc"    is 1 byte but only 3 bits.
1847      *     - "mpls_bos"   is 1 byte but only 1 bit.
1848      */
1849     unsigned int n_bytes;       /* Width of the field in bytes. */
1850     unsigned int n_bits;        /* Number of significant bits in field. */
1851     bool variable_len;          /* Length is variable, if so width is max. */
1852
1853     /* Properties. */
1854     enum mf_maskable maskable;
1855     enum mf_string string;
1856     enum mf_prereqs prereqs;
1857     bool writable;              /* May be written by actions? */
1858
1859     /* Usable protocols.
1860      *
1861      * NXM and OXM are extensible, allowing later extensions to be sent in
1862      * earlier protocol versions, so this does not necessarily correspond to
1863      * the OpenFlow protocol version the field was introduced in.
1864      * Also, some field types are tranparently mapped to each other via the
1865      * struct flow (like vlan and dscp/tos fields), so each variant supports
1866      * all protocols.
1867      *
1868      * These are combinations of OFPUTIL_P_*.  (They are not declared as type
1869      * enum ofputil_protocol because that would give meta-flow.h and ofp-util.h
1870      * a circular dependency.) */
1871     uint32_t usable_protocols_exact;   /* Matching or setting whole field. */
1872     uint32_t usable_protocols_cidr;    /* Matching a CIDR mask in field. */
1873     uint32_t usable_protocols_bitwise; /* Matching arbitrary bits in field. */
1874
1875     int flow_be32ofs;  /* Field's be32 offset in "struct flow", if prefix tree
1876                         * lookup is supported for the field, or -1. */
1877 };
1878
1879 /* The representation of a field's value. */
1880 union mf_value {
1881     uint8_t tun_metadata[128];
1882     struct in6_addr ipv6;
1883     struct eth_addr mac;
1884     ovs_be128 be128;
1885     ovs_be64 be64;
1886     ovs_be32 be32;
1887     ovs_be16 be16;
1888     uint8_t u8;
1889 };
1890 BUILD_ASSERT_DECL(sizeof(union mf_value) == 128);
1891 BUILD_ASSERT_DECL(sizeof(union mf_value) >= TLV_MAX_OPT_SIZE);
1892
1893 /* A const mf_value with all bits initialized to ones. */
1894 extern const union mf_value exact_match_mask;
1895
1896 /* Part of a field. */
1897 struct mf_subfield {
1898     const struct mf_field *field;
1899     unsigned int ofs;           /* Bit offset. */
1900     unsigned int n_bits;        /* Number of bits. */
1901 };
1902
1903 /* Data for some part of an mf_field.
1904  *
1905  * The data is stored "right-justified".  For example, if "union mf_subvalue
1906  * value" contains NXM_OF_VLAN_TCI[0..11], then one could access the
1907  * corresponding data in value.be16[7] as the bits in the mask htons(0xfff). */
1908 union mf_subvalue {
1909     /* Access to full data. */
1910     uint8_t u8[128];
1911     ovs_be16 be16[64];
1912     ovs_be32 be32[32];
1913     ovs_be64 be64[16];
1914
1915     /* Convenient access to just least-significant bits in various forms. */
1916     struct {
1917         ovs_be64 dummy_integer[15];
1918         ovs_be64 integer;
1919     };
1920     struct {
1921         uint8_t dummy_mac[122];
1922         struct eth_addr mac;
1923     };
1924     struct {
1925         ovs_be32 dummy_ipv4[31];
1926         ovs_be32 ipv4;
1927     };
1928     struct {
1929         struct in6_addr dummy_ipv6[7];
1930         struct in6_addr ipv6;
1931     };
1932 };
1933 BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof (union mf_subvalue));
1934
1935 bool mf_subvalue_intersect(const union mf_subvalue *a_value,
1936                            const union mf_subvalue *a_mask,
1937                            const union mf_subvalue *b_value,
1938                            const union mf_subvalue *b_mask,
1939                            union mf_subvalue *dst_value,
1940                            union mf_subvalue *dst_mask);
1941 int mf_subvalue_width(const union mf_subvalue *);
1942 void mf_subvalue_shift(union mf_subvalue *, int n);
1943 void mf_subvalue_format(const union mf_subvalue *, struct ds *);
1944
1945 /* An array of fields with values */
1946 struct field_array {
1947     struct mf_bitmap used;
1948     union mf_value value[MFF_N_IDS];
1949 };
1950
1951 /* Finding mf_fields. */
1952 const struct mf_field *mf_from_name(const char *name);
1953
1954 static inline const struct mf_field *
1955 mf_from_id(enum mf_field_id id)
1956 {
1957     extern const struct mf_field mf_fields[MFF_N_IDS];
1958     ovs_assert((unsigned int) id < MFF_N_IDS);
1959     return &mf_fields[id];
1960 }
1961
1962 /* Inspecting wildcarded bits. */
1963 bool mf_is_all_wild(const struct mf_field *, const struct flow_wildcards *);
1964
1965 bool mf_is_mask_valid(const struct mf_field *, const union mf_value *mask);
1966 void mf_get_mask(const struct mf_field *, const struct flow_wildcards *,
1967                  union mf_value *mask);
1968
1969 /* Prerequisites. */
1970 bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
1971 void mf_mask_field_and_prereqs(const struct mf_field *,
1972                                struct flow_wildcards *);
1973 void mf_bitmap_set_field_and_prereqs(const struct mf_field *mf, struct
1974                                      mf_bitmap *bm);
1975
1976 static inline bool
1977 mf_is_l3_or_higher(const struct mf_field *mf)
1978 {
1979     return mf->id >= MFF_IPV4_SRC;
1980 }
1981
1982 /* Field values. */
1983 bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
1984
1985 void mf_get_value(const struct mf_field *, const struct flow *,
1986                   union mf_value *value);
1987 void mf_set_value(const struct mf_field *, const union mf_value *value,
1988                   struct match *, char **err_str);
1989 void mf_set_flow_value(const struct mf_field *, const union mf_value *value,
1990                        struct flow *);
1991 void mf_set_flow_value_masked(const struct mf_field *,
1992                               const union mf_value *value,
1993                               const union mf_value *mask,
1994                               struct flow *);
1995 bool mf_is_tun_metadata(const struct mf_field *);
1996 bool mf_is_set(const struct mf_field *, const struct flow *);
1997 void mf_mask_field(const struct mf_field *, struct flow *);
1998 int mf_field_len(const struct mf_field *, const union mf_value *value,
1999                  const union mf_value *mask, bool *is_masked);
2000
2001 void mf_get(const struct mf_field *, const struct match *,
2002             union mf_value *value, union mf_value *mask);
2003
2004 /* Returns the set of usable protocols. */
2005 uint32_t mf_set(const struct mf_field *, const union mf_value *value,
2006                 const union mf_value *mask, struct match *, char **err_str);
2007
2008 void mf_set_wild(const struct mf_field *, struct match *, char **err_str);
2009
2010 /* Subfields. */
2011 void mf_write_subfield_flow(const struct mf_subfield *,
2012                             const union mf_subvalue *, struct flow *);
2013 void mf_write_subfield(const struct mf_subfield *, const union mf_subvalue *,
2014                        struct match *);
2015 void mf_mask_subfield(const struct mf_field *,
2016                       const union mf_subvalue *value,
2017                       const union mf_subvalue *mask,
2018                       struct match *);
2019
2020 void mf_read_subfield(const struct mf_subfield *, const struct flow *,
2021                       union mf_subvalue *);
2022 uint64_t mf_get_subfield(const struct mf_subfield *, const struct flow *);
2023
2024
2025 enum ofperr mf_check_src(const struct mf_subfield *, const struct flow *);
2026 enum ofperr mf_check_dst(const struct mf_subfield *, const struct flow *);
2027
2028 /* Parsing and formatting. */
2029 char *mf_parse(const struct mf_field *, const char *,
2030                union mf_value *value, union mf_value *mask);
2031 char *mf_parse_value(const struct mf_field *, const char *, union mf_value *);
2032 void mf_format(const struct mf_field *,
2033                const union mf_value *value, const union mf_value *mask,
2034                struct ds *);
2035 void mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s);
2036
2037 /* Field Arrays. */
2038 void field_array_set(enum mf_field_id id, const union mf_value *,
2039                      struct field_array *);
2040
2041 #endif /* meta-flow.h */