1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2014-2016 6WIND S.A.
6 #ifndef _RTE_MBUF_PTYPE_H_
7 #define _RTE_MBUF_PTYPE_H_
11 * RTE Mbuf Packet Types
13 * This file contains declarations for features related to mbuf packet
14 * types. The packet type gives information about the data carried by the
15 * mbuf, and is stored in the mbuf in a 32 bits field.
17 * The 32 bits are divided into several fields to mark packet types. Note that
18 * each field is indexical.
19 * - Bit 3:0 is for L2 types.
20 * - Bit 7:4 is for L3 or outer L3 (for tunneling case) types.
21 * - Bit 11:8 is for L4 or outer L4 (for tunneling case) types.
22 * - Bit 15:12 is for tunnel types.
23 * - Bit 19:16 is for inner L2 types.
24 * - Bit 23:20 is for inner L3 types.
25 * - Bit 27:24 is for inner L4 types.
26 * - Bit 31:28 is reserved.
28 * To be compatible with Vector PMD, RTE_PTYPE_L3_IPV4, RTE_PTYPE_L3_IPV4_EXT,
29 * RTE_PTYPE_L3_IPV6, RTE_PTYPE_L3_IPV6_EXT, RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP
30 * and RTE_PTYPE_L4_SCTP should be kept as below in a contiguous 7 bits.
32 * Note that L3 types values are selected for checking IPV4/IPV6 header from
33 * performance point of view. Reading annotations of RTE_ETH_IS_IPV4_HDR and
34 * RTE_ETH_IS_IPV6_HDR is needed for any future changes of L3 type values.
36 * Note that the packet types of the same packet recognized by different
37 * hardware may be different, as different hardware may have different
38 * capability of packet type recognition.
41 * <'ether type'=0x0800
42 * | 'version'=4, 'protocol'=0x29
43 * | 'version'=6, 'next header'=0x3A
45 * will be recognized on i40e hardware as packet type combination of,
46 * RTE_PTYPE_L2_ETHER |
47 * RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
48 * RTE_PTYPE_TUNNEL_IP |
49 * RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
50 * RTE_PTYPE_INNER_L4_ICMP.
52 * <'ether type'=0x86DD
53 * | 'version'=6, 'next header'=0x2F
55 * | 'version'=6, 'next header'=0x11
57 * will be recognized on i40e hardware as packet type combination of,
58 * RTE_PTYPE_L2_ETHER |
59 * RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
60 * RTE_PTYPE_TUNNEL_GRENAT |
61 * RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
62 * RTE_PTYPE_INNER_L4_UDP.
73 * No packet type information.
75 #define RTE_PTYPE_UNKNOWN 0x00000000
77 * Ethernet packet type.
78 * It is used for outer packet for tunneling cases.
81 * <'ether type'=[0x0800|0x86DD]>
83 #define RTE_PTYPE_L2_ETHER 0x00000001
85 * Ethernet packet type for time sync.
88 * <'ether type'=0x88F7>
90 #define RTE_PTYPE_L2_ETHER_TIMESYNC 0x00000002
92 * ARP (Address Resolution Protocol) packet type.
95 * <'ether type'=0x0806>
97 #define RTE_PTYPE_L2_ETHER_ARP 0x00000003
99 * LLDP (Link Layer Discovery Protocol) packet type.
102 * <'ether type'=0x88CC>
104 #define RTE_PTYPE_L2_ETHER_LLDP 0x00000004
106 * NSH (Network Service Header) packet type.
109 * <'ether type'=0x894F>
111 #define RTE_PTYPE_L2_ETHER_NSH 0x00000005
116 * <'ether type'=[0x8100]>
118 #define RTE_PTYPE_L2_ETHER_VLAN 0x00000006
123 * <'ether type'=[0x88A8]>
125 #define RTE_PTYPE_L2_ETHER_QINQ 0x00000007
130 * <'ether type'=[0x8863|0x8864]>
132 #define RTE_PTYPE_L2_ETHER_PPPOE 0x00000008
137 * <'ether type'=[0x8906]>
139 #define RTE_PTYPE_L2_ETHER_FCOE 0x00000009
144 * <'ether type'=[0x8847|0x8848]>
146 #define RTE_PTYPE_L2_ETHER_MPLS 0x0000000a
148 * Mask of layer 2 packet types.
149 * It is used for outer packet for tunneling cases.
151 #define RTE_PTYPE_L2_MASK 0x0000000f
153 * IP (Internet Protocol) version 4 packet type.
154 * It is used for outer packet for tunneling cases, and does not contain any
158 * <'ether type'=0x0800
159 * | 'version'=4, 'ihl'=5>
161 #define RTE_PTYPE_L3_IPV4 0x00000010
163 * IP (Internet Protocol) version 4 packet type.
164 * It is used for outer packet for tunneling cases, and contains header
168 * <'ether type'=0x0800
169 * | 'version'=4, 'ihl'=[6-15], 'options'>
171 #define RTE_PTYPE_L3_IPV4_EXT 0x00000030
173 * IP (Internet Protocol) version 6 packet type.
174 * It is used for outer packet for tunneling cases, and does not contain any
178 * <'ether type'=0x86DD
179 * | 'version'=6, 'next header'=0x3B>
181 #define RTE_PTYPE_L3_IPV6 0x00000040
183 * IP (Internet Protocol) version 4 packet type.
184 * It is used for outer packet for tunneling cases, and may or maynot contain
188 * <'ether type'=0x0800
189 * | 'version'=4, 'ihl'=[5-15], <'options'>>
191 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN 0x00000090
193 * IP (Internet Protocol) version 6 packet type.
194 * It is used for outer packet for tunneling cases, and contains extension
198 * <'ether type'=0x86DD
199 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
200 * 'extension headers'>
202 #define RTE_PTYPE_L3_IPV6_EXT 0x000000c0
204 * IP (Internet Protocol) version 6 packet type.
205 * It is used for outer packet for tunneling cases, and may or maynot contain
209 * <'ether type'=0x86DD
210 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
211 * <'extension headers'>>
213 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN 0x000000e0
215 * Mask of layer 3 packet types.
216 * It is used for outer packet for tunneling cases.
218 #define RTE_PTYPE_L3_MASK 0x000000f0
220 * TCP (Transmission Control Protocol) packet type.
221 * It is used for outer packet for tunneling cases.
224 * <'ether type'=0x0800
225 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
227 * <'ether type'=0x86DD
228 * | 'version'=6, 'next header'=6>
230 #define RTE_PTYPE_L4_TCP 0x00000100
232 * UDP (User Datagram Protocol) packet type.
233 * It is used for outer packet for tunneling cases.
236 * <'ether type'=0x0800
237 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
239 * <'ether type'=0x86DD
240 * | 'version'=6, 'next header'=17>
242 #define RTE_PTYPE_L4_UDP 0x00000200
244 * Fragmented IP (Internet Protocol) packet type.
245 * It is used for outer packet for tunneling cases.
247 * It refers to those packets of any IP types, which can be recognized as
248 * fragmented. A fragmented packet cannot be recognized as any other L4 types
249 * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
250 * RTE_PTYPE_L4_NONFRAG).
253 * <'ether type'=0x0800
254 * | 'version'=4, 'MF'=1>
256 * <'ether type'=0x0800
257 * | 'version'=4, 'frag_offset'!=0>
259 * <'ether type'=0x86DD
260 * | 'version'=6, 'next header'=44>
262 #define RTE_PTYPE_L4_FRAG 0x00000300
264 * SCTP (Stream Control Transmission Protocol) packet type.
265 * It is used for outer packet for tunneling cases.
268 * <'ether type'=0x0800
269 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
271 * <'ether type'=0x86DD
272 * | 'version'=6, 'next header'=132>
274 #define RTE_PTYPE_L4_SCTP 0x00000400
276 * ICMP (Internet Control Message Protocol) packet type.
277 * It is used for outer packet for tunneling cases.
280 * <'ether type'=0x0800
281 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
283 * <'ether type'=0x86DD
284 * | 'version'=6, 'next header'=1>
286 #define RTE_PTYPE_L4_ICMP 0x00000500
288 * Non-fragmented IP (Internet Protocol) packet type.
289 * It is used for outer packet for tunneling cases.
291 * It refers to those packets of any IP types, while cannot be recognized as
292 * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
293 * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
296 * <'ether type'=0x0800
297 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
299 * <'ether type'=0x86DD
300 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
302 #define RTE_PTYPE_L4_NONFRAG 0x00000600
304 * Mask of layer 4 packet types.
305 * It is used for outer packet for tunneling cases.
307 #define RTE_PTYPE_L4_MASK 0x00000f00
309 * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
312 * <'ether type'=0x0800
313 * | 'version'=4, 'protocol'=[4|41]>
315 * <'ether type'=0x86DD
316 * | 'version'=6, 'next header'=[4|41]>
318 #define RTE_PTYPE_TUNNEL_IP 0x00001000
320 * GRE (Generic Routing Encapsulation) tunneling packet type.
323 * <'ether type'=0x0800
324 * | 'version'=4, 'protocol'=47>
326 * <'ether type'=0x86DD
327 * | 'version'=6, 'next header'=47>
329 #define RTE_PTYPE_TUNNEL_GRE 0x00002000
331 * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
334 * <'ether type'=0x0800
335 * | 'version'=4, 'protocol'=17
336 * | 'destination port'=4789>
338 * <'ether type'=0x86DD
339 * | 'version'=6, 'next header'=17
340 * | 'destination port'=4789>
342 #define RTE_PTYPE_TUNNEL_VXLAN 0x00003000
344 * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
348 * <'ether type'=0x0800
349 * | 'version'=4, 'protocol'=47
350 * | 'protocol type'=0x6558>
352 * <'ether type'=0x86DD
353 * | 'version'=6, 'next header'=47
354 * | 'protocol type'=0x6558'>
356 #define RTE_PTYPE_TUNNEL_NVGRE 0x00004000
358 * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
361 * <'ether type'=0x0800
362 * | 'version'=4, 'protocol'=17
363 * | 'destination port'=6081>
365 * <'ether type'=0x86DD
366 * | 'version'=6, 'next header'=17
367 * | 'destination port'=6081>
369 #define RTE_PTYPE_TUNNEL_GENEVE 0x00005000
371 * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
372 * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
373 * packet type, if they can not be recognized independently as of hardware
376 #define RTE_PTYPE_TUNNEL_GRENAT 0x00006000
378 * GTP-C (GPRS Tunnelling Protocol) control tunneling packet type.
380 * <'ether type'=0x0800
381 * | 'version'=4, 'protocol'=17
382 * | 'destination port'=2123>
384 * <'ether type'=0x86DD
385 * | 'version'=6, 'next header'=17
386 * | 'destination port'=2123>
388 * <'ether type'=0x0800
389 * | 'version'=4, 'protocol'=17
390 * | 'source port'=2123>
392 * <'ether type'=0x86DD
393 * | 'version'=6, 'next header'=17
394 * | 'source port'=2123>
396 #define RTE_PTYPE_TUNNEL_GTPC 0x00007000
398 * GTP-U (GPRS Tunnelling Protocol) user data tunneling packet type.
400 * <'ether type'=0x0800
401 * | 'version'=4, 'protocol'=17
402 * | 'destination port'=2152>
404 * <'ether type'=0x86DD
405 * | 'version'=6, 'next header'=17
406 * | 'destination port'=2152>
408 #define RTE_PTYPE_TUNNEL_GTPU 0x00008000
410 * ESP (IP Encapsulating Security Payload) tunneling packet type.
413 * <'ether type'=0x0800
414 * | 'version'=4, 'protocol'=51>
416 * <'ether type'=0x86DD
417 * | 'version'=6, 'next header'=51>
419 #define RTE_PTYPE_TUNNEL_ESP 0x00009000
421 * L2TP (Layer 2 Tunneling Protocol) tunnleing packet type.
424 * <'ether type'=0x0800
425 * | 'version'=4, 'protocol'=17>
426 * | 'destination port'=1701>
428 * <'ether type'=0x86DD
429 * | 'version'=6, 'next header'=17
430 * | 'destination port'=1701>
432 * <'ether type'=0x0800
433 * | 'version'=4, 'protocol'=115>
435 * <'ether type'=0x86DD
436 * | 'version'=6, 'protocol'=115>
438 #define RTE_PTYPE_TUNNEL_L2TP 0x0000a000
440 * VXLAN-GPE (VXLAN Generic Protocol Extension) tunneling packet type.
443 * <'ether type'=0x0800
444 * | 'version'=4, 'protocol'=17
445 * | 'destination port'=4790>
447 * <'ether type'=0x86DD
448 * | 'version'=6, 'next header'=17
449 * | 'destination port'=4790>
451 #define RTE_PTYPE_TUNNEL_VXLAN_GPE 0x0000b000
453 * MPLS-in-GRE tunneling packet type (RFC 4023).
456 * <'ether type'=0x0800
457 * | 'version'=4, 'protocol'=47
458 * | 'protocol'=0x8847>
460 * <'ether type'=0x0800
461 * | 'version'=4, 'protocol'=47
462 * | 'protocol'=0x8848>
464 * <'ether type'=0x86DD
465 * | 'version'=6, 'protocol'=47
466 * | 'protocol'=0x8847>
468 * <'ether type'=0x86DD
469 * | 'version'=6, 'next header'=47
470 * | 'protocol'=0x8848>
472 #define RTE_PTYPE_TUNNEL_MPLS_IN_GRE 0x0000c000
474 * MPLS-in-UDP tunneling packet type (RFC 7510).
477 * <'ether type'=0x0800
478 * | 'version'=4, 'protocol'=17
479 * | 'destination port'=6635>
481 * <'ether type'=0x86DD
482 * | 'version'=6, 'next header'=17
483 * | 'destination port'=6635>
485 #define RTE_PTYPE_TUNNEL_MPLS_IN_UDP 0x0000d000
487 * Mask of tunneling packet types.
489 #define RTE_PTYPE_TUNNEL_MASK 0x0000f000
491 * Ethernet packet type.
492 * It is used for inner packet type only.
494 * Packet format (inner only):
495 * <'ether type'=[0x800|0x86DD]>
497 #define RTE_PTYPE_INNER_L2_ETHER 0x00010000
499 * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
501 * Packet format (inner only):
502 * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
504 #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000
509 * <'ether type'=[0x88A8]>
511 #define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000
513 * Mask of inner layer 2 packet types.
515 #define RTE_PTYPE_INNER_L2_MASK 0x000f0000
517 * IP (Internet Protocol) version 4 packet type.
518 * It is used for inner packet only, and does not contain any header option.
520 * Packet format (inner only):
521 * <'ether type'=0x0800
522 * | 'version'=4, 'ihl'=5>
524 #define RTE_PTYPE_INNER_L3_IPV4 0x00100000
526 * IP (Internet Protocol) version 4 packet type.
527 * It is used for inner packet only, and contains header options.
529 * Packet format (inner only):
530 * <'ether type'=0x0800
531 * | 'version'=4, 'ihl'=[6-15], 'options'>
533 #define RTE_PTYPE_INNER_L3_IPV4_EXT 0x00200000
535 * IP (Internet Protocol) version 6 packet type.
536 * It is used for inner packet only, and does not contain any extension header.
538 * Packet format (inner only):
539 * <'ether type'=0x86DD
540 * | 'version'=6, 'next header'=0x3B>
542 #define RTE_PTYPE_INNER_L3_IPV6 0x00300000
544 * IP (Internet Protocol) version 4 packet type.
545 * It is used for inner packet only, and may or maynot contain header options.
547 * Packet format (inner only):
548 * <'ether type'=0x0800
549 * | 'version'=4, 'ihl'=[5-15], <'options'>>
551 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
553 * IP (Internet Protocol) version 6 packet type.
554 * It is used for inner packet only, and contains extension headers.
556 * Packet format (inner only):
557 * <'ether type'=0x86DD
558 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
559 * 'extension headers'>
561 #define RTE_PTYPE_INNER_L3_IPV6_EXT 0x00500000
563 * IP (Internet Protocol) version 6 packet type.
564 * It is used for inner packet only, and may or maynot contain extension
567 * Packet format (inner only):
568 * <'ether type'=0x86DD
569 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
570 * <'extension headers'>>
572 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
574 * Mask of inner layer 3 packet types.
576 #define RTE_PTYPE_INNER_L3_MASK 0x00f00000
578 * TCP (Transmission Control Protocol) packet type.
579 * It is used for inner packet only.
581 * Packet format (inner only):
582 * <'ether type'=0x0800
583 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
585 * <'ether type'=0x86DD
586 * | 'version'=6, 'next header'=6>
588 #define RTE_PTYPE_INNER_L4_TCP 0x01000000
590 * UDP (User Datagram Protocol) packet type.
591 * It is used for inner packet only.
593 * Packet format (inner only):
594 * <'ether type'=0x0800
595 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
597 * <'ether type'=0x86DD
598 * | 'version'=6, 'next header'=17>
600 #define RTE_PTYPE_INNER_L4_UDP 0x02000000
602 * Fragmented IP (Internet Protocol) packet type.
603 * It is used for inner packet only, and may or maynot have layer 4 packet.
605 * Packet format (inner only):
606 * <'ether type'=0x0800
607 * | 'version'=4, 'MF'=1>
609 * <'ether type'=0x0800
610 * | 'version'=4, 'frag_offset'!=0>
612 * <'ether type'=0x86DD
613 * | 'version'=6, 'next header'=44>
615 #define RTE_PTYPE_INNER_L4_FRAG 0x03000000
617 * SCTP (Stream Control Transmission Protocol) packet type.
618 * It is used for inner packet only.
620 * Packet format (inner only):
621 * <'ether type'=0x0800
622 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
624 * <'ether type'=0x86DD
625 * | 'version'=6, 'next header'=132>
627 #define RTE_PTYPE_INNER_L4_SCTP 0x04000000
629 * ICMP (Internet Control Message Protocol) packet type.
630 * It is used for inner packet only.
632 * Packet format (inner only):
633 * <'ether type'=0x0800
634 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
636 * <'ether type'=0x86DD
637 * | 'version'=6, 'next header'=1>
639 #define RTE_PTYPE_INNER_L4_ICMP 0x05000000
641 * Non-fragmented IP (Internet Protocol) packet type.
642 * It is used for inner packet only, and may or maynot have other unknown layer
645 * Packet format (inner only):
646 * <'ether type'=0x0800
647 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
649 * <'ether type'=0x86DD
650 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
652 #define RTE_PTYPE_INNER_L4_NONFRAG 0x06000000
654 * Mask of inner layer 4 packet types.
656 #define RTE_PTYPE_INNER_L4_MASK 0x0f000000
658 * All valid layer masks.
660 #define RTE_PTYPE_ALL_MASK 0x0fffffff
663 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
664 * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
665 * determine if it is an IPV4 packet.
667 #define RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
670 * Check if the (outer) L3 header is IPv6. To avoid comparing IPv6 types one by
671 * one, bit 6 is selected to be used for IPv6 only. Then checking bit 6 can
672 * determine if it is an IPV6 packet.
674 #define RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
676 /* Check if it is a tunneling packet */
677 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) & \
678 (RTE_PTYPE_TUNNEL_MASK | \
679 RTE_PTYPE_INNER_L2_MASK | \
680 RTE_PTYPE_INNER_L3_MASK | \
681 RTE_PTYPE_INNER_L4_MASK))
684 * Get the name of the l2 packet type
687 * The packet type value.
689 * A non-null string describing the packet type.
691 const char *rte_get_ptype_l2_name(uint32_t ptype);
694 * Get the name of the l3 packet type
697 * The packet type value.
699 * A non-null string describing the packet type.
701 const char *rte_get_ptype_l3_name(uint32_t ptype);
704 * Get the name of the l4 packet type
707 * The packet type value.
709 * A non-null string describing the packet type.
711 const char *rte_get_ptype_l4_name(uint32_t ptype);
714 * Get the name of the tunnel packet type
717 * The packet type value.
719 * A non-null string describing the packet type.
721 const char *rte_get_ptype_tunnel_name(uint32_t ptype);
724 * Get the name of the inner_l2 packet type
727 * The packet type value.
729 * A non-null string describing the packet type.
731 const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
734 * Get the name of the inner_l3 packet type
737 * The packet type value.
739 * A non-null string describing the packet type.
741 const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
744 * Get the name of the inner_l4 packet type
747 * The packet type value.
749 * A non-null string describing the packet type.
751 const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
754 * Write the packet type name into the buffer
757 * The packet type value.
759 * The buffer where the string is written.
761 * The length of the buffer.
764 * - (-1) if the buffer is too small
766 int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
772 #endif /* _RTE_MBUF_PTYPE_H_ */