DPDK  20.11.10
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
9 extern "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 
54 __rte_experimental
55 int
56 rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,
57  int *frag);
58 
90 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
91  struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
92 
113 static inline int
114 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
115 {
116  /* Initialise ipv4_hdr to avoid false positive compiler warnings. */
117  struct rte_ipv4_hdr *ipv4_hdr = NULL;
118  struct rte_ipv6_hdr *ipv6_hdr;
119  struct rte_tcp_hdr *tcp_hdr;
120  struct rte_udp_hdr *udp_hdr;
121  uint64_t inner_l3_offset = m->l2_len;
122 
123  /*
124  * Does packet set any of available offloads?
125  * Mainly it is required to avoid fragmented headers check if
126  * no offloads are requested.
127  */
128  if (!(ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK | PKT_TX_TCP_SEG |
130  return 0;
131 
132  if (ol_flags & (PKT_TX_OUTER_IPV4 | PKT_TX_OUTER_IPV6)) {
133  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
134  /*
135  * prepare outer IPv4 header checksum by setting it to 0,
136  * in order to be computed by hardware NICs.
137  */
138  if (ol_flags & PKT_TX_OUTER_IP_CKSUM) {
139  ipv4_hdr = rte_pktmbuf_mtod_offset(m,
140  struct rte_ipv4_hdr *, m->outer_l2_len);
141  ipv4_hdr->hdr_checksum = 0;
142  }
143  }
144 
145  /*
146  * Check if headers are fragmented.
147  * The check could be less strict depending on which offloads are
148  * requested and headers to be used, but let's keep it simple.
149  */
151  inner_l3_offset + m->l3_len + m->l4_len))
152  return -ENOTSUP;
153 
154  if (ol_flags & PKT_TX_IPV4) {
155  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
156  inner_l3_offset);
157 
158  if (ol_flags & PKT_TX_IP_CKSUM)
159  ipv4_hdr->hdr_checksum = 0;
160  }
161 
162  if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_UDP_CKSUM) {
163  if (ol_flags & PKT_TX_IPV4) {
164  udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
165  m->l3_len);
166  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
167  ol_flags);
168  } else {
169  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
170  struct rte_ipv6_hdr *, inner_l3_offset);
171  /* non-TSO udp */
172  udp_hdr = rte_pktmbuf_mtod_offset(m,
173  struct rte_udp_hdr *,
174  inner_l3_offset + m->l3_len);
175  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
176  ol_flags);
177  }
178  } else if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM ||
179  (ol_flags & PKT_TX_TCP_SEG)) {
180  if (ol_flags & PKT_TX_IPV4) {
181  /* non-TSO tcp or TSO */
182  tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr +
183  m->l3_len);
184  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
185  ol_flags);
186  } else {
187  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
188  struct rte_ipv6_hdr *, inner_l3_offset);
189  /* non-TSO tcp or TSO */
190  tcp_hdr = rte_pktmbuf_mtod_offset(m,
191  struct rte_tcp_hdr *,
192  inner_l3_offset + m->l3_len);
193  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
194  ol_flags);
195  }
196  }
197 
198  return 0;
199 }
200 
219 static inline int
220 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
221 {
222  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
223 }
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 
230 #endif /* _RTE_NET_PTYPE_H_ */
#define PKT_TX_OUTER_IP_CKSUM
uint64_t l2_len
#define PKT_TX_TCP_CKSUM
#define PKT_TX_IPV4
uint64_t l4_len
#define PKT_TX_UDP_CKSUM
#define PKT_TX_OUTER_IPV4
rte_be16_t cksum
Definition: rte_tcp.h:36
uint64_t outer_l3_len
#define rte_pktmbuf_mtod_offset(m, t, o)
uint64_t l3_len
#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:307
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:416
#define PKT_TX_TCP_SEG
uint64_t outer_l2_len
#define PKT_TX_IP_CKSUM
uint64_t ol_flags
rte_be16_t dgram_cksum
Definition: rte_udp.h:32
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:1552
#define PKT_TX_L4_MASK
#define PKT_TX_OUTER_IPV6
rte_be16_t hdr_checksum
Definition: rte_ip.h:41