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