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 = (
const u16_p *)ptr;
175 while (len >= (
sizeof(*u16) * 4)) {
180 len -=
sizeof(*u16) * 4;
183 while (len >=
sizeof(*u16)) {
191 sum += *((
const uint8_t *)u16);
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 : ~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;
407 } __attribute__((__packed__));
425 static inline uint16_t
434 psd_hdr.proto = (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;