DPDK  18.02.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 
62 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
63  struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
64 
85 static inline int
86 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
87 {
88  struct ipv4_hdr *ipv4_hdr;
89  struct ipv6_hdr *ipv6_hdr;
90  struct tcp_hdr *tcp_hdr;
91  struct udp_hdr *udp_hdr;
92  uint64_t inner_l3_offset = m->l2_len;
93 
94  if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) ||
95  (ol_flags & PKT_TX_OUTER_IPV6))
96  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
97 
98  if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
99  if (ol_flags & PKT_TX_IPV4) {
100  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
101  inner_l3_offset);
102 
103  if (ol_flags & PKT_TX_IP_CKSUM)
104  ipv4_hdr->hdr_checksum = 0;
105 
106  udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
107  m->l3_len);
108  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
109  ol_flags);
110  } else {
111  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
112  inner_l3_offset);
113  /* non-TSO udp */
114  udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
115  inner_l3_offset + m->l3_len);
116  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
117  ol_flags);
118  }
119  } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
120  (ol_flags & PKT_TX_TCP_SEG)) {
121  if (ol_flags & PKT_TX_IPV4) {
122  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
123  inner_l3_offset);
124 
125  if (ol_flags & PKT_TX_IP_CKSUM)
126  ipv4_hdr->hdr_checksum = 0;
127 
128  /* non-TSO tcp or TSO */
129  tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
130  m->l3_len);
131  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
132  ol_flags);
133  } else {
134  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
135  inner_l3_offset);
136  /* non-TSO tcp or TSO */
137  tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
138  inner_l3_offset + m->l3_len);
139  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
140  ol_flags);
141  }
142  }
143 
144  return 0;
145 }
146 
165 static inline int
166 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
167 {
168  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
169 }
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 
176 #endif /* _RTE_NET_PTYPE_H_ */