net: support VLAN in software packet type parser
[dpdk.git] / lib / librte_mbuf / rte_mbuf_ptype.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation.
5  *   Copyright 2014-2016 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef _RTE_MBUF_PTYPE_H_
36 #define _RTE_MBUF_PTYPE_H_
37
38 /**
39  * @file
40  * RTE Mbuf Packet Types
41  *
42  * This file contains declarations for features related to mbuf packet
43  * types. The packet type gives information about the data carried by the
44  * mbuf, and is stored in the mbuf in a 32 bits field.
45  *
46  * The 32 bits are divided into several fields to mark packet types. Note that
47  * each field is indexical.
48  * - Bit 3:0 is for L2 types.
49  * - Bit 7:4 is for L3 or outer L3 (for tunneling case) types.
50  * - Bit 11:8 is for L4 or outer L4 (for tunneling case) types.
51  * - Bit 15:12 is for tunnel types.
52  * - Bit 19:16 is for inner L2 types.
53  * - Bit 23:20 is for inner L3 types.
54  * - Bit 27:24 is for inner L4 types.
55  * - Bit 31:28 is reserved.
56  *
57  * To be compatible with Vector PMD, RTE_PTYPE_L3_IPV4, RTE_PTYPE_L3_IPV4_EXT,
58  * RTE_PTYPE_L3_IPV6, RTE_PTYPE_L3_IPV6_EXT, RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP
59  * and RTE_PTYPE_L4_SCTP should be kept as below in a contiguous 7 bits.
60  *
61  * Note that L3 types values are selected for checking IPV4/IPV6 header from
62  * performance point of view. Reading annotations of RTE_ETH_IS_IPV4_HDR and
63  * RTE_ETH_IS_IPV6_HDR is needed for any future changes of L3 type values.
64  *
65  * Note that the packet types of the same packet recognized by different
66  * hardware may be different, as different hardware may have different
67  * capability of packet type recognition.
68  *
69  * examples:
70  * <'ether type'=0x0800
71  * | 'version'=4, 'protocol'=0x29
72  * | 'version'=6, 'next header'=0x3A
73  * | 'ICMPv6 header'>
74  * will be recognized on i40e hardware as packet type combination of,
75  * RTE_PTYPE_L2_ETHER |
76  * RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
77  * RTE_PTYPE_TUNNEL_IP |
78  * RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
79  * RTE_PTYPE_INNER_L4_ICMP.
80  *
81  * <'ether type'=0x86DD
82  * | 'version'=6, 'next header'=0x2F
83  * | 'GRE header'
84  * | 'version'=6, 'next header'=0x11
85  * | 'UDP header'>
86  * will be recognized on i40e hardware as packet type combination of,
87  * RTE_PTYPE_L2_ETHER |
88  * RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
89  * RTE_PTYPE_TUNNEL_GRENAT |
90  * RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
91  * RTE_PTYPE_INNER_L4_UDP.
92  */
93
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97
98 /**
99  * No packet type information.
100  */
101 #define RTE_PTYPE_UNKNOWN                   0x00000000
102 /**
103  * Ethernet packet type.
104  * It is used for outer packet for tunneling cases.
105  *
106  * Packet format:
107  * <'ether type'=[0x0800|0x86DD]>
108  */
109 #define RTE_PTYPE_L2_ETHER                  0x00000001
110 /**
111  * Ethernet packet type for time sync.
112  *
113  * Packet format:
114  * <'ether type'=0x88F7>
115  */
116 #define RTE_PTYPE_L2_ETHER_TIMESYNC         0x00000002
117 /**
118  * ARP (Address Resolution Protocol) packet type.
119  *
120  * Packet format:
121  * <'ether type'=0x0806>
122  */
123 #define RTE_PTYPE_L2_ETHER_ARP              0x00000003
124 /**
125  * LLDP (Link Layer Discovery Protocol) packet type.
126  *
127  * Packet format:
128  * <'ether type'=0x88CC>
129  */
130 #define RTE_PTYPE_L2_ETHER_LLDP             0x00000004
131 /**
132  * NSH (Network Service Header) packet type.
133  *
134  * Packet format:
135  * <'ether type'=0x894F>
136  */
137 #define RTE_PTYPE_L2_ETHER_NSH              0x00000005
138 /**
139  * VLAN packet type.
140  *
141  * Packet format:
142  * <'ether type'=[0x8100]>
143  */
144 #define RTE_PTYPE_L2_ETHER_VLAN             0x00000006
145 /**
146  * Mask of layer 2 packet types.
147  * It is used for outer packet for tunneling cases.
148  */
149 #define RTE_PTYPE_L2_MASK                   0x0000000f
150 /**
151  * IP (Internet Protocol) version 4 packet type.
152  * It is used for outer packet for tunneling cases, and does not contain any
153  * header option.
154  *
155  * Packet format:
156  * <'ether type'=0x0800
157  * | 'version'=4, 'ihl'=5>
158  */
159 #define RTE_PTYPE_L3_IPV4                   0x00000010
160 /**
161  * IP (Internet Protocol) version 4 packet type.
162  * It is used for outer packet for tunneling cases, and contains header
163  * options.
164  *
165  * Packet format:
166  * <'ether type'=0x0800
167  * | 'version'=4, 'ihl'=[6-15], 'options'>
168  */
169 #define RTE_PTYPE_L3_IPV4_EXT               0x00000030
170 /**
171  * IP (Internet Protocol) version 6 packet type.
172  * It is used for outer packet for tunneling cases, and does not contain any
173  * extension header.
174  *
175  * Packet format:
176  * <'ether type'=0x86DD
177  * | 'version'=6, 'next header'=0x3B>
178  */
179 #define RTE_PTYPE_L3_IPV6                   0x00000040
180 /**
181  * IP (Internet Protocol) version 4 packet type.
182  * It is used for outer packet for tunneling cases, and may or maynot contain
183  * header options.
184  *
185  * Packet format:
186  * <'ether type'=0x0800
187  * | 'version'=4, 'ihl'=[5-15], <'options'>>
188  */
189 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN       0x00000090
190 /**
191  * IP (Internet Protocol) version 6 packet type.
192  * It is used for outer packet for tunneling cases, and contains extension
193  * headers.
194  *
195  * Packet format:
196  * <'ether type'=0x86DD
197  * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
198  *   'extension headers'>
199  */
200 #define RTE_PTYPE_L3_IPV6_EXT               0x000000c0
201 /**
202  * IP (Internet Protocol) version 6 packet type.
203  * It is used for outer packet for tunneling cases, and may or maynot contain
204  * extension headers.
205  *
206  * Packet format:
207  * <'ether type'=0x86DD
208  * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
209  *   <'extension headers'>>
210  */
211 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN       0x000000e0
212 /**
213  * Mask of layer 3 packet types.
214  * It is used for outer packet for tunneling cases.
215  */
216 #define RTE_PTYPE_L3_MASK                   0x000000f0
217 /**
218  * TCP (Transmission Control Protocol) packet type.
219  * It is used for outer packet for tunneling cases.
220  *
221  * Packet format:
222  * <'ether type'=0x0800
223  * | 'version'=4, 'protocol'=6, 'MF'=0>
224  * or,
225  * <'ether type'=0x86DD
226  * | 'version'=6, 'next header'=6>
227  */
228 #define RTE_PTYPE_L4_TCP                    0x00000100
229 /**
230  * UDP (User Datagram Protocol) packet type.
231  * It is used for outer packet for tunneling cases.
232  *
233  * Packet format:
234  * <'ether type'=0x0800
235  * | 'version'=4, 'protocol'=17, 'MF'=0>
236  * or,
237  * <'ether type'=0x86DD
238  * | 'version'=6, 'next header'=17>
239  */
240 #define RTE_PTYPE_L4_UDP                    0x00000200
241 /**
242  * Fragmented IP (Internet Protocol) packet type.
243  * It is used for outer packet for tunneling cases.
244  *
245  * It refers to those packets of any IP types, which can be recognized as
246  * fragmented. A fragmented packet cannot be recognized as any other L4 types
247  * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
248  * RTE_PTYPE_L4_NONFRAG).
249  *
250  * Packet format:
251  * <'ether type'=0x0800
252  * | 'version'=4, 'MF'=1>
253  * or,
254  * <'ether type'=0x86DD
255  * | 'version'=6, 'next header'=44>
256  */
257 #define RTE_PTYPE_L4_FRAG                   0x00000300
258 /**
259  * SCTP (Stream Control Transmission Protocol) packet type.
260  * It is used for outer packet for tunneling cases.
261  *
262  * Packet format:
263  * <'ether type'=0x0800
264  * | 'version'=4, 'protocol'=132, 'MF'=0>
265  * or,
266  * <'ether type'=0x86DD
267  * | 'version'=6, 'next header'=132>
268  */
269 #define RTE_PTYPE_L4_SCTP                   0x00000400
270 /**
271  * ICMP (Internet Control Message Protocol) packet type.
272  * It is used for outer packet for tunneling cases.
273  *
274  * Packet format:
275  * <'ether type'=0x0800
276  * | 'version'=4, 'protocol'=1, 'MF'=0>
277  * or,
278  * <'ether type'=0x86DD
279  * | 'version'=6, 'next header'=1>
280  */
281 #define RTE_PTYPE_L4_ICMP                   0x00000500
282 /**
283  * Non-fragmented IP (Internet Protocol) packet type.
284  * It is used for outer packet for tunneling cases.
285  *
286  * It refers to those packets of any IP types, while cannot be recognized as
287  * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
288  * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
289  *
290  * Packet format:
291  * <'ether type'=0x0800
292  * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0>
293  * or,
294  * <'ether type'=0x86DD
295  * | 'version'=6, 'next header'!=[6|17|44|132|1]>
296  */
297 #define RTE_PTYPE_L4_NONFRAG                0x00000600
298 /**
299  * Mask of layer 4 packet types.
300  * It is used for outer packet for tunneling cases.
301  */
302 #define RTE_PTYPE_L4_MASK                   0x00000f00
303 /**
304  * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
305  *
306  * Packet format:
307  * <'ether type'=0x0800
308  * | 'version'=4, 'protocol'=[4|41]>
309  * or,
310  * <'ether type'=0x86DD
311  * | 'version'=6, 'next header'=[4|41]>
312  */
313 #define RTE_PTYPE_TUNNEL_IP                 0x00001000
314 /**
315  * GRE (Generic Routing Encapsulation) tunneling packet type.
316  *
317  * Packet format:
318  * <'ether type'=0x0800
319  * | 'version'=4, 'protocol'=47>
320  * or,
321  * <'ether type'=0x86DD
322  * | 'version'=6, 'next header'=47>
323  */
324 #define RTE_PTYPE_TUNNEL_GRE                0x00002000
325 /**
326  * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
327  *
328  * Packet format:
329  * <'ether type'=0x0800
330  * | 'version'=4, 'protocol'=17
331  * | 'destination port'=4798>
332  * or,
333  * <'ether type'=0x86DD
334  * | 'version'=6, 'next header'=17
335  * | 'destination port'=4798>
336  */
337 #define RTE_PTYPE_TUNNEL_VXLAN              0x00003000
338 /**
339  * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
340  * packet type.
341  *
342  * Packet format:
343  * <'ether type'=0x0800
344  * | 'version'=4, 'protocol'=47
345  * | 'protocol type'=0x6558>
346  * or,
347  * <'ether type'=0x86DD
348  * | 'version'=6, 'next header'=47
349  * | 'protocol type'=0x6558'>
350  */
351 #define RTE_PTYPE_TUNNEL_NVGRE              0x00004000
352 /**
353  * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
354  *
355  * Packet format:
356  * <'ether type'=0x0800
357  * | 'version'=4, 'protocol'=17
358  * | 'destination port'=6081>
359  * or,
360  * <'ether type'=0x86DD
361  * | 'version'=6, 'next header'=17
362  * | 'destination port'=6081>
363  */
364 #define RTE_PTYPE_TUNNEL_GENEVE             0x00005000
365 /**
366  * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
367  * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
368  * packet type, if they can not be recognized independently as of hardware
369  * capability.
370  */
371 #define RTE_PTYPE_TUNNEL_GRENAT             0x00006000
372 /**
373  * Mask of tunneling packet types.
374  */
375 #define RTE_PTYPE_TUNNEL_MASK               0x0000f000
376 /**
377  * Ethernet packet type.
378  * It is used for inner packet type only.
379  *
380  * Packet format (inner only):
381  * <'ether type'=[0x800|0x86DD]>
382  */
383 #define RTE_PTYPE_INNER_L2_ETHER            0x00010000
384 /**
385  * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
386  *
387  * Packet format (inner only):
388  * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
389  */
390 #define RTE_PTYPE_INNER_L2_ETHER_VLAN       0x00020000
391 /**
392  * Mask of inner layer 2 packet types.
393  */
394 #define RTE_PTYPE_INNER_L2_MASK             0x000f0000
395 /**
396  * IP (Internet Protocol) version 4 packet type.
397  * It is used for inner packet only, and does not contain any header option.
398  *
399  * Packet format (inner only):
400  * <'ether type'=0x0800
401  * | 'version'=4, 'ihl'=5>
402  */
403 #define RTE_PTYPE_INNER_L3_IPV4             0x00100000
404 /**
405  * IP (Internet Protocol) version 4 packet type.
406  * It is used for inner packet only, and contains header options.
407  *
408  * Packet format (inner only):
409  * <'ether type'=0x0800
410  * | 'version'=4, 'ihl'=[6-15], 'options'>
411  */
412 #define RTE_PTYPE_INNER_L3_IPV4_EXT         0x00200000
413 /**
414  * IP (Internet Protocol) version 6 packet type.
415  * It is used for inner packet only, and does not contain any extension header.
416  *
417  * Packet format (inner only):
418  * <'ether type'=0x86DD
419  * | 'version'=6, 'next header'=0x3B>
420  */
421 #define RTE_PTYPE_INNER_L3_IPV6             0x00300000
422 /**
423  * IP (Internet Protocol) version 4 packet type.
424  * It is used for inner packet only, and may or maynot contain header options.
425  *
426  * Packet format (inner only):
427  * <'ether type'=0x0800
428  * | 'version'=4, 'ihl'=[5-15], <'options'>>
429  */
430 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
431 /**
432  * IP (Internet Protocol) version 6 packet type.
433  * It is used for inner packet only, and contains extension headers.
434  *
435  * Packet format (inner only):
436  * <'ether type'=0x86DD
437  * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
438  *   'extension headers'>
439  */
440 #define RTE_PTYPE_INNER_L3_IPV6_EXT         0x00500000
441 /**
442  * IP (Internet Protocol) version 6 packet type.
443  * It is used for inner packet only, and may or maynot contain extension
444  * headers.
445  *
446  * Packet format (inner only):
447  * <'ether type'=0x86DD
448  * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
449  *   <'extension headers'>>
450  */
451 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
452 /**
453  * Mask of inner layer 3 packet types.
454  */
455 #define RTE_PTYPE_INNER_L3_MASK             0x00f00000
456 /**
457  * TCP (Transmission Control Protocol) packet type.
458  * It is used for inner packet only.
459  *
460  * Packet format (inner only):
461  * <'ether type'=0x0800
462  * | 'version'=4, 'protocol'=6, 'MF'=0>
463  * or,
464  * <'ether type'=0x86DD
465  * | 'version'=6, 'next header'=6>
466  */
467 #define RTE_PTYPE_INNER_L4_TCP              0x01000000
468 /**
469  * UDP (User Datagram Protocol) packet type.
470  * It is used for inner packet only.
471  *
472  * Packet format (inner only):
473  * <'ether type'=0x0800
474  * | 'version'=4, 'protocol'=17, 'MF'=0>
475  * or,
476  * <'ether type'=0x86DD
477  * | 'version'=6, 'next header'=17>
478  */
479 #define RTE_PTYPE_INNER_L4_UDP              0x02000000
480 /**
481  * Fragmented IP (Internet Protocol) packet type.
482  * It is used for inner packet only, and may or maynot have layer 4 packet.
483  *
484  * Packet format (inner only):
485  * <'ether type'=0x0800
486  * | 'version'=4, 'MF'=1>
487  * or,
488  * <'ether type'=0x86DD
489  * | 'version'=6, 'next header'=44>
490  */
491 #define RTE_PTYPE_INNER_L4_FRAG             0x03000000
492 /**
493  * SCTP (Stream Control Transmission Protocol) packet type.
494  * It is used for inner packet only.
495  *
496  * Packet format (inner only):
497  * <'ether type'=0x0800
498  * | 'version'=4, 'protocol'=132, 'MF'=0>
499  * or,
500  * <'ether type'=0x86DD
501  * | 'version'=6, 'next header'=132>
502  */
503 #define RTE_PTYPE_INNER_L4_SCTP             0x04000000
504 /**
505  * ICMP (Internet Control Message Protocol) packet type.
506  * It is used for inner packet only.
507  *
508  * Packet format (inner only):
509  * <'ether type'=0x0800
510  * | 'version'=4, 'protocol'=1, 'MF'=0>
511  * or,
512  * <'ether type'=0x86DD
513  * | 'version'=6, 'next header'=1>
514  */
515 #define RTE_PTYPE_INNER_L4_ICMP             0x05000000
516 /**
517  * Non-fragmented IP (Internet Protocol) packet type.
518  * It is used for inner packet only, and may or maynot have other unknown layer
519  * 4 packet types.
520  *
521  * Packet format (inner only):
522  * <'ether type'=0x0800
523  * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0>
524  * or,
525  * <'ether type'=0x86DD
526  * | 'version'=6, 'next header'!=[6|17|44|132|1]>
527  */
528 #define RTE_PTYPE_INNER_L4_NONFRAG          0x06000000
529 /**
530  * Mask of inner layer 4 packet types.
531  */
532 #define RTE_PTYPE_INNER_L4_MASK             0x0f000000
533
534 /**
535  * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
536  * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
537  * determine if it is an IPV4 packet.
538  */
539 #define  RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
540
541 /**
542  * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
543  * one, bit 6 is selected to be used for IPv4 only. Then checking bit 6 can
544  * determine if it is an IPV4 packet.
545  */
546 #define  RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
547
548 /* Check if it is a tunneling packet */
549 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) &                         \
550         (RTE_PTYPE_TUNNEL_MASK |                                        \
551                 RTE_PTYPE_INNER_L2_MASK |                               \
552                 RTE_PTYPE_INNER_L3_MASK |                               \
553                 RTE_PTYPE_INNER_L4_MASK))
554
555 #ifdef __cplusplus
556 }
557 #endif
558
559 #endif /* _RTE_MBUF_PTYPE_H_ */