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
159 * <'ether type'=[0x8863|0x8864]>
161 #define RTE_PTYPE_L2_ETHER_PPPOE 0x00000008
163 * Mask of layer 2 packet types.
164 * It is used for outer packet for tunneling cases.
166 #define RTE_PTYPE_L2_MASK 0x0000000f
168 * IP (Internet Protocol) version 4 packet type.
169 * It is used for outer packet for tunneling cases, and does not contain any
173 * <'ether type'=0x0800
174 * | 'version'=4, 'ihl'=5>
176 #define RTE_PTYPE_L3_IPV4 0x00000010
178 * IP (Internet Protocol) version 4 packet type.
179 * It is used for outer packet for tunneling cases, and contains header
183 * <'ether type'=0x0800
184 * | 'version'=4, 'ihl'=[6-15], 'options'>
186 #define RTE_PTYPE_L3_IPV4_EXT 0x00000030
188 * IP (Internet Protocol) version 6 packet type.
189 * It is used for outer packet for tunneling cases, and does not contain any
193 * <'ether type'=0x86DD
194 * | 'version'=6, 'next header'=0x3B>
196 #define RTE_PTYPE_L3_IPV6 0x00000040
198 * IP (Internet Protocol) version 4 packet type.
199 * It is used for outer packet for tunneling cases, and may or maynot contain
203 * <'ether type'=0x0800
204 * | 'version'=4, 'ihl'=[5-15], <'options'>>
206 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN 0x00000090
208 * IP (Internet Protocol) version 6 packet type.
209 * It is used for outer packet for tunneling cases, and contains extension
213 * <'ether type'=0x86DD
214 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
215 * 'extension headers'>
217 #define RTE_PTYPE_L3_IPV6_EXT 0x000000c0
219 * IP (Internet Protocol) version 6 packet type.
220 * It is used for outer packet for tunneling cases, and may or maynot contain
224 * <'ether type'=0x86DD
225 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
226 * <'extension headers'>>
228 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN 0x000000e0
230 * Mask of layer 3 packet types.
231 * It is used for outer packet for tunneling cases.
233 #define RTE_PTYPE_L3_MASK 0x000000f0
235 * TCP (Transmission Control Protocol) packet type.
236 * It is used for outer packet for tunneling cases.
239 * <'ether type'=0x0800
240 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
242 * <'ether type'=0x86DD
243 * | 'version'=6, 'next header'=6>
245 #define RTE_PTYPE_L4_TCP 0x00000100
247 * UDP (User Datagram Protocol) packet type.
248 * It is used for outer packet for tunneling cases.
251 * <'ether type'=0x0800
252 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
254 * <'ether type'=0x86DD
255 * | 'version'=6, 'next header'=17>
257 #define RTE_PTYPE_L4_UDP 0x00000200
259 * Fragmented IP (Internet Protocol) packet type.
260 * It is used for outer packet for tunneling cases.
262 * It refers to those packets of any IP types, which can be recognized as
263 * fragmented. A fragmented packet cannot be recognized as any other L4 types
264 * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
265 * RTE_PTYPE_L4_NONFRAG).
268 * <'ether type'=0x0800
269 * | 'version'=4, 'MF'=1>
271 * <'ether type'=0x0800
272 * | 'version'=4, 'frag_offset'!=0>
274 * <'ether type'=0x86DD
275 * | 'version'=6, 'next header'=44>
277 #define RTE_PTYPE_L4_FRAG 0x00000300
279 * SCTP (Stream Control Transmission Protocol) packet type.
280 * It is used for outer packet for tunneling cases.
283 * <'ether type'=0x0800
284 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
286 * <'ether type'=0x86DD
287 * | 'version'=6, 'next header'=132>
289 #define RTE_PTYPE_L4_SCTP 0x00000400
291 * ICMP (Internet Control Message Protocol) packet type.
292 * It is used for outer packet for tunneling cases.
295 * <'ether type'=0x0800
296 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
298 * <'ether type'=0x86DD
299 * | 'version'=6, 'next header'=1>
301 #define RTE_PTYPE_L4_ICMP 0x00000500
303 * Non-fragmented IP (Internet Protocol) packet type.
304 * It is used for outer packet for tunneling cases.
306 * It refers to those packets of any IP types, while cannot be recognized as
307 * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
308 * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
311 * <'ether type'=0x0800
312 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
314 * <'ether type'=0x86DD
315 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
317 #define RTE_PTYPE_L4_NONFRAG 0x00000600
319 * Mask of layer 4 packet types.
320 * It is used for outer packet for tunneling cases.
322 #define RTE_PTYPE_L4_MASK 0x00000f00
324 * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
327 * <'ether type'=0x0800
328 * | 'version'=4, 'protocol'=[4|41]>
330 * <'ether type'=0x86DD
331 * | 'version'=6, 'next header'=[4|41]>
333 #define RTE_PTYPE_TUNNEL_IP 0x00001000
335 * GRE (Generic Routing Encapsulation) tunneling packet type.
338 * <'ether type'=0x0800
339 * | 'version'=4, 'protocol'=47>
341 * <'ether type'=0x86DD
342 * | 'version'=6, 'next header'=47>
344 #define RTE_PTYPE_TUNNEL_GRE 0x00002000
346 * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
349 * <'ether type'=0x0800
350 * | 'version'=4, 'protocol'=17
351 * | 'destination port'=4789>
353 * <'ether type'=0x86DD
354 * | 'version'=6, 'next header'=17
355 * | 'destination port'=4789>
357 #define RTE_PTYPE_TUNNEL_VXLAN 0x00003000
359 * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
363 * <'ether type'=0x0800
364 * | 'version'=4, 'protocol'=47
365 * | 'protocol type'=0x6558>
367 * <'ether type'=0x86DD
368 * | 'version'=6, 'next header'=47
369 * | 'protocol type'=0x6558'>
371 #define RTE_PTYPE_TUNNEL_NVGRE 0x00004000
373 * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
376 * <'ether type'=0x0800
377 * | 'version'=4, 'protocol'=17
378 * | 'destination port'=6081>
380 * <'ether type'=0x86DD
381 * | 'version'=6, 'next header'=17
382 * | 'destination port'=6081>
384 #define RTE_PTYPE_TUNNEL_GENEVE 0x00005000
386 * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
387 * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
388 * packet type, if they can not be recognized independently as of hardware
391 #define RTE_PTYPE_TUNNEL_GRENAT 0x00006000
393 * GTP-C (GPRS Tunnelling Protocol) control tunneling packet type.
395 * <'ether type'=0x0800
396 * | 'version'=4, 'protocol'=17
397 * | 'destination port'=2123>
399 * <'ether type'=0x86DD
400 * | 'version'=6, 'next header'=17
401 * | 'destination port'=2123>
403 * <'ether type'=0x0800
404 * | 'version'=4, 'protocol'=17
405 * | 'source port'=2123>
407 * <'ether type'=0x86DD
408 * | 'version'=6, 'next header'=17
409 * | 'source port'=2123>
411 #define RTE_PTYPE_TUNNEL_GTPC 0x00007000
413 * GTP-U (GPRS Tunnelling Protocol) user data tunneling packet type.
415 * <'ether type'=0x0800
416 * | 'version'=4, 'protocol'=17
417 * | 'destination port'=2152>
419 * <'ether type'=0x86DD
420 * | 'version'=6, 'next header'=17
421 * | 'destination port'=2152>
423 #define RTE_PTYPE_TUNNEL_GTPU 0x00008000
425 * ESP (IP Encapsulating Security Payload) tunneling packet type.
428 * <'ether type'=0x0800
429 * | 'version'=4, 'protocol'=51>
431 * <'ether type'=0x86DD
432 * | 'version'=6, 'next header'=51>
434 #define RTE_PTYPE_TUNNEL_ESP 0x00009000
436 * L2TP (Layer 2 Tunneling Protocol) tunnleing packet type.
439 * <'ether type'=0x0800
440 * | 'version'=4, 'protocol'=17>
441 * | 'destination port'=1701>
443 * <'ether type'=0x86DD
444 * | 'version'=6, 'next header'=17
445 * | 'destination port'=1701>
447 * <'ether type'=0x0800
448 * | 'version'=4, 'protocol'=115>
450 * <'ether type'=0x86DD
451 * | 'version'=6, 'protocol'=115>
453 #define RTE_PTYPE_TUNNEL_L2TP 0x0000a000
455 * Mask of tunneling packet types.
457 #define RTE_PTYPE_TUNNEL_MASK 0x0000f000
459 * Ethernet packet type.
460 * It is used for inner packet type only.
462 * Packet format (inner only):
463 * <'ether type'=[0x800|0x86DD]>
465 #define RTE_PTYPE_INNER_L2_ETHER 0x00010000
467 * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
469 * Packet format (inner only):
470 * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
472 #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000
477 * <'ether type'=[0x88A8]>
479 #define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000
481 * Mask of inner layer 2 packet types.
483 #define RTE_PTYPE_INNER_L2_MASK 0x000f0000
485 * IP (Internet Protocol) version 4 packet type.
486 * It is used for inner packet only, and does not contain any header option.
488 * Packet format (inner only):
489 * <'ether type'=0x0800
490 * | 'version'=4, 'ihl'=5>
492 #define RTE_PTYPE_INNER_L3_IPV4 0x00100000
494 * IP (Internet Protocol) version 4 packet type.
495 * It is used for inner packet only, and contains header options.
497 * Packet format (inner only):
498 * <'ether type'=0x0800
499 * | 'version'=4, 'ihl'=[6-15], 'options'>
501 #define RTE_PTYPE_INNER_L3_IPV4_EXT 0x00200000
503 * IP (Internet Protocol) version 6 packet type.
504 * It is used for inner packet only, and does not contain any extension header.
506 * Packet format (inner only):
507 * <'ether type'=0x86DD
508 * | 'version'=6, 'next header'=0x3B>
510 #define RTE_PTYPE_INNER_L3_IPV6 0x00300000
512 * IP (Internet Protocol) version 4 packet type.
513 * It is used for inner packet only, and may or maynot contain header options.
515 * Packet format (inner only):
516 * <'ether type'=0x0800
517 * | 'version'=4, 'ihl'=[5-15], <'options'>>
519 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
521 * IP (Internet Protocol) version 6 packet type.
522 * It is used for inner packet only, and contains extension headers.
524 * Packet format (inner only):
525 * <'ether type'=0x86DD
526 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
527 * 'extension headers'>
529 #define RTE_PTYPE_INNER_L3_IPV6_EXT 0x00500000
531 * IP (Internet Protocol) version 6 packet type.
532 * It is used for inner packet only, and may or maynot contain extension
535 * Packet format (inner only):
536 * <'ether type'=0x86DD
537 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
538 * <'extension headers'>>
540 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
542 * Mask of inner layer 3 packet types.
544 #define RTE_PTYPE_INNER_L3_MASK 0x00f00000
546 * TCP (Transmission Control Protocol) packet type.
547 * It is used for inner packet only.
549 * Packet format (inner only):
550 * <'ether type'=0x0800
551 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
553 * <'ether type'=0x86DD
554 * | 'version'=6, 'next header'=6>
556 #define RTE_PTYPE_INNER_L4_TCP 0x01000000
558 * UDP (User Datagram Protocol) packet type.
559 * It is used for inner packet only.
561 * Packet format (inner only):
562 * <'ether type'=0x0800
563 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
565 * <'ether type'=0x86DD
566 * | 'version'=6, 'next header'=17>
568 #define RTE_PTYPE_INNER_L4_UDP 0x02000000
570 * Fragmented IP (Internet Protocol) packet type.
571 * It is used for inner packet only, and may or maynot have layer 4 packet.
573 * Packet format (inner only):
574 * <'ether type'=0x0800
575 * | 'version'=4, 'MF'=1>
577 * <'ether type'=0x0800
578 * | 'version'=4, 'frag_offset'!=0>
580 * <'ether type'=0x86DD
581 * | 'version'=6, 'next header'=44>
583 #define RTE_PTYPE_INNER_L4_FRAG 0x03000000
585 * SCTP (Stream Control Transmission Protocol) packet type.
586 * It is used for inner packet only.
588 * Packet format (inner only):
589 * <'ether type'=0x0800
590 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
592 * <'ether type'=0x86DD
593 * | 'version'=6, 'next header'=132>
595 #define RTE_PTYPE_INNER_L4_SCTP 0x04000000
597 * ICMP (Internet Control Message Protocol) packet type.
598 * It is used for inner packet only.
600 * Packet format (inner only):
601 * <'ether type'=0x0800
602 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
604 * <'ether type'=0x86DD
605 * | 'version'=6, 'next header'=1>
607 #define RTE_PTYPE_INNER_L4_ICMP 0x05000000
609 * Non-fragmented IP (Internet Protocol) packet type.
610 * It is used for inner packet only, and may or maynot have other unknown layer
613 * Packet format (inner only):
614 * <'ether type'=0x0800
615 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
617 * <'ether type'=0x86DD
618 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
620 #define RTE_PTYPE_INNER_L4_NONFRAG 0x06000000
622 * Mask of inner layer 4 packet types.
624 #define RTE_PTYPE_INNER_L4_MASK 0x0f000000
626 * All valid layer masks.
628 #define RTE_PTYPE_ALL_MASK 0x0fffffff
631 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
632 * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
633 * determine if it is an IPV4 packet.
635 #define RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
638 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
639 * one, bit 6 is selected to be used for IPv4 only. Then checking bit 6 can
640 * determine if it is an IPV4 packet.
642 #define RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
644 /* Check if it is a tunneling packet */
645 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) & \
646 (RTE_PTYPE_TUNNEL_MASK | \
647 RTE_PTYPE_INNER_L2_MASK | \
648 RTE_PTYPE_INNER_L3_MASK | \
649 RTE_PTYPE_INNER_L4_MASK))
652 * Get the name of the l2 packet type
655 * The packet type value.
657 * A non-null string describing the packet type.
659 const char *rte_get_ptype_l2_name(uint32_t ptype);
662 * Get the name of the l3 packet type
665 * The packet type value.
667 * A non-null string describing the packet type.
669 const char *rte_get_ptype_l3_name(uint32_t ptype);
672 * Get the name of the l4 packet type
675 * The packet type value.
677 * A non-null string describing the packet type.
679 const char *rte_get_ptype_l4_name(uint32_t ptype);
682 * Get the name of the tunnel packet type
685 * The packet type value.
687 * A non-null string describing the packet type.
689 const char *rte_get_ptype_tunnel_name(uint32_t ptype);
692 * Get the name of the inner_l2 packet type
695 * The packet type value.
697 * A non-null string describing the packet type.
699 const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
702 * Get the name of the inner_l3 packet type
705 * The packet type value.
707 * A non-null string describing the packet type.
709 const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
712 * Get the name of the inner_l4 packet type
715 * The packet type value.
717 * A non-null string describing the packet type.
719 const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
722 * Write the packet type name into the buffer
725 * The packet type value.
727 * The buffer where the string is written.
729 * The length of the buffer.
732 * - (-1) if the buffer is too small
734 int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
740 #endif /* _RTE_MBUF_PTYPE_H_ */