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