20 #ifdef RTE_EXEC_ENV_WINDOWS 23 #include <sys/socket.h> 24 #include <sys/types.h> 25 #include <netinet/in.h> 26 #include <arpa/inet.h> 27 #include <netinet/ip.h> 28 #include <netinet/ip6.h> 47 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN 50 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN 56 uint8_t type_of_service;
61 uint8_t next_proto_id;
68 #define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \ 69 (((b) & 0xff) << 16) | \ 70 (((c) & 0xff) << 8) | \ 74 #define RTE_IPV4_MAX_PKT_LEN 65535 77 #define RTE_IPV4_HDR_IHL_MASK (0x0f) 82 #define RTE_IPV4_IHL_MULTIPLIER (4) 85 #define RTE_IPV4_HDR_DSCP_MASK (0xfc) 86 #define RTE_IPV4_HDR_ECN_MASK (0x03) 87 #define RTE_IPV4_HDR_ECN_CE RTE_IPV4_HDR_ECN_MASK 90 #define RTE_IPV4_HDR_DF_SHIFT 14 91 #define RTE_IPV4_HDR_MF_SHIFT 13 92 #define RTE_IPV4_HDR_FO_SHIFT 3 94 #define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT) 95 #define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT) 97 #define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1) 99 #define RTE_IPV4_HDR_OFFSET_UNITS 8 102 #define RTE_IPV4_HDR_OPT_EOL 0 103 #define RTE_IPV4_HDR_OPT_NOP 1 104 #define RTE_IPV4_HDR_OPT_COPIED(v) ((v) & 0x80) 105 #define RTE_IPV4_HDR_OPT_MAX_LEN 40 110 #define RTE_IPV4_ANY ((uint32_t)0x00000000) 111 #define RTE_IPV4_LOOPBACK ((uint32_t)0x7f000001) 112 #define RTE_IPV4_BROADCAST ((uint32_t)0xe0000000) 113 #define RTE_IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001) 114 #define RTE_IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002) 115 #define RTE_IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff) 120 #define RTE_IPV4_MIN_MCAST \ 121 RTE_IPV4(224, 0, 0, 0) 122 #define RTE_IPV4_MAX_MCAST \ 123 RTE_IPV4(239, 255, 255, 255) 125 #define RTE_IS_IPV4_MCAST(x) \ 126 ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST) 130 #define RTE_IPV4_MIN_IHL (0x5) 131 #define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL) 141 static inline uint8_t
158 static inline uint16_t
163 return (uint16_t)~cksum;
181 static inline uint16_t
184 const uint16_t *v16_h;
191 v16_h = (
const uint16_t *)ipv4_hdr;
192 ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
193 v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
196 ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
197 ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
198 return (uint16_t)(~ip_cksum);
219 static inline uint16_t
222 struct ipv4_psd_header {
232 psd_hdr.src_addr = ipv4_hdr->src_addr;
233 psd_hdr.dst_addr = ipv4_hdr->dst_addr;
235 psd_hdr.proto = ipv4_hdr->next_proto_id;
249 static inline uint16_t
250 __rte_ipv4_udptcp_cksum(
const struct rte_ipv4_hdr *ipv4_hdr,
const void *l4_hdr)
253 uint32_t l3_len, l4_len;
258 if (l3_len < ip_hdr_len)
261 l4_len = l3_len - ip_hdr_len;
266 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
268 return (uint16_t)cksum;
283 static inline uint16_t
286 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
295 if (cksum == 0 && ipv4_hdr->next_proto_id == IPPROTO_UDP)
304 static inline uint16_t
305 __rte_ipv4_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
306 const struct rte_ipv4_hdr *ipv4_hdr,
323 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
325 return (uint16_t)cksum;
340 static inline uint16_t
342 const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
344 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
353 if (cksum == 0 && ipv4_hdr->next_proto_id == IPPROTO_UDP)
376 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
401 const struct rte_ipv4_hdr *ipv4_hdr,
404 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
#define RTE_IPV4_HDR_IHL_MASK
static int rte_ipv4_udptcp_cksum_verify(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
#define RTE_MBUF_F_TX_UDP_SEG
static uint8_t rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
struct __rte_aligned(2) rte_ipv4_hdr
static rte_be16_t rte_cpu_to_be_16(uint16_t x)
static uint16_t rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
static uint16_t rte_raw_cksum(const void *buf, size_t len)
#define RTE_MBUF_F_TX_TCP_SEG
static uint16_t rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
static int rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m, const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
static uint16_t rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
static int rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len, uint16_t *cksum)
static uint16_t rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
#define RTE_IPV4_IHL_MULTIPLIER
static uint16_t rte_be_to_cpu_16(rte_be16_t x)
static __rte_experimental uint16_t rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)