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> 46 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN 49 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN 67 #define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \ 68 (((b) & 0xff) << 16) | \ 69 (((c) & 0xff) << 8) | \ 73 #define RTE_IPV4_MAX_PKT_LEN 65535 76 #define RTE_IPV4_HDR_IHL_MASK (0x0f) 81 #define RTE_IPV4_IHL_MULTIPLIER (4) 84 #define RTE_IPV4_HDR_DSCP_MASK (0xfc) 85 #define RTE_IPV4_HDR_ECN_MASK (0x03) 86 #define RTE_IPV4_HDR_ECN_CE RTE_IPV4_HDR_ECN_MASK 89 #define RTE_IPV4_HDR_DF_SHIFT 14 90 #define RTE_IPV4_HDR_MF_SHIFT 13 91 #define RTE_IPV4_HDR_FO_SHIFT 3 93 #define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT) 94 #define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT) 96 #define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1) 98 #define RTE_IPV4_HDR_OFFSET_UNITS 8 103 #define RTE_IPV4_ANY ((uint32_t)0x00000000) 104 #define RTE_IPV4_LOOPBACK ((uint32_t)0x7f000001) 105 #define RTE_IPV4_BROADCAST ((uint32_t)0xe0000000) 106 #define RTE_IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001) 107 #define RTE_IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002) 108 #define RTE_IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff) 113 #define RTE_IPV4_MIN_MCAST \ 114 RTE_IPV4(224, 0, 0, 0) 115 #define RTE_IPV4_MAX_MCAST \ 116 RTE_IPV4(239, 255, 255, 255) 118 #define RTE_IS_IPV4_MCAST(x) \ 119 ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST) 123 #define RTE_IPV4_MIN_IHL (0x5) 124 #define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL) 134 static inline uint8_t
154 static inline uint32_t
155 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
158 typedef uint16_t __attribute__((__may_alias__)) u16_p;
159 const u16_p *u16_buf = (
const u16_p *)buf;
160 const u16_p *end = u16_buf + len /
sizeof(*u16_buf);
162 for (; u16_buf != end; ++u16_buf)
168 *(
unsigned char *)&left = *(
const unsigned char *)end;
184 static inline uint16_t
185 __rte_raw_cksum_reduce(uint32_t sum)
187 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
188 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
189 return (uint16_t)sum;
202 static inline uint16_t
207 sum = __rte_raw_cksum(buf, len, 0);
208 return __rte_raw_cksum_reduce(sum);
232 uint32_t seglen, done;
237 const char *, off), len);
246 for (seg = m; seg != NULL; seg = seg->
next) {
252 RTE_ASSERT(seg != NULL);
267 tmp = __rte_raw_cksum(buf, seglen, 0);
277 if (seglen > len - done)
281 *cksum = __rte_raw_cksum_reduce(sum);
295 static inline uint16_t
300 return (uint16_t)~cksum;
321 static inline uint16_t
324 struct ipv4_psd_header {
334 psd_hdr.src_addr = ipv4_hdr->
src_addr;
335 psd_hdr.dst_addr = ipv4_hdr->
dst_addr;
351 static inline uint16_t
352 __rte_ipv4_udptcp_cksum(
const struct rte_ipv4_hdr *ipv4_hdr,
const void *l4_hdr)
355 uint32_t l3_len, l4_len;
360 if (l3_len < ip_hdr_len)
363 l4_len = l3_len - ip_hdr_len;
368 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
370 return (uint16_t)cksum;
385 static inline uint16_t
388 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
406 static inline uint16_t
407 __rte_ipv4_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
422 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
424 return (uint16_t)cksum;
443 static inline uint16_t
447 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
480 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
507 static inline uint16_t
512 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
533 #define RTE_IPV6_HDR_FL_SHIFT 0 534 #define RTE_IPV6_HDR_TC_SHIFT 20 535 #define RTE_IPV6_HDR_FL_MASK ((1u << RTE_IPV6_HDR_TC_SHIFT) - 1) 536 #define RTE_IPV6_HDR_TC_MASK (0xff << RTE_IPV6_HDR_TC_SHIFT) 537 #define RTE_IPV6_HDR_DSCP_MASK (0xfc << RTE_IPV6_HDR_TC_SHIFT) 538 #define RTE_IPV6_HDR_ECN_MASK (0x03 << RTE_IPV6_HDR_TC_SHIFT) 539 #define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK 541 #define RTE_IPV6_MIN_MTU 1280 559 static inline uint16_t 568 psd_hdr.proto = (uint32_t)(ipv6_hdr->
proto << 24);
575 sum = __rte_raw_cksum(ipv6_hdr->
src_addr,
578 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
579 return __rte_raw_cksum_reduce(sum);
585 static inline uint16_t
586 __rte_ipv6_udptcp_cksum(
const struct rte_ipv6_hdr *ipv6_hdr,
const void *l4_hdr)
596 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
598 return (uint16_t)cksum;
614 static inline uint16_t
617 uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
626 if (cksum == 0 && ipv6_hdr->
proto == IPPROTO_UDP)
635 static inline uint16_t
636 __rte_ipv6_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
651 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
653 return (uint16_t)cksum;
675 static inline uint16_t
679 uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
688 if (cksum == 0 && ipv6_hdr->
proto == IPPROTO_UDP)
713 uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
746 uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
755 #define RTE_IPV6_EHDR_MF_SHIFT 0 756 #define RTE_IPV6_EHDR_MF_MASK 1 757 #define RTE_IPV6_EHDR_FO_SHIFT 3 758 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1)) 759 #define RTE_IPV6_EHDR_FO_ALIGN (1 << RTE_IPV6_EHDR_FO_SHIFT) 761 #define RTE_IPV6_FRAG_USED_MASK (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK) 763 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK) 764 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT) 766 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \ 767 (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK)) 769 struct rte_ipv6_fragment_ext {
777 #define RTE_IPV6_FRAG_HDR_SIZE sizeof(struct rte_ipv6_fragment_ext) 804 *ext_len = (*p + 2) *
sizeof(uint32_t);
807 case IPPROTO_HOPOPTS:
808 case IPPROTO_ROUTING:
809 case IPPROTO_DSTOPTS:
811 *ext_len = (*p + 1) *
sizeof(uint64_t);
814 case IPPROTO_FRAGMENT:
816 *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)
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)
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