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