19 #include <netinet/in.h> 42 } __attribute__((__packed__));
45 #define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \ 46 (((b) & 0xff) << 16) | \ 47 (((c) & 0xff) << 8) | \ 51 #define RTE_IPV4_MAX_PKT_LEN 65535 54 #define RTE_IPV4_HDR_IHL_MASK (0x0f) 59 #define RTE_IPV4_IHL_MULTIPLIER (4) 62 #define RTE_IPV4_HDR_DF_SHIFT 14 63 #define RTE_IPV4_HDR_MF_SHIFT 13 64 #define RTE_IPV4_HDR_FO_SHIFT 3 66 #define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT) 67 #define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT) 69 #define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1) 71 #define RTE_IPV4_HDR_OFFSET_UNITS 8 76 #define RTE_IPV4_ANY ((uint32_t)0x00000000) 77 #define RTE_IPV4_LOOPBACK ((uint32_t)0x7f000001) 78 #define RTE_IPV4_BROADCAST ((uint32_t)0xe0000000) 79 #define RTE_IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001) 80 #define RTE_IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002) 81 #define RTE_IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff) 86 #define RTE_IPV4_MIN_MCAST \ 87 RTE_IPV4(224, 0, 0, 0) 88 #define RTE_IPV4_MAX_MCAST \ 89 RTE_IPV4(239, 255, 255, 255) 91 #define RTE_IS_IPV4_MCAST(x) \ 92 ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST) 108 static inline uint32_t
109 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
112 uintptr_t ptr = (uintptr_t)buf;
113 typedef uint16_t __attribute__((__may_alias__)) u16_p;
114 const u16_p *u16_buf = (
const u16_p *)ptr;
116 while (len >= (
sizeof(*u16_buf) * 4)) {
121 len -=
sizeof(*u16_buf) * 4;
124 while (len >=
sizeof(*u16_buf)) {
126 len -=
sizeof(*u16_buf);
132 sum += *((
const uint8_t *)u16_buf);
146 static inline uint16_t
147 __rte_raw_cksum_reduce(uint32_t sum)
149 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
150 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
151 return (uint16_t)sum;
164 static inline uint16_t
169 sum = __rte_raw_cksum(buf, len, 0);
170 return __rte_raw_cksum_reduce(sum);
194 uint32_t seglen, done;
199 const char *, off), len);
208 for (seg = m; seg != NULL; seg = seg->
next) {
226 tmp = __rte_raw_cksum(buf, seglen, 0);
236 if (seglen > len - done)
240 *cksum = __rte_raw_cksum_reduce(sum);
254 static inline uint16_t
259 return (cksum == 0xffff) ? cksum : (uint16_t)~cksum;
280 static inline uint16_t
283 struct ipv4_psd_header {
291 psd_hdr.src_addr = ipv4_hdr->
src_addr;
292 psd_hdr.dst_addr = ipv4_hdr->
dst_addr;
319 static inline uint16_t
323 uint32_t l3_len, l4_len;
334 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
335 cksum = (~cksum) & 0xffff;
339 return (uint16_t)cksum;
352 } __attribute__((__packed__));
355 #define RTE_IPV6_HDR_FL_SHIFT 0 356 #define RTE_IPV6_HDR_TC_SHIFT 20 357 #define RTE_IPV6_HDR_FL_MASK ((1u << RTE_IPV6_HDR_TC_SHIFT) - 1) 358 #define RTE_IPV6_HDR_TC_MASK (0xf << RTE_IPV6_HDR_TC_SHIFT) 376 static inline uint16_t
385 psd_hdr.proto = (uint32_t)(ipv6_hdr->
proto << 24);
392 sum = __rte_raw_cksum(ipv6_hdr->
src_addr,
395 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
396 return __rte_raw_cksum_reduce(sum);
412 static inline uint16_t
423 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
424 cksum = (~cksum) & 0xffff;
428 return (uint16_t)cksum;
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)
static uint16_t rte_bswap16(uint16_t _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_pkt_len(m)
static uint16_t rte_raw_cksum(const void *buf, size_t len)
#define rte_pktmbuf_data_len(m)
#define rte_pktmbuf_mtod(m, t)
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)
#define rte_pktmbuf_mtod_offset(m, t, o)
static uint16_t rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)