19 #include <sys/types.h>
20 #include <netinet/in.h>
21 #include <netinet/ip.h>
47 #define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \
48 (((b) & 0xff) << 16) | \
49 (((c) & 0xff) << 8) | \
53 #define RTE_IPV4_MAX_PKT_LEN 65535
56 #define RTE_IPV4_HDR_IHL_MASK (0x0f)
61 #define RTE_IPV4_IHL_MULTIPLIER (4)
64 #define RTE_IPV4_HDR_DSCP_MASK (0xfc)
65 #define RTE_IPV4_HDR_ECN_MASK (0x03)
66 #define RTE_IPV4_HDR_ECN_CE RTE_IPV4_HDR_ECN_MASK
69 #define RTE_IPV4_HDR_DF_SHIFT 14
70 #define RTE_IPV4_HDR_MF_SHIFT 13
71 #define RTE_IPV4_HDR_FO_SHIFT 3
73 #define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT)
74 #define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT)
76 #define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1)
78 #define RTE_IPV4_HDR_OFFSET_UNITS 8
83 #define RTE_IPV4_ANY ((uint32_t)0x00000000)
84 #define RTE_IPV4_LOOPBACK ((uint32_t)0x7f000001)
85 #define RTE_IPV4_BROADCAST ((uint32_t)0xe0000000)
86 #define RTE_IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001)
87 #define RTE_IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002)
88 #define RTE_IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff)
93 #define RTE_IPV4_MIN_MCAST \
94 RTE_IPV4(224, 0, 0, 0)
95 #define RTE_IPV4_MAX_MCAST \
96 RTE_IPV4(239, 255, 255, 255)
98 #define RTE_IS_IPV4_MCAST(x) \
99 ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST)
103 #define RTE_IPV4_MIN_IHL (0x5)
104 #define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL)
119 static inline uint32_t
120 __rte_raw_cksum(
const void *buf,
size_t len, uint32_t sum)
123 uintptr_t ptr = (uintptr_t)buf;
124 typedef uint16_t __attribute__((__may_alias__)) u16_p;
125 const u16_p *u16_buf = (
const u16_p *)ptr;
127 while (len >= (
sizeof(*u16_buf) * 4)) {
132 len -=
sizeof(*u16_buf) * 4;
135 while (len >=
sizeof(*u16_buf)) {
137 len -=
sizeof(*u16_buf);
143 sum += *((
const uint8_t *)u16_buf);
157 static inline uint16_t
158 __rte_raw_cksum_reduce(uint32_t sum)
160 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
161 sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
162 return (uint16_t)sum;
175 static inline uint16_t
180 sum = __rte_raw_cksum(buf, len, 0);
181 return __rte_raw_cksum_reduce(sum);
205 uint32_t seglen, done;
210 const char *, off), len);
219 for (seg = m; seg != NULL; seg = seg->
next) {
237 tmp = __rte_raw_cksum(buf, seglen, 0);
247 if (seglen > len - done)
251 *cksum = __rte_raw_cksum_reduce(sum);
265 static inline uint16_t
270 return (cksum == 0xffff) ? cksum : (uint16_t)~cksum;
291 static inline uint16_t
294 struct ipv4_psd_header {
302 psd_hdr.src_addr = ipv4_hdr->
src_addr;
303 psd_hdr.dst_addr = ipv4_hdr->
dst_addr;
330 static inline uint16_t
334 uint32_t l3_len, l4_len;
345 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
346 cksum = (~cksum) & 0xffff;
350 return (uint16_t)cksum;
366 #define RTE_IPV6_HDR_FL_SHIFT 0
367 #define RTE_IPV6_HDR_TC_SHIFT 20
368 #define RTE_IPV6_HDR_FL_MASK ((1u << RTE_IPV6_HDR_TC_SHIFT) - 1)
369 #define RTE_IPV6_HDR_TC_MASK (0xff << RTE_IPV6_HDR_TC_SHIFT)
370 #define RTE_IPV6_HDR_DSCP_MASK (0xfc << RTE_IPV6_HDR_TC_SHIFT)
371 #define RTE_IPV6_HDR_ECN_MASK (0x03 << RTE_IPV6_HDR_TC_SHIFT)
372 #define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK
374 #define RTE_IPV6_MIN_MTU 1280
392 static inline uint16_t
401 psd_hdr.proto = (uint32_t)(ipv6_hdr->
proto << 24);
402 if (ol_flags & PKT_TX_TCP_SEG) {
408 sum = __rte_raw_cksum(ipv6_hdr->
src_addr,
411 sum = __rte_raw_cksum(&psd_hdr,
sizeof(psd_hdr), sum);
412 return __rte_raw_cksum_reduce(sum);
428 static inline uint16_t
439 cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
440 cksum = (~cksum) & 0xffff;
444 return (uint16_t)cksum;
448 #define RTE_IPV6_FRAG_HDR_SIZE 8
475 *ext_len = (*p + 2) *
sizeof(uint32_t);
478 case IPPROTO_HOPOPTS:
479 case IPPROTO_ROUTING:
480 case IPPROTO_DSTOPTS:
482 *ext_len = (*p + 1) *
sizeof(uint64_t);
485 case IPPROTO_FRAGMENT:
487 *ext_len = RTE_IPV6_FRAG_HDR_SIZE;
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)
rte_be16_t fragment_offset
static uint16_t rte_bswap16(uint16_t _x)
static __rte_experimental int rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
#define rte_pktmbuf_mtod_offset(m, t, o)
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_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_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)