81 #include <netinet/in.h>
104 } __attribute__((__packed__));
107 #define IPv4(a,b,c,d) ((uint32_t)(((a) & 0xff) << 24) | \
108 (((b) & 0xff) << 16) | \
109 (((c) & 0xff) << 8) | \
113 #define IPV4_MAX_PKT_LEN 65535
116 #define IPV4_HDR_IHL_MASK (0x0f)
121 #define IPV4_IHL_MULTIPLIER (4)
124 #define IPV4_HDR_DF_SHIFT 14
125 #define IPV4_HDR_MF_SHIFT 13
126 #define IPV4_HDR_FO_SHIFT 3
128 #define IPV4_HDR_DF_FLAG (1 << IPV4_HDR_DF_SHIFT)
129 #define IPV4_HDR_MF_FLAG (1 << IPV4_HDR_MF_SHIFT)
131 #define IPV4_HDR_OFFSET_MASK ((1 << IPV4_HDR_MF_SHIFT) - 1)
133 #define IPV4_HDR_OFFSET_UNITS 8
138 #define IPV4_ANY ((uint32_t)0x00000000)
139 #define IPV4_LOOPBACK ((uint32_t)0x7f000001)
140 #define IPV4_BROADCAST ((uint32_t)0xe0000000)
141 #define IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001)
142 #define IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002)
143 #define IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff)
148 #define IPV4_MIN_MCAST IPv4(224, 0, 0, 0)
149 #define IPV4_MAX_MCAST IPv4(239, 255, 255, 255)
151 #define IS_IPV4_MCAST(x) \
152 ((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST)
167 static inline uint32_t
168 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
171 uintptr_t ptr = (uintptr_t)buf;
172 typedef uint16_t __attribute__((__may_alias__)) u16_p;
173 const u16_p *u16_buf = (
const u16_p *)ptr;
175 while (len >= (
sizeof(*u16_buf) * 4)) {
180 len -=
sizeof(*u16_buf) * 4;
183 while (len >=
sizeof(*u16_buf)) {
185 len -=
sizeof(*u16_buf);
191 sum += *((
const uint8_t *)u16_buf);
205 static inline uint16_t
206 __rte_raw_cksum_reduce(uint32_t sum)
208 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
209 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
210 return (uint16_t)sum;
223 static inline uint16_t
228 sum = __rte_raw_cksum(buf, len, 0);
229 return __rte_raw_cksum_reduce(sum);
253 uint32_t seglen, done;
258 const char *, off), len);
267 for (seg = m; seg != NULL; seg = seg->
next) {
285 tmp = __rte_raw_cksum(buf, seglen, 0);
295 if (seglen > len - done)
299 *cksum = __rte_raw_cksum_reduce(sum);
313 static inline uint16_t
318 return (cksum == 0xffff) ? cksum : (uint16_t)~cksum;
339 static inline uint16_t
342 struct ipv4_psd_header {
350 psd_hdr.src_addr = ipv4_hdr->
src_addr;
351 psd_hdr.dst_addr = ipv4_hdr->
dst_addr;
359 -
sizeof(
struct ipv4_hdr)));
377 static inline uint16_t
384 sizeof(
struct ipv4_hdr));
389 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
390 cksum = (~cksum) & 0xffff;
394 return (uint16_t)cksum;
407 } __attribute__((__packed__));
425 static inline uint16_t
434 psd_hdr.proto = (uint32_t)(ipv6_hdr->
proto << 24);
441 sum = __rte_raw_cksum(ipv6_hdr->
src_addr,
444 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
445 return __rte_raw_cksum_reduce(sum);
461 static inline uint16_t
472 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
473 cksum = (~cksum) & 0xffff;
477 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_phdr_cksum(const struct ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
static uint16_t rte_bswap16(uint16_t _x)
static uint16_t rte_ipv4_udptcp_cksum(const struct ipv4_hdr *ipv4_hdr, const void *l4_hdr)
static uint16_t rte_cpu_to_be_16(uint16_t x)
static uint16_t rte_be_to_cpu_16(uint16_t x)
static uint16_t rte_ipv4_cksum(const struct ipv4_hdr *ipv4_hdr)
static uint16_t rte_ipv6_phdr_cksum(const struct 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)
#define rte_pktmbuf_mtod_offset(m, t, o)
static uint16_t rte_ipv6_udptcp_cksum(const struct ipv6_hdr *ipv6_hdr, const void *l4_hdr)