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
134 * Mask of layer 2 packet types.
135 * It is used for outer packet for tunneling cases.
137 #define RTE_PTYPE_L2_MASK 0x0000000f
139 * IP (Internet Protocol) version 4 packet type.
140 * It is used for outer packet for tunneling cases, and does not contain any
144 * <'ether type'=0x0800
145 * | 'version'=4, 'ihl'=5>
147 #define RTE_PTYPE_L3_IPV4 0x00000010
149 * IP (Internet Protocol) version 4 packet type.
150 * It is used for outer packet for tunneling cases, and contains header
154 * <'ether type'=0x0800
155 * | 'version'=4, 'ihl'=[6-15], 'options'>
157 #define RTE_PTYPE_L3_IPV4_EXT 0x00000030
159 * IP (Internet Protocol) version 6 packet type.
160 * It is used for outer packet for tunneling cases, and does not contain any
164 * <'ether type'=0x86DD
165 * | 'version'=6, 'next header'=0x3B>
167 #define RTE_PTYPE_L3_IPV6 0x00000040
169 * IP (Internet Protocol) version 4 packet type.
170 * It is used for outer packet for tunneling cases, and may or maynot contain
174 * <'ether type'=0x0800
175 * | 'version'=4, 'ihl'=[5-15], <'options'>>
177 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN 0x00000090
179 * IP (Internet Protocol) version 6 packet type.
180 * It is used for outer packet for tunneling cases, and contains extension
184 * <'ether type'=0x86DD
185 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
186 * 'extension headers'>
188 #define RTE_PTYPE_L3_IPV6_EXT 0x000000c0
190 * IP (Internet Protocol) version 6 packet type.
191 * It is used for outer packet for tunneling cases, and may or maynot contain
195 * <'ether type'=0x86DD
196 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
197 * <'extension headers'>>
199 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN 0x000000e0
201 * Mask of layer 3 packet types.
202 * It is used for outer packet for tunneling cases.
204 #define RTE_PTYPE_L3_MASK 0x000000f0
206 * TCP (Transmission Control Protocol) packet type.
207 * It is used for outer packet for tunneling cases.
210 * <'ether type'=0x0800
211 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
213 * <'ether type'=0x86DD
214 * | 'version'=6, 'next header'=6>
216 #define RTE_PTYPE_L4_TCP 0x00000100
218 * UDP (User Datagram Protocol) packet type.
219 * It is used for outer packet for tunneling cases.
222 * <'ether type'=0x0800
223 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
225 * <'ether type'=0x86DD
226 * | 'version'=6, 'next header'=17>
228 #define RTE_PTYPE_L4_UDP 0x00000200
230 * Fragmented IP (Internet Protocol) packet type.
231 * It is used for outer packet for tunneling cases.
233 * It refers to those packets of any IP types, which can be recognized as
234 * fragmented. A fragmented packet cannot be recognized as any other L4 types
235 * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
236 * RTE_PTYPE_L4_NONFRAG).
239 * <'ether type'=0x0800
240 * | 'version'=4, 'MF'=1>
242 * <'ether type'=0x0800
243 * | 'version'=4, 'frag_offset'!=0>
245 * <'ether type'=0x86DD
246 * | 'version'=6, 'next header'=44>
248 #define RTE_PTYPE_L4_FRAG 0x00000300
250 * SCTP (Stream Control Transmission Protocol) packet type.
251 * It is used for outer packet for tunneling cases.
254 * <'ether type'=0x0800
255 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
257 * <'ether type'=0x86DD
258 * | 'version'=6, 'next header'=132>
260 #define RTE_PTYPE_L4_SCTP 0x00000400
262 * ICMP (Internet Control Message Protocol) packet type.
263 * It is used for outer packet for tunneling cases.
266 * <'ether type'=0x0800
267 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
269 * <'ether type'=0x86DD
270 * | 'version'=6, 'next header'=1>
272 #define RTE_PTYPE_L4_ICMP 0x00000500
274 * Non-fragmented IP (Internet Protocol) packet type.
275 * It is used for outer packet for tunneling cases.
277 * It refers to those packets of any IP types, while cannot be recognized as
278 * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
279 * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
282 * <'ether type'=0x0800
283 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
285 * <'ether type'=0x86DD
286 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
288 #define RTE_PTYPE_L4_NONFRAG 0x00000600
290 * Mask of layer 4 packet types.
291 * It is used for outer packet for tunneling cases.
293 #define RTE_PTYPE_L4_MASK 0x00000f00
295 * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
298 * <'ether type'=0x0800
299 * | 'version'=4, 'protocol'=[4|41]>
301 * <'ether type'=0x86DD
302 * | 'version'=6, 'next header'=[4|41]>
304 #define RTE_PTYPE_TUNNEL_IP 0x00001000
306 * GRE (Generic Routing Encapsulation) tunneling packet type.
309 * <'ether type'=0x0800
310 * | 'version'=4, 'protocol'=47>
312 * <'ether type'=0x86DD
313 * | 'version'=6, 'next header'=47>
315 #define RTE_PTYPE_TUNNEL_GRE 0x00002000
317 * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
320 * <'ether type'=0x0800
321 * | 'version'=4, 'protocol'=17
322 * | 'destination port'=4789>
324 * <'ether type'=0x86DD
325 * | 'version'=6, 'next header'=17
326 * | 'destination port'=4789>
328 #define RTE_PTYPE_TUNNEL_VXLAN 0x00003000
330 * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
334 * <'ether type'=0x0800
335 * | 'version'=4, 'protocol'=47
336 * | 'protocol type'=0x6558>
338 * <'ether type'=0x86DD
339 * | 'version'=6, 'next header'=47
340 * | 'protocol type'=0x6558'>
342 #define RTE_PTYPE_TUNNEL_NVGRE 0x00004000
344 * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
347 * <'ether type'=0x0800
348 * | 'version'=4, 'protocol'=17
349 * | 'destination port'=6081>
351 * <'ether type'=0x86DD
352 * | 'version'=6, 'next header'=17
353 * | 'destination port'=6081>
355 #define RTE_PTYPE_TUNNEL_GENEVE 0x00005000
357 * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
358 * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
359 * packet type, if they can not be recognized independently as of hardware
362 #define RTE_PTYPE_TUNNEL_GRENAT 0x00006000
364 * GTP-C (GPRS Tunnelling Protocol) control tunneling packet type.
366 * <'ether type'=0x0800
367 * | 'version'=4, 'protocol'=17
368 * | 'destination port'=2123>
370 * <'ether type'=0x86DD
371 * | 'version'=6, 'next header'=17
372 * | 'destination port'=2123>
374 * <'ether type'=0x0800
375 * | 'version'=4, 'protocol'=17
376 * | 'source port'=2123>
378 * <'ether type'=0x86DD
379 * | 'version'=6, 'next header'=17
380 * | 'source port'=2123>
382 #define RTE_PTYPE_TUNNEL_GTPC 0x00007000
384 * GTP-U (GPRS Tunnelling Protocol) user data tunneling packet type.
386 * <'ether type'=0x0800
387 * | 'version'=4, 'protocol'=17
388 * | 'destination port'=2152>
390 * <'ether type'=0x86DD
391 * | 'version'=6, 'next header'=17
392 * | 'destination port'=2152>
394 #define RTE_PTYPE_TUNNEL_GTPU 0x00008000
396 * ESP (IP Encapsulating Security Payload) tunneling packet type.
399 * <'ether type'=0x0800
400 * | 'version'=4, 'protocol'=51>
402 * <'ether type'=0x86DD
403 * | 'version'=6, 'next header'=51>
405 #define RTE_PTYPE_TUNNEL_ESP 0x00009000
407 * L2TP (Layer 2 Tunneling Protocol) tunnleing packet type.
410 * <'ether type'=0x0800
411 * | 'version'=4, 'protocol'=17>
412 * | 'destination port'=1701>
414 * <'ether type'=0x86DD
415 * | 'version'=6, 'next header'=17
416 * | 'destination port'=1701>
418 * <'ether type'=0x0800
419 * | 'version'=4, 'protocol'=115>
421 * <'ether type'=0x86DD
422 * | 'version'=6, 'protocol'=115>
424 #define RTE_PTYPE_TUNNEL_L2TP 0x0000a000
426 * VXLAN-GPE (VXLAN Generic Protocol Extension) tunneling packet type.
429 * <'ether type'=0x0800
430 * | 'version'=4, 'protocol'=17
431 * | 'destination port'=4790>
433 * <'ether type'=0x86DD
434 * | 'version'=6, 'next header'=17
435 * | 'destination port'=4790>
437 #define RTE_PTYPE_TUNNEL_VXLAN_GPE 0x0000b000
439 * Mask of tunneling packet types.
441 #define RTE_PTYPE_TUNNEL_MASK 0x0000f000
443 * Ethernet packet type.
444 * It is used for inner packet type only.
446 * Packet format (inner only):
447 * <'ether type'=[0x800|0x86DD]>
449 #define RTE_PTYPE_INNER_L2_ETHER 0x00010000
451 * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
453 * Packet format (inner only):
454 * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
456 #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000
461 * <'ether type'=[0x88A8]>
463 #define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000
465 * Mask of inner layer 2 packet types.
467 #define RTE_PTYPE_INNER_L2_MASK 0x000f0000
469 * IP (Internet Protocol) version 4 packet type.
470 * It is used for inner packet only, and does not contain any header option.
472 * Packet format (inner only):
473 * <'ether type'=0x0800
474 * | 'version'=4, 'ihl'=5>
476 #define RTE_PTYPE_INNER_L3_IPV4 0x00100000
478 * IP (Internet Protocol) version 4 packet type.
479 * It is used for inner packet only, and contains header options.
481 * Packet format (inner only):
482 * <'ether type'=0x0800
483 * | 'version'=4, 'ihl'=[6-15], 'options'>
485 #define RTE_PTYPE_INNER_L3_IPV4_EXT 0x00200000
487 * IP (Internet Protocol) version 6 packet type.
488 * It is used for inner packet only, and does not contain any extension header.
490 * Packet format (inner only):
491 * <'ether type'=0x86DD
492 * | 'version'=6, 'next header'=0x3B>
494 #define RTE_PTYPE_INNER_L3_IPV6 0x00300000
496 * IP (Internet Protocol) version 4 packet type.
497 * It is used for inner packet only, and may or maynot contain header options.
499 * Packet format (inner only):
500 * <'ether type'=0x0800
501 * | 'version'=4, 'ihl'=[5-15], <'options'>>
503 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
505 * IP (Internet Protocol) version 6 packet type.
506 * It is used for inner packet only, and contains extension headers.
508 * Packet format (inner only):
509 * <'ether type'=0x86DD
510 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
511 * 'extension headers'>
513 #define RTE_PTYPE_INNER_L3_IPV6_EXT 0x00500000
515 * IP (Internet Protocol) version 6 packet type.
516 * It is used for inner packet only, and may or maynot contain extension
519 * Packet format (inner only):
520 * <'ether type'=0x86DD
521 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
522 * <'extension headers'>>
524 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
526 * Mask of inner layer 3 packet types.
528 #define RTE_PTYPE_INNER_L3_MASK 0x00f00000
530 * TCP (Transmission Control Protocol) packet type.
531 * It is used for inner packet only.
533 * Packet format (inner only):
534 * <'ether type'=0x0800
535 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
537 * <'ether type'=0x86DD
538 * | 'version'=6, 'next header'=6>
540 #define RTE_PTYPE_INNER_L4_TCP 0x01000000
542 * UDP (User Datagram Protocol) packet type.
543 * It is used for inner packet only.
545 * Packet format (inner only):
546 * <'ether type'=0x0800
547 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
549 * <'ether type'=0x86DD
550 * | 'version'=6, 'next header'=17>
552 #define RTE_PTYPE_INNER_L4_UDP 0x02000000
554 * Fragmented IP (Internet Protocol) packet type.
555 * It is used for inner packet only, and may or maynot have layer 4 packet.
557 * Packet format (inner only):
558 * <'ether type'=0x0800
559 * | 'version'=4, 'MF'=1>
561 * <'ether type'=0x0800
562 * | 'version'=4, 'frag_offset'!=0>
564 * <'ether type'=0x86DD
565 * | 'version'=6, 'next header'=44>
567 #define RTE_PTYPE_INNER_L4_FRAG 0x03000000
569 * SCTP (Stream Control Transmission Protocol) packet type.
570 * It is used for inner packet only.
572 * Packet format (inner only):
573 * <'ether type'=0x0800
574 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
576 * <'ether type'=0x86DD
577 * | 'version'=6, 'next header'=132>
579 #define RTE_PTYPE_INNER_L4_SCTP 0x04000000
581 * ICMP (Internet Control Message Protocol) packet type.
582 * It is used for inner packet only.
584 * Packet format (inner only):
585 * <'ether type'=0x0800
586 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
588 * <'ether type'=0x86DD
589 * | 'version'=6, 'next header'=1>
591 #define RTE_PTYPE_INNER_L4_ICMP 0x05000000
593 * Non-fragmented IP (Internet Protocol) packet type.
594 * It is used for inner packet only, and may or maynot have other unknown layer
597 * Packet format (inner only):
598 * <'ether type'=0x0800
599 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
601 * <'ether type'=0x86DD
602 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
604 #define RTE_PTYPE_INNER_L4_NONFRAG 0x06000000
606 * Mask of inner layer 4 packet types.
608 #define RTE_PTYPE_INNER_L4_MASK 0x0f000000
610 * All valid layer masks.
612 #define RTE_PTYPE_ALL_MASK 0x0fffffff
615 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
616 * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
617 * determine if it is an IPV4 packet.
619 #define RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
622 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
623 * one, bit 6 is selected to be used for IPv4 only. Then checking bit 6 can
624 * determine if it is an IPV4 packet.
626 #define RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
628 /* Check if it is a tunneling packet */
629 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) & \
630 (RTE_PTYPE_TUNNEL_MASK | \
631 RTE_PTYPE_INNER_L2_MASK | \
632 RTE_PTYPE_INNER_L3_MASK | \
633 RTE_PTYPE_INNER_L4_MASK))
636 * Get the name of the l2 packet type
639 * The packet type value.
641 * A non-null string describing the packet type.
643 const char *rte_get_ptype_l2_name(uint32_t ptype);
646 * Get the name of the l3 packet type
649 * The packet type value.
651 * A non-null string describing the packet type.
653 const char *rte_get_ptype_l3_name(uint32_t ptype);
656 * Get the name of the l4 packet type
659 * The packet type value.
661 * A non-null string describing the packet type.
663 const char *rte_get_ptype_l4_name(uint32_t ptype);
666 * Get the name of the tunnel packet type
669 * The packet type value.
671 * A non-null string describing the packet type.
673 const char *rte_get_ptype_tunnel_name(uint32_t ptype);
676 * Get the name of the inner_l2 packet type
679 * The packet type value.
681 * A non-null string describing the packet type.
683 const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
686 * Get the name of the inner_l3 packet type
689 * The packet type value.
691 * A non-null string describing the packet type.
693 const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
696 * Get the name of the inner_l4 packet type
699 * The packet type value.
701 * A non-null string describing the packet type.
703 const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
706 * Write the packet type name into the buffer
709 * The packet type value.
711 * The buffer where the string is written.
713 * The length of the buffer.
716 * - (-1) if the buffer is too small
718 int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
724 #endif /* _RTE_MBUF_PTYPE_H_ */