DPDK  17.11.10
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  (ol_flags & PKT_TX_OUTER_IPV6))
125  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
126 
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 
135  if ((ol_flags & PKT_TX_UDP_CKSUM) == PKT_TX_UDP_CKSUM) {
136  if (ol_flags & PKT_TX_IPV4) {
137  udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
138  m->l3_len);
139  udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
140  ol_flags);
141  } else {
142  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
143  inner_l3_offset);
144  /* non-TSO udp */
145  udp_hdr = rte_pktmbuf_mtod_offset(m, struct udp_hdr *,
146  inner_l3_offset + m->l3_len);
147  udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
148  ol_flags);
149  }
150  } else if ((ol_flags & PKT_TX_TCP_CKSUM) ||
151  (ol_flags & PKT_TX_TCP_SEG)) {
152  if (ol_flags & PKT_TX_IPV4) {
153  /* non-TSO tcp or TSO */
154  tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
155  m->l3_len);
156  tcp_hdr->cksum = rte_ipv4_phdr_cksum(ipv4_hdr,
157  ol_flags);
158  } else {
159  ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *,
160  inner_l3_offset);
161  /* non-TSO tcp or TSO */
162  tcp_hdr = rte_pktmbuf_mtod_offset(m, struct tcp_hdr *,
163  inner_l3_offset + m->l3_len);
164  tcp_hdr->cksum = rte_ipv6_phdr_cksum(ipv6_hdr,
165  ol_flags);
166  }
167  }
168 
169  return 0;
170 }
171 
190 static inline int
191 rte_net_intel_cksum_prepare(struct rte_mbuf *m)
192 {
193  return rte_net_intel_cksum_flags_prepare(m, m->ol_flags);
194 }
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 
201 #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:557
#define PKT_TX_OUTER_IP_CKSUM
Definition: rte_mbuf.h:304
uint64_t outer_l3_len
Definition: rte_mbuf.h:566
uint64_t l3_len
Definition: rte_mbuf.h:561
#define PKT_TX_TCP_SEG
Definition: rte_mbuf.h:254
#define PKT_TX_IPV4
Definition: rte_mbuf.h:286
static uint16_t rte_ipv6_phdr_cksum(const struct ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: rte_ip.h:437
uint64_t outer_l2_len
Definition: rte_mbuf.h:567
#define PKT_TX_OUTER_IPV6
Definition: rte_mbuf.h:318
uint64_t ol_flags
Definition: rte_mbuf.h:462
#define PKT_TX_IP_CKSUM
Definition: rte_mbuf.h:278
uint16_t dgram_cksum
Definition: rte_udp.h:92
#define PKT_TX_UDP_CKSUM
Definition: rte_mbuf.h:269
#define rte_pktmbuf_mtod_offset(m, t, o)
Definition: rte_mbuf.h:1581
#define PKT_TX_TCP_CKSUM
Definition: rte_mbuf.h:267