2017-12-22 15:59:02 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 1982, 1986, 1990, 1993
|
|
|
|
* The Regents of the University of California.
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation.
|
|
|
|
* Copyright(c) 2014 6WIND S.A.
|
|
|
|
* All rights reserved.
|
2012-09-04 12:54:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RTE_IP_H_
|
|
|
|
#define _RTE_IP_H_
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* IP-related defines
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-04-10 22:47:32 +00:00
|
|
|
|
|
|
|
#ifdef RTE_EXEC_ENV_WINDOWS
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#else
|
|
|
|
#include <sys/socket.h>
|
2019-07-04 07:33:19 +00:00
|
|
|
#include <sys/types.h>
|
2014-11-27 11:28:17 +00:00
|
|
|
#include <netinet/in.h>
|
2021-05-06 14:25:19 +00:00
|
|
|
#include <arpa/inet.h>
|
2019-07-04 07:33:19 +00:00
|
|
|
#include <netinet/ip.h>
|
2021-10-06 22:35:41 +00:00
|
|
|
#include <netinet/ip6.h>
|
2021-04-10 22:47:32 +00:00
|
|
|
#endif
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2014-11-26 15:04:51 +00:00
|
|
|
#include <rte_byteorder.h>
|
2014-11-26 15:04:52 +00:00
|
|
|
#include <rte_mbuf.h>
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2012-09-04 12:54:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IPv4 Header
|
|
|
|
*/
|
2019-05-21 16:13:10 +00:00
|
|
|
struct rte_ipv4_hdr {
|
2021-10-14 17:41:13 +00:00
|
|
|
__extension__
|
|
|
|
union {
|
|
|
|
uint8_t version_ihl; /**< version and header length */
|
|
|
|
struct {
|
|
|
|
#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
|
|
|
|
uint8_t ihl:4; /**< header length */
|
|
|
|
uint8_t version:4; /**< version */
|
|
|
|
#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
|
|
|
|
uint8_t version:4; /**< version */
|
|
|
|
uint8_t ihl:4; /**< header length */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
};
|
2012-09-04 12:54:00 +00:00
|
|
|
uint8_t type_of_service; /**< type of service */
|
2019-09-27 11:58:02 +00:00
|
|
|
rte_be16_t total_length; /**< length of packet */
|
|
|
|
rte_be16_t packet_id; /**< packet ID */
|
|
|
|
rte_be16_t fragment_offset; /**< fragmentation offset */
|
2012-09-04 12:54:00 +00:00
|
|
|
uint8_t time_to_live; /**< time to live */
|
|
|
|
uint8_t next_proto_id; /**< protocol ID */
|
2019-09-27 11:58:02 +00:00
|
|
|
rte_be16_t hdr_checksum; /**< header checksum */
|
|
|
|
rte_be32_t src_addr; /**< source address */
|
|
|
|
rte_be32_t dst_addr; /**< destination address */
|
2020-02-09 17:29:23 +00:00
|
|
|
} __rte_packed;
|
2012-09-04 12:54:00 +00:00
|
|
|
|
|
|
|
/** Create IPv4 address */
|
2019-05-29 11:29:16 +00:00
|
|
|
#define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \
|
2012-09-04 12:54:00 +00:00
|
|
|
(((b) & 0xff) << 16) | \
|
|
|
|
(((c) & 0xff) << 8) | \
|
|
|
|
((d) & 0xff))
|
|
|
|
|
2015-03-30 19:21:11 +00:00
|
|
|
/** Maximal IPv4 packet length (including a header) */
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_MAX_PKT_LEN 65535
|
2015-03-30 19:21:11 +00:00
|
|
|
|
2014-12-16 12:45:10 +00:00
|
|
|
/** Internet header length mask for version_ihl field */
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_HDR_IHL_MASK (0x0f)
|
2014-12-16 12:45:10 +00:00
|
|
|
/**
|
|
|
|
* Internet header length field multiplier (IHL field specifies overall header
|
|
|
|
* length in number of 4-byte words)
|
|
|
|
*/
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_IHL_MULTIPLIER (4)
|
2014-12-16 12:45:10 +00:00
|
|
|
|
2019-07-01 13:59:04 +00:00
|
|
|
/* Type of Service fields */
|
|
|
|
#define RTE_IPV4_HDR_DSCP_MASK (0xfc)
|
|
|
|
#define RTE_IPV4_HDR_ECN_MASK (0x03)
|
2019-07-04 10:42:35 +00:00
|
|
|
#define RTE_IPV4_HDR_ECN_CE RTE_IPV4_HDR_ECN_MASK
|
2019-07-01 13:59:04 +00:00
|
|
|
|
2013-06-03 00:00:00 +00:00
|
|
|
/* Fragment Offset * Flags. */
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_HDR_DF_SHIFT 14
|
|
|
|
#define RTE_IPV4_HDR_MF_SHIFT 13
|
|
|
|
#define RTE_IPV4_HDR_FO_SHIFT 3
|
2013-06-03 00:00:00 +00:00
|
|
|
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT)
|
|
|
|
#define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT)
|
2013-06-03 00:00:00 +00:00
|
|
|
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1)
|
2013-06-03 00:00:00 +00:00
|
|
|
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_HDR_OFFSET_UNITS 8
|
2013-06-03 00:00:00 +00:00
|
|
|
|
2022-04-15 03:26:50 +00:00
|
|
|
/* IPv4 options */
|
|
|
|
#define RTE_IPV4_HDR_OPT_EOL 0
|
|
|
|
#define RTE_IPV4_HDR_OPT_NOP 1
|
|
|
|
#define RTE_IPV4_HDR_OPT_COPIED(v) ((v) & 0x80)
|
|
|
|
#define RTE_IPV4_HDR_OPT_MAX_LEN 40
|
|
|
|
|
2012-09-04 12:54:00 +00:00
|
|
|
/*
|
|
|
|
* IPv4 address types
|
|
|
|
*/
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_ANY ((uint32_t)0x00000000) /**< 0.0.0.0 */
|
|
|
|
#define RTE_IPV4_LOOPBACK ((uint32_t)0x7f000001) /**< 127.0.0.1 */
|
|
|
|
#define RTE_IPV4_BROADCAST ((uint32_t)0xe0000000) /**< 224.0.0.0 */
|
|
|
|
#define RTE_IPV4_ALLHOSTS_GROUP ((uint32_t)0xe0000001) /**< 224.0.0.1 */
|
|
|
|
#define RTE_IPV4_ALLRTRS_GROUP ((uint32_t)0xe0000002) /**< 224.0.0.2 */
|
|
|
|
#define RTE_IPV4_MAX_LOCAL_GROUP ((uint32_t)0xe00000ff) /**< 224.0.0.255 */
|
2012-09-04 12:54:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IPv4 Multicast-related macros
|
|
|
|
*/
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_MIN_MCAST \
|
2019-05-29 11:29:16 +00:00
|
|
|
RTE_IPV4(224, 0, 0, 0) /**< Minimal IPv4-multicast address */
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV4_MAX_MCAST \
|
2019-05-29 11:29:16 +00:00
|
|
|
RTE_IPV4(239, 255, 255, 255) /**< Maximum IPv4 multicast address */
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IS_IPV4_MCAST(x) \
|
|
|
|
((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST)
|
|
|
|
/**< check if IPv4 address is multicast */
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2019-07-04 07:33:19 +00:00
|
|
|
/* IPv4 default fields values */
|
|
|
|
#define RTE_IPV4_MIN_IHL (0x5)
|
2019-11-06 14:49:41 +00:00
|
|
|
#define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL)
|
2019-07-04 07:33:19 +00:00
|
|
|
|
2020-10-12 14:55:46 +00:00
|
|
|
/**
|
|
|
|
* Get the length of an IPv4 header.
|
|
|
|
*
|
|
|
|
* @param ipv4_hdr
|
|
|
|
* Pointer to the IPv4 header.
|
|
|
|
* @return
|
|
|
|
* The length of the IPv4 header (with options if present) in bytes.
|
|
|
|
*/
|
|
|
|
static inline uint8_t
|
|
|
|
rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
|
|
|
|
{
|
|
|
|
return (uint8_t)((ipv4_hdr->version_ihl & RTE_IPV4_HDR_IHL_MASK) *
|
|
|
|
RTE_IPV4_IHL_MULTIPLIER);
|
|
|
|
}
|
|
|
|
|
2014-11-26 15:04:51 +00:00
|
|
|
/**
|
2014-12-11 11:49:42 +00:00
|
|
|
* @internal Calculate a sum of all words in the buffer.
|
|
|
|
* Helper routine for the rte_raw_cksum().
|
2014-11-26 15:04:51 +00:00
|
|
|
*
|
|
|
|
* @param buf
|
|
|
|
* Pointer to the buffer.
|
|
|
|
* @param len
|
|
|
|
* Length of the buffer.
|
2014-12-11 11:49:42 +00:00
|
|
|
* @param sum
|
|
|
|
* Initial value of the sum.
|
2014-11-26 15:04:51 +00:00
|
|
|
* @return
|
2014-12-11 11:49:42 +00:00
|
|
|
* sum += Sum of all words in the buffer.
|
2014-11-26 15:04:51 +00:00
|
|
|
*/
|
2014-12-11 11:49:42 +00:00
|
|
|
static inline uint32_t
|
|
|
|
__rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
|
2014-11-26 15:04:51 +00:00
|
|
|
{
|
2021-10-17 20:37:18 +00:00
|
|
|
/* extend strict-aliasing rules */
|
2015-11-24 16:31:18 +00:00
|
|
|
typedef uint16_t __attribute__((__may_alias__)) u16_p;
|
2021-10-17 20:37:18 +00:00
|
|
|
const u16_p *u16_buf = (const u16_p *)buf;
|
|
|
|
const u16_p *end = u16_buf + len / sizeof(*u16_buf);
|
|
|
|
|
|
|
|
for (; u16_buf != end; ++u16_buf)
|
2018-06-04 19:40:00 +00:00
|
|
|
sum += *u16_buf;
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2021-10-17 20:37:18 +00:00
|
|
|
/* if length is odd, keeping it byte order independent */
|
|
|
|
if (unlikely(len % 2)) {
|
2020-07-10 11:43:13 +00:00
|
|
|
uint16_t left = 0;
|
2021-10-17 20:37:18 +00:00
|
|
|
*(unsigned char *)&left = *(const unsigned char *)end;
|
2020-07-10 11:43:13 +00:00
|
|
|
sum += left;
|
|
|
|
}
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2014-12-11 11:49:42 +00:00
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal Reduce a sum to the non-complemented checksum.
|
|
|
|
* Helper routine for the rte_raw_cksum().
|
|
|
|
*
|
|
|
|
* @param sum
|
|
|
|
* Value of the sum.
|
|
|
|
* @return
|
|
|
|
* The non-complemented checksum.
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
|
|
|
__rte_raw_cksum_reduce(uint32_t sum)
|
|
|
|
{
|
2014-11-26 15:04:51 +00:00
|
|
|
sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
|
|
|
|
sum = ((sum & 0xffff0000) >> 16) + (sum & 0xffff);
|
|
|
|
return (uint16_t)sum;
|
|
|
|
}
|
|
|
|
|
2014-12-11 11:49:42 +00:00
|
|
|
/**
|
|
|
|
* Process the non-complemented checksum of a buffer.
|
|
|
|
*
|
|
|
|
* @param buf
|
|
|
|
* Pointer to the buffer.
|
|
|
|
* @param len
|
|
|
|
* Length of the buffer.
|
|
|
|
* @return
|
|
|
|
* The non-complemented checksum.
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
|
|
|
rte_raw_cksum(const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
uint32_t sum;
|
|
|
|
|
|
|
|
sum = __rte_raw_cksum(buf, len, 0);
|
|
|
|
return __rte_raw_cksum_reduce(sum);
|
|
|
|
}
|
|
|
|
|
2016-10-13 14:16:03 +00:00
|
|
|
/**
|
|
|
|
* Compute the raw (non complemented) checksum of a packet.
|
|
|
|
*
|
|
|
|
* @param m
|
|
|
|
* The pointer to the mbuf.
|
|
|
|
* @param off
|
|
|
|
* The offset in bytes to start the checksum.
|
|
|
|
* @param len
|
2017-11-10 08:24:23 +00:00
|
|
|
* The length in bytes of the data to checksum.
|
2016-10-13 14:16:03 +00:00
|
|
|
* @param cksum
|
|
|
|
* A pointer to the checksum, filled on success.
|
|
|
|
* @return
|
|
|
|
* 0 on success, -1 on error (bad length or offset).
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len,
|
|
|
|
uint16_t *cksum)
|
|
|
|
{
|
|
|
|
const struct rte_mbuf *seg;
|
|
|
|
const char *buf;
|
|
|
|
uint32_t sum, tmp;
|
|
|
|
uint32_t seglen, done;
|
|
|
|
|
|
|
|
/* easy case: all data in the first segment */
|
|
|
|
if (off + len <= rte_pktmbuf_data_len(m)) {
|
|
|
|
*cksum = rte_raw_cksum(rte_pktmbuf_mtod_offset(m,
|
|
|
|
const char *, off), len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(off + len > rte_pktmbuf_pkt_len(m)))
|
|
|
|
return -1; /* invalid params, return a dummy value */
|
|
|
|
|
|
|
|
/* else browse the segment to find offset */
|
|
|
|
seglen = 0;
|
|
|
|
for (seg = m; seg != NULL; seg = seg->next) {
|
|
|
|
seglen = rte_pktmbuf_data_len(seg);
|
|
|
|
if (off < seglen)
|
|
|
|
break;
|
|
|
|
off -= seglen;
|
|
|
|
}
|
2020-10-01 10:22:44 +00:00
|
|
|
RTE_ASSERT(seg != NULL);
|
|
|
|
if (seg == NULL)
|
|
|
|
return -1;
|
2016-10-13 14:16:03 +00:00
|
|
|
seglen -= off;
|
|
|
|
buf = rte_pktmbuf_mtod_offset(seg, const char *, off);
|
|
|
|
if (seglen >= len) {
|
|
|
|
/* all in one segment */
|
|
|
|
*cksum = rte_raw_cksum(buf, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hard case: process checksum of several segments */
|
|
|
|
sum = 0;
|
|
|
|
done = 0;
|
|
|
|
for (;;) {
|
|
|
|
tmp = __rte_raw_cksum(buf, seglen, 0);
|
|
|
|
if (done & 1)
|
2018-05-17 13:49:57 +00:00
|
|
|
tmp = rte_bswap16((uint16_t)tmp);
|
2016-10-13 14:16:03 +00:00
|
|
|
sum += tmp;
|
|
|
|
done += seglen;
|
|
|
|
if (done == len)
|
|
|
|
break;
|
|
|
|
seg = seg->next;
|
|
|
|
buf = rte_pktmbuf_mtod(seg, const char *);
|
|
|
|
seglen = rte_pktmbuf_data_len(seg);
|
|
|
|
if (seglen > len - done)
|
|
|
|
seglen = len - done;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cksum = __rte_raw_cksum_reduce(sum);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-26 15:04:51 +00:00
|
|
|
/**
|
|
|
|
* Process the IPv4 checksum of an IPv4 header.
|
|
|
|
*
|
|
|
|
* The checksum field must be set to 0 by the caller.
|
|
|
|
*
|
|
|
|
* @param ipv4_hdr
|
|
|
|
* The pointer to the contiguous IPv4 header.
|
|
|
|
* @return
|
|
|
|
* The complemented checksum to set in the IP packet.
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
2019-05-21 16:13:10 +00:00
|
|
|
rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
|
2014-11-26 15:04:51 +00:00
|
|
|
{
|
|
|
|
uint16_t cksum;
|
2020-10-12 14:55:46 +00:00
|
|
|
cksum = rte_raw_cksum(ipv4_hdr, rte_ipv4_hdr_len(ipv4_hdr));
|
2020-05-26 10:08:05 +00:00
|
|
|
return (uint16_t)~cksum;
|
2014-11-26 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the pseudo-header checksum of an IPv4 header.
|
|
|
|
*
|
|
|
|
* The checksum field must be set to 0 by the caller.
|
|
|
|
*
|
2014-11-26 15:04:52 +00:00
|
|
|
* Depending on the ol_flags, the pseudo-header checksum expected by the
|
|
|
|
* drivers is not the same. For instance, when TSO is enabled, the IP
|
|
|
|
* payload length must not be included in the packet.
|
|
|
|
*
|
|
|
|
* When ol_flags is 0, it computes the standard pseudo-header checksum.
|
|
|
|
*
|
2014-11-26 15:04:51 +00:00
|
|
|
* @param ipv4_hdr
|
|
|
|
* The pointer to the contiguous IPv4 header.
|
2014-11-26 15:04:52 +00:00
|
|
|
* @param ol_flags
|
|
|
|
* The ol_flags of the associated mbuf.
|
2014-11-26 15:04:51 +00:00
|
|
|
* @return
|
|
|
|
* The non-complemented checksum to set in the L4 header.
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
2019-05-21 16:13:10 +00:00
|
|
|
rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
|
2014-11-26 15:04:51 +00:00
|
|
|
{
|
|
|
|
struct ipv4_psd_header {
|
|
|
|
uint32_t src_addr; /* IP address of source host. */
|
|
|
|
uint32_t dst_addr; /* IP address of destination host. */
|
|
|
|
uint8_t zero; /* zero. */
|
|
|
|
uint8_t proto; /* L4 protocol type. */
|
|
|
|
uint16_t len; /* L4 length. */
|
|
|
|
} psd_hdr;
|
|
|
|
|
2020-09-01 09:47:55 +00:00
|
|
|
uint32_t l3_len;
|
|
|
|
|
2014-11-26 15:04:51 +00:00
|
|
|
psd_hdr.src_addr = ipv4_hdr->src_addr;
|
|
|
|
psd_hdr.dst_addr = ipv4_hdr->dst_addr;
|
|
|
|
psd_hdr.zero = 0;
|
|
|
|
psd_hdr.proto = ipv4_hdr->next_proto_id;
|
2021-10-15 19:24:08 +00:00
|
|
|
if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
|
2014-11-26 15:04:52 +00:00
|
|
|
psd_hdr.len = 0;
|
|
|
|
} else {
|
2020-09-01 09:47:55 +00:00
|
|
|
l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
|
2020-10-12 14:55:46 +00:00
|
|
|
psd_hdr.len = rte_cpu_to_be_16((uint16_t)(l3_len -
|
|
|
|
rte_ipv4_hdr_len(ipv4_hdr)));
|
2014-11-26 15:04:52 +00:00
|
|
|
}
|
2014-12-11 11:49:42 +00:00
|
|
|
return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr));
|
2014-11-26 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-06-30 13:51:57 +00:00
|
|
|
* @internal Calculate the non-complemented IPv4 L4 checksum
|
2014-11-26 15:04:51 +00:00
|
|
|
*/
|
|
|
|
static inline uint16_t
|
2021-06-30 13:51:57 +00:00
|
|
|
__rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
|
2014-11-26 15:04:51 +00:00
|
|
|
{
|
|
|
|
uint32_t cksum;
|
2018-12-17 15:50:04 +00:00
|
|
|
uint32_t l3_len, l4_len;
|
2020-09-01 09:47:55 +00:00
|
|
|
uint8_t ip_hdr_len;
|
2018-12-17 15:50:04 +00:00
|
|
|
|
2020-10-12 14:55:46 +00:00
|
|
|
ip_hdr_len = rte_ipv4_hdr_len(ipv4_hdr);
|
2018-12-17 15:50:04 +00:00
|
|
|
l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
|
2020-09-01 09:47:55 +00:00
|
|
|
if (l3_len < ip_hdr_len)
|
2018-12-17 15:50:04 +00:00
|
|
|
return 0;
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2020-09-01 09:47:55 +00:00
|
|
|
l4_len = l3_len - ip_hdr_len;
|
2014-11-26 15:04:51 +00:00
|
|
|
|
|
|
|
cksum = rte_raw_cksum(l4_hdr, l4_len);
|
2014-11-26 15:04:52 +00:00
|
|
|
cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);
|
2014-11-26 15:04:51 +00:00
|
|
|
|
|
|
|
cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
|
2021-06-30 13:51:57 +00:00
|
|
|
|
|
|
|
return (uint16_t)cksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the IPv4 UDP or TCP checksum.
|
|
|
|
*
|
2021-09-21 14:59:24 +00:00
|
|
|
* The layer 4 checksum must be set to 0 in the L4 header by the caller.
|
2021-06-30 13:51:57 +00:00
|
|
|
*
|
|
|
|
* @param ipv4_hdr
|
|
|
|
* The pointer to the contiguous IPv4 header.
|
|
|
|
* @param l4_hdr
|
|
|
|
* The pointer to the beginning of the L4 header.
|
|
|
|
* @return
|
2021-09-21 14:59:24 +00:00
|
|
|
* The complemented checksum to set in the L4 header.
|
2021-06-30 13:51:57 +00:00
|
|
|
*/
|
|
|
|
static inline uint16_t
|
|
|
|
rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
|
|
|
|
|
|
|
|
cksum = ~cksum;
|
|
|
|
|
2020-07-10 06:55:51 +00:00
|
|
|
/*
|
2021-06-30 13:51:57 +00:00
|
|
|
* Per RFC 768: If the computed checksum is zero for UDP,
|
2020-07-10 06:55:51 +00:00
|
|
|
* it is transmitted as all ones
|
|
|
|
* (the equivalent in one's complement arithmetic).
|
|
|
|
*/
|
|
|
|
if (cksum == 0 && ipv4_hdr->next_proto_id == IPPROTO_UDP)
|
2014-11-26 15:04:51 +00:00
|
|
|
cksum = 0xffff;
|
|
|
|
|
2021-06-30 13:51:57 +00:00
|
|
|
return cksum;
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:28:56 +00:00
|
|
|
/**
|
|
|
|
* @internal Calculate the non-complemented IPv4 L4 checksum of a packet
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
|
|
|
__rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m,
|
|
|
|
const struct rte_ipv4_hdr *ipv4_hdr,
|
|
|
|
uint16_t l4_off)
|
|
|
|
{
|
|
|
|
uint16_t raw_cksum;
|
|
|
|
uint32_t cksum;
|
|
|
|
|
|
|
|
if (l4_off > m->pkt_len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0);
|
|
|
|
|
|
|
|
cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
|
|
|
|
|
|
|
|
return (uint16_t)cksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @warning
|
|
|
|
* @b EXPERIMENTAL: this API may change without prior notice.
|
|
|
|
*
|
|
|
|
* Compute the IPv4 UDP/TCP checksum of a packet.
|
|
|
|
*
|
|
|
|
* @param m
|
|
|
|
* The pointer to the mbuf.
|
|
|
|
* @param ipv4_hdr
|
|
|
|
* The pointer to the contiguous IPv4 header.
|
|
|
|
* @param l4_off
|
|
|
|
* The offset in bytes to start L4 checksum.
|
|
|
|
* @return
|
|
|
|
* The complemented checksum to set in the L4 header.
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline uint16_t
|
|
|
|
rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m,
|
|
|
|
const struct rte_ipv4_hdr *ipv4_hdr, uint16_t l4_off)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
|
|
|
|
|
|
|
|
cksum = ~cksum;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per RFC 768: If the computed checksum is zero for UDP,
|
|
|
|
* it is transmitted as all ones
|
|
|
|
* (the equivalent in one's complement arithmetic).
|
|
|
|
*/
|
|
|
|
if (cksum == 0 && ipv4_hdr->next_proto_id == IPPROTO_UDP)
|
|
|
|
cksum = 0xffff;
|
|
|
|
|
|
|
|
return cksum;
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:51:57 +00:00
|
|
|
/**
|
|
|
|
* Validate the IPv4 UDP or TCP checksum.
|
|
|
|
*
|
|
|
|
* In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0
|
|
|
|
* (i.e. no checksum).
|
|
|
|
*
|
|
|
|
* @param ipv4_hdr
|
|
|
|
* The pointer to the contiguous IPv4 header.
|
|
|
|
* @param l4_hdr
|
|
|
|
* The pointer to the beginning of the L4 header.
|
|
|
|
* @return
|
|
|
|
* Return 0 if the checksum is correct, else -1.
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline int
|
|
|
|
rte_ipv4_udptcp_cksum_verify(const struct rte_ipv4_hdr *ipv4_hdr,
|
|
|
|
const void *l4_hdr)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv4_udptcp_cksum(ipv4_hdr, l4_hdr);
|
|
|
|
|
|
|
|
if (cksum != 0xffff)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2014-11-26 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 12:28:56 +00:00
|
|
|
/**
|
|
|
|
* @warning
|
|
|
|
* @b EXPERIMENTAL: this API may change without prior notice.
|
|
|
|
*
|
|
|
|
* Verify the IPv4 UDP/TCP checksum of a packet.
|
|
|
|
*
|
|
|
|
* In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0
|
|
|
|
* (i.e. no checksum).
|
|
|
|
*
|
|
|
|
* @param m
|
|
|
|
* The pointer to the mbuf.
|
|
|
|
* @param ipv4_hdr
|
|
|
|
* The pointer to the contiguous IPv4 header.
|
|
|
|
* @param l4_off
|
|
|
|
* The offset in bytes to start L4 checksum.
|
|
|
|
* @return
|
|
|
|
* Return 0 if the checksum is correct, else -1.
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline uint16_t
|
|
|
|
rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m,
|
|
|
|
const struct rte_ipv4_hdr *ipv4_hdr,
|
|
|
|
uint16_t l4_off)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv4_udptcp_cksum_mbuf(m, ipv4_hdr, l4_off);
|
|
|
|
|
|
|
|
if (cksum != 0xffff)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:54:00 +00:00
|
|
|
/**
|
|
|
|
* IPv6 Header
|
|
|
|
*/
|
2019-05-21 16:13:10 +00:00
|
|
|
struct rte_ipv6_hdr {
|
2019-09-27 11:58:02 +00:00
|
|
|
rte_be32_t vtc_flow; /**< IP version, traffic class & flow label. */
|
2021-03-08 06:51:04 +00:00
|
|
|
rte_be16_t payload_len; /**< IP payload size, including ext. headers */
|
2019-09-27 11:58:02 +00:00
|
|
|
uint8_t proto; /**< Protocol, next header. */
|
|
|
|
uint8_t hop_limits; /**< Hop limits. */
|
|
|
|
uint8_t src_addr[16]; /**< IP address of source host. */
|
|
|
|
uint8_t dst_addr[16]; /**< IP address of destination host(s). */
|
2020-02-09 17:29:23 +00:00
|
|
|
} __rte_packed;
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2018-01-16 09:17:51 +00:00
|
|
|
/* IPv6 vtc_flow: IPv / TC / flow_label */
|
2019-05-21 16:13:11 +00:00
|
|
|
#define RTE_IPV6_HDR_FL_SHIFT 0
|
|
|
|
#define RTE_IPV6_HDR_TC_SHIFT 20
|
2019-07-01 13:59:04 +00:00
|
|
|
#define RTE_IPV6_HDR_FL_MASK ((1u << RTE_IPV6_HDR_TC_SHIFT) - 1)
|
|
|
|
#define RTE_IPV6_HDR_TC_MASK (0xff << RTE_IPV6_HDR_TC_SHIFT)
|
|
|
|
#define RTE_IPV6_HDR_DSCP_MASK (0xfc << RTE_IPV6_HDR_TC_SHIFT)
|
|
|
|
#define RTE_IPV6_HDR_ECN_MASK (0x03 << RTE_IPV6_HDR_TC_SHIFT)
|
2019-07-04 10:42:35 +00:00
|
|
|
#define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK
|
2018-01-16 09:17:51 +00:00
|
|
|
|
2020-04-20 19:25:22 +00:00
|
|
|
#define RTE_IPV6_MIN_MTU 1280 /**< Minimum MTU for IPv6, see RFC 8200. */
|
|
|
|
|
2014-11-26 15:04:51 +00:00
|
|
|
/**
|
|
|
|
* Process the pseudo-header checksum of an IPv6 header.
|
|
|
|
*
|
2014-11-26 15:04:52 +00:00
|
|
|
* Depending on the ol_flags, the pseudo-header checksum expected by the
|
|
|
|
* drivers is not the same. For instance, when TSO is enabled, the IPv6
|
|
|
|
* payload length must not be included in the packet.
|
|
|
|
*
|
|
|
|
* When ol_flags is 0, it computes the standard pseudo-header checksum.
|
|
|
|
*
|
2014-11-26 15:04:51 +00:00
|
|
|
* @param ipv6_hdr
|
|
|
|
* The pointer to the contiguous IPv6 header.
|
2014-11-26 15:04:52 +00:00
|
|
|
* @param ol_flags
|
|
|
|
* The ol_flags of the associated mbuf.
|
2014-11-26 15:04:51 +00:00
|
|
|
* @return
|
|
|
|
* The non-complemented checksum to set in the L4 header.
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
2019-05-21 16:13:10 +00:00
|
|
|
rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
|
2014-11-26 15:04:51 +00:00
|
|
|
{
|
2014-12-11 11:49:42 +00:00
|
|
|
uint32_t sum;
|
|
|
|
struct {
|
2019-09-27 11:58:02 +00:00
|
|
|
rte_be32_t len; /* L4 length. */
|
|
|
|
rte_be32_t proto; /* L4 protocol - top 3 bytes must be zero */
|
2014-11-26 15:04:51 +00:00
|
|
|
} psd_hdr;
|
|
|
|
|
2018-05-17 13:50:17 +00:00
|
|
|
psd_hdr.proto = (uint32_t)(ipv6_hdr->proto << 24);
|
2021-10-15 19:24:08 +00:00
|
|
|
if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
|
2014-11-26 15:04:52 +00:00
|
|
|
psd_hdr.len = 0;
|
|
|
|
} else {
|
|
|
|
psd_hdr.len = ipv6_hdr->payload_len;
|
|
|
|
}
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2014-12-11 11:49:42 +00:00
|
|
|
sum = __rte_raw_cksum(ipv6_hdr->src_addr,
|
|
|
|
sizeof(ipv6_hdr->src_addr) + sizeof(ipv6_hdr->dst_addr),
|
|
|
|
0);
|
|
|
|
sum = __rte_raw_cksum(&psd_hdr, sizeof(psd_hdr), sum);
|
|
|
|
return __rte_raw_cksum_reduce(sum);
|
2014-11-26 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:51:57 +00:00
|
|
|
/**
|
2021-09-21 14:59:24 +00:00
|
|
|
* @internal Calculate the non-complemented IPv6 L4 checksum
|
2021-06-30 13:51:57 +00:00
|
|
|
*/
|
|
|
|
static inline uint16_t
|
|
|
|
__rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
|
|
|
|
{
|
|
|
|
uint32_t cksum;
|
|
|
|
uint32_t l4_len;
|
|
|
|
|
|
|
|
l4_len = rte_be_to_cpu_16(ipv6_hdr->payload_len);
|
|
|
|
|
|
|
|
cksum = rte_raw_cksum(l4_hdr, l4_len);
|
|
|
|
cksum += rte_ipv6_phdr_cksum(ipv6_hdr, 0);
|
|
|
|
|
|
|
|
cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
|
|
|
|
|
|
|
|
return (uint16_t)cksum;
|
|
|
|
}
|
|
|
|
|
2014-11-26 15:04:51 +00:00
|
|
|
/**
|
|
|
|
* Process the IPv6 UDP or TCP checksum.
|
|
|
|
*
|
2021-09-21 14:59:24 +00:00
|
|
|
* The IPv6 header must not be followed by extension headers. The layer 4
|
|
|
|
* checksum must be set to 0 in the L4 header by the caller.
|
2014-11-26 15:04:51 +00:00
|
|
|
*
|
|
|
|
* @param ipv6_hdr
|
|
|
|
* The pointer to the contiguous IPv6 header.
|
|
|
|
* @param l4_hdr
|
|
|
|
* The pointer to the beginning of the L4 header.
|
|
|
|
* @return
|
2021-09-21 14:59:24 +00:00
|
|
|
* The complemented checksum to set in the L4 header.
|
2014-11-26 15:04:51 +00:00
|
|
|
*/
|
|
|
|
static inline uint16_t
|
2019-05-21 16:13:10 +00:00
|
|
|
rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
|
2014-11-26 15:04:51 +00:00
|
|
|
{
|
2021-06-30 13:51:57 +00:00
|
|
|
uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2021-06-30 13:51:57 +00:00
|
|
|
cksum = ~cksum;
|
2014-11-26 15:04:51 +00:00
|
|
|
|
2020-07-10 06:55:51 +00:00
|
|
|
/*
|
|
|
|
* Per RFC 768: If the computed checksum is zero for UDP,
|
|
|
|
* it is transmitted as all ones
|
|
|
|
* (the equivalent in one's complement arithmetic).
|
|
|
|
*/
|
|
|
|
if (cksum == 0 && ipv6_hdr->proto == IPPROTO_UDP)
|
2014-11-26 15:04:51 +00:00
|
|
|
cksum = 0xffff;
|
|
|
|
|
2021-06-30 13:51:57 +00:00
|
|
|
return cksum;
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:28:56 +00:00
|
|
|
/**
|
|
|
|
* @internal Calculate the non-complemented IPv6 L4 checksum of a packet
|
|
|
|
*/
|
|
|
|
static inline uint16_t
|
|
|
|
__rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m,
|
|
|
|
const struct rte_ipv6_hdr *ipv6_hdr,
|
|
|
|
uint16_t l4_off)
|
|
|
|
{
|
|
|
|
uint16_t raw_cksum;
|
|
|
|
uint32_t cksum;
|
|
|
|
|
|
|
|
if (l4_off > m->pkt_len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0);
|
|
|
|
|
|
|
|
cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
|
|
|
|
|
|
|
|
return (uint16_t)cksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @warning
|
|
|
|
* @b EXPERIMENTAL: this API may change without prior notice.
|
|
|
|
*
|
|
|
|
* Process the IPv6 UDP or TCP checksum of a packet.
|
|
|
|
*
|
|
|
|
* The IPv6 header must not be followed by extension headers. The layer 4
|
|
|
|
* checksum must be set to 0 in the L4 header by the caller.
|
|
|
|
*
|
|
|
|
* @param m
|
|
|
|
* The pointer to the mbuf.
|
|
|
|
* @param ipv6_hdr
|
|
|
|
* The pointer to the contiguous IPv6 header.
|
|
|
|
* @param l4_off
|
|
|
|
* The offset in bytes to start L4 checksum.
|
|
|
|
* @return
|
|
|
|
* The complemented checksum to set in the L4 header.
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline uint16_t
|
|
|
|
rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m,
|
|
|
|
const struct rte_ipv6_hdr *ipv6_hdr, uint16_t l4_off)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
|
|
|
|
|
|
|
|
cksum = ~cksum;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per RFC 768: If the computed checksum is zero for UDP,
|
|
|
|
* it is transmitted as all ones
|
|
|
|
* (the equivalent in one's complement arithmetic).
|
|
|
|
*/
|
|
|
|
if (cksum == 0 && ipv6_hdr->proto == IPPROTO_UDP)
|
|
|
|
cksum = 0xffff;
|
|
|
|
|
|
|
|
return cksum;
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:51:57 +00:00
|
|
|
/**
|
|
|
|
* Validate the IPv6 UDP or TCP checksum.
|
|
|
|
*
|
|
|
|
* In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0:
|
|
|
|
* this is either invalid or means no checksum in some situations. See 8.1
|
|
|
|
* (Upper-Layer Checksums) in RFC 8200.
|
|
|
|
*
|
|
|
|
* @param ipv6_hdr
|
|
|
|
* The pointer to the contiguous IPv6 header.
|
|
|
|
* @param l4_hdr
|
|
|
|
* The pointer to the beginning of the L4 header.
|
|
|
|
* @return
|
|
|
|
* Return 0 if the checksum is correct, else -1.
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline int
|
|
|
|
rte_ipv6_udptcp_cksum_verify(const struct rte_ipv6_hdr *ipv6_hdr,
|
|
|
|
const void *l4_hdr)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
|
|
|
|
|
|
|
|
if (cksum != 0xffff)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2014-11-26 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 12:28:56 +00:00
|
|
|
/**
|
|
|
|
* @warning
|
|
|
|
* @b EXPERIMENTAL: this API may change without prior notice.
|
|
|
|
*
|
|
|
|
* Validate the IPv6 UDP or TCP checksum of a packet.
|
|
|
|
*
|
|
|
|
* In case of UDP, the caller must first check if udp_hdr->dgram_cksum is 0:
|
|
|
|
* this is either invalid or means no checksum in some situations. See 8.1
|
|
|
|
* (Upper-Layer Checksums) in RFC 8200.
|
|
|
|
*
|
|
|
|
* @param m
|
|
|
|
* The pointer to the mbuf.
|
|
|
|
* @param ipv6_hdr
|
|
|
|
* The pointer to the contiguous IPv6 header.
|
|
|
|
* @param l4_off
|
|
|
|
* The offset in bytes to start L4 checksum.
|
|
|
|
* @return
|
|
|
|
* Return 0 if the checksum is correct, else -1.
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline int
|
|
|
|
rte_ipv6_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m,
|
|
|
|
const struct rte_ipv6_hdr *ipv6_hdr,
|
|
|
|
uint16_t l4_off)
|
|
|
|
{
|
|
|
|
uint16_t cksum = __rte_ipv6_udptcp_cksum_mbuf(m, ipv6_hdr, l4_off);
|
|
|
|
|
|
|
|
if (cksum != 0xffff)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-14 16:35:48 +00:00
|
|
|
/** IPv6 fragment extension header. */
|
|
|
|
#define RTE_IPV6_EHDR_MF_SHIFT 0
|
|
|
|
#define RTE_IPV6_EHDR_MF_MASK 1
|
|
|
|
#define RTE_IPV6_EHDR_FO_SHIFT 3
|
|
|
|
#define RTE_IPV6_EHDR_FO_MASK (~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
|
|
|
|
#define RTE_IPV6_EHDR_FO_ALIGN (1 << RTE_IPV6_EHDR_FO_SHIFT)
|
|
|
|
|
|
|
|
#define RTE_IPV6_FRAG_USED_MASK (RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
|
|
|
|
|
|
|
|
#define RTE_IPV6_GET_MF(x) ((x) & RTE_IPV6_EHDR_MF_MASK)
|
|
|
|
#define RTE_IPV6_GET_FO(x) ((x) >> RTE_IPV6_EHDR_FO_SHIFT)
|
|
|
|
|
|
|
|
#define RTE_IPV6_SET_FRAG_DATA(fo, mf) \
|
|
|
|
(((fo) & RTE_IPV6_EHDR_FO_MASK) | ((mf) & RTE_IPV6_EHDR_MF_MASK))
|
|
|
|
|
|
|
|
struct rte_ipv6_fragment_ext {
|
|
|
|
uint8_t next_header; /**< Next header type */
|
|
|
|
uint8_t reserved; /**< Reserved */
|
|
|
|
rte_be16_t frag_data; /**< All fragmentation data */
|
|
|
|
rte_be32_t id; /**< Packet ID */
|
|
|
|
} __rte_packed;
|
|
|
|
|
|
|
|
/* IPv6 fragment extension header size */
|
|
|
|
#define RTE_IPV6_FRAG_HDR_SIZE sizeof(struct rte_ipv6_fragment_ext)
|
2019-06-24 13:39:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse next IPv6 header extension
|
|
|
|
*
|
|
|
|
* This function checks if proto number is an IPv6 extensions and parses its
|
|
|
|
* data if so, providing information on next header and extension length.
|
|
|
|
*
|
|
|
|
* @param p
|
|
|
|
* Pointer to an extension raw data.
|
|
|
|
* @param proto
|
|
|
|
* Protocol number extracted from the "next header" field from
|
|
|
|
* the IPv6 header or the previous extension.
|
|
|
|
* @param ext_len
|
|
|
|
* Extension data length.
|
|
|
|
* @return
|
|
|
|
* next protocol number if proto is an IPv6 extension, -EINVAL otherwise
|
|
|
|
*/
|
|
|
|
__rte_experimental
|
|
|
|
static inline int
|
2019-11-15 00:02:59 +00:00
|
|
|
rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
|
2019-06-24 13:39:57 +00:00
|
|
|
{
|
|
|
|
int next_proto;
|
|
|
|
|
|
|
|
switch (proto) {
|
|
|
|
case IPPROTO_AH:
|
|
|
|
next_proto = *p++;
|
|
|
|
*ext_len = (*p + 2) * sizeof(uint32_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPPROTO_HOPOPTS:
|
|
|
|
case IPPROTO_ROUTING:
|
|
|
|
case IPPROTO_DSTOPTS:
|
|
|
|
next_proto = *p++;
|
|
|
|
*ext_len = (*p + 1) * sizeof(uint64_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPPROTO_FRAGMENT:
|
|
|
|
next_proto = *p;
|
|
|
|
*ext_len = RTE_IPV6_FRAG_HDR_SIZE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next_proto;
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:54:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _RTE_IP_H_ */
|