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.
99 * No packet type information.
101 #define RTE_PTYPE_UNKNOWN 0x00000000
103 * Ethernet packet type.
104 * It is used for outer packet for tunneling cases.
107 * <'ether type'=[0x0800|0x86DD]>
109 #define RTE_PTYPE_L2_ETHER 0x00000001
111 * Ethernet packet type for time sync.
114 * <'ether type'=0x88F7>
116 #define RTE_PTYPE_L2_ETHER_TIMESYNC 0x00000002
118 * ARP (Address Resolution Protocol) packet type.
121 * <'ether type'=0x0806>
123 #define RTE_PTYPE_L2_ETHER_ARP 0x00000003
125 * LLDP (Link Layer Discovery Protocol) packet type.
128 * <'ether type'=0x88CC>
130 #define RTE_PTYPE_L2_ETHER_LLDP 0x00000004
132 * NSH (Network Service Header) packet type.
135 * <'ether type'=0x894F>
137 #define RTE_PTYPE_L2_ETHER_NSH 0x00000005
142 * <'ether type'=[0x8100]>
144 #define RTE_PTYPE_L2_ETHER_VLAN 0x00000006
149 * <'ether type'=[0x88A8]>
151 #define RTE_PTYPE_L2_ETHER_QINQ 0x00000007
153 * Mask of layer 2 packet types.
154 * It is used for outer packet for tunneling cases.
156 #define RTE_PTYPE_L2_MASK 0x0000000f
158 * IP (Internet Protocol) version 4 packet type.
159 * It is used for outer packet for tunneling cases, and does not contain any
163 * <'ether type'=0x0800
164 * | 'version'=4, 'ihl'=5>
166 #define RTE_PTYPE_L3_IPV4 0x00000010
168 * IP (Internet Protocol) version 4 packet type.
169 * It is used for outer packet for tunneling cases, and contains header
173 * <'ether type'=0x0800
174 * | 'version'=4, 'ihl'=[6-15], 'options'>
176 #define RTE_PTYPE_L3_IPV4_EXT 0x00000030
178 * IP (Internet Protocol) version 6 packet type.
179 * It is used for outer packet for tunneling cases, and does not contain any
183 * <'ether type'=0x86DD
184 * | 'version'=6, 'next header'=0x3B>
186 #define RTE_PTYPE_L3_IPV6 0x00000040
188 * IP (Internet Protocol) version 4 packet type.
189 * It is used for outer packet for tunneling cases, and may or maynot contain
193 * <'ether type'=0x0800
194 * | 'version'=4, 'ihl'=[5-15], <'options'>>
196 #define RTE_PTYPE_L3_IPV4_EXT_UNKNOWN 0x00000090
198 * IP (Internet Protocol) version 6 packet type.
199 * It is used for outer packet for tunneling cases, and contains extension
203 * <'ether type'=0x86DD
204 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
205 * 'extension headers'>
207 #define RTE_PTYPE_L3_IPV6_EXT 0x000000c0
209 * IP (Internet Protocol) version 6 packet type.
210 * It is used for outer packet for tunneling cases, and may or maynot contain
214 * <'ether type'=0x86DD
215 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
216 * <'extension headers'>>
218 #define RTE_PTYPE_L3_IPV6_EXT_UNKNOWN 0x000000e0
220 * Mask of layer 3 packet types.
221 * It is used for outer packet for tunneling cases.
223 #define RTE_PTYPE_L3_MASK 0x000000f0
225 * TCP (Transmission Control Protocol) packet type.
226 * It is used for outer packet for tunneling cases.
229 * <'ether type'=0x0800
230 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
232 * <'ether type'=0x86DD
233 * | 'version'=6, 'next header'=6>
235 #define RTE_PTYPE_L4_TCP 0x00000100
237 * UDP (User Datagram Protocol) packet type.
238 * It is used for outer packet for tunneling cases.
241 * <'ether type'=0x0800
242 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
244 * <'ether type'=0x86DD
245 * | 'version'=6, 'next header'=17>
247 #define RTE_PTYPE_L4_UDP 0x00000200
249 * Fragmented IP (Internet Protocol) packet type.
250 * It is used for outer packet for tunneling cases.
252 * It refers to those packets of any IP types, which can be recognized as
253 * fragmented. A fragmented packet cannot be recognized as any other L4 types
254 * (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP,
255 * RTE_PTYPE_L4_NONFRAG).
258 * <'ether type'=0x0800
259 * | 'version'=4, 'MF'=1>
261 * <'ether type'=0x0800
262 * | 'version'=4, 'frag_offset'!=0>
264 * <'ether type'=0x86DD
265 * | 'version'=6, 'next header'=44>
267 #define RTE_PTYPE_L4_FRAG 0x00000300
269 * SCTP (Stream Control Transmission Protocol) packet type.
270 * It is used for outer packet for tunneling cases.
273 * <'ether type'=0x0800
274 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
276 * <'ether type'=0x86DD
277 * | 'version'=6, 'next header'=132>
279 #define RTE_PTYPE_L4_SCTP 0x00000400
281 * ICMP (Internet Control Message Protocol) packet type.
282 * It is used for outer packet for tunneling cases.
285 * <'ether type'=0x0800
286 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
288 * <'ether type'=0x86DD
289 * | 'version'=6, 'next header'=1>
291 #define RTE_PTYPE_L4_ICMP 0x00000500
293 * Non-fragmented IP (Internet Protocol) packet type.
294 * It is used for outer packet for tunneling cases.
296 * It refers to those packets of any IP types, while cannot be recognized as
297 * any of above L4 types (RTE_PTYPE_L4_TCP, RTE_PTYPE_L4_UDP,
298 * RTE_PTYPE_L4_FRAG, RTE_PTYPE_L4_SCTP, RTE_PTYPE_L4_ICMP).
301 * <'ether type'=0x0800
302 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
304 * <'ether type'=0x86DD
305 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
307 #define RTE_PTYPE_L4_NONFRAG 0x00000600
309 * Mask of layer 4 packet types.
310 * It is used for outer packet for tunneling cases.
312 #define RTE_PTYPE_L4_MASK 0x00000f00
314 * IP (Internet Protocol) in IP (Internet Protocol) tunneling packet type.
317 * <'ether type'=0x0800
318 * | 'version'=4, 'protocol'=[4|41]>
320 * <'ether type'=0x86DD
321 * | 'version'=6, 'next header'=[4|41]>
323 #define RTE_PTYPE_TUNNEL_IP 0x00001000
325 * GRE (Generic Routing Encapsulation) tunneling packet type.
328 * <'ether type'=0x0800
329 * | 'version'=4, 'protocol'=47>
331 * <'ether type'=0x86DD
332 * | 'version'=6, 'next header'=47>
334 #define RTE_PTYPE_TUNNEL_GRE 0x00002000
336 * VXLAN (Virtual eXtensible Local Area Network) tunneling packet type.
339 * <'ether type'=0x0800
340 * | 'version'=4, 'protocol'=17
341 * | 'destination port'=4798>
343 * <'ether type'=0x86DD
344 * | 'version'=6, 'next header'=17
345 * | 'destination port'=4798>
347 #define RTE_PTYPE_TUNNEL_VXLAN 0x00003000
349 * NVGRE (Network Virtualization using Generic Routing Encapsulation) tunneling
353 * <'ether type'=0x0800
354 * | 'version'=4, 'protocol'=47
355 * | 'protocol type'=0x6558>
357 * <'ether type'=0x86DD
358 * | 'version'=6, 'next header'=47
359 * | 'protocol type'=0x6558'>
361 #define RTE_PTYPE_TUNNEL_NVGRE 0x00004000
363 * GENEVE (Generic Network Virtualization Encapsulation) tunneling packet type.
366 * <'ether type'=0x0800
367 * | 'version'=4, 'protocol'=17
368 * | 'destination port'=6081>
370 * <'ether type'=0x86DD
371 * | 'version'=6, 'next header'=17
372 * | 'destination port'=6081>
374 #define RTE_PTYPE_TUNNEL_GENEVE 0x00005000
376 * Tunneling packet type of Teredo, VXLAN (Virtual eXtensible Local Area
377 * Network) or GRE (Generic Routing Encapsulation) could be recognized as this
378 * packet type, if they can not be recognized independently as of hardware
381 #define RTE_PTYPE_TUNNEL_GRENAT 0x00006000
383 * Mask of tunneling packet types.
385 #define RTE_PTYPE_TUNNEL_MASK 0x0000f000
387 * Ethernet packet type.
388 * It is used for inner packet type only.
390 * Packet format (inner only):
391 * <'ether type'=[0x800|0x86DD]>
393 #define RTE_PTYPE_INNER_L2_ETHER 0x00010000
395 * Ethernet packet type with VLAN (Virtual Local Area Network) tag.
397 * Packet format (inner only):
398 * <'ether type'=[0x800|0x86DD], vlan=[1-4095]>
400 #define RTE_PTYPE_INNER_L2_ETHER_VLAN 0x00020000
405 * <'ether type'=[0x88A8]>
407 #define RTE_PTYPE_INNER_L2_ETHER_QINQ 0x00030000
409 * Mask of inner layer 2 packet types.
411 #define RTE_PTYPE_INNER_L2_MASK 0x000f0000
413 * IP (Internet Protocol) version 4 packet type.
414 * It is used for inner packet only, and does not contain any header option.
416 * Packet format (inner only):
417 * <'ether type'=0x0800
418 * | 'version'=4, 'ihl'=5>
420 #define RTE_PTYPE_INNER_L3_IPV4 0x00100000
422 * IP (Internet Protocol) version 4 packet type.
423 * It is used for inner packet only, and contains header options.
425 * Packet format (inner only):
426 * <'ether type'=0x0800
427 * | 'version'=4, 'ihl'=[6-15], 'options'>
429 #define RTE_PTYPE_INNER_L3_IPV4_EXT 0x00200000
431 * IP (Internet Protocol) version 6 packet type.
432 * It is used for inner packet only, and does not contain any extension header.
434 * Packet format (inner only):
435 * <'ether type'=0x86DD
436 * | 'version'=6, 'next header'=0x3B>
438 #define RTE_PTYPE_INNER_L3_IPV6 0x00300000
440 * IP (Internet Protocol) version 4 packet type.
441 * It is used for inner packet only, and may or maynot contain header options.
443 * Packet format (inner only):
444 * <'ether type'=0x0800
445 * | 'version'=4, 'ihl'=[5-15], <'options'>>
447 #define RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN 0x00400000
449 * IP (Internet Protocol) version 6 packet type.
450 * It is used for inner packet only, and contains extension headers.
452 * Packet format (inner only):
453 * <'ether type'=0x86DD
454 * | 'version'=6, 'next header'=[0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
455 * 'extension headers'>
457 #define RTE_PTYPE_INNER_L3_IPV6_EXT 0x00500000
459 * IP (Internet Protocol) version 6 packet type.
460 * It is used for inner packet only, and may or maynot contain extension
463 * Packet format (inner only):
464 * <'ether type'=0x86DD
465 * | 'version'=6, 'next header'=[0x3B|0x0|0x2B|0x2C|0x32|0x33|0x3C|0x87],
466 * <'extension headers'>>
468 #define RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN 0x00600000
470 * Mask of inner layer 3 packet types.
472 #define RTE_PTYPE_INNER_L3_MASK 0x00f00000
474 * TCP (Transmission Control Protocol) packet type.
475 * It is used for inner packet only.
477 * Packet format (inner only):
478 * <'ether type'=0x0800
479 * | 'version'=4, 'protocol'=6, 'MF'=0, 'frag_offset'=0>
481 * <'ether type'=0x86DD
482 * | 'version'=6, 'next header'=6>
484 #define RTE_PTYPE_INNER_L4_TCP 0x01000000
486 * UDP (User Datagram Protocol) packet type.
487 * It is used for inner packet only.
489 * Packet format (inner only):
490 * <'ether type'=0x0800
491 * | 'version'=4, 'protocol'=17, 'MF'=0, 'frag_offset'=0>
493 * <'ether type'=0x86DD
494 * | 'version'=6, 'next header'=17>
496 #define RTE_PTYPE_INNER_L4_UDP 0x02000000
498 * Fragmented IP (Internet Protocol) packet type.
499 * It is used for inner packet only, and may or maynot have layer 4 packet.
501 * Packet format (inner only):
502 * <'ether type'=0x0800
503 * | 'version'=4, 'MF'=1>
505 * <'ether type'=0x0800
506 * | 'version'=4, 'frag_offset'!=0>
508 * <'ether type'=0x86DD
509 * | 'version'=6, 'next header'=44>
511 #define RTE_PTYPE_INNER_L4_FRAG 0x03000000
513 * SCTP (Stream Control Transmission Protocol) packet type.
514 * It is used for inner packet only.
516 * Packet format (inner only):
517 * <'ether type'=0x0800
518 * | 'version'=4, 'protocol'=132, 'MF'=0, 'frag_offset'=0>
520 * <'ether type'=0x86DD
521 * | 'version'=6, 'next header'=132>
523 #define RTE_PTYPE_INNER_L4_SCTP 0x04000000
525 * ICMP (Internet Control Message Protocol) packet type.
526 * It is used for inner packet only.
528 * Packet format (inner only):
529 * <'ether type'=0x0800
530 * | 'version'=4, 'protocol'=1, 'MF'=0, 'frag_offset'=0>
532 * <'ether type'=0x86DD
533 * | 'version'=6, 'next header'=1>
535 #define RTE_PTYPE_INNER_L4_ICMP 0x05000000
537 * Non-fragmented IP (Internet Protocol) packet type.
538 * It is used for inner packet only, and may or maynot have other unknown layer
541 * Packet format (inner only):
542 * <'ether type'=0x0800
543 * | 'version'=4, 'protocol'!=[6|17|132|1], 'MF'=0, 'frag_offset'=0>
545 * <'ether type'=0x86DD
546 * | 'version'=6, 'next header'!=[6|17|44|132|1]>
548 #define RTE_PTYPE_INNER_L4_NONFRAG 0x06000000
550 * Mask of inner layer 4 packet types.
552 #define RTE_PTYPE_INNER_L4_MASK 0x0f000000
554 * All valid layer masks.
556 #define RTE_PTYPE_ALL_MASK 0x0fffffff
559 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
560 * one, bit 4 is selected to be used for IPv4 only. Then checking bit 4 can
561 * determine if it is an IPV4 packet.
563 #define RTE_ETH_IS_IPV4_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV4)
566 * Check if the (outer) L3 header is IPv4. To avoid comparing IPv4 types one by
567 * one, bit 6 is selected to be used for IPv4 only. Then checking bit 6 can
568 * determine if it is an IPV4 packet.
570 #define RTE_ETH_IS_IPV6_HDR(ptype) ((ptype) & RTE_PTYPE_L3_IPV6)
572 /* Check if it is a tunneling packet */
573 #define RTE_ETH_IS_TUNNEL_PKT(ptype) ((ptype) & \
574 (RTE_PTYPE_TUNNEL_MASK | \
575 RTE_PTYPE_INNER_L2_MASK | \
576 RTE_PTYPE_INNER_L3_MASK | \
577 RTE_PTYPE_INNER_L4_MASK))
580 * Get the name of the l2 packet type
583 * The packet type value.
585 * A non-null string describing the packet type.
587 const char *rte_get_ptype_l2_name(uint32_t ptype);
590 * Get the name of the l3 packet type
593 * The packet type value.
595 * A non-null string describing the packet type.
597 const char *rte_get_ptype_l3_name(uint32_t ptype);
600 * Get the name of the l4 packet type
603 * The packet type value.
605 * A non-null string describing the packet type.
607 const char *rte_get_ptype_l4_name(uint32_t ptype);
610 * Get the name of the tunnel packet type
613 * The packet type value.
615 * A non-null string describing the packet type.
617 const char *rte_get_ptype_tunnel_name(uint32_t ptype);
620 * Get the name of the inner_l2 packet type
623 * The packet type value.
625 * A non-null string describing the packet type.
627 const char *rte_get_ptype_inner_l2_name(uint32_t ptype);
630 * Get the name of the inner_l3 packet type
633 * The packet type value.
635 * A non-null string describing the packet type.
637 const char *rte_get_ptype_inner_l3_name(uint32_t ptype);
640 * Get the name of the inner_l4 packet type
643 * The packet type value.
645 * A non-null string describing the packet type.
647 const char *rte_get_ptype_inner_l4_name(uint32_t ptype);
650 * Write the packet type name into the buffer
653 * The packet type value.
655 * The buffer where the string is written.
657 * The length of the buffer.
660 * - (-1) if the buffer is too small
662 int rte_get_ptype_name(uint32_t ptype, char *buf, size_t buflen);
668 #endif /* _RTE_MBUF_PTYPE_H_ */