4 * Copyright 2016 6WIND S.A.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _RTE_NET_PTYPE_H_
35 #define _RTE_NET_PTYPE_H_
47 * Structure containing header lengths associated to a packet, filled
48 * by rte_net_get_ptype().
50 struct rte_net_hdr_lens {
61 * Parse an Ethernet packet to get its packet type.
63 * This function parses the network headers in mbuf data and return its
66 * If it is provided by the user, it also fills a rte_net_hdr_lens
67 * structure that contains the lengths of the parsed network
68 * headers. Each length field is valid only if the associated packet
69 * type is set. For instance, hdr_lens->l2_len is valid only if
70 * (retval & RTE_PTYPE_L2_MASK) != RTE_PTYPE_UNKNOWN.
72 * Supported packet types are:
73 * L2: Ether, Vlan, QinQ
76 * Tunnels: IPv4, IPv6, Gre, Nvgre
79 * The packet mbuf to be parsed.
81 * A pointer to a structure where the header lengths will be returned,
84 * List of layers to parse. The function will stop at the first
85 * empty layer. Examples:
86 * - To parse all known layers, use RTE_PTYPE_ALL_MASK.
87 * - To parse only L2 and L3, use RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
89 * The packet type of the packet.
91 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
92 struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
95 * Prepare pseudo header checksum
97 * This function prepares pseudo header checksum for TSO and non-TSO tcp/udp in
98 * provided mbufs packet data and based on the requested offload flags.
100 * - for non-TSO tcp/udp packets full pseudo-header checksum is counted and set
102 * - for TSO the IP payload length is not included in pseudo header.
104 * This function expects that used headers are in the first data segment of
105 * mbuf, are not fragmented and can be safely modified.
108 * The packet mbuf to be fixed.
110 * TX offloads flags to use with this packet.
112 * 0 if checksum is initialized properly
115 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
117 struct ipv4_hdr *ipv4_hdr;
118 struct ipv6_hdr *ipv6_hdr;
119 struct tcp_hdr *tcp_hdr;
120 struct udp_hdr *udp_hdr;
121 uint64_t inner_l3_offset = m->l2_len;
123 if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
124 (ol_flags & PKT_TX_OUTER_IPV6))
125 inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
127 if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
128 if (ol_flags & PKT_TX_IPV4) {
129 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
132 if (ol_flags & PKT_TX_IP_CKSUM)
133 ipv4_hdr->hdr_checksum = 0;
135 udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
137 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
140 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
143 udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
144 inner_l3_offset + m->l3_len);
145 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
148 } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
149 (ol_flags & PKT_TX_TCP_SEG)) {
150 if (ol_flags & PKT_TX_IPV4) {
151 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
154 if (ol_flags & PKT_TX_IP_CKSUM)
155 ipv4_hdr->hdr_checksum = 0;
157 /* non-TSO tcp or TSO */
158 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
160 tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
163 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
165 /* non-TSO tcp or TSO */
166 tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
167 inner_l3_offset + m->l3_len);
168 tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
177 * Prepare pseudo header checksum
179 * This function prepares pseudo header checksum for TSO and non-TSO tcp/udp in
180 * provided mbufs packet data.
182 * - for non-TSO tcp/udp packets full pseudo-header checksum is counted and set
184 * - for TSO the IP payload length is not included in pseudo header.
186 * This function expects that used headers are in the first data segment of
187 * mbuf, are not fragmented and can be safely modified.
190 * The packet mbuf to be fixed.
192 * 0 if checksum is initialized properly
195 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
197 return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
205 #endif /* _RTE_NET_PTYPE_H_ */