DPDK  19.02.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 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 ipv4_hdr *ipv4_hdr;
116  struct ipv6_hdr *ipv6_hdr;
117  struct tcp_hdr *tcp_hdr;
118  struct udp_hdr *udp_hdr;
119  uint64_t inner_l3_offset = m->l2_len;
120 
121  if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
122  (ol_flags & PKT_TX_OUTER_IPV6))
123  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
124 
125  if (ol_flags & PKT_TX_IPV4) {
126  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
127  inner_l3_offset);
128 
129  if (ol_flags & PKT_TX_IP_CKSUM)
130  ipv4_hdr->hdr_checksum = 0;
131  }
132 
133  if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
134  if (ol_flags & PKT_TX_IPV4) {
135  udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
136  m->l3_len);
137  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
138  ol_flags);
139  } else {
140  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
141  inner_l3_offset);
142  /* non-TSO udp */
143  udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
144  inner_l3_offset + m->l3_len);
145  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
146  ol_flags);
147  }
148  } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
149  (ol_flags & PKT_TX_TCP_SEG)) {
150  if (ol_flags & PKT_TX_IPV4) {
151  /* non-TSO tcp or TSO */
152  tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
153  m->l3_len);
154  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
155  ol_flags);
156  } else {
157  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
158  inner_l3_offset);
159  /* non-TSO tcp or TSO */
160  tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
161  inner_l3_offset + m->l3_len);
162  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
163  ol_flags);
164  }
165  }
166 
167  return 0;
168 }
169 
188 static inline int
189 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
190 {
191  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
192 }
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 
199 #endif /* _RTE_NET_PTYPE_H_ */