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> 31 #include <rte_compat.h> 47 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN 50 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN 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
161 static inline uint32_t
162 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
167 buf != end; buf =
RTE_PTR_ADD(buf,
sizeof(uint16_t))) {
170 memcpy(&v, buf,
sizeof(uint16_t));
178 memcpy(&left, end, 1);
194 static inline uint16_t
195 __rte_raw_cksum_reduce(uint32_t sum)
197 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
198 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
199 return (uint16_t)sum;
212 static inline uint16_t
217 sum = __rte_raw_cksum(buf, len, 0);
218 return __rte_raw_cksum_reduce(sum);
242 uint32_t seglen, done;
247 const char *, off), len);
256 for (seg = m; seg != NULL; seg = seg->
next) {
262 RTE_ASSERT(seg != NULL);
277 tmp = __rte_raw_cksum(buf, seglen, 0);
287 if (seglen > len - done)
291 *cksum = __rte_raw_cksum_reduce(sum);
305 static inline uint16_t
310 return (uint16_t)~cksum;
331 static inline uint16_t
334 struct ipv4_psd_header {
344 psd_hdr.src_addr = ipv4_hdr->
src_addr;
345 psd_hdr.dst_addr = ipv4_hdr->
dst_addr;
361 static inline uint16_t
362 __rte_ipv4_udptcp_cksum(
const struct rte_ipv4_hdr *ipv4_hdr,
const void *l4_hdr)
365 uint32_t l3_len, l4_len;
370 if (l3_len < ip_hdr_len)
373 l4_len = l3_len - ip_hdr_len;
378 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
380 return (uint16_t)cksum;
395 static inline uint16_t
398 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
416 static inline uint16_t
417 __rte_ipv4_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
432 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
434 return (uint16_t)cksum;
453 static inline uint16_t
457 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
490 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
517 static inline uint16_t
522 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
549 uint8_t segments_left;
563 #define RTE_IPV6_HDR_FL_SHIFT 0 564 #define RTE_IPV6_HDR_TC_SHIFT 20 565 #define RTE_IPV6_HDR_FL_MASK ((1u << RTE_IPV6_HDR_TC_SHIFT) - 1) 566 #define RTE_IPV6_HDR_TC_MASK (0xff << RTE_IPV6_HDR_TC_SHIFT) 567 #define RTE_IPV6_HDR_DSCP_MASK (0xfc << RTE_IPV6_HDR_TC_SHIFT) 568 #define RTE_IPV6_HDR_ECN_MASK (0x03 << RTE_IPV6_HDR_TC_SHIFT) 569 #define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK 571 #define RTE_IPV6_MIN_MTU 1280 589 static inline uint16_t 598 psd_hdr.proto = (uint32_t)(ipv6_hdr->
proto << 24);
605 sum = __rte_raw_cksum(ipv6_hdr->
src_addr,
608 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
609 return __rte_raw_cksum_reduce(sum);
615 static inline uint16_t
616 __rte_ipv6_udptcp_cksum(
const struct rte_ipv6_hdr *ipv6_hdr,
const void *l4_hdr)
626 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
628 return (uint16_t)cksum;
644 static inline uint16_t
647 uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
656 if (cksum == 0 && ipv6_hdr->
proto == IPPROTO_UDP)
665 static inline uint16_t
666 __rte_ipv6_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
681 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
683 return (uint16_t)cksum;
705 static inline uint16_t
709 uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
718 if (cksum == 0 && ipv6_hdr->
proto == IPPROTO_UDP)
743 uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
776 uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
785 #define RTE_IPV6_EHDR_MF_SHIFT 0 786 #define RTE_IPV6_EHDR_MF_MASK 1 787 #define RTE_IPV6_EHDR_FO_SHIFT 3 788 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1)) 789 #define RTE_IPV6_EHDR_FO_ALIGN (1 << RTE_IPV6_EHDR_FO_SHIFT) 791 #define RTE_IPV6_FRAG_USED_MASK (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK) 793 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK) 794 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT) 796 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \ 797 (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK)) 799 struct rte_ipv6_fragment_ext {
807 #define RTE_IPV6_FRAG_HDR_SIZE sizeof(struct rte_ipv6_fragment_ext) 834 *ext_len = (*p + 2) *
sizeof(uint32_t);
837 case IPPROTO_HOPOPTS:
838 case IPPROTO_ROUTING:
839 case IPPROTO_DSTOPTS:
841 *ext_len = (*p + 1) *
sizeof(uint64_t);
844 case IPPROTO_FRAGMENT:
846 *ext_len = RTE_IPV6_FRAG_HDR_SIZE;
static uint8_t rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
static int rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len, uint16_t *cksum)
#define RTE_ALIGN_FLOOR(val, align)
static uint16_t rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
rte_be16_t fragment_offset
static uint16_t rte_bswap16(uint16_t _x)
static __rte_experimental int rte_ipv6_udptcp_cksum_verify(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
static __rte_experimental uint16_t rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
static __rte_experimental uint16_t rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
static __rte_experimental int rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
#define rte_pktmbuf_mtod_offset(m, t, o)
static __rte_experimental int rte_ipv6_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m, const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
#define RTE_PTR_ADD(ptr, x)
static rte_be16_t rte_cpu_to_be_16(uint16_t x)
static uint16_t rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
static uint16_t rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
#define rte_pktmbuf_mtod(m, t)
#define rte_pktmbuf_pkt_len(m)
static uint16_t rte_raw_cksum(const void *buf, size_t len)
#define rte_pktmbuf_data_len(m)
#define RTE_MBUF_F_TX_TCP_SEG
#define RTE_IPV4_HDR_IHL_MASK
static uint16_t rte_be_to_cpu_16(rte_be16_t x)
static __rte_experimental int rte_ipv4_udptcp_cksum_verify(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
static uint16_t rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
static __rte_experimental uint16_t 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_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
#define RTE_IPV4_IHL_MULTIPLIER