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 101 #define RTE_IPV4_HDR_OPT_EOL 0 102 #define RTE_IPV4_HDR_OPT_NOP 1 103 #define RTE_IPV4_HDR_OPT_COPIED(v) ((v) & 0x80) 104 #define RTE_IPV4_HDR_OPT_MAX_LEN 40 109 #define RTE_IPV4_ANY ((uint32_t)0x00000000) 110 #define RTE_IPV4_LOOPBACK ((uint32_t)0x7f000001) 111 #define RTE_IPV4_BROADCAST ((uint32_t)0xe0000000) 112 #define RTE_IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001) 113 #define RTE_IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002) 114 #define RTE_IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff) 119 #define RTE_IPV4_MIN_MCAST \ 120 RTE_IPV4(224, 0, 0, 0) 121 #define RTE_IPV4_MAX_MCAST \ 122 RTE_IPV4(239, 255, 255, 255) 124 #define RTE_IS_IPV4_MCAST(x) \ 125 ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST) 129 #define RTE_IPV4_MIN_IHL (0x5) 130 #define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL) 140 static inline uint8_t
160 static inline uint32_t
161 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
166 buf != end; buf =
RTE_PTR_ADD(buf,
sizeof(uint16_t))) {
169 memcpy(&v, buf,
sizeof(uint16_t));
177 memcpy(&left, end, 1);
193 static inline uint16_t
194 __rte_raw_cksum_reduce(uint32_t sum)
196 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
197 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
198 return (uint16_t)sum;
211 static inline uint16_t
216 sum = __rte_raw_cksum(buf, len, 0);
217 return __rte_raw_cksum_reduce(sum);
241 uint32_t seglen, done;
246 const char *, off), len);
255 for (seg = m; seg != NULL; seg = seg->
next) {
261 RTE_ASSERT(seg != NULL);
276 tmp = __rte_raw_cksum(buf, seglen, 0);
286 if (seglen > len - done)
290 *cksum = __rte_raw_cksum_reduce(sum);
304 static inline uint16_t
309 return (uint16_t)~cksum;
330 static inline uint16_t
333 struct ipv4_psd_header {
343 psd_hdr.src_addr = ipv4_hdr->
src_addr;
344 psd_hdr.dst_addr = ipv4_hdr->
dst_addr;
360 static inline uint16_t
361 __rte_ipv4_udptcp_cksum(
const struct rte_ipv4_hdr *ipv4_hdr,
const void *l4_hdr)
364 uint32_t l3_len, l4_len;
369 if (l3_len < ip_hdr_len)
372 l4_len = l3_len - ip_hdr_len;
377 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
379 return (uint16_t)cksum;
394 static inline uint16_t
397 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
415 static inline uint16_t
416 __rte_ipv4_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
434 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
436 return (uint16_t)cksum;
451 static inline uint16_t
455 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
487 uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
515 uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
536 #define RTE_IPV6_SRCRT_TYPE_4 4 545 uint8_t segments_left;
559 #define RTE_IPV6_HDR_FL_SHIFT 0 560 #define RTE_IPV6_HDR_TC_SHIFT 20 561 #define RTE_IPV6_HDR_FL_MASK ((1u << RTE_IPV6_HDR_TC_SHIFT) - 1) 562 #define RTE_IPV6_HDR_TC_MASK (0xff << RTE_IPV6_HDR_TC_SHIFT) 563 #define RTE_IPV6_HDR_DSCP_MASK (0xfc << RTE_IPV6_HDR_TC_SHIFT) 564 #define RTE_IPV6_HDR_ECN_MASK (0x03 << RTE_IPV6_HDR_TC_SHIFT) 565 #define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK 567 #define RTE_IPV6_MIN_MTU 1280 585 static inline uint16_t 594 psd_hdr.proto = (uint32_t)(ipv6_hdr->
proto << 24);
601 sum = __rte_raw_cksum(ipv6_hdr->
src_addr,
604 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
605 return __rte_raw_cksum_reduce(sum);
611 static inline uint16_t
612 __rte_ipv6_udptcp_cksum(
const struct rte_ipv6_hdr *ipv6_hdr,
const void *l4_hdr)
622 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
624 return (uint16_t)cksum;
640 static inline uint16_t
643 uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
652 if (cksum == 0 && ipv6_hdr->
proto == IPPROTO_UDP)
661 static inline uint16_t
662 __rte_ipv6_udptcp_cksum_mbuf(
const struct rte_mbuf *m,
677 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
679 return (uint16_t)cksum;
697 static inline uint16_t
701 uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
710 if (cksum == 0 && ipv6_hdr->
proto == IPPROTO_UDP)
734 uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
763 uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
772 #define RTE_IPV6_EHDR_MF_SHIFT 0 773 #define RTE_IPV6_EHDR_MF_MASK 1 774 #define RTE_IPV6_EHDR_FO_SHIFT 3 775 #define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1)) 776 #define RTE_IPV6_EHDR_FO_ALIGN (1 << RTE_IPV6_EHDR_FO_SHIFT) 778 #define RTE_IPV6_FRAG_USED_MASK (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK) 780 #define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK) 781 #define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT) 783 #define RTE_IPV6_SET_FRAG_DATA(fo, mf) \ 784 (((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK)) 786 struct rte_ipv6_fragment_ext {
794 #define RTE_IPV6_FRAG_HDR_SIZE sizeof(struct rte_ipv6_fragment_ext) 820 *ext_len = (*p + 2) *
sizeof(uint32_t);
823 case IPPROTO_HOPOPTS:
824 case IPPROTO_ROUTING:
825 case IPPROTO_DSTOPTS:
827 *ext_len = (*p + 1) *
sizeof(uint64_t);
830 case IPPROTO_FRAGMENT:
832 *ext_len = RTE_IPV6_FRAG_HDR_SIZE;
static uint8_t rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
static int rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
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)
static int rte_ipv6_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m, const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
static int rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m, const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
rte_be16_t fragment_offset
static int rte_ipv6_udptcp_cksum_verify(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
static uint16_t rte_bswap16(uint16_t _x)
#define RTE_MBUF_F_TX_UDP_SEG
static uint16_t rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
#define rte_pktmbuf_mtod_offset(m, t, o)
#define RTE_PTR_ADD(ptr, x)
static rte_be16_t rte_cpu_to_be_16(uint16_t x)
static int rte_ipv4_udptcp_cksum_verify(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
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)
static uint16_t rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
#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 uint16_t rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
static uint16_t rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
#define RTE_IPV4_IHL_MULTIPLIER