DPDK  19.08.0-rc0
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 int __rte_experimental
55 rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,
56  int *frag);
57 
89 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
90  struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
91 
112 static inline int
113 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
114 {
115  struct rte_ipv4_hdr *ipv4_hdr;
116  struct rte_ipv6_hdr *ipv6_hdr;
117  struct rte_tcp_hdr *tcp_hdr;
118  struct rte_udp_hdr *udp_hdr;
119  uint64_t inner_l3_offset = m->l2_len;
120 
121 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
122  /*
123  * Does packet set any of available offloads?
124  * Mainly it is required to avoid fragmented headers check if
125  * no offloads are requested.
126  */
127  if (!(ol_flags & PKT_TX_OFFLOAD_MASK))
128  return 0;
129 #endif
130 
131  if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
132  (ol_flags & PKT_TX_OUTER_IPV6))
133  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
134 
135 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
136  /*
137  * Check if headers are fragmented.
138  * The check could be less strict depending on which offloads are
139  * requested and headers to be used, but let's keep it simple.
140  */
142  inner_l3_offset + m->l3_len + m->l4_len))
143  return -ENOTSUP;
144 #endif
145 
146  if (ol_flags & PKT_TX_IPV4) {
147  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
148  inner_l3_offset);
149 
150  if (ol_flags & PKT_TX_IP_CKSUM)
151  ipv4_hdr->hdr_checksum = 0;
152  }
153 
154  if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
155  if (ol_flags & PKT_TX_IPV4) {
156  udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr +
157  m->l3_len);
158  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
159  ol_flags);
160  } else {
161  ipv6_hdr = rte_pktmbuf_mtod_offset(m,
162  struct rte_ipv6_hdr *, inner_l3_offset);
163  /* non-TSO udp */
164  udp_hdr = rte_pktmbuf_mtod_offset(m,
165  struct rte_udp_hdr *,
166  inner_l3_offset + m->l3_len);
167  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
168  ol_flags);
169  }
170  } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
171  (ol_flags & PKT_TX_TCP_SEG)) {
172  if (ol_flags & PKT_TX_IPV4) {
173  /* non-TSO tcp or TSO */
174  tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr +
175  m->l3_len);
176  tcp_hdr->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 tcp or TSO */
182  tcp_hdr = rte_pktmbuf_mtod_offset(m,
183  struct rte_tcp_hdr *,
184  inner_l3_offset + m->l3_len);
185  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
186  ol_flags);
187  }
188  }
189 
190  return 0;
191 }
192 
211 static inline int
212 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
213 {
214  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
215 }
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 
222 #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
#define PKT_TX_OUTER_IP_CKSUM
Definition: rte_mbuf.h:357
uint64_t outer_l3_len
Definition: rte_mbuf.h:706
uint64_t l3_len
Definition: rte_mbuf.h:698
uint16_t dgram_cksum
Definition: rte_udp.h:30
#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:283
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:379
#define PKT_TX_IPV4
Definition: rte_mbuf.h:332
uint64_t outer_l2_len
Definition: rte_mbuf.h:708
#define PKT_TX_OUTER_IPV6
Definition: rte_mbuf.h:371
uint64_t ol_flags
Definition: rte_mbuf.h:575
#define rte_pktmbuf_data_len(m)
Definition: rte_mbuf.h:2085
#define PKT_TX_IP_CKSUM
Definition: rte_mbuf.h:324
uint16_t hdr_checksum
Definition: rte_ip.h:39
#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:2022
#define PKT_TX_TCP_CKSUM
Definition: rte_mbuf.h:313