DPDK  make-f/builddir/build/BUILD/dpdk-17.02/mk/rte.sdkconfig.mkshowversion
rte_net.h
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright 2016 6WIND S.A.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_NET_PTYPE_H_
35 #define _RTE_NET_PTYPE_H_
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <rte_ip.h>
42 #include <rte_udp.h>
43 #include <rte_tcp.h>
44 #include <rte_sctp.h>
45 
51  uint8_t l2_len;
52  uint8_t l3_len;
53  uint8_t l4_len;
54  uint8_t tunnel_len;
55  uint8_t inner_l2_len;
56  uint8_t inner_l3_len;
57  uint8_t inner_l4_len;
58 };
59 
91 uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
92  struct rte_net_hdr_lens *hdr_lens, uint32_t layers);
93 
114 static inline int
115 rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags)
116 {
117  struct ipv4_hdr *ipv4_hdr;
118  struct ipv6_hdr *ipv6_hdr;
119  struct tcp_hdr *tcp_hdr;
120  struct udp_hdr *udp_hdr;
121  uint64_t inner_l3_offset = m->l2_len;
122 
123  if (ol_flags & PKT_TX_OUTER_IP_CKSUM)
124  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
125 
126  if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
127  if (ol_flags & PKT_TX_IPV4) {
128  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
129  inner_l3_offset);
130 
131  if (ol_flags & PKT_TX_IP_CKSUM)
132  ipv4_hdr->hdr_checksum = 0;
133 
134  udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
135  m->l3_len);
136  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
137  ol_flags);
138  } else {
139  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
140  inner_l3_offset);
141  /* non-TSO udp */
142  udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
143  inner_l3_offset + m->l3_len);
144  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
145  ol_flags);
146  }
147  } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
148  (ol_flags & PKT_TX_TCP_SEG)) {
149  if (ol_flags & PKT_TX_IPV4) {
150  ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *,
151  inner_l3_offset);
152 
153  if (ol_flags & PKT_TX_IP_CKSUM)
154  ipv4_hdr->hdr_checksum = 0;
155 
156  /* non-TSO tcp or TSO */
157  tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
158  m->l3_len);
159  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
160  ol_flags);
161  } else {
162  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
163  inner_l3_offset);
164  /* non-TSO tcp or TSO */
165  tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
166  inner_l3_offset + m->l3_len);
167  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
168  ol_flags);
169  }
170  }
171 
172  return 0;
173 }
174 
193 static inline int
194 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
195 {
196  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
197 }
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 
204 #endif /* _RTE_NET_PTYPE_H_ */
uint16_t cksum
Definition: rte_tcp.h:96
static uint16_t rte_ipv4_phdr_cksum(const struct ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
Definition: rte_ip.h:341
uint16_t hdr_checksum
Definition: rte_ip.h:101
uint64_t l2_len
Definition: rte_mbuf.h:495
#define PKT_TX_OUTER_IP_CKSUM
Definition: rte_mbuf.h:276
uint64_t outer_l3_len
Definition: rte_mbuf.h:504
uint64_t l3_len
Definition: rte_mbuf.h:499
#define PKT_TX_TCP_SEG
Definition: rte_mbuf.h:220
#define PKT_TX_IPV4
Definition: rte_mbuf.h:256
static uint16_t rte_ipv6_phdr_cksum(const struct ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:427
uint64_t outer_l2_len
Definition: rte_mbuf.h:505
uint64_t ol_flags
Definition: rte_mbuf.h:418
#define PKT_TX_IP_CKSUM
Definition: rte_mbuf.h:248
uint16_t dgram_cksum
Definition: rte_udp.h:92
#define PKT_TX_UDP_CKSUM
Definition: rte_mbuf.h:238
#define rte_pktmbuf_mtod_offset(m, t, o)
Definition: rte_mbuf.h:1405
#define PKT_TX_TCP_CKSUM
Definition: rte_mbuf.h:236