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