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