4 * Copyright(c) 2010-2016 Intel Corporation.
5 * Copyright 2014-2016 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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
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.
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.
35 #ifndef _RTE_MBUF_PTYPE_H_
36 #define _RTE_MBUF_PTYPE_H_
40 * RTE Mbuf Packet Types
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.
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.
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.
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.
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.
70 * <'ether type'=0x0800
71 * | 'version'=4, 'protocol'=0x29
72 * | 'version'=6, 'next header'=0x3A
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.
81 * <'ether type'=0x86DD
82 * | 'version'=6, 'next header'=0x2F
84 * | 'version'=6, 'next header'=0x11
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.
102 * No packet type information.
104 #define RTE_PTYPE_UNKNOWN 0x00000000
106 * Ethernet packet type.
107 * It is used for outer packet for tunneling cases.
110 * <'ether type'=[0x0800|0x86DD]>
112 #define RTE_PTYPE_L2_ETHER 0x00000001
114 * Ethernet packet type for time sync.
117 * <'ether type'=0x88F7>
119 #define RTE_PTYPE_L2_ETHER_TIMESYNC 0x00000002
121 * ARP (Address Resolution Protocol) packet type.
124 * <'ether type'=0x0806>
126 #define RTE_PTYPE_L2_ETHER_ARP 0x00000003
128 * LLDP (Link Layer Discovery Protocol) packet type.
131 * <'ether type'=0x88CC>
133 #define RTE_PTYPE_L2_ETHER_LLDP 0x00000004
135 * NSH (Network Service Header) packet type.
138 * <'ether type'=0x894F>
140 #define RTE_PTYPE_L2_ETHER_NSH 0x00000005
145 * <'ether type'=[0x8100]>
147 #define RTE_PTYPE_L2_ETHER_VLAN 0x00000006
152 * <'ether type'=[0x88A8]>
154 #define RTE_PTYPE_L2_ETHER_QINQ 0x00000007
156 * Mask of layer 2 packet types.
157 * It is used for outer packet for tunneling cases.
159 #define RTE_PTYPE_L2_MASK 0x0000000f
161 * IP (Internet Protocol) version 4 packet type.
162 * It is used for outer packet for tunneling cases, and does not contain any
166 * <'ether type'=0x0800
167 * | 'version'=4, 'ihl'=5>
169 #define RTE_PTYPE_L3_IPV4 0x00000010
171 * IP (Internet Protocol) version 4 packet type.
172 * It is used for outer packet for tunneling cases, and contains header
176 * <'ether type'=0x0800
177 * | 'version'=4, 'ihl'=[6-15], 'options'>
179 #define RTE_PTYPE_L3_IPV4_EXT 0x00000030
181 * IP (Internet Protocol) version 6 packet type.
182 * It is used for outer packet for tunneling cases, and does not contain any
186 * <'ether type'=0x86DD
187 * | 'version'=6, 'next header'=0x3B>
189 #define RTE_PTYPE_L3_IPV6 0x00000040
191 * IP (Internet Protocol) version 4 packet type.
192 * It is used for outer packet for tunneling cases, and may or maynot contain
196 * <'ether type'=0x0800
197 * | 'version'=4, 'ihl'=[5-15], <'options'>>
199 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN 0x00000090
201 * IP (Internet Protocol) version 6 packet type.
202 * It is used for outer packet for tunneling cases, and contains extension
206 * <'ether type'=0x86DD
207 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
208 * 'extension headers'>
210 #define RTE_PTYPE_L3_IPV6_EXT 0x000000c0
212 * IP (Internet Protocol) version 6 packet type.
213 * It is used for outer packet for tunneling cases, and may or maynot contain
217 * <'ether type'=0x86DD
218 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
219 * <'extension headers'>>
221 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN 0x000000e0
223 * Mask of layer 3 packet types.
224 * It is used for outer packet for tunneling cases.
226 #define RTE_PTYPE_L3_MASK 0x000000f0
228 * TCP (Transmission Control Protocol) packet type.
229 * It is used for outer packet for tunneling cases.
232 * <'ether type'=0x0800
233 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
235 * <'ether type'=0x86DD
236 * | 'version'=6, 'next header'=6>
238 #define RTE_PTYPE_L4_TCP 0x00000100
240 * UDP (User Datagram Protocol) packet type.
241 * It is used for outer packet for tunneling cases.
244 * <'ether type'=0x0800
245 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
247 * <'ether type'=0x86DD
248 * | 'version'=6, 'next header'=17>
250 #define RTE_PTYPE_L4_UDP 0x00000200
252 * Fragmented IP (Internet Protocol) packet type.
253 * It is used for outer packet for tunneling cases.
255 * It refers to those packets of any IP types, which can be recognized as
256 * fragmented. A fragmented packet cannot be recognized as any other L4 types
257 * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
258 * RTE_PTYPE_L4_NONFRAG).
261 * <'ether type'=0x0800
262 * | 'version'=4, 'MF'=1>
264 * <'ether type'=0x0800
265 * | 'version'=4, 'frag_offset'!=0>
267 * <'ether type'=0x86DD
268 * | 'version'=6, 'next header'=44>
270 #define RTE_PTYPE_L4_FRAG 0x00000300
272 * SCTP (Stream Control Transmission Protocol) packet type.
273 * It is used for outer packet for tunneling cases.
276 * <'ether type'=0x0800
277 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
279 * <'ether type'=0x86DD
280 * | 'version'=6, 'next header'=132>
282 #define RTE_PTYPE_L4_SCTP 0x00000400
284 * ICMP (Internet Control Message Protocol) packet type.
285 * It is used for outer packet for tunneling cases.
288 * <'ether type'=0x0800
289 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
291 * <'ether type'=0x86DD
292 * | 'version'=6, 'next header'=1>
294 #define RTE_PTYPE_L4_ICMP 0x00000500
296 * Non-fragmented IP (Internet Protocol) packet type.
297 * It is used for outer packet for tunneling cases.
299 * It refers to those packets of any IP types, while cannot be recognized as
300 * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
301 * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
304 * <'ether type'=0x0800
305 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
307 * <'ether type'=0x86DD
308 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
310 #define RTE_PTYPE_L4_NONFRAG 0x00000600
312 * Mask of layer 4 packet types.
313 * It is used for outer packet for tunneling cases.
315 #define RTE_PTYPE_L4_MASK 0x00000f00
317 * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
320 * <'ether type'=0x0800
321 * | 'version'=4, 'protocol'=[4|41]>
323 * <'ether type'=0x86DD
324 * | 'version'=6, 'next header'=[4|41]>
326 #define RTE_PTYPE_TUNNEL_IP 0x00001000
328 * GRE (Generic Routing Encapsulation) tunneling packet type.
331 * <'ether type'=0x0800
332 * | 'version'=4, 'protocol'=47>
334 * <'ether type'=0x86DD
335 * | 'version'=6, 'next header'=47>
337 #define RTE_PTYPE_TUNNEL_GRE 0x00002000
339 * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
342 * <'ether type'=0x0800
343 * | 'version'=4, 'protocol'=17
344 * | 'destination port'=4789>
346 * <'ether type'=0x86DD
347 * | 'version'=6, 'next header'=17
348 * | 'destination port'=4789>
350 #define RTE_PTYPE_TUNNEL_VXLAN 0x00003000
352 * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
356 * <'ether type'=0x0800
357 * | 'version'=4, 'protocol'=47
358 * | 'protocol type'=0x6558>
360 * <'ether type'=0x86DD
361 * | 'version'=6, 'next header'=47
362 * | 'protocol type'=0x6558'>
364 #define RTE_PTYPE_TUNNEL_NVGRE 0x00004000
366 * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
369 * <'ether type'=0x0800
370 * | 'version'=4, 'protocol'=17
371 * | 'destination port'=6081>
373 * <'ether type'=0x86DD
374 * | 'version'=6, 'next header'=17
375 * | 'destination port'=6081>
377 #define RTE_PTYPE_TUNNEL_GENEVE 0x00005000
379 * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
380 * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
381 * packet type, if they can not be recognized independently as of hardware
384 #define RTE_PTYPE_TUNNEL_GRENAT 0x00006000
386 * GTP-C (GPRS Tunnelling Protocol) control tunneling packet type.
388 * <'ether type'=0x0800
389 * | 'version'=4, 'protocol'=17
390 * | 'destination port'=2123>
392 * <'ether type'=0x86DD
393 * | 'version'=6, 'next header'=17
394 * | 'destination port'=2123>
396 * <'ether type'=0x0800
397 * | 'version'=4, 'protocol'=17
398 * | 'source port'=2123>
400 * <'ether type'=0x86DD
401 * | 'version'=6, 'next header'=17
402 * | 'source port'=2123>
404 #define RTE_PTYPE_TUNNEL_GTPC 0x00007000
406 * GTP-U (GPRS Tunnelling Protocol) user data tunneling packet type.
408 * <'ether type'=0x0800
409 * | 'version'=4, 'protocol'=17
410 * | 'destination port'=2152>
412 * <'ether type'=0x86DD
413 * | 'version'=6, 'next header'=17
414 * | 'destination port'=2152>
416 #define RTE_PTYPE_TUNNEL_GTPU 0x00008000
418 * Mask of tunneling packet types.
420 #define RTE_PTYPE_TUNNEL_MASK 0x0000f000
422 * Ethernet packet type.
423 * It is used for inner packet type only.
425 * Packet format (inner only):
426 * <'ether type'=[0x800|0x86DD]>
428 #define RTE_PTYPE_INNER_L2_ETHER 0x00010000
430 * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
432 * Packet format (inner only):
433 * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
435 #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000
440 * <'ether type'=[0x88A8]>
442 #define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000
444 * Mask of inner layer 2 packet types.
446 #define RTE_PTYPE_INNER_L2_MASK 0x000f0000
448 * IP (Internet Protocol) version 4 packet type.
449 * It is used for inner packet only, and does not contain any header option.
451 * Packet format (inner only):
452 * <'ether type'=0x0800
453 * | 'version'=4, 'ihl'=5>
455 #define RTE_PTYPE_INNER_L3_IPV4 0x00100000
457 * IP (Internet Protocol) version 4 packet type.
458 * It is used for inner packet only, and contains header options.
460 * Packet format (inner only):
461 * <'ether type'=0x0800
462 * | 'version'=4, 'ihl'=[6-15], 'options'>
464 #define RTE_PTYPE_INNER_L3_IPV4_EXT 0x00200000
466 * IP (Internet Protocol) version 6 packet type.
467 * It is used for inner packet only, and does not contain any extension header.
469 * Packet format (inner only):
470 * <'ether type'=0x86DD
471 * | 'version'=6, 'next header'=0x3B>
473 #define RTE_PTYPE_INNER_L3_IPV6 0x00300000
475 * IP (Internet Protocol) version 4 packet type.
476 * It is used for inner packet only, and may or maynot contain header options.
478 * Packet format (inner only):
479 * <'ether type'=0x0800
480 * | 'version'=4, 'ihl'=[5-15], <'options'>>
482 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
484 * IP (Internet Protocol) version 6 packet type.
485 * It is used for inner packet only, and contains extension headers.
487 * Packet format (inner only):
488 * <'ether type'=0x86DD
489 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
490 * 'extension headers'>
492 #define RTE_PTYPE_INNER_L3_IPV6_EXT 0x00500000
494 * IP (Internet Protocol) version 6 packet type.
495 * It is used for inner packet only, and may or maynot contain extension
498 * Packet format (inner only):
499 * <'ether type'=0x86DD
500 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
501 * <'extension headers'>>
503 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
505 * Mask of inner layer 3 packet types.
507 #define RTE_PTYPE_INNER_L3_MASK 0x00f00000
509 * TCP (Transmission Control Protocol) packet type.
510 * It is used for inner packet only.
512 * Packet format (inner only):
513 * <'ether type'=0x0800
514 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
516 * <'ether type'=0x86DD
517 * | 'version'=6, 'next header'=6>
519 #define RTE_PTYPE_INNER_L4_TCP 0x01000000
521 * UDP (User Datagram Protocol) packet type.
522 * It is used for inner packet only.
524 * Packet format (inner only):
525 * <'ether type'=0x0800
526 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
528 * <'ether type'=0x86DD
529 * | 'version'=6, 'next header'=17>
531 #define RTE_PTYPE_INNER_L4_UDP 0x02000000
533 * Fragmented IP (Internet Protocol) packet type.
534 * It is used for inner packet only, and may or maynot have layer 4 packet.
536 * Packet format (inner only):
537 * <'ether type'=0x0800
538 * | 'version'=4, 'MF'=1>
540 * <'ether type'=0x0800
541 * | 'version'=4, 'frag_offset'!=0>
543 * <'ether type'=0x86DD
544 * | 'version'=6, 'next header'=44>
546 #define RTE_PTYPE_INNER_L4_FRAG 0x03000000
548 * SCTP (Stream Control Transmission Protocol) packet type.
549 * It is used for inner packet only.
551 * Packet format (inner only):
552 * <'ether type'=0x0800
553 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
555 * <'ether type'=0x86DD
556 * | 'version'=6, 'next header'=132>
558 #define RTE_PTYPE_INNER_L4_SCTP 0x04000000
560 * ICMP (Internet Control Message Protocol) packet type.
561 * It is used for inner packet only.
563 * Packet format (inner only):
564 * <'ether type'=0x0800
565 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
567 * <'ether type'=0x86DD
568 * | 'version'=6, 'next header'=1>
570 #define RTE_PTYPE_INNER_L4_ICMP 0x05000000
572 * Non-fragmented IP (Internet Protocol) packet type.
573 * It is used for inner packet only, and may or maynot have other unknown layer
576 * Packet format (inner only):
577 * <'ether type'=0x0800
578 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
580 * <'ether type'=0x86DD
581 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
583 #define RTE_PTYPE_INNER_L4_NONFRAG 0x06000000
585 * Mask of inner layer 4 packet types.
587 #define RTE_PTYPE_INNER_L4_MASK 0x0f000000
589 * All valid layer masks.
591 #define RTE_PTYPE_ALL_MASK 0x0fffffff
594 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
595 * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
596 * determine if it is an IPV4 packet.
598 #define RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
601 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
602 * one, bit 6 is selected to be used for IPv4 only. Then checking bit 6 can
603 * determine if it is an IPV4 packet.
605 #define RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
607 /* Check if it is a tunneling packet */
608 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) & \
609 (RTE_PTYPE_TUNNEL_MASK | \
610 RTE_PTYPE_INNER_L2_MASK | \
611 RTE_PTYPE_INNER_L3_MASK | \
612 RTE_PTYPE_INNER_L4_MASK))
615 * Get the name of the l2 packet type
618 * The packet type value.
620 * A non-null string describing the packet type.
622 const char *rte_get_ptype_l2_name(uint32_t ptype);
625 * Get the name of the l3 packet type
628 * The packet type value.
630 * A non-null string describing the packet type.
632 const char *rte_get_ptype_l3_name(uint32_t ptype);
635 * Get the name of the l4 packet type
638 * The packet type value.
640 * A non-null string describing the packet type.
642 const char *rte_get_ptype_l4_name(uint32_t ptype);
645 * Get the name of the tunnel packet type
648 * The packet type value.
650 * A non-null string describing the packet type.
652 const char *rte_get_ptype_tunnel_name(uint32_t ptype);
655 * Get the name of the inner_l2 packet type
658 * The packet type value.
660 * A non-null string describing the packet type.
662 const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
665 * Get the name of the inner_l3 packet type
668 * The packet type value.
670 * A non-null string describing the packet type.
672 const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
675 * Get the name of the inner_l4 packet type
678 * The packet type value.
680 * A non-null string describing the packet type.
682 const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
685 * Write the packet type name into the buffer
688 * The packet type value.
690 * The buffer where the string is written.
692 * The length of the buffer.
695 * - (-1) if the buffer is too small
697 int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
703 #endif /* _RTE_MBUF_PTYPE_H_ */