CNDP  22.08.0
cne_net.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2016 6WIND S.A.
3  */
4 
5 #ifndef _CNE_NET_H_
6 #define _CNE_NET_H_
7 
8 #include <net/cne_ip.h>
9 #include <net/cne_udp.h>
10 #include <net/cne_tcp.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
43 static inline int
44 cne_net_cksum_flags_prepare(pktmbuf_t *m, uint64_t ol_flags)
45 {
46  /* Initialise ipv4_hdr to avoid false positive compiler warnings. */
47  struct cne_ipv4_hdr *ipv4_hdr = NULL;
48  struct cne_ipv6_hdr *ipv6_hdr;
49  struct cne_tcp_hdr *tcp_hdr;
50  struct cne_udp_hdr *udp_hdr;
51  uint64_t inner_l3_offset = m->l2_len;
52 
53  /*
54  * Does packet set any of available offloads?
55  * Mainly it is required to avoid fragmented headers check if
56  * no offloads are requested.
57  */
59  return 0;
60 
62  inner_l3_offset += m->outer_l2_len + m->outer_l3_len;
63 
64  /*
65  * Check if headers are fragmented.
66  * The check could be less strict depending on which offloads are
67  * requested and headers to be used, but let's keep it simple.
68  */
69  if (unlikely(pktmbuf_data_len(m) < inner_l3_offset + m->l3_len + m->l4_len))
70  return -ENOTSUP;
71 
72  if (ol_flags & CNE_MBUF_F_TX_IPV4) {
73  ipv4_hdr = pktmbuf_mtod_offset(m, struct cne_ipv4_hdr *, inner_l3_offset);
74 
75  if (ol_flags & CNE_MBUF_F_TX_IP_CKSUM)
76  ipv4_hdr->hdr_checksum = 0;
77  }
78 
79  if ((ol_flags & CNE_MBUF_F_TX_L4_MASK) == CNE_MBUF_F_TX_UDP_CKSUM) {
80  if (ol_flags & CNE_MBUF_F_TX_IPV4) {
81  udp_hdr = (struct cne_udp_hdr *)((char *)ipv4_hdr + m->l3_len);
82  udp_hdr->dgram_cksum = cne_ipv4_phdr_cksum(ipv4_hdr, ol_flags);
83  } else {
84  ipv6_hdr = pktmbuf_mtod_offset(m, struct cne_ipv6_hdr *, inner_l3_offset);
85  /* non-TSO udp */
86  udp_hdr = pktmbuf_mtod_offset(m, struct cne_udp_hdr *, inner_l3_offset + m->l3_len);
87  udp_hdr->dgram_cksum = cne_ipv6_phdr_cksum(ipv6_hdr, ol_flags);
88  }
89  } else if ((ol_flags & CNE_MBUF_F_TX_L4_MASK) == CNE_MBUF_F_TX_TCP_CKSUM ||
90  (ol_flags & CNE_MBUF_F_TX_TCP_SEG)) {
91  if (ol_flags & CNE_MBUF_F_TX_IPV4) {
92  /* non-TSO tcp or TSO */
93  tcp_hdr = (struct cne_tcp_hdr *)((char *)ipv4_hdr + m->l3_len);
94  tcp_hdr->cksum = cne_ipv4_phdr_cksum(ipv4_hdr, ol_flags);
95  } else {
96  ipv6_hdr = pktmbuf_mtod_offset(m, struct cne_ipv6_hdr *, inner_l3_offset);
97  /* non-TSO tcp or TSO */
98  tcp_hdr = pktmbuf_mtod_offset(m, struct cne_tcp_hdr *, inner_l3_offset + m->l3_len);
99  tcp_hdr->cksum = cne_ipv6_phdr_cksum(ipv6_hdr, ol_flags);
100  }
101  }
102 
103  return 0;
104 }
105 
124 static inline int
126 {
128 }
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* _CNE_NET_H_ */
#define unlikely(x)
static uint16_t cne_ipv4_phdr_cksum(const struct cne_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
Definition: cne_ip.h:254
static uint16_t cne_ipv6_phdr_cksum(const struct cne_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
Definition: cne_ip.h:409
static int cne_net_cksum_flags_prepare(pktmbuf_t *m, uint64_t ol_flags)
Definition: cne_net.h:44
static int cne_net_cksum_prepare(pktmbuf_t *m)
Definition: cne_net.h:125
#define pktmbuf_data_len(m)
Definition: pktmbuf.h:370
#define pktmbuf_mtod_offset(m, t, o)
Definition: pktmbuf.h:402
#define CNE_MBUF_F_TX_TCP_CKSUM
#define CNE_MBUF_F_TX_UDP_CKSUM
#define CNE_MBUF_F_TX_OUTER_IPV6
#define CNE_MBUF_F_TX_TCP_SEG
#define CNE_MBUF_F_TX_L4_MASK
#define CNE_MBUF_F_TX_OUTER_IPV4
#define CNE_MBUF_F_TX_IPV4
#define CNE_MBUF_F_TX_IP_CKSUM
cne_be16_t hdr_checksum
Definition: cne_ip.h:41
cne_be16_t cksum
Definition: cne_tcp.h:36
cne_be16_t dgram_cksum
Definition: cne_udp.h:32
uint64_t ol_flags
Definition: pktmbuf.h:195
uint64_t l4_len
Definition: pktmbuf.h:173
uint64_t l3_len
Definition: pktmbuf.h:172
uint64_t l2_len
Definition: pktmbuf.h:168
uint64_t outer_l3_len
Definition: pktmbuf.h:188
uint64_t outer_l2_len
Definition: pktmbuf.h:189