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 4637A45AC4; Sun, 6 Oct 2024 11:02:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBFDB4025D; Sun, 6 Oct 2024 11:02:27 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 2787140150 for ; Sun, 6 Oct 2024 11:02:26 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id E90C720EDB; Sun, 6 Oct 2024 11:02:25 +0200 (CEST) Subject: RE: [PATCH dpdk v2 16/16] ipv6: add function to check ipv6 version MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Sun, 6 Oct 2024 11:02:24 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F77C@smartserver.smartshare.dk> Content-class: urn:content-classes:message In-Reply-To: <20241001081728.301272-17-rjarry@redhat.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH dpdk v2 16/16] ipv6: add function to check ipv6 version Thread-Index: AdsT2rH5aKoHuCpLR66cxrQZjCGbcQD8drNA X-MimeOLE: Produced By Microsoft Exchange V6.5 References: <20240821162516.610624-17-rjarry@redhat.com> <20241001081728.301272-1-rjarry@redhat.com> <20241001081728.301272-17-rjarry@redhat.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Robin Jarry" , 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 > From: Robin Jarry [mailto:rjarry@redhat.com] > Sent: Tuesday, 1 October 2024 10.17 >=20 > This is a slow path version to verify the version field in IPv6 > headers. It doesn't look slow to me. No need to mention slow path here. >=20 > Signed-off-by: Robin Jarry > --- >=20 > Notes: > v2: new patch >=20 > app/test/test_net_ipv6.c | 16 ++++++++++++++++ > lib/net/rte_ip6.h | 17 +++++++++++++++++ > 2 files changed, 33 insertions(+) >=20 > diff --git a/app/test/test_net_ipv6.c b/app/test/test_net_ipv6.c > index b087b5c60d73..79a43a2b5491 100644 > --- a/app/test/test_net_ipv6.c > +++ b/app/test/test_net_ipv6.c > @@ -11,6 +11,21 @@ static const struct rte_ipv6_addr bcast_addr =3D { > }; > static const struct rte_ipv6_addr zero_addr =3D { 0 }; >=20 > +static int > +test_ipv6_check_version(void) > +{ > + struct rte_ipv6_hdr h; > + > + h.vtc_flow =3D 0; > + TEST_ASSERT_EQUAL(rte_ipv6_check_version(&h), -EINVAL, ""); > + h.vtc_flow =3D RTE_BE32(0x7f00ba44); > + TEST_ASSERT_EQUAL(rte_ipv6_check_version(&h), -EINVAL, ""); > + h.vtc_flow =3D RTE_BE32(0x6badcaca); > + TEST_ASSERT_EQUAL(rte_ipv6_check_version(&h), 0, ""); > + > + return 0; > +} > + > static int > test_ipv6_addr_mask(void) > { > @@ -191,6 +206,7 @@ test_ether_mcast_from_ipv6(void) > static int > test_net_ipv6(void) > { > + TEST_ASSERT_SUCCESS(test_ipv6_check_version(), ""); > TEST_ASSERT_SUCCESS(test_ipv6_addr_mask(), ""); > TEST_ASSERT_SUCCESS(test_ipv6_addr_eq_prefix(), ""); > TEST_ASSERT_SUCCESS(test_ipv6_addr_kind(), ""); > diff --git a/lib/net/rte_ip6.h b/lib/net/rte_ip6.h > index c552fa54c095..de3ddc0348c5 100644 > --- a/lib/net/rte_ip6.h > +++ b/lib/net/rte_ip6.h > @@ -323,6 +323,23 @@ struct rte_ipv6_hdr { > struct rte_ipv6_addr dst_addr; /**< IP address of > destination host(s). */ > } __rte_packed; >=20 > +#define RTE_IPV6_VTC_FLOW_VERSION RTE_BE32(0x60000000) > +#define RTE_IPV6_VTC_FLOW_VERSION_MASK RTE_BE32(0xf0000000) > + > +/** > + * Check that the IPv6 header version field is valid according to RFC > 8200 section 3. > + * > + * @return > + * 0 if the version field is valid. -EINVAL otherwise. > + */ > +static inline int rte_ipv6_check_version(const struct rte_ipv6_hdr > *ip) > +{ > + rte_be32_t v =3D ip->vtc_flow & RTE_IPV6_VTC_FLOW_VERSION_MASK; > + if (v !=3D RTE_IPV6_VTC_FLOW_VERSION) > + return -EINVAL; > + return 0; > +} Personally, I would prefer following the convention of rte_ether = functions to return boolean (as int)... static inline int = rte_is__ether_addr(const struct rte_ether_addr *ea) static inline int rte_is_ipv6_version(const struct rte_ipv6_hdr *ip) { return ip->vtc_flow & RTE_IPV6_VTC_FLOW_VERSION_MASK =3D=3D = RTE_IPV6_VTC_FLOW_VERSION; } Or, at your preference, an optimized variant: static inline int rte_is_version_ipv6(const struct rte_ipv6_hdr *ip) { return *(const unsigned char *)ip & 0xf0 =3D=3D 0x60; } The first nibble is also used for version in IPv4, so an IPv4 variant = would look similar: static inline int rte_is_version_ipv4(const struct rte_ip_hdr *ip) { return *(const unsigned char *)ip & 0xf0 =3D=3D 0x40; }