DPDK  22.03.0
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 
51 int
52 rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,
53  int *frag);
54 
86 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
87  struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
88 
109 static inline int
110 rte_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  */
126  return 0;
127 
129  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
130  /*
131  * prepare outer IPv4 header checksum by setting it to 0,
132  * in order to be computed by hardware NICs.
133  */
134  if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
135  ipv4_hdr = rte_pktmbuf_mtod_offset(m,
136  struct rte_ipv4_hdr *, m->outer_l2_len);
137  ipv4_hdr->hdr_checksum = 0;
138  }
139  }
140 
141  /*
142  * Check if headers are fragmented.
143  * The check could be less strict depending on which offloads are
144  * requested and headers to be used, but let's keep it simple.
145  */
147  inner_l3_offset + m->l3_len + m->l4_len))
148  return -ENOTSUP;
149 
150  if (ol_flags & RTE_MBUF_F_TX_IPV4) {
151  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
152  inner_l3_offset);
153 
154  if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
155  ipv4_hdr->hdr_checksum = 0;
156  }
157 
158  if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_UDP_CKSUM) {
159  if (ol_flags & RTE_MBUF_F_TX_IPV4) {
160  udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
161  m->l3_len);
162  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
163  ol_flags);
164  } else {
165  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
166  struct rte_ipv6_hdr *, inner_l3_offset);
167  /* non-TSO udp */
168  udp_hdr = rte_pktmbuf_mtod_offset(m,
169  struct rte_udp_hdr *,
170  inner_l3_offset + m->l3_len);
171  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
172  ol_flags);
173  }
174  } else if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_TCP_CKSUM ||
175  (ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
176  if (ol_flags & RTE_MBUF_F_TX_IPV4) {
177  /* non-TSO tcp or TSO */
178  tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr +
179  m->l3_len);
180  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
181  ol_flags);
182  } else {
183  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
184  struct rte_ipv6_hdr *, inner_l3_offset);
185  /* non-TSO tcp or TSO */
186  tcp_hdr = rte_pktmbuf_mtod_offset(m,
187  struct rte_tcp_hdr *,
188  inner_l3_offset + m->l3_len);
189  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
190  ol_flags);
191  }
192  }
193 
194  return 0;
195 }
196 
215 static inline int
216 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
217 {
218  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
219 }
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 
226 #endif /* _RTE_NET_PTYPE_H_ */
#define RTE_MBUF_F_TX_TCP_CKSUM
#define RTE_MBUF_F_TX_OUTER_IPV6
uint64_t l2_len
uint64_t l4_len
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:324
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:562
uint64_t outer_l2_len
#define RTE_MBUF_F_TX_OUTER_IP_CKSUM
#define RTE_MBUF_F_TX_UDP_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:1532
#define RTE_MBUF_F_TX_L4_MASK
#define RTE_MBUF_F_TX_IP_CKSUM
#define RTE_MBUF_F_TX_TCP_SEG
#define RTE_MBUF_F_TX_OUTER_IPV4
#define RTE_MBUF_F_TX_IPV4
rte_be16_t hdr_checksum
Definition: rte_ip.h:61