4a6c443d866618fde30b0dec101ddb9d78e87b17
[cascardo/ovs.git] / lib / meta-flow.h
1 /*
2  * Copyright (c) 2011, 2012, 2013, 2014 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  *
141  *   Maskable:
142  *
143  *     Either "bitwise", if OVS supports matching any subset of bits in the
144  *     field, or "no", if OVS only supports matching or wildcarding the entire
145  *     field.
146  *
147  *   Formatting:
148  *
149  *     Explains how a field's value is formatted and parsed for human
150  *     consumption.  Some of the options are fairly generally useful:
151  *
152  *       decimal: Formats the value as a decimal number.  On parsing, accepts
153  *         decimal (with no prefix), hexadecimal with 0x prefix, or octal
154  *         with 0 prefix.
155  *
156  *       hexadecimal: Same as decimal except nonzero values are formatted in
157  *         hex with 0x prefix.  The default for parsing is *not* hexadecimal:
158  *         only with a 0x prefix is the input in hexadecimal.
159  *
160  *       Ethernet: Formats and accepts the common format xx:xx:xx:xx:xx:xx.
161  *         6-byte fields only.
162  *
163  *       IPv4: Formats and accepts the common format w.x.y.z.  4-byte fields
164  *         only.
165  *
166  *       IPv6: Formats and accepts the common IPv6 formats.  16-byte fields
167  *         only.
168  *
169  *       OpenFlow 1.0 port: Accepts an OpenFlow well-known port name
170  *         (e.g. "IN_PORT") in uppercase or lowercase, or a 16-bit port
171  *         number in decimal.  Formats ports using their well-known names in
172  *         uppercase, or in decimal otherwise.  2-byte fields only.
173  *
174  *       OpenFlow 1.1+ port: Same syntax as for OpenFlow 1.0 ports but for
175  *         4-byte OpenFlow 1.1+ port number fields.
176  *
177  *     Others are very specific to particular fields:
178  *
179  *       frag: One of the strings "no", "first", "later", "yes", "not_later"
180  *         describing which IPv4/v6 fragments are matched.
181  *
182  *       tunnel flags: Any number of the strings "df", "csum", "key", or
183  *         "oam" separated by "|".
184  *
185  *       TCP flags: See the description of tcp_flags in ovs-ofctl(8).
186  *
187  *   Prerequisites:
188  *
189  *     The field's prerequisites.  The values should be straightfoward.
190  *
191  *   Access:
192  *
193  *     Either "read-only", for a field that cannot be changed via OpenFlow, or
194  *     "read/write" for a modifiable field.
195  *
196  *   NXM:
197  *
198  *     If the field has an NXM field assignment, then this specifies the NXM
199  *     name of the field (e.g. "NXM_OF_ETH_SRC"), followed by its nxm_type in
200  *     parentheses, followed by "since v<x>.<y>" specifying the version of Open
201  *     vSwitch that first supported this field in NXM (e.g. "since v1.1" if it
202  *     was introduced in Open vSwitch 1.1).
203  *
204  *     The NXM name must begin with NXM_OF_ or NXM_NX_.  This allows OVS to
205  *     determine the correct NXM class.
206  *
207  *     If the field does not have an NXM field assignment, specify "none".
208  *
209  *   OXM:
210  *
211  *     If the field has an OXM field assignment, then this specifies the OXM
212  *     name of the field (e.g. "OXM_OF_ETH_SRC"), followed by its nxm_type in
213  *     parentheses, followed by "since OF<a>.<b> v<x>.<y>" specifying the
214  *     versions of OpenFlow and Open vSwitch that first supported this field in
215  *     OXM (e.g. "since OF1.3 and v1.10" if it was introduced in OpenFlow 1.3
216  *     and first supported by Open vSwitch in version 1.10).
217  *
218  *     Some fields have more than one OXM field assignment.  For example,
219  *     actset_output has an experimenter OXM assignment in OpenFlow 1.3 and a
220  *     standard OXM assignment in OpenFlow 1.5.  In such a case, specify both,
221  *     separated by commas.
222  *
223  *     OVS uses the start of the OXM field name to determine the correct OXM
224  *     class.  To support a new OXM class, edit the mapping table in
225  *     build-aux/extract-ofp-fields.
226  *
227  *     If the field does not have an OXM field assignment, specify "none".
228  *
229  * The following key-value pairs are optional.  Open vSwitch already supports
230  * all the fields to which they apply, so new fields should probably not
231  * include these pairs:
232  *
233  *   OF1.0:
234  *
235  *     Specify this as "exact match" if OpenFlow 1.0 can match or wildcard the
236  *     entire field, or as "CIDR mask" if OpenFlow 1.0 can match any CIDR
237  *     prefix of the field.  (OpenFlow 1.0 did not support bitwise matching.)
238  *     Omit, if OpenFlow 1.0 did not support this field.
239  *
240  *   OF1.1:
241  *
242  *     Specify this as "exact match" if OpenFlow 1.1 can match or wildcard the
243  *     entire field, or as "bitwise" if OpenFlow 1.1 can match any subset of
244  *     bits in the field.  Omit, if OpenFlow 1.1 did not support this field.
245  *
246  * The following key-value pair is optional:
247  *
248  *   Prefix lookup member:
249  *
250  *     If this field makes sense for use with classifier_set_prefix_fields(),
251  *     specify the name of the "struct flow" member that corresponds to the
252  *     field.
253  *
254  * Finally, a few "register" fields have very similar names and purposes,
255  * e.g. MFF_REG0 through MFF_REG7.  For these, the comments may be merged
256  * together using <N> as a metasyntactic variable for the numeric suffix.
257  * Lines in the comment that are specific to one of the particular fields by
258  * writing, e.g. <1>, to consider that line only for e.g. MFF_REG1.
259  */
260
261 enum OVS_PACKED_ENUM mf_field_id {
262 /* ## -------- ## */
263 /* ## Metadata ## */
264 /* ## -------- ## */
265
266     /* "dp_hash".
267      *
268      * Flow hash computed in the datapath.  Internal use only, not programmable
269      * from controller.
270      *
271      * The OXM code point for this is an attempt to test OXM experimenter
272      * support, which is otherwise difficult to test due to the dearth of use
273      * out in the wild.  Because controllers can't add flows that match on
274      * dp_hash, this doesn't commit OVS to supporting this OXM experimenter
275      * code point in the future.
276      *
277      * Type: be32.
278      * Maskable: bitwise.
279      * Formatting: hexadecimal.
280      * Prerequisites: none.
281      * Access: read-only.
282      * NXM: NXM_NX_DP_HASH(35) since v2.2.
283      * OXM: NXOXM_ET_DP_HASH(0) since OF1.5 and v2.4.
284      */
285     MFF_DP_HASH,
286
287     /* "recirc_id".
288      *
289      * ID for recirculation.  The value 0 is reserved for initially received
290      * packets.  Internal use only, not programmable from controller.
291      *
292      * Type: be32.
293      * Maskable: no.
294      * Formatting: decimal.
295      * Prerequisites: none.
296      * Access: read-only.
297      * NXM: NXM_NX_RECIRC_ID(36) since v2.2.
298      * OXM: none.
299      */
300     MFF_RECIRC_ID,
301
302     /* "conj_id".
303      *
304      * ID for "conjunction" actions.  Please refer to ovs-ofctl(8)
305      * documentation of "conjunction" for details.
306      *
307      * Type: be32.
308      * Maskable: no.
309      * Formatting: decimal.
310      * Prerequisites: none.
311      * Access: read-only.
312      * NXM: NXM_NX_CONJ_ID(37) since v2.4.
313      * OXM: none. */
314     MFF_CONJ_ID,
315
316     /* "tun_id" (aka "tunnel_id").
317      *
318      * The "key" or "tunnel ID" or "VNI" in a packet received via a keyed
319      * tunnel.  For protocols in which the key is shorter than 64 bits, the key
320      * is stored in the low bits and the high bits are zeroed.  For non-keyed
321      * tunnels and packets not received via a tunnel, the value is 0.
322      *
323      * Type: be64.
324      * Maskable: bitwise.
325      * Formatting: hexadecimal.
326      * Prerequisites: none.
327      * Access: read/write.
328      * NXM: NXM_NX_TUN_ID(16) since v1.1.
329      * OXM: OXM_OF_TUNNEL_ID(38) since OF1.3 and v1.10.
330      * Prefix lookup member: tunnel.tun_id.
331      */
332     MFF_TUN_ID,
333
334     /* "tun_src".
335      *
336      * The IPv4 source address in the outer IP header of a tunneled packet.
337      *
338      * For non-tunneled packets, the value is 0.
339      *
340      * Type: be32.
341      * Maskable: bitwise.
342      * Formatting: IPv4.
343      * Prerequisites: none.
344      * Access: read/write.
345      * NXM: NXM_NX_TUN_IPV4_SRC(31) since v2.0.
346      * OXM: none.
347      * Prefix lookup member: tunnel.ip_src.
348      */
349     MFF_TUN_SRC,
350
351     /* "tun_dst".
352      *
353      * The IPv4 destination address in the outer IP header of a tunneled
354      * packet.
355      *
356      * For non-tunneled packets, the value is 0.
357      *
358      * Type: be32.
359      * Maskable: bitwise.
360      * Formatting: IPv4.
361      * Prerequisites: none.
362      * Access: read/write.
363      * NXM: NXM_NX_TUN_IPV4_DST(32) since v2.0.
364      * OXM: none.
365      * Prefix lookup member: tunnel.ip_dst.
366      */
367     MFF_TUN_DST,
368
369     /* "tun_flags".
370      *
371      * Combination of FLOW_TNL_F_* bitmapped flags that indicate properties of
372      * a tunneled packet.  Internal use only, not programmable from controller.
373      *
374      * For non-tunneled packets, the value is 0.
375      *
376      * Type: be16.
377      * Maskable: no.
378      * Formatting: tunnel flags.
379      * Prerequisites: none.
380      * Access: read-only.
381      * NXM: none.
382      * OXM: none.
383      */
384     MFF_TUN_FLAGS,
385
386     /* "tun_ttl".
387      *
388      * The TTL in the outer IP header of a tunneled packet.  Internal use only,
389      * not programmable from controller.
390      *
391      * For non-tunneled packets, the value is 0.
392      *
393      * Type: u8.
394      * Maskable: no.
395      * Formatting: decimal.
396      * Prerequisites: none.
397      * Access: read-only.
398      * NXM: none.
399      * OXM: none.
400      */
401     MFF_TUN_TTL,
402
403     /* "tun_tos".
404      *
405      * The ToS value in the outer IP header of a tunneled packet.  Internal use
406      * only, not programmable from controller.
407      *
408      * Type: u8.
409      * Maskable: no.
410      * Formatting: decimal.
411      * Prerequisites: none.
412      * Access: read-only.
413      * NXM: none.
414      * OXM: none.
415      */
416     MFF_TUN_TOS,
417
418     /* "metadata".
419      *
420      * A scratch pad value standardized in OpenFlow 1.1+.  Initially zero, at
421      * the beginning of the pipeline.
422      *
423      * Type: be64.
424      * Maskable: bitwise.
425      * Formatting: hexadecimal.
426      * Prerequisites: none.
427      * Access: read/write.
428      * NXM: none.
429      * OXM: OXM_OF_METADATA(2) since OF1.2 and v1.8.
430      * OF1.1: bitwise mask.
431      */
432     MFF_METADATA,
433
434     /* "in_port".
435      *
436      * 16-bit (OpenFlow 1.0) view of the physical or virtual port on which the
437      * packet was received.
438      *
439      * Type: be16.
440      * Maskable: no.
441      * Formatting: OpenFlow 1.0 port.
442      * Prerequisites: none.
443      * Access: read/write.
444      * NXM: NXM_OF_IN_PORT(0) since v1.1.
445      * OXM: none.
446      * OF1.0: exact match.
447      * OF1.1: exact match.
448      */
449     MFF_IN_PORT,
450
451     /* "in_port_oxm".
452      *
453      * 32-bit (OpenFlow 1.1+) view of the physical or virtual port on which the
454      * packet was received.
455      *
456      * Type: be32.
457      * Maskable: no.
458      * Formatting: OpenFlow 1.1+ port.
459      * Prerequisites: none.
460      * Access: read/write.
461      * NXM: none.
462      * OXM: OXM_OF_IN_PORT(0) since OF1.2 and v1.7.
463      * OF1.1: exact match.
464      */
465     MFF_IN_PORT_OXM,
466
467     /* "actset_output".
468      *
469      * Type: be32.
470      * Maskable: no.
471      * Formatting: OpenFlow 1.1+ port.
472      * Prerequisites: none.
473      * Access: read-only.
474      * NXM: none.
475      * OXM: ONFOXM_ET_ACTSET_OUTPUT(43) since OF1.3 and v2.4,
476      *      OXM_OF_ACTSET_OUTPUT(43) since OF1.5 and v2.4.
477      */
478     MFF_ACTSET_OUTPUT,
479
480     /* "skb_priority".
481      *
482      * Designates the queue to which output will be directed.  The value in
483      * this field is not necessarily the OpenFlow queue number; with the Linux
484      * kernel switch, it instead has a pair of subfields designating the
485      * "major" and "minor" numbers of a Linux kernel qdisc handle.
486      *
487      * This field is "semi-internal" in that it can be set with the "set_queue"
488      * action but not matched or read or written other ways.
489      *
490      * Type: be32.
491      * Maskable: no.
492      * Formatting: hexadecimal.
493      * Prerequisites: none.
494      * Access: read-only.
495      * NXM: none.
496      * OXM: none.
497      */
498     MFF_SKB_PRIORITY,
499
500     /* "pkt_mark".
501      *
502      * Packet metadata mark.  The mark may be passed into other system
503      * components in order to facilitate interaction between subsystems.  On
504      * Linux this corresponds to struct sk_buff's "skb_mark" member but the
505      * exact implementation is platform-dependent.
506      *
507      * Type: be32.
508      * Maskable: bitwise.
509      * Formatting: hexadecimal.
510      * Prerequisites: none.
511      * Access: read/write.
512      * NXM: NXM_NX_PKT_MARK(33) since v2.0.
513      * OXM: none.
514      */
515     MFF_PKT_MARK,
516
517 #if FLOW_N_REGS == 8
518     /* "reg<N>".
519      *
520      * Nicira extension scratch pad register with initial value 0.
521      *
522      * Type: be32.
523      * Maskable: bitwise.
524      * Formatting: hexadecimal.
525      * Prerequisites: none.
526      * Access: read/write.
527      * NXM: NXM_NX_REG0(0) since v1.1.        <0>
528      * NXM: NXM_NX_REG1(1) since v1.1.        <1>
529      * NXM: NXM_NX_REG2(2) since v1.1.        <2>
530      * NXM: NXM_NX_REG3(3) since v1.1.        <3>
531      * NXM: NXM_NX_REG4(4) since v1.3.        <4>
532      * NXM: NXM_NX_REG5(5) since v1.7.        <5>
533      * NXM: NXM_NX_REG6(6) since v1.7.        <6>
534      * NXM: NXM_NX_REG7(7) since v1.7.        <7>
535      * OXM: none.
536      */
537     MFF_REG0,
538     MFF_REG1,
539     MFF_REG2,
540     MFF_REG3,
541     MFF_REG4,
542     MFF_REG5,
543     MFF_REG6,
544     MFF_REG7,
545 #else
546 #error "Need to update MFF_REG* to match FLOW_N_REGS"
547 #endif
548
549 #if FLOW_N_XREGS == 4
550     /* "xreg<N>".
551      *
552      * OpenFlow 1.5 (draft) ``extended register".  Each extended register
553      * overlays two of the Nicira extension 32-bit registers: xreg0 overlays
554      * reg0 and reg1, with reg0 supplying the most-significant bits of xreg0
555      * and reg1 the least-significant.  xreg1 similarly overlays reg2 and reg3,
556      * and so on.
557      *
558      * These registers were introduced in OpenFlow 1.5, but EXT-244 in the ONF
559      * JIRA also publishes them as a (draft) OpenFlow extension to OpenFlow
560      * 1.3.
561      *
562      * Type: be64.
563      * Maskable: bitwise.
564      * Formatting: hexadecimal.
565      * Prerequisites: none.
566      * Access: read/write.
567      * NXM: none.
568      * OXM: OXM_OF_PKT_REG<N>(<N>) since OF1.3 and v2.4.
569      */
570     MFF_XREG0,
571     MFF_XREG1,
572     MFF_XREG2,
573     MFF_XREG3,
574 #else
575 #error "Need to update MFF_REG* to match FLOW_N_XREGS"
576 #endif
577
578 /* ## -------- ## */
579 /* ## Ethernet ## */
580 /* ## -------- ## */
581
582     /* "eth_src" (aka "dl_src").
583      *
584      * Source address in Ethernet header.
585      *
586      * This field was not maskable before Open vSwitch 1.8.
587      *
588      * Type: MAC.
589      * Maskable: bitwise.
590      * Formatting: Ethernet.
591      * Prerequisites: none.
592      * Access: read/write.
593      * NXM: NXM_OF_ETH_SRC(2) since v1.1.
594      * OXM: OXM_OF_ETH_SRC(4) since OF1.2 and v1.7.
595      * OF1.0: exact match.
596      * OF1.1: bitwise mask.
597      */
598     MFF_ETH_SRC,
599
600     /* "eth_dst" (aka "dl_dst").
601      *
602      * Destination address in Ethernet header.
603      *
604      * Before Open vSwitch 1.8, the allowed masks were restricted to
605      * 00:00:00:00:00:00, fe:ff:ff:ff:ff:ff, 01:00:00:00:00:00,
606      * ff:ff:ff:ff:ff:ff.
607      *
608      * Type: MAC.
609      * Maskable: bitwise.
610      * Formatting: Ethernet.
611      * Prerequisites: none.
612      * Access: read/write.
613      * NXM: NXM_OF_ETH_DST(1) since v1.1.
614      * OXM: OXM_OF_ETH_DST(3) since OF1.2 and v1.7.
615      * OF1.0: exact match.
616      * OF1.1: bitwise mask.
617      */
618     MFF_ETH_DST,
619
620     /* "eth_type" (aka "dl_type").
621      *
622      * Packet's Ethernet type.
623      *
624      * For an Ethernet II packet this is taken from the Ethernet header.  For
625      * an 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP
626      * header.  A packet that has neither format has value 0x05ff
627      * (OFP_DL_TYPE_NOT_ETH_TYPE).
628      *
629      * For a packet with an 802.1Q header, this is the type of the encapsulated
630      * frame.
631      *
632      * Type: be16.
633      * Maskable: no.
634      * Formatting: hexadecimal.
635      * Prerequisites: none.
636      * Access: read-only.
637      * NXM: NXM_OF_ETH_TYPE(3) since v1.1.
638      * OXM: OXM_OF_ETH_TYPE(5) since OF1.2 and v1.7.
639      * OF1.0: exact match.
640      * OF1.1: exact match.
641      */
642     MFF_ETH_TYPE,
643
644 /* ## ---- ## */
645 /* ## VLAN ## */
646 /* ## ---- ## */
647
648 /* It looks odd for vlan_tci, vlan_vid, and vlan_pcp to say that they are
649  * supported in OF1.0 and OF1.1, since the detailed semantics of these fields
650  * only apply to NXM or OXM.  They are marked as supported for exact matches in
651  * OF1.0 and OF1.1 because exact matches on those fields can be successfully
652  * translated into the OF1.0 and OF1.1 flow formats. */
653
654     /* "vlan_tci".
655      *
656      * 802.1Q TCI.
657      *
658      * For a packet with an 802.1Q header, this is the Tag Control Information
659      * (TCI) field, with the CFI bit forced to 1.  For a packet with no 802.1Q
660      * header, this has value 0.
661      *
662      * This field can be used in various ways:
663      *
664      *   - If it is not constrained at all, the nx_match matches packets
665      *     without an 802.1Q header or with an 802.1Q header that has any TCI
666      *     value.
667      *
668      *   - Testing for an exact match with 0 matches only packets without an
669      *     802.1Q header.
670      *
671      *   - Testing for an exact match with a TCI value with CFI=1 matches
672      *     packets that have an 802.1Q header with a specified VID and PCP.
673      *
674      *   - Testing for an exact match with a nonzero TCI value with CFI=0 does
675      *     not make sense.  The switch may reject this combination.
676      *
677      *   - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
678      *     packets that have an 802.1Q header with that VID (and any PCP).
679      *
680      *   - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
681      *     packets that have an 802.1Q header with that PCP (and any VID).
682      *
683      *   - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no
684      *     802.1Q header or with an 802.1Q header with a VID of 0.
685      *
686      *   - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no
687      *     802.1Q header or with an 802.1Q header with a PCP of 0.
688      *
689      *   - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no
690      *     802.1Q header or with an 802.1Q header with both VID and PCP of 0.
691      *
692      * Type: be16.
693      * Maskable: bitwise.
694      * Formatting: hexadecimal.
695      * Prerequisites: none.
696      * Access: read/write.
697      * NXM: NXM_OF_VLAN_TCI(4) since v1.1.
698      * OXM: none.
699      * OF1.0: exact match.
700      * OF1.1: exact match.
701      */
702     MFF_VLAN_TCI,
703
704     /* "dl_vlan" (OpenFlow 1.0).
705      *
706      * VLAN ID field.  Zero if no 802.1Q header is present.
707      *
708      * Type: be16 (low 12 bits).
709      * Maskable: no.
710      * Formatting: decimal.
711      * Prerequisites: none.
712      * Access: read/write.
713      * NXM: none.
714      * OXM: none.
715      * OF1.0: exact match.
716      * OF1.1: exact match.
717      */
718     MFF_DL_VLAN,
719
720     /* "vlan_vid" (OpenFlow 1.2+).
721      *
722      * If an 802.1Q header is present, this field's value is 0x1000
723      * bitwise-or'd with the VLAN ID.  If no 802.1Q is present, this field's
724      * value is 0.
725      *
726      * Type: be16 (low 12 bits).
727      * Maskable: bitwise.
728      * Formatting: decimal.
729      * Prerequisites: none.
730      * Access: read/write.
731      * NXM: none.
732      * OXM: OXM_OF_VLAN_VID(6) since OF1.2 and v1.7.
733      * OF1.0: exact match.
734      * OF1.1: exact match.
735      */
736     MFF_VLAN_VID,
737
738     /* "dl_vlan_pcp" (OpenFlow 1.0).
739      *
740      * VLAN priority (PCP) field.  Zero if no 802.1Q header is present.
741      *
742      * Type: u8 (low 3 bits).
743      * Maskable: no.
744      * Formatting: decimal.
745      * Prerequisites: none.
746      * Access: read/write.
747      * NXM: none.
748      * OXM: none.
749      * OF1.0: exact match.
750      * OF1.1: exact match.
751      */
752     MFF_DL_VLAN_PCP,
753
754     /* "vlan_pcp" (OpenFlow 1.2+).
755      *
756      * VLAN priority (PCP) field.  Zero if no 802.1Q header is present.
757      *
758      * Type: u8 (low 3 bits).
759      * Maskable: no.
760      * Formatting: decimal.
761      * Prerequisites: VLAN VID.
762      * Access: read/write.
763      * NXM: none.
764      * OXM: OXM_OF_VLAN_PCP(7) since OF1.2 and v1.7.
765      * OF1.0: exact match.
766      * OF1.1: exact match.
767      */
768     MFF_VLAN_PCP,
769
770 /* ## ---- ## */
771 /* ## MPLS ## */
772 /* ## ---- ## */
773
774     /* "mpls_label".
775      *
776      * The outermost MPLS label, or 0 if no MPLS labels are present.
777      *
778      * Type: be32 (low 20 bits).
779      * Maskable: no.
780      * Formatting: decimal.
781      * Prerequisites: MPLS.
782      * Access: read/write.
783      * NXM: none.
784      * OXM: OXM_OF_MPLS_LABEL(34) since OF1.2 and v1.11.
785      * OF1.1: exact match.
786      */
787     MFF_MPLS_LABEL,
788
789     /* "mpls_tc".
790      *
791      * The outermost MPLS label's traffic control (TC) field, or 0 if no MPLS
792      * labels are present.
793      *
794      * Type: u8 (low 3 bits).
795      * Maskable: no.
796      * Formatting: decimal.
797      * Prerequisites: MPLS.
798      * Access: read/write.
799      * NXM: none.
800      * OXM: OXM_OF_MPLS_TC(35) since OF1.2 and v1.11.
801      * OF1.1: exact match.
802      */
803     MFF_MPLS_TC,
804
805     /* "mpls_bos".
806      *
807      * The outermost MPLS label's bottom of stack (BoS) field, or 0 if no MPLS
808      * labels are present.
809      *
810      * Type: u8 (low 1 bits).
811      * Maskable: no.
812      * Formatting: decimal.
813      * Prerequisites: MPLS.
814      * Access: read-only.
815      * NXM: none.
816      * OXM: OXM_OF_MPLS_BOS(36) since OF1.3 and v1.11.
817      */
818     MFF_MPLS_BOS,
819
820 /* ## ---- ## */
821 /* ## IPv4 ## */
822 /* ## ---- ## */
823
824 /* Update mf_is_l3_or_higher() if MFF_IPV4_SRC is no longer the first element
825  * for a field of layer 3 or higher */
826
827     /* "ip_src" (aka "nw_src").
828      *
829      * The source address in the IPv4 header.
830      *
831      * Before Open vSwitch 1.8, only CIDR masks were supported.
832      *
833      * Type: be32.
834      * Maskable: bitwise.
835      * Formatting: IPv4.
836      * Prerequisites: IPv4.
837      * Access: read/write.
838      * NXM: NXM_OF_IP_SRC(7) since v1.1.
839      * OXM: OXM_OF_IPV4_SRC(11) since OF1.2 and v1.7.
840      * OF1.0: CIDR mask.
841      * OF1.1: bitwise mask.
842      * Prefix lookup member: nw_src.
843      */
844     MFF_IPV4_SRC,
845
846     /* "ip_dst" (aka "nw_dst").
847      *
848      * The destination address in the IPv4 header.
849      *
850      * Before Open vSwitch 1.8, only CIDR masks were supported.
851      *
852      * Type: be32.
853      * Maskable: bitwise.
854      * Formatting: IPv4.
855      * Prerequisites: IPv4.
856      * Access: read/write.
857      * NXM: NXM_OF_IP_DST(8) since v1.1.
858      * OXM: OXM_OF_IPV4_DST(12) since OF1.2 and v1.7.
859      * OF1.0: CIDR mask.
860      * OF1.1: bitwise mask.
861      * Prefix lookup member: nw_dst.
862      */
863     MFF_IPV4_DST,
864
865 /* ## ---- ## */
866 /* ## IPv6 ## */
867 /* ## ---- ## */
868
869     /* "ipv6_src".
870      *
871      * The source address in the IPv6 header.
872      *
873      * Type: IPv6.
874      * Maskable: bitwise.
875      * Formatting: IPv6.
876      * Prerequisites: IPv6.
877      * Access: read/write.
878      * NXM: NXM_NX_IPV6_SRC(19) since v1.1.
879      * OXM: OXM_OF_IPV6_SRC(26) since OF1.2 and v1.1.
880      * Prefix lookup member: ipv6_src.
881      */
882     MFF_IPV6_SRC,
883
884     /* "ipv6_dst".
885      *
886      * The destination address in the IPv6 header.
887      *
888      * Type: IPv6.
889      * Maskable: bitwise.
890      * Formatting: IPv6.
891      * Prerequisites: IPv6.
892      * Access: read/write.
893      * NXM: NXM_NX_IPV6_DST(20) since v1.1.
894      * OXM: OXM_OF_IPV6_DST(27) since OF1.2 and v1.1.
895      * Prefix lookup member: ipv6_dst.
896      */
897     MFF_IPV6_DST,
898
899     /* "ipv6_label".
900      *
901      * The flow label in the IPv6 header.
902      *
903      * Type: be32 (low 20 bits).
904      * Maskable: bitwise.
905      * Formatting: hexadecimal.
906      * Prerequisites: IPv6.
907      * Access: read/write.
908      * NXM: NXM_NX_IPV6_LABEL(27) since v1.4.
909      * OXM: OXM_OF_IPV6_FLABEL(28) since OF1.2 and v1.7.
910      */
911     MFF_IPV6_LABEL,
912
913 /* ## ----------------------- ## */
914 /* ## IPv4/IPv6 common fields ## */
915 /* ## ----------------------- ## */
916
917     /* "nw_proto" (aka "ip_proto").
918      *
919      * The "protocol" byte in the IPv4 or IPv6 header.
920      *
921      * Type: u8.
922      * Maskable: no.
923      * Formatting: decimal.
924      * Prerequisites: IPv4/IPv6.
925      * Access: read-only.
926      * NXM: NXM_OF_IP_PROTO(6) since v1.1.
927      * OXM: OXM_OF_IP_PROTO(10) since OF1.2 and v1.7.
928      * OF1.0: exact match.
929      * OF1.1: exact match.
930      */
931     MFF_IP_PROTO,
932
933 /* Both views of the DSCP below are marked as supported in all of the versions
934  * of OpenFlow because a match on either view can be successfully translated
935  * into every OpenFlow flow format. */
936
937     /* "nw_tos" (OpenFlow 1.0/1.1).
938      *
939      * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
940      * header, with the ECN bits forced to 0.  (That is, bits 2-7 contain the
941      * type of service and bits 0-1 are zero.)
942      *
943      * Type: u8.
944      * Maskable: no.
945      * Formatting: decimal.
946      * Prerequisites: IPv4/IPv6.
947      * Access: read/write.
948      * NXM: NXM_OF_IP_TOS(5) since v1.1.
949      * OXM: none.
950      * OF1.0: exact match.
951      * OF1.1: exact match.
952      */
953     MFF_IP_DSCP,
954
955     /* "ip_dscp" (OpenFlow 1.2+).
956      *
957      * The DSCP byte in the IPv4 header or the traffic class byte from the IPv6
958      * header, shifted right 2 bits.  (That is, bits 0-5 contain the type of
959      * service and bits 6-7 are zero.)
960      *
961      * Type: u8 (low 6 bits).
962      * Maskable: no.
963      * Formatting: decimal.
964      * Prerequisites: IPv4/IPv6.
965      * Access: read/write.
966      * NXM: none.
967      * OXM: OXM_OF_IP_DSCP(8) since OF1.2 and v1.7.
968      * OF1.0: exact match.
969      * OF1.1: exact match.
970      */
971     MFF_IP_DSCP_SHIFTED,
972
973     /* "nw_ecn" (aka "ip_ecn").
974      *
975      * The ECN bits in the IPv4 or IPv6 header.
976      *
977      * Type: u8 (low 2 bits).
978      * Maskable: no.
979      * Formatting: decimal.
980      * Prerequisites: IPv4/IPv6.
981      * Access: read/write.
982      * NXM: NXM_NX_IP_ECN(28) since v1.4.
983      * OXM: OXM_OF_IP_ECN(9) since OF1.2 and v1.7.
984      */
985     MFF_IP_ECN,
986
987     /* "nw_ttl".
988      *
989      * The time-to-live (TTL) in the IPv4 header or hop limit in the IPv6
990      * header.
991      *
992      * Type: u8.
993      * Maskable: no.
994      * Formatting: decimal.
995      * Prerequisites: IPv4/IPv6.
996      * Access: read/write.
997      * NXM: NXM_NX_IP_TTL(29) since v1.4.
998      * OXM: none.
999      */
1000     MFF_IP_TTL,
1001
1002     /* "ip_frag".
1003      *
1004      * IP fragment information.
1005      *
1006      * This field has three possible values:
1007      *
1008      *   - A packet that is not an IP fragment has value 0.
1009      *
1010      *   - A packet that is an IP fragment with offset 0 (the first fragment)
1011      *     has bit 0 set and thus value 1.
1012      *
1013      *   - A packet that is an IP fragment with nonzero offset has bits 0 and 1
1014      *     set and thus value 3.
1015      *
1016      * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically
1017      * represent the meanings of bits 0 and 1.
1018      *
1019      * The switch may reject matches against values that can never appear.
1020      *
1021      * It is important to understand how this field interacts with the OpenFlow
1022      * IP fragment handling mode:
1023      *
1024      *   - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
1025      *     before they reach the flow table, so every packet that is available
1026      *     for matching will have value 0 in this field.
1027      *
1028      *   - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did
1029      *     then IP fragments would be reassembled before they reached the flow
1030      *     table and again every packet available for matching would always
1031      *     have value 0.
1032      *
1033      *   - In OFPC_FRAG_NORMAL mode, all three values are possible, but
1034      *     OpenFlow 1.0 says that fragments' transport ports are always 0, even
1035      *     for the first fragment, so this does not provide much extra
1036      *     information.
1037      *
1038      *   - In OFPC_FRAG_NX_MATCH mode, all three values are possible.  For
1039      *     fragments with offset 0, Open vSwitch makes L4 header information
1040      *     available.
1041      *
1042      * Type: u8 (low 2 bits).
1043      * Maskable: bitwise.
1044      * Formatting: frag.
1045      * Prerequisites: IPv4/IPv6.
1046      * Access: read-only.
1047      * NXM: NXM_NX_IP_FRAG(26) since v1.3.
1048      * OXM: none.
1049      */
1050     MFF_IP_FRAG,
1051
1052 /* ## --- ## */
1053 /* ## ARP ## */
1054 /* ## --- ## */
1055
1056     /* "arp_op".
1057      *
1058      * ARP opcode.
1059      *
1060      * For an Ethernet+IP ARP packet, the opcode in the ARP header.  Always 0
1061      * otherwise.  Only ARP opcodes between 1 and 255 should be specified for
1062      * matching.
1063      *
1064      * Type: be16.
1065      * Maskable: no.
1066      * Formatting: decimal.
1067      * Prerequisites: ARP.
1068      * Access: read/write.
1069      * NXM: NXM_OF_ARP_OP(15) since v1.1.
1070      * OXM: OXM_OF_ARP_OP(21) since OF1.2 and v1.7.
1071      * OF1.0: exact match.
1072      * OF1.1: exact match.
1073      */
1074     MFF_ARP_OP,
1075
1076     /* "arp_spa".
1077      *
1078      * For an Ethernet+IP ARP packet, the source protocol (IPv4) address in the
1079      * ARP header.  Always 0 otherwise.
1080      *
1081      * Before Open vSwitch 1.8, only CIDR masks were supported.
1082      *
1083      * Type: be32.
1084      * Maskable: bitwise.
1085      * Formatting: IPv4.
1086      * Prerequisites: ARP.
1087      * Access: read/write.
1088      * NXM: NXM_OF_ARP_SPA(16) since v1.1.
1089      * OXM: OXM_OF_ARP_SPA(22) since OF1.2 and v1.7.
1090      * OF1.0: CIDR mask.
1091      * OF1.1: bitwise mask.
1092      */
1093     MFF_ARP_SPA,
1094
1095     /* "arp_tpa".
1096      *
1097      * For an Ethernet+IP ARP packet, the target protocol (IPv4) address in the
1098      * ARP header.  Always 0 otherwise.
1099      *
1100      * Before Open vSwitch 1.8, only CIDR masks were supported.
1101      *
1102      * Type: be32.
1103      * Maskable: bitwise.
1104      * Formatting: IPv4.
1105      * Prerequisites: ARP.
1106      * Access: read/write.
1107      * NXM: NXM_OF_ARP_TPA(17) since v1.1.
1108      * OXM: OXM_OF_ARP_TPA(23) since OF1.2 and v1.7.
1109      * OF1.0: CIDR mask.
1110      * OF1.1: bitwise mask.
1111      */
1112     MFF_ARP_TPA,
1113
1114     /* "arp_sha".
1115      *
1116      * For an Ethernet+IP ARP packet, the source hardware (Ethernet) address in
1117      * the ARP header.  Always 0 otherwise.
1118      *
1119      * Type: MAC.
1120      * Maskable: bitwise.
1121      * Formatting: Ethernet.
1122      * Prerequisites: ARP.
1123      * Access: read/write.
1124      * NXM: NXM_NX_ARP_SHA(17) since v1.1.
1125      * OXM: OXM_OF_ARP_SHA(24) since OF1.2 and v1.7.
1126      */
1127     MFF_ARP_SHA,
1128
1129     /* "arp_tha".
1130      *
1131      * For an Ethernet+IP ARP packet, the target hardware (Ethernet) address in
1132      * the ARP header.  Always 0 otherwise.
1133      *
1134      * Type: MAC.
1135      * Maskable: bitwise.
1136      * Formatting: Ethernet.
1137      * Prerequisites: ARP.
1138      * Access: read/write.
1139      * NXM: NXM_NX_ARP_THA(18) since v1.1.
1140      * OXM: OXM_OF_ARP_THA(25) since OF1.2 and v1.7.
1141      */
1142     MFF_ARP_THA,
1143
1144 /* ## --- ## */
1145 /* ## TCP ## */
1146 /* ## --- ## */
1147
1148     /* "tcp_src" (aka "tp_src").
1149      *
1150      * TCP source port.
1151      *
1152      * Type: be16.
1153      * Maskable: bitwise.
1154      * Formatting: decimal.
1155      * Prerequisites: TCP.
1156      * Access: read/write.
1157      * NXM: NXM_OF_TCP_SRC(9) since v1.1.
1158      * OXM: OXM_OF_TCP_SRC(13) since OF1.2 and v1.7.
1159      * OF1.0: exact match.
1160      * OF1.1: exact match.
1161      */
1162     MFF_TCP_SRC,
1163
1164     /* "tcp_dst" (aka "tp_dst").
1165      *
1166      * TCP destination port.
1167      *
1168      * Type: be16.
1169      * Maskable: bitwise.
1170      * Formatting: decimal.
1171      * Prerequisites: TCP.
1172      * Access: read/write.
1173      * NXM: NXM_OF_TCP_DST(10) since v1.1.
1174      * OXM: OXM_OF_TCP_DST(14) since OF1.2 and v1.7.
1175      * OF1.0: exact match.
1176      * OF1.1: exact match.
1177      */
1178     MFF_TCP_DST,
1179
1180     /* "tcp_flags".
1181      *
1182      * Flags in the TCP header.
1183      *
1184      * TCP currently defines 9 flag bits, and additional 3 bits are reserved
1185      * (must be transmitted as zero).  See RFCs 793, 3168, and 3540.
1186      *
1187      * Type: be16 (low 12 bits).
1188      * Maskable: bitwise.
1189      * Formatting: TCP flags.
1190      * Prerequisites: TCP.
1191      * Access: read-only.
1192      * NXM: NXM_NX_TCP_FLAGS(34) since v2.1.
1193      * OXM: ONFOXM_ET_TCP_FLAGS(42) since OF1.3 and v2.4,
1194      *      OXM_OF_TCP_FLAGS(42) since OF1.5 and v2.3.
1195      */
1196     MFF_TCP_FLAGS,
1197
1198 /* ## --- ## */
1199 /* ## UDP ## */
1200 /* ## --- ## */
1201
1202     /* "udp_src".
1203      *
1204      * UDP source port.
1205      *
1206      * Type: be16.
1207      * Maskable: bitwise.
1208      * Formatting: decimal.
1209      * Prerequisites: UDP.
1210      * Access: read/write.
1211      * NXM: NXM_OF_UDP_SRC(11) since v1.1.
1212      * OXM: OXM_OF_UDP_SRC(15) since OF1.2 and v1.7.
1213      * OF1.0: exact match.
1214      * OF1.1: exact match.
1215      */
1216     MFF_UDP_SRC,
1217
1218     /* "udp_dst".
1219      *
1220      * UDP destination port
1221      *
1222      * Type: be16.
1223      * Maskable: bitwise.
1224      * Formatting: decimal.
1225      * Prerequisites: UDP.
1226      * Access: read/write.
1227      * NXM: NXM_OF_UDP_DST(12) since v1.1.
1228      * OXM: OXM_OF_UDP_DST(16) since OF1.2 and v1.7.
1229      * OF1.0: exact match.
1230      * OF1.1: exact match.
1231      */
1232     MFF_UDP_DST,
1233
1234 /* ## ---- ## */
1235 /* ## SCTP ## */
1236 /* ## ---- ## */
1237
1238     /* "sctp_src".
1239      *
1240      * SCTP source port.
1241      *
1242      * Type: be16.
1243      * Maskable: bitwise.
1244      * Formatting: decimal.
1245      * Prerequisites: SCTP.
1246      * Access: read/write.
1247      * NXM: none.
1248      * OXM: OXM_OF_SCTP_SRC(17) since OF1.2 and v2.0.
1249      * OF1.1: exact match.
1250      */
1251     MFF_SCTP_SRC,
1252
1253     /* "sctp_dst".
1254      *
1255      * SCTP destination port.
1256      *
1257      * Type: be16.
1258      * Maskable: bitwise.
1259      * Formatting: decimal.
1260      * Prerequisites: SCTP.
1261      * Access: read/write.
1262      * NXM: none.
1263      * OXM: OXM_OF_SCTP_DST(18) since OF1.2 and v2.0.
1264      * OF1.1: exact match.
1265      */
1266     MFF_SCTP_DST,
1267
1268 /* ## ---- ## */
1269 /* ## ICMP ## */
1270 /* ## ---- ## */
1271
1272     /* "icmp_type".
1273      *
1274      * ICMPv4 type.
1275      *
1276      * Type: u8.
1277      * Maskable: no.
1278      * Formatting: decimal.
1279      * Prerequisites: ICMPv4.
1280      * Access: read-only.
1281      * NXM: NXM_OF_ICMP_TYPE(13) since v1.1.
1282      * OXM: OXM_OF_ICMPV4_TYPE(19) since OF1.2 and v1.7.
1283      * OF1.0: exact match.
1284      * OF1.1: exact match.
1285      */
1286     MFF_ICMPV4_TYPE,
1287
1288     /* "icmp_code".
1289      *
1290      * ICMPv4 code.
1291      *
1292      * Type: u8.
1293      * Maskable: no.
1294      * Formatting: decimal.
1295      * Prerequisites: ICMPv4.
1296      * Access: read-only.
1297      * NXM: NXM_OF_ICMP_CODE(14) since v1.1.
1298      * OXM: OXM_OF_ICMPV4_CODE(20) since OF1.2 and v1.7.
1299      * OF1.0: exact match.
1300      * OF1.1: exact match.
1301      */
1302     MFF_ICMPV4_CODE,
1303
1304     /* "icmpv6_type".
1305      *
1306      * ICMPv6 type.
1307      *
1308      * Type: u8.
1309      * Maskable: no.
1310      * Formatting: decimal.
1311      * Prerequisites: ICMPv6.
1312      * Access: read-only.
1313      * NXM: NXM_NX_ICMPV6_TYPE(21) since v1.1.
1314      * OXM: OXM_OF_ICMPV6_TYPE(29) since OF1.2 and v1.7.
1315      */
1316     MFF_ICMPV6_TYPE,
1317
1318     /* "icmpv6_code".
1319      *
1320      * ICMPv6 code.
1321      *
1322      * Type: u8.
1323      * Maskable: no.
1324      * Formatting: decimal.
1325      * Prerequisites: ICMPv6.
1326      * Access: read-only.
1327      * NXM: NXM_NX_ICMPV6_CODE(22) since v1.1.
1328      * OXM: OXM_OF_ICMPV6_CODE(30) since OF1.2 and v1.7.
1329      */
1330     MFF_ICMPV6_CODE,
1331
1332 /* ## ------------------------- ## */
1333 /* ## ICMPv6 Neighbor Discovery ## */
1334 /* ## ------------------------- ## */
1335
1336     /* "nd_target".
1337      *
1338      * The target address in an IPv6 Neighbor Discovery message.
1339      *
1340      * Before Open vSwitch 1.8, only CIDR masks were supported.
1341      *
1342      * Type: IPv6.
1343      * Maskable: bitwise.
1344      * Formatting: IPv6.
1345      * Prerequisites: ND.
1346      * Access: read/write.
1347      * NXM: NXM_NX_ND_TARGET(23) since v1.1.
1348      * OXM: OXM_OF_IPV6_ND_TARGET(31) since OF1.2 and v1.7.
1349      */
1350     MFF_ND_TARGET,
1351
1352     /* "nd_sll".
1353      *
1354      * The source link layer address in an IPv6 Neighbor Discovery message.
1355      *
1356      * Type: MAC.
1357      * Maskable: bitwise.
1358      * Formatting: Ethernet.
1359      * Prerequisites: ND solicit.
1360      * Access: read/write.
1361      * NXM: NXM_NX_ND_SLL(24) since v1.1.
1362      * OXM: OXM_OF_IPV6_ND_SLL(32) since OF1.2 and v1.7.
1363      */
1364     MFF_ND_SLL,
1365
1366     /* "nd_tll".
1367      *
1368      * The target link layer address in an IPv6 Neighbor Discovery message.
1369      *
1370      * Type: MAC.
1371      * Maskable: bitwise.
1372      * Formatting: Ethernet.
1373      * Prerequisites: ND advert.
1374      * Access: read/write.
1375      * NXM: NXM_NX_ND_TLL(25) since v1.1.
1376      * OXM: OXM_OF_IPV6_ND_TLL(33) since OF1.2 and v1.7.
1377      */
1378     MFF_ND_TLL,
1379
1380     MFF_N_IDS
1381 };
1382
1383 /* A set of mf_field_ids. */
1384 struct mf_bitmap {
1385     unsigned long bm[BITMAP_N_LONGS(MFF_N_IDS)];
1386 };
1387 #define MF_BITMAP_INITIALIZER { { [0] = 0 } }
1388
1389 /* Use this macro as CASE_MFF_REGS: in a switch statement to choose all of the
1390  * MFF_REGn cases. */
1391 #if FLOW_N_REGS == 8
1392 #define CASE_MFF_REGS                                           \
1393     case MFF_REG0: case MFF_REG1: case MFF_REG2: case MFF_REG3: \
1394     case MFF_REG4: case MFF_REG5: case MFF_REG6: case MFF_REG7
1395 #else
1396 #error "Need to update CASE_MFF_REGS to match FLOW_N_REGS"
1397 #endif
1398
1399 /* Use this macro as CASE_MFF_XREGS: in a switch statement to choose all of the
1400  * MFF_REGn cases. */
1401 #if FLOW_N_XREGS == 4
1402 #define CASE_MFF_XREGS                                              \
1403     case MFF_XREG0: case MFF_XREG1: case MFF_XREG2: case MFF_XREG3
1404 #else
1405 #error "Need to update CASE_MFF_XREGS to match FLOW_N_XREGS"
1406 #endif
1407
1408 /* Prerequisites for matching a field.
1409  *
1410  * A field may only be matched if the correct lower-level protocols are also
1411  * matched.  For example, the TCP port may be matched only if the Ethernet type
1412  * matches ETH_TYPE_IP and the IP protocol matches IPPROTO_TCP. */
1413 enum OVS_PACKED_ENUM mf_prereqs {
1414     MFP_NONE,
1415
1416     /* L2 requirements. */
1417     MFP_ARP,
1418     MFP_VLAN_VID,
1419     MFP_IPV4,
1420     MFP_IPV6,
1421     MFP_IP_ANY,
1422
1423     /* L2.5 requirements. */
1424     MFP_MPLS,
1425
1426     /* L2+L3 requirements. */
1427     MFP_TCP,                    /* On IPv4 or IPv6. */
1428     MFP_UDP,                    /* On IPv4 or IPv6. */
1429     MFP_SCTP,                   /* On IPv4 or IPv6. */
1430     MFP_ICMPV4,
1431     MFP_ICMPV6,
1432
1433     /* L2+L3+L4 requirements. */
1434     MFP_ND,
1435     MFP_ND_SOLICIT,
1436     MFP_ND_ADVERT
1437 };
1438
1439 /* Forms of partial-field masking allowed for a field.
1440  *
1441  * Every field may be masked as a whole. */
1442 enum OVS_PACKED_ENUM mf_maskable {
1443     MFM_NONE,                   /* No sub-field masking. */
1444     MFM_FULLY,                  /* Every bit is individually maskable. */
1445 };
1446
1447 /* How to format or parse a field's value. */
1448 enum OVS_PACKED_ENUM mf_string {
1449     /* Integer formats.
1450      *
1451      * The particular MFS_* constant sets the output format.  On input, either
1452      * decimal or hexadecimal (prefixed with 0x) is accepted. */
1453     MFS_DECIMAL,
1454     MFS_HEXADECIMAL,
1455
1456     /* Other formats. */
1457     MFS_ETHERNET,
1458     MFS_IPV4,
1459     MFS_IPV6,
1460     MFS_OFP_PORT,               /* 16-bit OpenFlow 1.0 port number or name. */
1461     MFS_OFP_PORT_OXM,           /* 32-bit OpenFlow 1.1+ port number or name. */
1462     MFS_FRAG,                   /* no, yes, first, later, not_later */
1463     MFS_TNL_FLAGS,              /* FLOW_TNL_F_* flags */
1464     MFS_TCP_FLAGS,              /* TCP_* flags */
1465 };
1466
1467 struct mf_field {
1468     /* Identification. */
1469     enum mf_field_id id;        /* MFF_*. */
1470     const char *name;           /* Name of this field, e.g. "eth_type". */
1471     const char *extra_name;     /* Alternate name, e.g. "dl_type", or NULL. */
1472
1473     /* Size.
1474      *
1475      * Most fields have n_bytes * 8 == n_bits.  There are a few exceptions:
1476      *
1477      *     - "dl_vlan" is 2 bytes but only 12 bits.
1478      *     - "dl_vlan_pcp" is 1 byte but only 3 bits.
1479      *     - "is_frag" is 1 byte but only 2 bits.
1480      *     - "ipv6_label" is 4 bytes but only 20 bits.
1481      *     - "mpls_label" is 4 bytes but only 20 bits.
1482      *     - "mpls_tc"    is 1 byte but only 3 bits.
1483      *     - "mpls_bos"   is 1 byte but only 1 bit.
1484      */
1485     unsigned int n_bytes;       /* Width of the field in bytes. */
1486     unsigned int n_bits;        /* Number of significant bits in field. */
1487
1488     /* Properties. */
1489     enum mf_maskable maskable;
1490     enum mf_string string;
1491     enum mf_prereqs prereqs;
1492     bool writable;              /* May be written by actions? */
1493
1494     /* Usable protocols.
1495      *
1496      * NXM and OXM are extensible, allowing later extensions to be sent in
1497      * earlier protocol versions, so this does not necessarily correspond to
1498      * the OpenFlow protocol version the field was introduced in.
1499      * Also, some field types are tranparently mapped to each other via the
1500      * struct flow (like vlan and dscp/tos fields), so each variant supports
1501      * all protocols.
1502      *
1503      * These are combinations of OFPUTIL_P_*.  (They are not declared as type
1504      * enum ofputil_protocol because that would give meta-flow.h and ofp-util.h
1505      * a circular dependency.) */
1506     uint32_t usable_protocols_exact;   /* Matching or setting whole field. */
1507     uint32_t usable_protocols_cidr;    /* Matching a CIDR mask in field. */
1508     uint32_t usable_protocols_bitwise; /* Matching arbitrary bits in field. */
1509
1510     int flow_be32ofs;  /* Field's be32 offset in "struct flow", if prefix tree
1511                         * lookup is supported for the field, or -1. */
1512 };
1513
1514 /* The representation of a field's value. */
1515 union mf_value {
1516     struct in6_addr ipv6;
1517     uint8_t mac[ETH_ADDR_LEN];
1518     ovs_be64 be64;
1519     ovs_be32 be32;
1520     ovs_be16 be16;
1521     uint8_t u8;
1522 };
1523 BUILD_ASSERT_DECL(sizeof(union mf_value) == 16);
1524
1525 /* An all-1-bits mf_value.  Needs to be updated if struct mf_value grows.*/
1526 #define MF_EXACT_MASK_INITIALIZER { IN6ADDR_EXACT_INIT }
1527 BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof(struct in6_addr));
1528
1529 /* Part of a field. */
1530 struct mf_subfield {
1531     const struct mf_field *field;
1532     unsigned int ofs;           /* Bit offset. */
1533     unsigned int n_bits;        /* Number of bits. */
1534 };
1535
1536 /* Data for some part of an mf_field.
1537  *
1538  * The data is stored "right-justified".  For example, if "union mf_subvalue
1539  * value" contains NXM_OF_VLAN_TCI[0..11], then one could access the
1540  * corresponding data in value.be16[7] as the bits in the mask htons(0xfff). */
1541 union mf_subvalue {
1542     uint8_t u8[16];
1543     ovs_be16 be16[8];
1544     ovs_be32 be32[4];
1545     ovs_be64 be64[2];
1546 };
1547 BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof (union mf_subvalue));
1548
1549 /* Finding mf_fields. */
1550 const struct mf_field *mf_from_name(const char *name);
1551
1552 static inline const struct mf_field *
1553 mf_from_id(enum mf_field_id id)
1554 {
1555     extern const struct mf_field mf_fields[MFF_N_IDS];
1556     ovs_assert((unsigned int) id < MFF_N_IDS);
1557     return &mf_fields[id];
1558 }
1559
1560 /* Inspecting wildcarded bits. */
1561 bool mf_is_all_wild(const struct mf_field *, const struct flow_wildcards *);
1562
1563 bool mf_is_mask_valid(const struct mf_field *, const union mf_value *mask);
1564 void mf_get_mask(const struct mf_field *, const struct flow_wildcards *,
1565                  union mf_value *mask);
1566
1567 /* Prerequisites. */
1568 bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
1569 void mf_mask_field_and_prereqs(const struct mf_field *, struct flow *mask);
1570
1571 static inline bool
1572 mf_is_l3_or_higher(const struct mf_field *mf)
1573 {
1574     return mf->id >= MFF_IPV4_SRC;
1575 }
1576
1577 /* Field values. */
1578 bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
1579
1580 void mf_get_value(const struct mf_field *, const struct flow *,
1581                   union mf_value *value);
1582 void mf_set_value(const struct mf_field *, const union mf_value *value,
1583                   struct match *);
1584 void mf_set_flow_value(const struct mf_field *, const union mf_value *value,
1585                        struct flow *);
1586 void mf_set_flow_value_masked(const struct mf_field *,
1587                               const union mf_value *value,
1588                               const union mf_value *mask,
1589                               struct flow *);
1590 bool mf_is_zero(const struct mf_field *, const struct flow *);
1591 void mf_mask_field(const struct mf_field *, struct flow *);
1592
1593 void mf_get(const struct mf_field *, const struct match *,
1594             union mf_value *value, union mf_value *mask);
1595
1596 /* Returns the set of usable protocols. */
1597 enum ofputil_protocol mf_set(const struct mf_field *,
1598                              const union mf_value *value,
1599                              const union mf_value *mask,
1600                              struct match *);
1601
1602 void mf_set_wild(const struct mf_field *, struct match *);
1603
1604 /* Subfields. */
1605 void mf_write_subfield_flow(const struct mf_subfield *,
1606                             const union mf_subvalue *, struct flow *);
1607 void mf_write_subfield(const struct mf_subfield *, const union mf_subvalue *,
1608                        struct match *);
1609
1610 void mf_read_subfield(const struct mf_subfield *, const struct flow *,
1611                       union mf_subvalue *);
1612 uint64_t mf_get_subfield(const struct mf_subfield *, const struct flow *);
1613
1614
1615 enum ofperr mf_check_src(const struct mf_subfield *, const struct flow *);
1616 enum ofperr mf_check_dst(const struct mf_subfield *, const struct flow *);
1617
1618 /* Parsing and formatting. */
1619 char *mf_parse(const struct mf_field *, const char *,
1620                union mf_value *value, union mf_value *mask);
1621 char *mf_parse_value(const struct mf_field *, const char *, union mf_value *);
1622 void mf_format(const struct mf_field *,
1623                const union mf_value *value, const union mf_value *mask,
1624                struct ds *);
1625 void mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s);
1626
1627 #endif /* meta-flow.h */