fbe764a6c02d0c9fa563372df51d371369784dfc
[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  * QinQ packet type.
147  *
148  * Packet format:
149  * <'ether type'=[0x88A8]>
150  */
151 #define RTE_PTYPE_L2_ETHER_QINQ             0x00000007
152 /**
153  * Mask of layer 2 packet types.
154  * It is used for outer packet for tunneling cases.
155  */
156 #define RTE_PTYPE_L2_MASK                   0x0000000f
157 /**
158  * IP (Internet Protocol) version 4 packet type.
159  * It is used for outer packet for tunneling cases, and does not contain any
160  * header option.
161  *
162  * Packet format:
163  * <'ether type'=0x0800
164  * | 'version'=4, 'ihl'=5>
165  */
166 #define RTE_PTYPE_L3_IPV4                   0x00000010
167 /**
168  * IP (Internet Protocol) version 4 packet type.
169  * It is used for outer packet for tunneling cases, and contains header
170  * options.
171  *
172  * Packet format:
173  * <'ether type'=0x0800
174  * | 'version'=4, 'ihl'=[6-15], 'options'>
175  */
176 #define RTE_PTYPE_L3_IPV4_EXT               0x00000030
177 /**
178  * IP (Internet Protocol) version 6 packet type.
179  * It is used for outer packet for tunneling cases, and does not contain any
180  * extension header.
181  *
182  * Packet format:
183  * <'ether type'=0x86DD
184  * | 'version'=6, 'next header'=0x3B>
185  */
186 #define RTE_PTYPE_L3_IPV6                   0x00000040
187 /**
188  * IP (Internet Protocol) version 4 packet type.
189  * It is used for outer packet for tunneling cases, and may or maynot contain
190  * header options.
191  *
192  * Packet format:
193  * <'ether type'=0x0800
194  * | 'version'=4, 'ihl'=[5-15], <'options'>>
195  */
196 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN       0x00000090
197 /**
198  * IP (Internet Protocol) version 6 packet type.
199  * It is used for outer packet for tunneling cases, and contains extension
200  * headers.
201  *
202  * Packet format:
203  * <'ether type'=0x86DD
204  * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
205  *   'extension headers'>
206  */
207 #define RTE_PTYPE_L3_IPV6_EXT               0x000000c0
208 /**
209  * IP (Internet Protocol) version 6 packet type.
210  * It is used for outer packet for tunneling cases, and may or maynot contain
211  * extension headers.
212  *
213  * Packet format:
214  * <'ether type'=0x86DD
215  * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
216  *   <'extension headers'>>
217  */
218 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN       0x000000e0
219 /**
220  * Mask of layer 3 packet types.
221  * It is used for outer packet for tunneling cases.
222  */
223 #define RTE_PTYPE_L3_MASK                   0x000000f0
224 /**
225  * TCP (Transmission Control Protocol) packet type.
226  * It is used for outer packet for tunneling cases.
227  *
228  * Packet format:
229  * <'ether type'=0x0800
230  * | 'version'=4, 'protocol'=6, 'MF'=0>
231  * or,
232  * <'ether type'=0x86DD
233  * | 'version'=6, 'next header'=6>
234  */
235 #define RTE_PTYPE_L4_TCP                    0x00000100
236 /**
237  * UDP (User Datagram Protocol) packet type.
238  * It is used for outer packet for tunneling cases.
239  *
240  * Packet format:
241  * <'ether type'=0x0800
242  * | 'version'=4, 'protocol'=17, 'MF'=0>
243  * or,
244  * <'ether type'=0x86DD
245  * | 'version'=6, 'next header'=17>
246  */
247 #define RTE_PTYPE_L4_UDP                    0x00000200
248 /**
249  * Fragmented IP (Internet Protocol) packet type.
250  * It is used for outer packet for tunneling cases.
251  *
252  * It refers to those packets of any IP types, which can be recognized as
253  * fragmented. A fragmented packet cannot be recognized as any other L4 types
254  * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
255  * RTE_PTYPE_L4_NONFRAG).
256  *
257  * Packet format:
258  * <'ether type'=0x0800
259  * | 'version'=4, 'MF'=1>
260  * or,
261  * <'ether type'=0x86DD
262  * | 'version'=6, 'next header'=44>
263  */
264 #define RTE_PTYPE_L4_FRAG                   0x00000300
265 /**
266  * SCTP (Stream Control Transmission Protocol) packet type.
267  * It is used for outer packet for tunneling cases.
268  *
269  * Packet format:
270  * <'ether type'=0x0800
271  * | 'version'=4, 'protocol'=132, 'MF'=0>
272  * or,
273  * <'ether type'=0x86DD
274  * | 'version'=6, 'next header'=132>
275  */
276 #define RTE_PTYPE_L4_SCTP                   0x00000400
277 /**
278  * ICMP (Internet Control Message Protocol) packet type.
279  * It is used for outer packet for tunneling cases.
280  *
281  * Packet format:
282  * <'ether type'=0x0800
283  * | 'version'=4, 'protocol'=1, 'MF'=0>
284  * or,
285  * <'ether type'=0x86DD
286  * | 'version'=6, 'next header'=1>
287  */
288 #define RTE_PTYPE_L4_ICMP                   0x00000500
289 /**
290  * Non-fragmented IP (Internet Protocol) packet type.
291  * It is used for outer packet for tunneling cases.
292  *
293  * It refers to those packets of any IP types, while cannot be recognized as
294  * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
295  * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
296  *
297  * Packet format:
298  * <'ether type'=0x0800
299  * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0>
300  * or,
301  * <'ether type'=0x86DD
302  * | 'version'=6, 'next header'!=[6|17|44|132|1]>
303  */
304 #define RTE_PTYPE_L4_NONFRAG                0x00000600
305 /**
306  * Mask of layer 4 packet types.
307  * It is used for outer packet for tunneling cases.
308  */
309 #define RTE_PTYPE_L4_MASK                   0x00000f00
310 /**
311  * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
312  *
313  * Packet format:
314  * <'ether type'=0x0800
315  * | 'version'=4, 'protocol'=[4|41]>
316  * or,
317  * <'ether type'=0x86DD
318  * | 'version'=6, 'next header'=[4|41]>
319  */
320 #define RTE_PTYPE_TUNNEL_IP                 0x00001000
321 /**
322  * GRE (Generic Routing Encapsulation) tunneling packet type.
323  *
324  * Packet format:
325  * <'ether type'=0x0800
326  * | 'version'=4, 'protocol'=47>
327  * or,
328  * <'ether type'=0x86DD
329  * | 'version'=6, 'next header'=47>
330  */
331 #define RTE_PTYPE_TUNNEL_GRE                0x00002000
332 /**
333  * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
334  *
335  * Packet format:
336  * <'ether type'=0x0800
337  * | 'version'=4, 'protocol'=17
338  * | 'destination port'=4798>
339  * or,
340  * <'ether type'=0x86DD
341  * | 'version'=6, 'next header'=17
342  * | 'destination port'=4798>
343  */
344 #define RTE_PTYPE_TUNNEL_VXLAN              0x00003000
345 /**
346  * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
347  * packet type.
348  *
349  * Packet format:
350  * <'ether type'=0x0800
351  * | 'version'=4, 'protocol'=47
352  * | 'protocol type'=0x6558>
353  * or,
354  * <'ether type'=0x86DD
355  * | 'version'=6, 'next header'=47
356  * | 'protocol type'=0x6558'>
357  */
358 #define RTE_PTYPE_TUNNEL_NVGRE              0x00004000
359 /**
360  * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
361  *
362  * Packet format:
363  * <'ether type'=0x0800
364  * | 'version'=4, 'protocol'=17
365  * | 'destination port'=6081>
366  * or,
367  * <'ether type'=0x86DD
368  * | 'version'=6, 'next header'=17
369  * | 'destination port'=6081>
370  */
371 #define RTE_PTYPE_TUNNEL_GENEVE             0x00005000
372 /**
373  * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
374  * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
375  * packet type, if they can not be recognized independently as of hardware
376  * capability.
377  */
378 #define RTE_PTYPE_TUNNEL_GRENAT             0x00006000
379 /**
380  * Mask of tunneling packet types.
381  */
382 #define RTE_PTYPE_TUNNEL_MASK               0x0000f000
383 /**
384  * Ethernet packet type.
385  * It is used for inner packet type only.
386  *
387  * Packet format (inner only):
388  * <'ether type'=[0x800|0x86DD]>
389  */
390 #define RTE_PTYPE_INNER_L2_ETHER            0x00010000
391 /**
392  * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
393  *
394  * Packet format (inner only):
395  * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
396  */
397 #define RTE_PTYPE_INNER_L2_ETHER_VLAN       0x00020000
398 /**
399  * QinQ packet type.
400  *
401  * Packet format:
402  * <'ether type'=[0x88A8]>
403  */
404 #define RTE_PTYPE_INNER_L2_ETHER_QINQ       0x00030000
405 /**
406  * Mask of inner layer 2 packet types.
407  */
408 #define RTE_PTYPE_INNER_L2_MASK             0x000f0000
409 /**
410  * IP (Internet Protocol) version 4 packet type.
411  * It is used for inner packet only, and does not contain any header option.
412  *
413  * Packet format (inner only):
414  * <'ether type'=0x0800
415  * | 'version'=4, 'ihl'=5>
416  */
417 #define RTE_PTYPE_INNER_L3_IPV4             0x00100000
418 /**
419  * IP (Internet Protocol) version 4 packet type.
420  * It is used for inner packet only, and contains header options.
421  *
422  * Packet format (inner only):
423  * <'ether type'=0x0800
424  * | 'version'=4, 'ihl'=[6-15], 'options'>
425  */
426 #define RTE_PTYPE_INNER_L3_IPV4_EXT         0x00200000
427 /**
428  * IP (Internet Protocol) version 6 packet type.
429  * It is used for inner packet only, and does not contain any extension header.
430  *
431  * Packet format (inner only):
432  * <'ether type'=0x86DD
433  * | 'version'=6, 'next header'=0x3B>
434  */
435 #define RTE_PTYPE_INNER_L3_IPV6             0x00300000
436 /**
437  * IP (Internet Protocol) version 4 packet type.
438  * It is used for inner packet only, and may or maynot contain header options.
439  *
440  * Packet format (inner only):
441  * <'ether type'=0x0800
442  * | 'version'=4, 'ihl'=[5-15], <'options'>>
443  */
444 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
445 /**
446  * IP (Internet Protocol) version 6 packet type.
447  * It is used for inner packet only, and contains extension headers.
448  *
449  * Packet format (inner only):
450  * <'ether type'=0x86DD
451  * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
452  *   'extension headers'>
453  */
454 #define RTE_PTYPE_INNER_L3_IPV6_EXT         0x00500000
455 /**
456  * IP (Internet Protocol) version 6 packet type.
457  * It is used for inner packet only, and may or maynot contain extension
458  * headers.
459  *
460  * Packet format (inner only):
461  * <'ether type'=0x86DD
462  * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
463  *   <'extension headers'>>
464  */
465 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
466 /**
467  * Mask of inner layer 3 packet types.
468  */
469 #define RTE_PTYPE_INNER_L3_MASK             0x00f00000
470 /**
471  * TCP (Transmission Control Protocol) packet type.
472  * It is used for inner packet only.
473  *
474  * Packet format (inner only):
475  * <'ether type'=0x0800
476  * | 'version'=4, 'protocol'=6, 'MF'=0>
477  * or,
478  * <'ether type'=0x86DD
479  * | 'version'=6, 'next header'=6>
480  */
481 #define RTE_PTYPE_INNER_L4_TCP              0x01000000
482 /**
483  * UDP (User Datagram Protocol) packet type.
484  * It is used for inner packet only.
485  *
486  * Packet format (inner only):
487  * <'ether type'=0x0800
488  * | 'version'=4, 'protocol'=17, 'MF'=0>
489  * or,
490  * <'ether type'=0x86DD
491  * | 'version'=6, 'next header'=17>
492  */
493 #define RTE_PTYPE_INNER_L4_UDP              0x02000000
494 /**
495  * Fragmented IP (Internet Protocol) packet type.
496  * It is used for inner packet only, and may or maynot have layer 4 packet.
497  *
498  * Packet format (inner only):
499  * <'ether type'=0x0800
500  * | 'version'=4, 'MF'=1>
501  * or,
502  * <'ether type'=0x86DD
503  * | 'version'=6, 'next header'=44>
504  */
505 #define RTE_PTYPE_INNER_L4_FRAG             0x03000000
506 /**
507  * SCTP (Stream Control Transmission Protocol) packet type.
508  * It is used for inner packet only.
509  *
510  * Packet format (inner only):
511  * <'ether type'=0x0800
512  * | 'version'=4, 'protocol'=132, 'MF'=0>
513  * or,
514  * <'ether type'=0x86DD
515  * | 'version'=6, 'next header'=132>
516  */
517 #define RTE_PTYPE_INNER_L4_SCTP             0x04000000
518 /**
519  * ICMP (Internet Control Message Protocol) packet type.
520  * It is used for inner packet only.
521  *
522  * Packet format (inner only):
523  * <'ether type'=0x0800
524  * | 'version'=4, 'protocol'=1, 'MF'=0>
525  * or,
526  * <'ether type'=0x86DD
527  * | 'version'=6, 'next header'=1>
528  */
529 #define RTE_PTYPE_INNER_L4_ICMP             0x05000000
530 /**
531  * Non-fragmented IP (Internet Protocol) packet type.
532  * It is used for inner packet only, and may or maynot have other unknown layer
533  * 4 packet types.
534  *
535  * Packet format (inner only):
536  * <'ether type'=0x0800
537  * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0>
538  * or,
539  * <'ether type'=0x86DD
540  * | 'version'=6, 'next header'!=[6|17|44|132|1]>
541  */
542 #define RTE_PTYPE_INNER_L4_NONFRAG          0x06000000
543 /**
544  * Mask of inner layer 4 packet types.
545  */
546 #define RTE_PTYPE_INNER_L4_MASK             0x0f000000
547
548 /**
549  * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
550  * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
551  * determine if it is an IPV4 packet.
552  */
553 #define  RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
554
555 /**
556  * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
557  * one, bit 6 is selected to be used for IPv4 only. Then checking bit 6 can
558  * determine if it is an IPV4 packet.
559  */
560 #define  RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
561
562 /* Check if it is a tunneling packet */
563 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) &                         \
564         (RTE_PTYPE_TUNNEL_MASK |                                        \
565                 RTE_PTYPE_INNER_L2_MASK |                               \
566                 RTE_PTYPE_INNER_L3_MASK |                               \
567                 RTE_PTYPE_INNER_L4_MASK))
568
569 #ifdef __cplusplus
570 }
571 #endif
572
573 #endif /* _RTE_MBUF_PTYPE_H_ */