DPDK 21.11.9
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#include <rte_sctp.h>
16
22 uint8_t l2_len;
23 uint8_t inner_l2_len;
24 uint16_t l3_len;
25 uint16_t inner_l3_len;
26 uint16_t tunnel_len;
27 uint8_t l4_len;
28 uint8_t inner_l4_len;
29};
30
51int
52rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,
53 int *frag);
54
86uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
87 struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
88
109static inline int
110rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
111{
112 /* Initialise ipv4_hdr to avoid false positive compiler warnings. */
113 struct rte_ipv4_hdr *ipv4_hdr = NULL;
114 struct rte_ipv6_hdr *ipv6_hdr;
115 struct rte_tcp_hdr *tcp_hdr;
116 struct rte_udp_hdr *udp_hdr;
117 uint64_t inner_l3_offset = m->l2_len;
118
119 /*
120 * Does packet set any of available offloads?
121 * Mainly it is required to avoid fragmented headers check if
122 * no offloads are requested.
123 */
127 return 0;
128
130 inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
131 /*
132 * prepare outer IPv4 header checksum by setting it to 0,
133 * in order to be computed by hardware NICs.
134 */
135 if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
136 ipv4_hdr = rte_pktmbuf_mtod_offset(m,
137 struct rte_ipv4_hdr *, m->outer_l2_len);
138 ipv4_hdr->hdr_checksum = 0;
139 }
140 if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) {
141 if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) {
142 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
143 m->outer_l2_len);
144 udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
145 m->outer_l3_len);
146 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr, m->ol_flags);
147 } else {
148 ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *,
149 m->outer_l2_len);
150 udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *,
151 m->outer_l2_len + m->outer_l3_len);
152 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr, m->ol_flags);
153 }
154 }
155 }
156
157 /*
158 * Check if headers are fragmented.
159 * The check could be less strict depending on which offloads are
160 * requested and headers to be used, but let's keep it simple.
161 */
163 inner_l3_offset + m->l3_len + m->l4_len))
164 return -ENOTSUP;
165
166 if (ol_flags & RTE_MBUF_F_TX_IPV4) {
167 ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
168 inner_l3_offset);
169
170 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
171 ipv4_hdr->hdr_checksum = 0;
172 }
173
175 if (ol_flags & RTE_MBUF_F_TX_IPV4) {
176 udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
177 m->l3_len);
178 udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
179 ol_flags);
180 } else {
181 ipv6_hdr = rte_pktmbuf_mtod_offset(m,
182 struct rte_ipv6_hdr *, inner_l3_offset);
183 /* non-TSO udp */
184 udp_hdr = rte_pktmbuf_mtod_offset(m,
185 struct rte_udp_hdr *,
186 inner_l3_offset + m->l3_len);
187 udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
188 ol_flags);
189 }
190 } else if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_TCP_CKSUM ||
191 (ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
192 if (ol_flags & RTE_MBUF_F_TX_IPV4) {
193 /* non-TSO tcp or TSO */
194 tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr +
195 m->l3_len);
196 tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
197 ol_flags);
198 } else {
199 ipv6_hdr = rte_pktmbuf_mtod_offset(m,
200 struct rte_ipv6_hdr *, inner_l3_offset);
201 /* non-TSO tcp or TSO */
202 tcp_hdr = rte_pktmbuf_mtod_offset(m,
203 struct rte_tcp_hdr *,
204 inner_l3_offset + m->l3_len);
205 tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
206 ol_flags);
207 }
208 }
209
210 return 0;
211}
212
231static inline int
232rte_net_intel_cksum_prepare(struct rte_mbuf *m)
233{
234 return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
235}
236
237#ifdef __cplusplus
238}
239#endif
240
241
242#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:327
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:474
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:1531
#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:61
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