From: Robin Jarry <rjarry@redhat.com>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH dpdk v4 02/17] net: split IPv4 and IPv6 symbols in separate headers
Date: Fri, 18 Oct 2024 11:17:19 +0200 [thread overview]
Message-ID: <20241018091734.64601-3-rjarry@redhat.com> (raw)
In-Reply-To: <20241018091734.64601-1-rjarry@redhat.com>
Split IPv4 and IPv6 symbols in two separate headers. rte_ip4.h and
rte_ip6.h, respectively.
Update doxygen index accordingly.
Include rte_ip4.h and rte_ip6.h in rte_ip.h for backward compatibility
in applications.
Signed-off-by: Robin Jarry <rjarry@redhat.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
doc/api/doxy-api-index.md | 3 +-
lib/net/meson.build | 2 +
lib/net/rte_ip.h | 694 +-------------------------------
lib/net/{rte_ip.h => rte_ip4.h} | 325 +--------------
lib/net/{rte_ip.h => rte_ip6.h} | 352 +---------------
5 files changed, 16 insertions(+), 1360 deletions(-)
copy lib/net/{rte_ip.h => rte_ip4.h} (52%)
copy lib/net/{rte_ip.h => rte_ip6.h} (50%)
diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md
index 8b83af53a863..266c8b90dcfb 100644
--- a/doc/api/doxy-api-index.md
+++ b/doc/api/doxy-api-index.md
@@ -117,7 +117,8 @@ The public API headers are grouped by topics:
[IPsec group](@ref rte_ipsec_group.h),
[IPsec SA](@ref rte_ipsec_sa.h),
[IPsec SAD](@ref rte_ipsec_sad.h),
- [IP](@ref rte_ip.h),
+ [IPv4](@ref rte_ip4.h),
+ [IPv6](@ref rte_ip6.h),
[frag/reass](@ref rte_ip_frag.h),
[UDP](@ref rte_udp.h),
[SCTP](@ref rte_sctp.h),
diff --git a/lib/net/meson.build b/lib/net/meson.build
index 63d2fabbaf6c..3406cb6ca543 100644
--- a/lib/net/meson.build
+++ b/lib/net/meson.build
@@ -3,6 +3,8 @@
headers = files(
'rte_ip.h',
+ 'rte_ip4.h',
+ 'rte_ip6.h',
'rte_cksum.h',
'rte_tcp.h',
'rte_udp.h',
diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
index 0ae7c0565047..3807d82d0605 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip.h
@@ -1,700 +1,12 @@
/* 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.
+ * Copyright (c) 2024 Robin Jarry
* All rights reserved.
*/
#ifndef _RTE_IP_H_
#define _RTE_IP_H_
-/**
- * @file
- *
- * IP-related defines
- */
-
-#include <stdint.h>
-
-#ifdef RTE_EXEC_ENV_WINDOWS
-#include <ws2tcpip.h>
-#else
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
-#endif
-
-#include <rte_byteorder.h>
-#include <rte_mbuf.h>
-#include <rte_cksum.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * IPv4 Header
- */
-struct rte_ipv4_hdr {
- __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
- };
- };
- uint8_t type_of_service; /**< type of service */
- rte_be16_t total_length; /**< length of packet */
- rte_be16_t packet_id; /**< packet ID */
- rte_be16_t fragment_offset; /**< fragmentation offset */
- uint8_t time_to_live; /**< time to live */
- uint8_t next_proto_id; /**< protocol ID */
- rte_be16_t hdr_checksum; /**< header checksum */
- rte_be32_t src_addr; /**< source address */
- rte_be32_t dst_addr; /**< destination address */
-} __rte_packed;
-
-/** Create IPv4 address */
-#define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \
- (((b) & 0xff) << 16) | \
- (((c) & 0xff) << 8) | \
- ((d) & 0xff))
-
-/** Maximal IPv4 packet length (including a header) */
-#define RTE_IPV4_MAX_PKT_LEN 65535
-
-/** Internet header length mask for version_ihl field */
-#define RTE_IPV4_HDR_IHL_MASK (0x0f)
-/**
- * Internet header length field multiplier (IHL field specifies overall header
- * length in number of 4-byte words)
- */
-#define RTE_IPV4_IHL_MULTIPLIER (4)
-
-/* Type of Service fields */
-#define RTE_IPV4_HDR_DSCP_MASK (0xfc)
-#define RTE_IPV4_HDR_ECN_MASK (0x03)
-#define RTE_IPV4_HDR_ECN_CE RTE_IPV4_HDR_ECN_MASK
-
-/* Fragment Offset * Flags. */
-#define RTE_IPV4_HDR_DF_SHIFT 14
-#define RTE_IPV4_HDR_MF_SHIFT 13
-#define RTE_IPV4_HDR_FO_SHIFT 3
-
-#define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT)
-#define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT)
-
-#define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1)
-
-#define RTE_IPV4_HDR_OFFSET_UNITS 8
-
-/* 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
-
-/*
- * IPv4 address types
- */
-#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 */
-
-/*
- * IPv4 Multicast-related macros
- */
-#define RTE_IPV4_MIN_MCAST \
- RTE_IPV4(224, 0, 0, 0) /**< Minimal IPv4-multicast address */
-#define RTE_IPV4_MAX_MCAST \
- RTE_IPV4(239, 255, 255, 255) /**< Maximum IPv4 multicast address */
-
-#define RTE_IS_IPV4_MCAST(x) \
- ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST)
- /**< check if IPv4 address is multicast */
-
-/* IPv4 default fields values */
-#define RTE_IPV4_MIN_IHL (0x5)
-#define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL)
-
-/**
- * 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);
-}
-
-/**
- * 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
-rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
-{
- uint16_t cksum;
- cksum = rte_raw_cksum(ipv4_hdr, rte_ipv4_hdr_len(ipv4_hdr));
- return (uint16_t)~cksum;
-}
-
-/**
- * Process the pseudo-header checksum of an IPv4 header.
- *
- * The checksum field must be set to 0 by the caller.
- *
- * 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.
- *
- * @param ipv4_hdr
- * The pointer to the contiguous IPv4 header.
- * @param ol_flags
- * The ol_flags of the associated mbuf.
- * @return
- * The non-complemented checksum to set in the L4 header.
- */
-static inline uint16_t
-rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
-{
- 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;
-
- uint32_t l3_len;
-
- 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;
- if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
- psd_hdr.len = 0;
- } else {
- l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
- psd_hdr.len = rte_cpu_to_be_16((uint16_t)(l3_len -
- rte_ipv4_hdr_len(ipv4_hdr)));
- }
- return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr));
-}
-
-/**
- * @internal Calculate the non-complemented IPv4 L4 checksum
- */
-static inline uint16_t
-__rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
-{
- uint32_t cksum;
- uint32_t l3_len, l4_len;
- uint8_t ip_hdr_len;
-
- ip_hdr_len = rte_ipv4_hdr_len(ipv4_hdr);
- l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
- if (l3_len < ip_hdr_len)
- return 0;
-
- l4_len = l3_len - ip_hdr_len;
-
- cksum = rte_raw_cksum(l4_hdr, l4_len);
- cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);
-
- cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
-
- return (uint16_t)cksum;
-}
-
-/**
- * Process the IPv4 UDP or TCP checksum.
- *
- * The layer 4 checksum must be set to 0 in the L4 header by the caller.
- *
- * @param ipv4_hdr
- * The pointer to the contiguous IPv4 header.
- * @param l4_hdr
- * The pointer to the beginning of the L4 header.
- * @return
- * The complemented checksum to set in the L4 header.
- */
-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;
-
- /*
- * 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;
-}
-
-/**
- * @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;
- uint16_t len;
-
- if (unlikely(l4_off > m->pkt_len))
- return 0; /* invalid params, return a dummy value */
-
- len = rte_be_to_cpu_16(ipv4_hdr->total_length) - (uint16_t)rte_ipv4_hdr_len(ipv4_hdr);
-
- if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum))
- return 0;
-
- cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0);
-
- cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
-
- return (uint16_t)cksum;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-static inline int
-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;
-}
-
-/**
- * IPv6 Header
- */
-struct rte_ipv6_hdr {
- rte_be32_t vtc_flow; /**< IP version, traffic class & flow label. */
- rte_be16_t payload_len; /**< IP payload size, including ext. headers */
- 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). */
-} __rte_packed;
-
-/* IPv6 routing extension type definition. */
-#define RTE_IPV6_SRCRT_TYPE_4 4
-
-/**
- * IPv6 Routing Extension Header
- */
-struct rte_ipv6_routing_ext {
- uint8_t next_hdr; /**< Protocol, next header. */
- uint8_t hdr_len; /**< Header length. */
- uint8_t type; /**< Extension header type. */
- uint8_t segments_left; /**< Valid segments number. */
- __extension__
- union {
- rte_be32_t flags; /**< Packet control data per type. */
- struct {
- uint8_t last_entry; /**< The last_entry field of SRH */
- uint8_t flag; /**< Packet flag. */
- rte_be16_t tag; /**< Packet tag. */
- };
- };
- /* Next are 128-bit IPv6 address fields to describe segments. */
-} __rte_packed;
-
-/* IPv6 vtc_flow: IPv / TC / flow_label */
-#define RTE_IPV6_HDR_FL_SHIFT 0
-#define RTE_IPV6_HDR_TC_SHIFT 20
-#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)
-#define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK
-
-#define RTE_IPV6_MIN_MTU 1280 /**< Minimum MTU for IPv6, see RFC 8200. */
-
-/**
- * Process the pseudo-header checksum of an IPv6 header.
- *
- * 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.
- *
- * @param ipv6_hdr
- * The pointer to the contiguous IPv6 header.
- * @param ol_flags
- * The ol_flags of the associated mbuf.
- * @return
- * The non-complemented checksum to set in the L4 header.
- */
-static inline uint16_t
-rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
-{
- uint32_t sum;
- struct {
- rte_be32_t len; /* L4 length. */
- rte_be32_t proto; /* L4 protocol - top 3 bytes must be zero */
- } psd_hdr;
-
- psd_hdr.proto = (uint32_t)(ipv6_hdr->proto << 24);
- if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
- psd_hdr.len = 0;
- } else {
- psd_hdr.len = ipv6_hdr->payload_len;
- }
-
- 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);
-}
-
-/**
- * @internal Calculate the non-complemented IPv6 L4 checksum
- */
-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;
-}
-
-/**
- * Process the IPv6 UDP or TCP checksum.
- *
- * 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 ipv6_hdr
- * The pointer to the contiguous IPv6 header.
- * @param l4_hdr
- * The pointer to the beginning of the L4 header.
- * @return
- * The complemented checksum to set in the L4 header.
- */
-static inline uint16_t
-rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
-{
- uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
-
- 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;
-}
-
-/**
- * @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 (unlikely(l4_off > m->pkt_len))
- return 0; /* invalid params, return a dummy value */
-
- if (rte_raw_cksum_mbuf(m, l4_off, rte_be_to_cpu_16(ipv6_hdr->payload_len), &raw_cksum))
- return 0;
-
- cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0);
-
- cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
-
- return (uint16_t)cksum;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/** 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)
-
-/**
- * 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
- */
-static inline int
-rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
-{
- 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;
-}
-
-#ifdef __cplusplus
-}
-#endif
+#include <rte_ip4.h>
+#include <rte_ip6.h>
#endif /* _RTE_IP_H_ */
diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip4.h
similarity index 52%
copy from lib/net/rte_ip.h
copy to lib/net/rte_ip4.h
index 0ae7c0565047..3191d2788efe 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip4.h
@@ -6,13 +6,13 @@
* All rights reserved.
*/
-#ifndef _RTE_IP_H_
-#define _RTE_IP_H_
+#ifndef _RTE_IP4_H_
+#define _RTE_IP4_H_
/**
* @file
*
- * IP-related defines
+ * IPv4-related defines
*/
#include <stdint.h>
@@ -374,325 +374,6 @@ rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m,
return 0;
}
-/**
- * IPv6 Header
- */
-struct rte_ipv6_hdr {
- rte_be32_t vtc_flow; /**< IP version, traffic class & flow label. */
- rte_be16_t payload_len; /**< IP payload size, including ext. headers */
- 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). */
-} __rte_packed;
-
-/* IPv6 routing extension type definition. */
-#define RTE_IPV6_SRCRT_TYPE_4 4
-
-/**
- * IPv6 Routing Extension Header
- */
-struct rte_ipv6_routing_ext {
- uint8_t next_hdr; /**< Protocol, next header. */
- uint8_t hdr_len; /**< Header length. */
- uint8_t type; /**< Extension header type. */
- uint8_t segments_left; /**< Valid segments number. */
- __extension__
- union {
- rte_be32_t flags; /**< Packet control data per type. */
- struct {
- uint8_t last_entry; /**< The last_entry field of SRH */
- uint8_t flag; /**< Packet flag. */
- rte_be16_t tag; /**< Packet tag. */
- };
- };
- /* Next are 128-bit IPv6 address fields to describe segments. */
-} __rte_packed;
-
-/* IPv6 vtc_flow: IPv / TC / flow_label */
-#define RTE_IPV6_HDR_FL_SHIFT 0
-#define RTE_IPV6_HDR_TC_SHIFT 20
-#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)
-#define RTE_IPV6_HDR_ECN_CE RTE_IPV6_HDR_ECN_MASK
-
-#define RTE_IPV6_MIN_MTU 1280 /**< Minimum MTU for IPv6, see RFC 8200. */
-
-/**
- * Process the pseudo-header checksum of an IPv6 header.
- *
- * 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.
- *
- * @param ipv6_hdr
- * The pointer to the contiguous IPv6 header.
- * @param ol_flags
- * The ol_flags of the associated mbuf.
- * @return
- * The non-complemented checksum to set in the L4 header.
- */
-static inline uint16_t
-rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
-{
- uint32_t sum;
- struct {
- rte_be32_t len; /* L4 length. */
- rte_be32_t proto; /* L4 protocol - top 3 bytes must be zero */
- } psd_hdr;
-
- psd_hdr.proto = (uint32_t)(ipv6_hdr->proto << 24);
- if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
- psd_hdr.len = 0;
- } else {
- psd_hdr.len = ipv6_hdr->payload_len;
- }
-
- 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);
-}
-
-/**
- * @internal Calculate the non-complemented IPv6 L4 checksum
- */
-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;
-}
-
-/**
- * Process the IPv6 UDP or TCP checksum.
- *
- * 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 ipv6_hdr
- * The pointer to the contiguous IPv6 header.
- * @param l4_hdr
- * The pointer to the beginning of the L4 header.
- * @return
- * The complemented checksum to set in the L4 header.
- */
-static inline uint16_t
-rte_ipv6_udptcp_cksum(const struct rte_ipv6_hdr *ipv6_hdr, const void *l4_hdr)
-{
- uint16_t cksum = __rte_ipv6_udptcp_cksum(ipv6_hdr, l4_hdr);
-
- 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;
-}
-
-/**
- * @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 (unlikely(l4_off > m->pkt_len))
- return 0; /* invalid params, return a dummy value */
-
- if (rte_raw_cksum_mbuf(m, l4_off, rte_be_to_cpu_16(ipv6_hdr->payload_len), &raw_cksum))
- return 0;
-
- cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0);
-
- cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
-
- return (uint16_t)cksum;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/** 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)
-
-/**
- * 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
- */
-static inline int
-rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
-{
- 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;
-}
-
#ifdef __cplusplus
}
#endif
diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip6.h
similarity index 50%
copy from lib/net/rte_ip.h
copy to lib/net/rte_ip6.h
index 0ae7c0565047..9ed737d5eb81 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip6.h
@@ -6,13 +6,13 @@
* All rights reserved.
*/
-#ifndef _RTE_IP_H_
-#define _RTE_IP_H_
+#ifndef _RTE_IP6_H_
+#define _RTE_IP6_H_
/**
* @file
*
- * IP-related defines
+ * IPv6-related defines
*/
#include <stdint.h>
@@ -24,7 +24,6 @@
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <netinet/ip.h>
#include <netinet/ip6.h>
#endif
@@ -36,344 +35,6 @@
extern "C" {
#endif
-/**
- * IPv4 Header
- */
-struct rte_ipv4_hdr {
- __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
- };
- };
- uint8_t type_of_service; /**< type of service */
- rte_be16_t total_length; /**< length of packet */
- rte_be16_t packet_id; /**< packet ID */
- rte_be16_t fragment_offset; /**< fragmentation offset */
- uint8_t time_to_live; /**< time to live */
- uint8_t next_proto_id; /**< protocol ID */
- rte_be16_t hdr_checksum; /**< header checksum */
- rte_be32_t src_addr; /**< source address */
- rte_be32_t dst_addr; /**< destination address */
-} __rte_packed;
-
-/** Create IPv4 address */
-#define RTE_IPV4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \
- (((b) & 0xff) << 16) | \
- (((c) & 0xff) << 8) | \
- ((d) & 0xff))
-
-/** Maximal IPv4 packet length (including a header) */
-#define RTE_IPV4_MAX_PKT_LEN 65535
-
-/** Internet header length mask for version_ihl field */
-#define RTE_IPV4_HDR_IHL_MASK (0x0f)
-/**
- * Internet header length field multiplier (IHL field specifies overall header
- * length in number of 4-byte words)
- */
-#define RTE_IPV4_IHL_MULTIPLIER (4)
-
-/* Type of Service fields */
-#define RTE_IPV4_HDR_DSCP_MASK (0xfc)
-#define RTE_IPV4_HDR_ECN_MASK (0x03)
-#define RTE_IPV4_HDR_ECN_CE RTE_IPV4_HDR_ECN_MASK
-
-/* Fragment Offset * Flags. */
-#define RTE_IPV4_HDR_DF_SHIFT 14
-#define RTE_IPV4_HDR_MF_SHIFT 13
-#define RTE_IPV4_HDR_FO_SHIFT 3
-
-#define RTE_IPV4_HDR_DF_FLAG (1 << RTE_IPV4_HDR_DF_SHIFT)
-#define RTE_IPV4_HDR_MF_FLAG (1 << RTE_IPV4_HDR_MF_SHIFT)
-
-#define RTE_IPV4_HDR_OFFSET_MASK ((1 << RTE_IPV4_HDR_MF_SHIFT) - 1)
-
-#define RTE_IPV4_HDR_OFFSET_UNITS 8
-
-/* 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
-
-/*
- * IPv4 address types
- */
-#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 */
-
-/*
- * IPv4 Multicast-related macros
- */
-#define RTE_IPV4_MIN_MCAST \
- RTE_IPV4(224, 0, 0, 0) /**< Minimal IPv4-multicast address */
-#define RTE_IPV4_MAX_MCAST \
- RTE_IPV4(239, 255, 255, 255) /**< Maximum IPv4 multicast address */
-
-#define RTE_IS_IPV4_MCAST(x) \
- ((x) >= RTE_IPV4_MIN_MCAST && (x) <= RTE_IPV4_MAX_MCAST)
- /**< check if IPv4 address is multicast */
-
-/* IPv4 default fields values */
-#define RTE_IPV4_MIN_IHL (0x5)
-#define RTE_IPV4_VHL_DEF ((IPVERSION << 4) | RTE_IPV4_MIN_IHL)
-
-/**
- * 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);
-}
-
-/**
- * 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
-rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
-{
- uint16_t cksum;
- cksum = rte_raw_cksum(ipv4_hdr, rte_ipv4_hdr_len(ipv4_hdr));
- return (uint16_t)~cksum;
-}
-
-/**
- * Process the pseudo-header checksum of an IPv4 header.
- *
- * The checksum field must be set to 0 by the caller.
- *
- * 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.
- *
- * @param ipv4_hdr
- * The pointer to the contiguous IPv4 header.
- * @param ol_flags
- * The ol_flags of the associated mbuf.
- * @return
- * The non-complemented checksum to set in the L4 header.
- */
-static inline uint16_t
-rte_ipv4_phdr_cksum(const struct rte_ipv4_hdr *ipv4_hdr, uint64_t ol_flags)
-{
- 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;
-
- uint32_t l3_len;
-
- 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;
- if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
- psd_hdr.len = 0;
- } else {
- l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
- psd_hdr.len = rte_cpu_to_be_16((uint16_t)(l3_len -
- rte_ipv4_hdr_len(ipv4_hdr)));
- }
- return rte_raw_cksum(&psd_hdr, sizeof(psd_hdr));
-}
-
-/**
- * @internal Calculate the non-complemented IPv4 L4 checksum
- */
-static inline uint16_t
-__rte_ipv4_udptcp_cksum(const struct rte_ipv4_hdr *ipv4_hdr, const void *l4_hdr)
-{
- uint32_t cksum;
- uint32_t l3_len, l4_len;
- uint8_t ip_hdr_len;
-
- ip_hdr_len = rte_ipv4_hdr_len(ipv4_hdr);
- l3_len = rte_be_to_cpu_16(ipv4_hdr->total_length);
- if (l3_len < ip_hdr_len)
- return 0;
-
- l4_len = l3_len - ip_hdr_len;
-
- cksum = rte_raw_cksum(l4_hdr, l4_len);
- cksum += rte_ipv4_phdr_cksum(ipv4_hdr, 0);
-
- cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
-
- return (uint16_t)cksum;
-}
-
-/**
- * Process the IPv4 UDP or TCP checksum.
- *
- * The layer 4 checksum must be set to 0 in the L4 header by the caller.
- *
- * @param ipv4_hdr
- * The pointer to the contiguous IPv4 header.
- * @param l4_hdr
- * The pointer to the beginning of the L4 header.
- * @return
- * The complemented checksum to set in the L4 header.
- */
-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;
-
- /*
- * 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;
-}
-
-/**
- * @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;
- uint16_t len;
-
- if (unlikely(l4_off > m->pkt_len))
- return 0; /* invalid params, return a dummy value */
-
- len = rte_be_to_cpu_16(ipv4_hdr->total_length) - (uint16_t)rte_ipv4_hdr_len(ipv4_hdr);
-
- if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum))
- return 0;
-
- cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0);
-
- cksum = ((cksum & 0xffff0000) >> 16) + (cksum & 0xffff);
-
- return (uint16_t)cksum;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-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;
-}
-
-/**
- * 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.
- */
-static inline int
-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;
-}
-
/**
* IPv6 Header
*/
@@ -446,11 +107,10 @@ rte_ipv6_phdr_cksum(const struct rte_ipv6_hdr *ipv6_hdr, uint64_t ol_flags)
} psd_hdr;
psd_hdr.proto = (uint32_t)(ipv6_hdr->proto << 24);
- if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) {
+ if (ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
psd_hdr.len = 0;
- } else {
+ else
psd_hdr.len = ipv6_hdr->payload_len;
- }
sum = __rte_raw_cksum(ipv6_hdr->src_addr,
sizeof(ipv6_hdr->src_addr) + sizeof(ipv6_hdr->dst_addr),
@@ -697,4 +357,4 @@ rte_ipv6_get_next_ext(const uint8_t *p, int proto, size_t *ext_len)
}
#endif
-#endif /* _RTE_IP_H_ */
+#endif /* _RTE_IP6_H_ */
--
2.47.0
next prev parent reply other threads:[~2024-10-18 9:17 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 16:25 [PATCH dpdk v1 00/15] IPv6 APIs overhaul Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 01/15] net: split raw checksum functions in separate header Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 02/15] net: split ipv6 symbols " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 03/15] net: add structure for ipv6 addresses Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 04/15] net: use ipv6 structure for header addresses Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 05/15] fib6,rib6,lpm6: use ipv6 addr struct Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 06/15] net: add ipv6 address utilities Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 07/15] fib6,rib6,lpm6: use ipv6 utils Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 08/15] graph,node: use ipv6 addr struct and utils Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 09/15] pipeline: use ipv6 addr struct Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 10/15] ipsec: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 11/15] thash: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 12/15] gro: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 13/15] rte_flow: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 14/15] rib6,fib6,lpm6: remove duplicate constants Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 15/15] net: add utilities for well known ipv6 address types Robin Jarry
2024-08-21 22:28 ` [PATCH dpdk v1 00/15] IPv6 APIs overhaul Morten Brørup
2024-08-22 14:13 ` Stephen Hemminger
2024-08-22 15:13 ` Morten Brørup
2024-08-22 15:27 ` Robin Jarry
2024-08-22 18:41 ` Morten Brørup
2024-08-22 15:14 ` Robin Jarry
2024-08-22 15:16 ` Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 00/16] " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 01/16] net: split raw checksum functions in separate header Robin Jarry
2024-10-03 23:12 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 02/16] net: split ipv6 symbols " Robin Jarry
2024-10-03 23:15 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 03/16] net: add structure for ipv6 addresses Robin Jarry
2024-10-03 23:18 ` Stephen Hemminger
2024-10-04 11:59 ` Robin Jarry
2024-10-06 8:18 ` Morten Brørup
2024-10-10 20:08 ` Robin Jarry
2024-10-11 12:37 ` Morten Brørup
2024-10-11 17:02 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 04/16] net: use ipv6 structure for header addresses Robin Jarry
2024-10-03 23:20 ` Stephen Hemminger
2024-10-04 18:01 ` Ferruh Yigit
2024-10-04 20:04 ` Robin Jarry
2024-10-06 21:03 ` Ferruh Yigit
2024-10-01 8:17 ` [PATCH dpdk v2 05/16] fib6,rib6,lpm6: use ipv6 addr struct Robin Jarry
2024-10-03 23:21 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 06/16] net: add ipv6 address utilities Robin Jarry
2024-10-01 15:35 ` Stephen Hemminger
2024-10-03 23:22 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 07/16] fib6,rib6,lpm6: use ipv6 utils Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 08/16] graph,node: use ipv6 addr struct and utils Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 09/16] pipeline: use ipv6 addr struct Robin Jarry
2024-10-03 23:23 ` Stephen Hemminger
2024-10-04 11:55 ` Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 10/16] ipsec: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 11/16] thash: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 12/16] gro: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 13/16] rte_flow: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 14/16] rib6,fib6,lpm6: remove duplicate constants Robin Jarry
2024-10-03 23:12 ` Stephen Hemminger
2024-10-04 11:54 ` Robin Jarry
2024-10-04 16:16 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 15/16] net: add utilities for well known ipv6 address types Robin Jarry
2024-10-03 23:24 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 16/16] ipv6: add function to check ipv6 version Robin Jarry
2024-10-06 9:02 ` Morten Brørup
2024-10-10 20:00 ` Robin Jarry
2024-10-11 12:05 ` Morten Brørup
2024-10-10 15:26 ` Konstantin Ananyev
2024-10-06 9:04 ` [PATCH dpdk v2 00/16] IPv6 APIs overhaul Morten Brørup
2024-10-10 15:27 ` Konstantin Ananyev
2024-10-10 19:41 ` [PATCH dpdk v3 00/17] " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 01/17] net: split raw checksum functions in separate header Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 02/17] net: split ipv6 symbols " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 03/17] net: add structure for ipv6 addresses Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 04/17] net: add ipv6 address utilities Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 05/17] net: use struct rte_ipv6_addr for header addresses Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 06/17] fib6,rib6,lpm6: use struct rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 07/17] fib6,rib6,lpm6: use ipv6 utils Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 08/17] rib6,fib6,lpm6: remove duplicate constants Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 09/17] cmdline: replace in6_addr with rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 10/17] graph,node: use struct rte_ipv6_addr and utils Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 11/17] pipeline: use struct rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 12/17] ipsec, security: use struct rte_ipv6_addr and utils Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 13/17] thash: use struct rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 14/17] gro: " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 15/17] rte_flow: " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 16/17] net: add utilities for well known ipv6 address types Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 17/17] ipv6: add function to check ipv6 version Robin Jarry
2024-10-15 17:12 ` Stephen Hemminger
2024-10-17 13:52 ` [PATCH dpdk v3 00/17] IPv6 APIs overhaul David Marchand
2024-10-17 18:03 ` Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 01/17] net: split raw checksum functions in separate header Robin Jarry
2024-10-18 9:17 ` Robin Jarry [this message]
2024-10-18 9:17 ` [PATCH dpdk v4 03/17] net: add IPv6 address structure and utils Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 04/17] net: use IPv6 structure for packet headers Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 05/17] lpm6: use IPv6 address structure and utils Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 06/17] fib6: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 07/17] rib6: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 08/17] cmdline: use IPv6 address structure Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 09/17] node: use IPv6 address structure and utils Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 10/17] pipeline: use IPv6 structures Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 11/17] ipsec: use IPv6 address structure Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 12/17] security: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 13/17] hash: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 14/17] gro: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 15/17] flow: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 16/17] net: add utilities for well known IPv6 address types Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 17/17] net: add function to check IPv6 version Robin Jarry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241018091734.64601-3-rjarry@redhat.com \
--to=rjarry@redhat.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).