DPDK  19.08.2
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 l3_len;
24  uint8_t l4_len;
25  uint8_t tunnel_len;
26  uint8_t inner_l2_len;
27  uint8_t inner_l3_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 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
124  /*
125  * Does packet set any of available offloads?
126  * Mainly it is required to avoid fragmented headers check if
127  * no offloads are requested.
128  */
129  if (!(ol_flags & PKT_TX_OFFLOAD_MASK))
130  return 0;
131 #endif
132 
133  if (ol_flags & (PKT_TX_OUTER_IPV4 | PKT_TX_OUTER_IPV6))
134  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
135 
136 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
137  /*
138  * Check if headers are fragmented.
139  * The check could be less strict depending on which offloads are
140  * requested and headers to be used, but let's keep it simple.
141  */
143  inner_l3_offset + m->l3_len + m->l4_len))
144  return -ENOTSUP;
145 #endif
146 
147  if (ol_flags & PKT_TX_IPV4) {
148  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
149  inner_l3_offset);
150 
151  if (ol_flags & PKT_TX_IP_CKSUM)
152  ipv4_hdr->hdr_checksum = 0;
153  }
154 
155  if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_UDP_CKSUM) {
156  if (ol_flags & PKT_TX_IPV4) {
157  udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
158  m->l3_len);
159  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
160  ol_flags);
161  } else {
162  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
163  struct rte_ipv6_hdr *, inner_l3_offset);
164  /* non-TSO udp */
165  udp_hdr = rte_pktmbuf_mtod_offset(m,
166  struct rte_udp_hdr *,
167  inner_l3_offset + m->l3_len);
168  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
169  ol_flags);
170  }
171  } else if ((ol_flags & PKT_TX_L4_MASK) == PKT_TX_TCP_CKSUM ||
172  (ol_flags & PKT_TX_TCP_SEG)) {
173  if (ol_flags & PKT_TX_IPV4) {
174  /* non-TSO tcp or TSO */
175  tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr +
176  m->l3_len);
177  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
178  ol_flags);
179  } else {
180  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
181  struct rte_ipv6_hdr *, inner_l3_offset);
182  /* non-TSO tcp or TSO */
183  tcp_hdr = rte_pktmbuf_mtod_offset(m,
184  struct rte_tcp_hdr *,
185  inner_l3_offset + m->l3_len);
186  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
187  ol_flags);
188  }
189  }
190 
191  return 0;
192 }
193 
212 static inline int
213 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
214 {
215  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
216 }
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 
223 #endif /* _RTE_NET_PTYPE_H_ */
uint16_t cksum
Definition: rte_tcp.h:34
uint64_t l2_len
Definition: rte_mbuf.h:694
uint64_t l4_len
Definition: rte_mbuf.h:700
uint64_t outer_l3_len
Definition: rte_mbuf.h:717
uint64_t l3_len
Definition: rte_mbuf.h:698
uint16_t dgram_cksum
Definition: rte_udp.h:30
#define PKT_TX_OUTER_IPV4
Definition: rte_mbuf.h:364
#define PKT_TX_TCP_SEG
Definition: rte_mbuf.h:300
#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:294
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:393
#define PKT_TX_IPV4
Definition: rte_mbuf.h:332
uint64_t outer_l2_len
Definition: rte_mbuf.h:719
#define PKT_TX_OUTER_IPV6
Definition: rte_mbuf.h:371
uint64_t ol_flags
Definition: rte_mbuf.h:575
#define PKT_TX_L4_MASK
Definition: rte_mbuf.h:316
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:2106
#define PKT_TX_IP_CKSUM
Definition: rte_mbuf.h:324
uint16_t hdr_checksum
Definition: rte_ip.h:41
#define PKT_TX_OFFLOAD_MASK
Definition: rte_mbuf.h:377
#define PKT_TX_UDP_CKSUM
Definition: rte_mbuf.h:315
#define rte_pktmbuf_mtod_offset(m, t, o)
Definition: rte_mbuf.h:2043
#define PKT_TX_TCP_CKSUM
Definition: rte_mbuf.h:313