19 #include <sys/types.h> 20 #include <netinet/in.h> 21 #include <netinet/ip.h> 44 } __attribute__((__packed__));
47 #define IPv4(a,b,c,d) ((uint32_t)(((a) & 0xff) << 24) | \ 48 (((b) & 0xff) << 16) | \ 49 (((c) & 0xff) << 8) | \ 53 #define IPV4_MAX_PKT_LEN 65535 56 #define IPV4_HDR_IHL_MASK (0x0f) 61 #define IPV4_IHL_MULTIPLIER (4) 64 #define IPV4_HDR_DF_SHIFT 14 65 #define IPV4_HDR_MF_SHIFT 13 66 #define IPV4_HDR_FO_SHIFT 3 68 #define IPV4_HDR_DF_FLAG (1 << IPV4_HDR_DF_SHIFT) 69 #define IPV4_HDR_MF_FLAG (1 << IPV4_HDR_MF_SHIFT) 71 #define IPV4_HDR_OFFSET_MASK ((1 << IPV4_HDR_MF_SHIFT) - 1) 73 #define IPV4_HDR_OFFSET_UNITS 8 78 #define IPV4_ANY ((uint32_t)0x00000000) 79 #define IPV4_LOOPBACK ((uint32_t)0x7f000001) 80 #define IPV4_BROADCAST ((uint32_t)0xe0000000) 81 #define IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001) 82 #define IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002) 83 #define IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff) 88 #define IPV4_MIN_MCAST IPv4(224, 0, 0, 0) 89 #define IPV4_MAX_MCAST IPv4(239, 255, 255, 255) 91 #define IS_IPV4_MCAST(x) \ 92 ((x) >= IPV4_MIN_MCAST && (x) <= IPV4_MAX_MCAST) 95 #define IPV4_MIN_IHL (0x5) 96 #define IPV4_VHL_DEF (IPVERSION | IPV4_MIN_IHL) 111 static inline uint32_t
112 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
115 uintptr_t ptr = (uintptr_t)buf;
116 typedef uint16_t __attribute__((__may_alias__)) u16_p;
117 const u16_p *u16_buf = (
const u16_p *)ptr;
119 while (len >= (
sizeof(*u16_buf) * 4)) {
124 len -=
sizeof(*u16_buf) * 4;
127 while (len >=
sizeof(*u16_buf)) {
129 len -=
sizeof(*u16_buf);
136 *(uint8_t *)&left = *(
const uint8_t *)u16_buf;
152 static inline uint16_t
153 __rte_raw_cksum_reduce(uint32_t sum)
155 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
156 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
157 return (uint16_t)sum;
170 static inline uint16_t
175 sum = __rte_raw_cksum(buf, len, 0);
176 return __rte_raw_cksum_reduce(sum);
200 uint32_t seglen, done;
205 const char *, off), len);
214 for (seg = m; seg != NULL; seg = seg->
next) {
232 tmp = __rte_raw_cksum(buf, seglen, 0);
242 if (seglen > len - done)
246 *cksum = __rte_raw_cksum_reduce(sum);
260 static inline uint16_t
265 return (uint16_t)~cksum;
286 static inline uint16_t
289 struct ipv4_psd_header {
324 static inline uint16_t
328 uint32_t l3_len, l4_len;
331 if (l3_len <
sizeof(
struct ipv4_hdr))
334 l4_len = l3_len -
sizeof(
struct ipv4_hdr);
339 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
340 cksum = (~cksum) & 0xffff;
349 return (uint16_t)cksum;
362 } __attribute__((__packed__));
365 #define IPV6_HDR_FL_SHIFT 0 366 #define IPV6_HDR_TC_SHIFT 20 367 #define IPV6_HDR_FL_MASK ((1u << IPV6_HDR_TC_SHIFT) - 1) 368 #define IPV6_HDR_TC_MASK (0xff << IPV6_HDR_TC_SHIFT) 386 static inline uint16_t
405 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
406 return __rte_raw_cksum_reduce(sum);
422 static inline uint16_t
433 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
434 cksum = (~cksum) & 0xffff;
443 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 rte_be16_t rte_cpu_to_be_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)
static uint16_t rte_be_to_cpu_16(rte_be16_t x)
#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)