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
141 * Mask of layer 2 packet types.
142 * It is used for outer packet for tunneling cases.
144 #define RTE_PTYPE_L2_MASK 0x0000000f
146 * IP (Internet Protocol) version 4 packet type.
147 * It is used for outer packet for tunneling cases, and does not contain any
151 * <'ether type'=0x0800
152 * | 'version'=4, 'ihl'=5>
154 #define RTE_PTYPE_L3_IPV4 0x00000010
156 * IP (Internet Protocol) version 4 packet type.
157 * It is used for outer packet for tunneling cases, and contains header
161 * <'ether type'=0x0800
162 * | 'version'=4, 'ihl'=[6-15], 'options'>
164 #define RTE_PTYPE_L3_IPV4_EXT 0x00000030
166 * IP (Internet Protocol) version 6 packet type.
167 * It is used for outer packet for tunneling cases, and does not contain any
171 * <'ether type'=0x86DD
172 * | 'version'=6, 'next header'=0x3B>
174 #define RTE_PTYPE_L3_IPV6 0x00000040
176 * IP (Internet Protocol) version 4 packet type.
177 * It is used for outer packet for tunneling cases, and may or maynot contain
181 * <'ether type'=0x0800
182 * | 'version'=4, 'ihl'=[5-15], <'options'>>
184 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN 0x00000090
186 * IP (Internet Protocol) version 6 packet type.
187 * It is used for outer packet for tunneling cases, and contains extension
191 * <'ether type'=0x86DD
192 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
193 * 'extension headers'>
195 #define RTE_PTYPE_L3_IPV6_EXT 0x000000c0
197 * IP (Internet Protocol) version 6 packet type.
198 * It is used for outer packet for tunneling cases, and may or maynot contain
202 * <'ether type'=0x86DD
203 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
204 * <'extension headers'>>
206 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN 0x000000e0
208 * Mask of layer 3 packet types.
209 * It is used for outer packet for tunneling cases.
211 #define RTE_PTYPE_L3_MASK 0x000000f0
213 * TCP (Transmission Control Protocol) packet type.
214 * It is used for outer packet for tunneling cases.
217 * <'ether type'=0x0800
218 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
220 * <'ether type'=0x86DD
221 * | 'version'=6, 'next header'=6>
223 #define RTE_PTYPE_L4_TCP 0x00000100
225 * UDP (User Datagram Protocol) packet type.
226 * It is used for outer packet for tunneling cases.
229 * <'ether type'=0x0800
230 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
232 * <'ether type'=0x86DD
233 * | 'version'=6, 'next header'=17>
235 #define RTE_PTYPE_L4_UDP 0x00000200
237 * Fragmented IP (Internet Protocol) packet type.
238 * It is used for outer packet for tunneling cases.
240 * It refers to those packets of any IP types, which can be recognized as
241 * fragmented. A fragmented packet cannot be recognized as any other L4 types
242 * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
243 * RTE_PTYPE_L4_NONFRAG).
246 * <'ether type'=0x0800
247 * | 'version'=4, 'MF'=1>
249 * <'ether type'=0x0800
250 * | 'version'=4, 'frag_offset'!=0>
252 * <'ether type'=0x86DD
253 * | 'version'=6, 'next header'=44>
255 #define RTE_PTYPE_L4_FRAG 0x00000300
257 * SCTP (Stream Control Transmission Protocol) packet type.
258 * It is used for outer packet for tunneling cases.
261 * <'ether type'=0x0800
262 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
264 * <'ether type'=0x86DD
265 * | 'version'=6, 'next header'=132>
267 #define RTE_PTYPE_L4_SCTP 0x00000400
269 * ICMP (Internet Control Message Protocol) packet type.
270 * It is used for outer packet for tunneling cases.
273 * <'ether type'=0x0800
274 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
276 * <'ether type'=0x86DD
277 * | 'version'=6, 'next header'=1>
279 #define RTE_PTYPE_L4_ICMP 0x00000500
281 * Non-fragmented IP (Internet Protocol) packet type.
282 * It is used for outer packet for tunneling cases.
284 * It refers to those packets of any IP types, while cannot be recognized as
285 * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
286 * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
289 * <'ether type'=0x0800
290 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
292 * <'ether type'=0x86DD
293 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
295 #define RTE_PTYPE_L4_NONFRAG 0x00000600
297 * Mask of layer 4 packet types.
298 * It is used for outer packet for tunneling cases.
300 #define RTE_PTYPE_L4_MASK 0x00000f00
302 * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
305 * <'ether type'=0x0800
306 * | 'version'=4, 'protocol'=[4|41]>
308 * <'ether type'=0x86DD
309 * | 'version'=6, 'next header'=[4|41]>
311 #define RTE_PTYPE_TUNNEL_IP 0x00001000
313 * GRE (Generic Routing Encapsulation) tunneling packet type.
316 * <'ether type'=0x0800
317 * | 'version'=4, 'protocol'=47>
319 * <'ether type'=0x86DD
320 * | 'version'=6, 'next header'=47>
322 #define RTE_PTYPE_TUNNEL_GRE 0x00002000
324 * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
327 * <'ether type'=0x0800
328 * | 'version'=4, 'protocol'=17
329 * | 'destination port'=4789>
331 * <'ether type'=0x86DD
332 * | 'version'=6, 'next header'=17
333 * | 'destination port'=4789>
335 #define RTE_PTYPE_TUNNEL_VXLAN 0x00003000
337 * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
341 * <'ether type'=0x0800
342 * | 'version'=4, 'protocol'=47
343 * | 'protocol type'=0x6558>
345 * <'ether type'=0x86DD
346 * | 'version'=6, 'next header'=47
347 * | 'protocol type'=0x6558'>
349 #define RTE_PTYPE_TUNNEL_NVGRE 0x00004000
351 * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
354 * <'ether type'=0x0800
355 * | 'version'=4, 'protocol'=17
356 * | 'destination port'=6081>
358 * <'ether type'=0x86DD
359 * | 'version'=6, 'next header'=17
360 * | 'destination port'=6081>
362 #define RTE_PTYPE_TUNNEL_GENEVE 0x00005000
364 * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
365 * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
366 * packet type, if they can not be recognized independently as of hardware
369 #define RTE_PTYPE_TUNNEL_GRENAT 0x00006000
371 * GTP-C (GPRS Tunnelling Protocol) control tunneling packet type.
373 * <'ether type'=0x0800
374 * | 'version'=4, 'protocol'=17
375 * | 'destination port'=2123>
377 * <'ether type'=0x86DD
378 * | 'version'=6, 'next header'=17
379 * | 'destination port'=2123>
381 * <'ether type'=0x0800
382 * | 'version'=4, 'protocol'=17
383 * | 'source port'=2123>
385 * <'ether type'=0x86DD
386 * | 'version'=6, 'next header'=17
387 * | 'source port'=2123>
389 #define RTE_PTYPE_TUNNEL_GTPC 0x00007000
391 * GTP-U (GPRS Tunnelling Protocol) user data tunneling packet type.
393 * <'ether type'=0x0800
394 * | 'version'=4, 'protocol'=17
395 * | 'destination port'=2152>
397 * <'ether type'=0x86DD
398 * | 'version'=6, 'next header'=17
399 * | 'destination port'=2152>
401 #define RTE_PTYPE_TUNNEL_GTPU 0x00008000
403 * ESP (IP Encapsulating Security Payload) tunneling packet type.
406 * <'ether type'=0x0800
407 * | 'version'=4, 'protocol'=51>
409 * <'ether type'=0x86DD
410 * | 'version'=6, 'next header'=51>
412 #define RTE_PTYPE_TUNNEL_ESP 0x00009000
414 * L2TP (Layer 2 Tunneling Protocol) tunnleing packet type.
417 * <'ether type'=0x0800
418 * | 'version'=4, 'protocol'=17>
419 * | 'destination port'=1701>
421 * <'ether type'=0x86DD
422 * | 'version'=6, 'next header'=17
423 * | 'destination port'=1701>
425 * <'ether type'=0x0800
426 * | 'version'=4, 'protocol'=115>
428 * <'ether type'=0x86DD
429 * | 'version'=6, 'protocol'=115>
431 #define RTE_PTYPE_TUNNEL_L2TP 0x0000a000
433 * VXLAN-GPE (VXLAN Generic Protocol Extension) tunneling packet type.
436 * <'ether type'=0x0800
437 * | 'version'=4, 'protocol'=17
438 * | 'destination port'=4790>
440 * <'ether type'=0x86DD
441 * | 'version'=6, 'next header'=17
442 * | 'destination port'=4790>
444 #define RTE_PTYPE_TUNNEL_VXLAN_GPE 0x0000b000
446 * MPLS-in-GRE tunneling packet type (RFC 4023).
449 * <'ether type'=0x0800
450 * | 'version'=4, 'protocol'=47
451 * | 'protocol'=0x8847>
453 * <'ether type'=0x0800
454 * | 'version'=4, 'protocol'=47
455 * | 'protocol'=0x8848>
457 * <'ether type'=0x86DD
458 * | 'version'=6, 'protocol'=47
459 * | 'protocol'=0x8847>
461 * <'ether type'=0x86DD
462 * | 'version'=6, 'next header'=47
463 * | 'protocol'=0x8848>
465 #define RTE_PTYPE_TUNNEL_MPLS_IN_GRE 0x0000c000
467 * MPLS-in-UDP tunneling packet type (RFC 7510).
470 * <'ether type'=0x0800
471 * | 'version'=4, 'protocol'=17
472 * | 'destination port'=6635>
474 * <'ether type'=0x86DD
475 * | 'version'=6, 'next header'=17
476 * | 'destination port'=6635>
478 #define RTE_PTYPE_TUNNEL_MPLS_IN_UDP 0x0000d000
480 * Mask of tunneling packet types.
482 #define RTE_PTYPE_TUNNEL_MASK 0x0000f000
484 * Ethernet packet type.
485 * It is used for inner packet type only.
487 * Packet format (inner only):
488 * <'ether type'=[0x800|0x86DD]>
490 #define RTE_PTYPE_INNER_L2_ETHER 0x00010000
492 * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
494 * Packet format (inner only):
495 * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
497 #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000
502 * <'ether type'=[0x88A8]>
504 #define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000
506 * Mask of inner layer 2 packet types.
508 #define RTE_PTYPE_INNER_L2_MASK 0x000f0000
510 * IP (Internet Protocol) version 4 packet type.
511 * It is used for inner packet only, and does not contain any header option.
513 * Packet format (inner only):
514 * <'ether type'=0x0800
515 * | 'version'=4, 'ihl'=5>
517 #define RTE_PTYPE_INNER_L3_IPV4 0x00100000
519 * IP (Internet Protocol) version 4 packet type.
520 * It is used for inner packet only, and contains header options.
522 * Packet format (inner only):
523 * <'ether type'=0x0800
524 * | 'version'=4, 'ihl'=[6-15], 'options'>
526 #define RTE_PTYPE_INNER_L3_IPV4_EXT 0x00200000
528 * IP (Internet Protocol) version 6 packet type.
529 * It is used for inner packet only, and does not contain any extension header.
531 * Packet format (inner only):
532 * <'ether type'=0x86DD
533 * | 'version'=6, 'next header'=0x3B>
535 #define RTE_PTYPE_INNER_L3_IPV6 0x00300000
537 * IP (Internet Protocol) version 4 packet type.
538 * It is used for inner packet only, and may or maynot contain header options.
540 * Packet format (inner only):
541 * <'ether type'=0x0800
542 * | 'version'=4, 'ihl'=[5-15], <'options'>>
544 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
546 * IP (Internet Protocol) version 6 packet type.
547 * It is used for inner packet only, and contains extension headers.
549 * Packet format (inner only):
550 * <'ether type'=0x86DD
551 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
552 * 'extension headers'>
554 #define RTE_PTYPE_INNER_L3_IPV6_EXT 0x00500000
556 * IP (Internet Protocol) version 6 packet type.
557 * It is used for inner packet only, and may or maynot contain extension
560 * Packet format (inner only):
561 * <'ether type'=0x86DD
562 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
563 * <'extension headers'>>
565 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
567 * Mask of inner layer 3 packet types.
569 #define RTE_PTYPE_INNER_L3_MASK 0x00f00000
571 * TCP (Transmission Control Protocol) packet type.
572 * It is used for inner packet only.
574 * Packet format (inner only):
575 * <'ether type'=0x0800
576 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
578 * <'ether type'=0x86DD
579 * | 'version'=6, 'next header'=6>
581 #define RTE_PTYPE_INNER_L4_TCP 0x01000000
583 * UDP (User Datagram Protocol) packet type.
584 * It is used for inner packet only.
586 * Packet format (inner only):
587 * <'ether type'=0x0800
588 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
590 * <'ether type'=0x86DD
591 * | 'version'=6, 'next header'=17>
593 #define RTE_PTYPE_INNER_L4_UDP 0x02000000
595 * Fragmented IP (Internet Protocol) packet type.
596 * It is used for inner packet only, and may or maynot have layer 4 packet.
598 * Packet format (inner only):
599 * <'ether type'=0x0800
600 * | 'version'=4, 'MF'=1>
602 * <'ether type'=0x0800
603 * | 'version'=4, 'frag_offset'!=0>
605 * <'ether type'=0x86DD
606 * | 'version'=6, 'next header'=44>
608 #define RTE_PTYPE_INNER_L4_FRAG 0x03000000
610 * SCTP (Stream Control Transmission Protocol) packet type.
611 * It is used for inner packet only.
613 * Packet format (inner only):
614 * <'ether type'=0x0800
615 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
617 * <'ether type'=0x86DD
618 * | 'version'=6, 'next header'=132>
620 #define RTE_PTYPE_INNER_L4_SCTP 0x04000000
622 * ICMP (Internet Control Message Protocol) packet type.
623 * It is used for inner packet only.
625 * Packet format (inner only):
626 * <'ether type'=0x0800
627 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
629 * <'ether type'=0x86DD
630 * | 'version'=6, 'next header'=1>
632 #define RTE_PTYPE_INNER_L4_ICMP 0x05000000
634 * Non-fragmented IP (Internet Protocol) packet type.
635 * It is used for inner packet only, and may or maynot have other unknown layer
638 * Packet format (inner only):
639 * <'ether type'=0x0800
640 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
642 * <'ether type'=0x86DD
643 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
645 #define RTE_PTYPE_INNER_L4_NONFRAG 0x06000000
647 * Mask of inner layer 4 packet types.
649 #define RTE_PTYPE_INNER_L4_MASK 0x0f000000
651 * All valid layer masks.
653 #define RTE_PTYPE_ALL_MASK 0x0fffffff
656 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
657 * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
658 * determine if it is an IPV4 packet.
660 #define RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
663 * Check if the (outer) L3 header is IPv6. To avoid comparing IPv6 types one by
664 * one, bit 6 is selected to be used for IPv6 only. Then checking bit 6 can
665 * determine if it is an IPV6 packet.
667 #define RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
669 /* Check if it is a tunneling packet */
670 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) & \
671 (RTE_PTYPE_TUNNEL_MASK | \
672 RTE_PTYPE_INNER_L2_MASK | \
673 RTE_PTYPE_INNER_L3_MASK | \
674 RTE_PTYPE_INNER_L4_MASK))
677 * Get the name of the l2 packet type
680 * The packet type value.
682 * A non-null string describing the packet type.
684 const char *rte_get_ptype_l2_name(uint32_t ptype);
687 * Get the name of the l3 packet type
690 * The packet type value.
692 * A non-null string describing the packet type.
694 const char *rte_get_ptype_l3_name(uint32_t ptype);
697 * Get the name of the l4 packet type
700 * The packet type value.
702 * A non-null string describing the packet type.
704 const char *rte_get_ptype_l4_name(uint32_t ptype);
707 * Get the name of the tunnel packet type
710 * The packet type value.
712 * A non-null string describing the packet type.
714 const char *rte_get_ptype_tunnel_name(uint32_t ptype);
717 * Get the name of the inner_l2 packet type
720 * The packet type value.
722 * A non-null string describing the packet type.
724 const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
727 * Get the name of the inner_l3 packet type
730 * The packet type value.
732 * A non-null string describing the packet type.
734 const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
737 * Get the name of the inner_l4 packet type
740 * The packet type value.
742 * A non-null string describing the packet type.
744 const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
747 * Write the packet type name into the buffer
750 * The packet type value.
752 * The buffer where the string is written.
754 * The length of the buffer.
757 * - (-1) if the buffer is too small
759 int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
765 #endif /* _RTE_MBUF_PTYPE_H_ */