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