DPDK 22.11.6
rte_net.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016 6WIND S.A.
3 */
4
5#ifndef _RTE_NET_PTYPE_H_
6#define _RTE_NET_PTYPE_H_
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <rte_ip.h>
13#include <rte_udp.h>
14#include <rte_tcp.h>
15
21 uint8_t l2_len;
22 uint8_t inner_l2_len;
23 uint16_t l3_len;
24 uint16_t inner_l3_len;
25 uint16_t tunnel_len;
26 uint8_t l4_len;
27 uint8_t inner_l4_len;
28};
29
50int
51rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,
52 int *frag);
53
85uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
86 struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
87
108static inline int
109rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
110{
111 /* Initialise ipv4_hdr to avoid false positive compiler warnings. */
112 struct rte_ipv4_hdr *ipv4_hdr = NULL;
113 struct rte_ipv6_hdr *ipv6_hdr;
114 struct rte_tcp_hdr *tcp_hdr;
115 struct rte_udp_hdr *udp_hdr;
116 uint64_t inner_l3_offset = m->l2_len;
117
118 /*
119 * Does packet set any of available offloads?
120 * Mainly it is required to avoid fragmented headers check if
121 * no offloads are requested.
122 */
125 return 0;
126
128 inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
129 /*
130 * prepare outer IPv4 header checksum by setting it to 0,
131 * in order to be computed by hardware NICs.
132 */
133 if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
134 ipv4_hdr = rte_pktmbuf_mtod_offset(m,
135 struct rte_ipv4_hdr *, m->outer_l2_len);
136 ipv4_hdr->hdr_checksum = 0;
137 }
138 if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) {
139 if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) {
140 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
141 m->outer_l2_len);
142 udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
143 m->outer_l3_len);
144 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr, m->ol_flags);
145 } else {
146 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
147 m->outer_l2_len);
148 udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *,
149 m->outer_l2_len + m->outer_l3_len);
150 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr, m->ol_flags);
151 }
152 }
153 }
154
155 /*
156 * Check if headers are fragmented.
157 * The check could be less strict depending on which offloads are
158 * requested and headers to be used, but let's keep it simple.
159 */
161 inner_l3_offset + m->l3_len + m->l4_len))
162 return -ENOTSUP;
163
164 if (ol_flags & RTE_MBUF_F_TX_IPV4) {
165 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
166 inner_l3_offset);
167
168 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
169 ipv4_hdr->hdr_checksum = 0;
170 }
171
173 if (ol_flags & RTE_MBUF_F_TX_IPV4) {
174 udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
175 m->l3_len);
176 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
177 ol_flags);
178 } else {
179 ipv6_hdr = rte_pktmbuf_mtod_offset(m,
180 struct rte_ipv6_hdr *, inner_l3_offset);
181 /* non-TSO udp */
182 udp_hdr = rte_pktmbuf_mtod_offset(m,
183 struct rte_udp_hdr *,
184 inner_l3_offset + m->l3_len);
185 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
186 ol_flags);
187 }
188 } else if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_TCP_CKSUM ||
189 (ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
190 if (ol_flags & RTE_MBUF_F_TX_IPV4) {
191 /* non-TSO tcp or TSO */
192 tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr +
193 m->l3_len);
194 tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
195 ol_flags);
196 } else {
197 ipv6_hdr = rte_pktmbuf_mtod_offset(m,
198 struct rte_ipv6_hdr *, inner_l3_offset);
199 /* non-TSO tcp or TSO */
200 tcp_hdr = rte_pktmbuf_mtod_offset(m,
201 struct rte_tcp_hdr *,
202 inner_l3_offset + m->l3_len);
203 tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
204 ol_flags);
205 }
206 }
207
208 return 0;
209}
210
229static inline int
230rte_net_intel_cksum_prepare(struct rte_mbuf *m)
231{
232 return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
233}
234
235#ifdef __cplusplus
236}
237#endif
238
239
240#endif /* _RTE_NET_PTYPE_H_ */
#define unlikely(x)
static uint16_t rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
Definition: rte_ip.h:334
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:575
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:1569
#define RTE_MBUF_F_TX_OUTER_UDP_CKSUM
#define RTE_MBUF_F_TX_OUTER_IP_CKSUM
#define RTE_MBUF_F_TX_IP_CKSUM
#define RTE_MBUF_F_TX_OUTER_IPV6
#define RTE_MBUF_F_TX_TCP_SEG
#define RTE_MBUF_F_TX_L4_MASK
#define RTE_MBUF_F_TX_OUTER_IPV4
#define RTE_MBUF_F_TX_TCP_CKSUM
#define RTE_MBUF_F_TX_IPV4
#define rte_pktmbuf_mtod_offset(m, t, o)
#define RTE_MBUF_F_TX_UDP_CKSUM
rte_be16_t hdr_checksum
Definition: rte_ip.h:62
uint64_t ol_flags
uint64_t l4_len
uint64_t l3_len
uint64_t l2_len
uint64_t outer_l3_len
uint64_t outer_l2_len
rte_be16_t cksum
Definition: rte_tcp.h:36
rte_be16_t dgram_cksum
Definition: rte_udp.h:32