From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8908245834; Wed, 21 Aug 2024 18:26:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BA6A8427AF; Wed, 21 Aug 2024 18:26:10 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id C9D8F427AF for ; Wed, 21 Aug 2024 18:26:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724257569; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cTEnrY8uBesameT22DPmocfKG0ImO1mKpVpd/sKPlwQ=; b=A3D0M7A3c/h+sJEogboYXxBN7PhdlXAT+wCt+jLC8WiQVZxKE0IcaNnxd8FC9UFQYMlg2I XV7gsNLxNjmsKtv5/Fus+Z2UeQBtcKb55Rq01fsAx9FzrAKLKnik5Uqo1iUZehccCNUDY9 XIZv5sFcKBXbgEfDJEJQeeJ7FsB2Xa8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-afPIIKtlOfu6B8S4a_hvMA-1; Wed, 21 Aug 2024 12:26:02 -0400 X-MC-Unique: afPIIKtlOfu6B8S4a_hvMA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 724DA1955EB3; Wed, 21 Aug 2024 16:25:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.208.21]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C8131955F42; Wed, 21 Aug 2024 16:25:49 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Akhil Goyal , Fan Zhang , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao , Harman Kalra , Ankur Dwivedi , Anoob Joseph , Tejasree Kondoj , Gagandeep Singh , Hemant Agrawal , Cristian Dumitrescu , Ori Kam , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin , Konstantin Ananyev , Maxime Coquelin , Chenbo Xia Subject: [PATCH dpdk v1 02/15] net: split ipv6 symbols in separate header Date: Wed, 21 Aug 2024 18:25:19 +0200 Message-ID: <20240821162516.610624-19-rjarry@redhat.com> In-Reply-To: <20240821162516.610624-17-rjarry@redhat.com> References: <20240821162516.610624-17-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Move all ipv6 related symbols to a dedicated header. Update all code accordingly. Signed-off-by: Robin Jarry --- app/test/packet_burst_generator.c | 1 + app/test/test_cryptodev_security_ipsec.c | 1 + drivers/common/cnxk/cnxk_security.c | 1 + drivers/crypto/cnxk/cn9k_cryptodev_ops.c | 1 + drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 1 + examples/ip_pipeline/pipeline.c | 1 + lib/ethdev/rte_flow.h | 1 + lib/hash/rte_thash.h | 1 + lib/ip_frag/rte_ip_frag.h | 1 + lib/ipsec/iph.h | 1 + lib/net/meson.build | 1 + lib/net/rte_ip.h | 319 ------------------ lib/net/{rte_ip.h => rte_ip6.h} | 352 +------------------- lib/net/rte_net.c | 1 + lib/net/rte_net.h | 1 + lib/pipeline/rte_swx_ipsec.c | 1 + lib/pipeline/rte_table_action.c | 1 + lib/vhost/virtio_net.c | 1 + 18 files changed, 22 insertions(+), 665 deletions(-) copy lib/net/{rte_ip.h => rte_ip6.h} (50%) diff --git a/app/test/packet_burst_generator.c b/app/test/packet_burst_generator.c index 867a88da0055..2cd34abc1a65 100644 --- a/app/test/packet_burst_generator.c +++ b/app/test/packet_burst_generator.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "packet_burst_generator.h" diff --git a/app/test/test_cryptodev_security_ipsec.c b/app/test/test_cryptodev_security_ipsec.c index 1aba1ad9934b..9ac4a6e599b0 100644 --- a/app/test/test_cryptodev_security_ipsec.c +++ b/app/test/test_cryptodev_security_ipsec.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/common/cnxk/cnxk_security.c b/drivers/common/cnxk/cnxk_security.c index 15b0bedf43e2..e275d6cad3ea 100644 --- a/drivers/common/cnxk/cnxk_security.c +++ b/drivers/common/cnxk/cnxk_security.c @@ -2,6 +2,7 @@ * Copyright(C) 2021 Marvell. */ +#include #include #include "cnxk_security.h" diff --git a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c index f443cb9563ec..a3c737ef40f7 100644 --- a/drivers/crypto/cnxk/cn9k_cryptodev_ops.c +++ b/drivers/crypto/cnxk/cn9k_cryptodev_ops.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "roc_cpt.h" diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c index c1f7181d5587..5bf690e3d82a 100644 --- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c +++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/examples/ip_pipeline/pipeline.c b/examples/ip_pipeline/pipeline.c index 63352257c6e9..301c52d061be 100644 --- a/examples/ip_pipeline/pipeline.c +++ b/examples/ip_pipeline/pipeline.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h index f864578f806b..3a3ab781c494 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/hash/rte_thash.h b/lib/hash/rte_thash.h index 30b657e67a7d..af40afd2d475 100644 --- a/lib/hash/rte_thash.h +++ b/lib/hash/rte_thash.h @@ -23,6 +23,7 @@ extern "C" { #include #include +#include #include #include diff --git a/lib/ip_frag/rte_ip_frag.h b/lib/ip_frag/rte_ip_frag.h index 2ad318096b7b..cb06d5f5977a 100644 --- a/lib/ip_frag/rte_ip_frag.h +++ b/lib/ip_frag/rte_ip_frag.h @@ -23,6 +23,7 @@ extern "C" { #include #include #include +#include #include struct rte_mbuf; diff --git a/lib/ipsec/iph.h b/lib/ipsec/iph.h index 861f16905ad0..815a3c90d76b 100644 --- a/lib/ipsec/iph.h +++ b/lib/ipsec/iph.h @@ -6,6 +6,7 @@ #define _IPH_H_ #include +#include /** * @file iph.h diff --git a/lib/net/meson.build b/lib/net/meson.build index 2e65bd19b7d4..35ac334a18cf 100644 --- a/lib/net/meson.build +++ b/lib/net/meson.build @@ -3,6 +3,7 @@ headers = files( 'rte_ip.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..e3c8d0163f64 100644 --- a/lib/net/rte_ip.h +++ b/lib/net/rte_ip.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 @@ -24,7 +24,6 @@ #include #include #include -#include #include #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_ */ diff --git a/lib/net/rte_net.c b/lib/net/rte_net.c index d680accc1631..13aef6147ab0 100644 --- a/lib/net/rte_net.c +++ b/lib/net/rte_net.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/net/rte_net.h b/lib/net/rte_net.h index cdc6cf956df2..a47beb60adf0 100644 --- a/lib/net/rte_net.h +++ b/lib/net/rte_net.h @@ -10,6 +10,7 @@ extern "C" { #endif #include +#include #include #include diff --git a/lib/pipeline/rte_swx_ipsec.c b/lib/pipeline/rte_swx_ipsec.c index 73e8211b2818..56a401d0fa63 100644 --- a/lib/pipeline/rte_swx_ipsec.c +++ b/lib/pipeline/rte_swx_ipsec.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/pipeline/rte_table_action.c b/lib/pipeline/rte_table_action.c index 87c3e0e2c935..ebbdd3f4cebe 100644 --- a/lib/pipeline/rte_table_action.c +++ b/lib/pipeline/rte_table_action.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 370402d84903..d4dcc811c55f 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include -- 2.46.0