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 450BB45A78; Tue, 1 Oct 2024 10:19:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 10E0C40E0C; Tue, 1 Oct 2024 10:18:20 +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 EFDB040DDB for ; Tue, 1 Oct 2024 10:18:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727770696; 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=LtDMzVF/ltj7JMcgYm/dir4L6yfg/MyY0KZXG4GD0yQ=; b=WoBK0nQwO8Pjy6zT+ASKdBaATaTTLzdayLhNk3nhRGIJNbTtiwxFKW6zr1OZdhp5nDqeIZ Oi+5aYymGoITPWfHPkU1HiKfzhcqq3L18gwAQUKYJdl9LRSG7sgRsxPZmFYjPSsr4ysLUy aXIWNcXdmu1x+vkXuftBB0I5Kk0xruQ= Received: from mx-prod-mc-03.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-288-o2yLszEhNHWkn2o9kqfsDw-1; Tue, 01 Oct 2024 04:18:15 -0400 X-MC-Unique: o2yLszEhNHWkn2o9kqfsDw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 57B6319772F4; Tue, 1 Oct 2024 08:18:14 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.39.208.33]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 944A91979060; Tue, 1 Oct 2024 08:18:12 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Konstantin Ananyev , Vladimir Medvedkin , Radu Nicolau , Akhil Goyal Subject: [PATCH dpdk v2 10/16] ipsec: use ipv6 addr struct Date: Tue, 1 Oct 2024 10:17:22 +0200 Message-ID: <20241001081728.301272-11-rjarry@redhat.com> In-Reply-To: <20241001081728.301272-1-rjarry@redhat.com> References: <20240821162516.610624-17-rjarry@redhat.com> <20241001081728.301272-1-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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 Update rte_ipsec_sadv6_key to use the recently introduced IPv6 address structure instead of ad-hoc uint8_t[16] arrays. Signed-off-by: Robin Jarry --- Notes: v2: updated changelog for 24.11 app/test-sad/main.c | 24 +++++++------- app/test/test_ipsec_sad.c | 44 +++++++++++++------------- doc/guides/rel_notes/deprecation.rst | 2 -- doc/guides/rel_notes/release_24_11.rst | 2 ++ examples/ipsec-secgw/sad.h | 10 +++--- lib/ipsec/rte_ipsec_sad.h | 7 ++-- 6 files changed, 46 insertions(+), 43 deletions(-) diff --git a/app/test-sad/main.c b/app/test-sad/main.c index addfc0714521..7253f6488dce 100644 --- a/app/test-sad/main.c +++ b/app/test-sad/main.c @@ -248,8 +248,8 @@ get_random_rules(struct rule *tbl, uint32_t nb_rules, int rule_tbl) (uint64_t)(edge + step)); if (config.ipv6) { for (j = 0; j < 16; j++) { - tbl[i].tuple.v6.dip[j] = rte_rand(); - tbl[i].tuple.v6.sip[j] = rte_rand(); + tbl[i].tuple.v6.dip.a[j] = rte_rand(); + tbl[i].tuple.v6.sip.a[j] = rte_rand(); } } else { tbl[i].tuple.v4.dip = rte_rand(); @@ -274,9 +274,9 @@ get_random_rules(struct rule *tbl, uint32_t nb_rules, int rule_tbl) (uint64_t)(edge + step)); if (config.ipv6) { for (j = 0; j < 16; j++) { - tbl[i].tuple.v6.dip[j] = + tbl[i].tuple.v6.dip.a[j] = rte_rand(); - tbl[i].tuple.v6.sip[j] = + tbl[i].tuple.v6.sip.a[j] = rte_rand(); } } else { @@ -289,11 +289,11 @@ get_random_rules(struct rule *tbl, uint32_t nb_rules, int rule_tbl) config.nb_rules].tuple.v4.spi; if (config.ipv6) { int r_idx = i % config.nb_rules; - memcpy(tbl[i].tuple.v6.dip, - rules_tbl[r_idx].tuple.v6.dip, + memcpy(&tbl[i].tuple.v6.dip, + &rules_tbl[r_idx].tuple.v6.dip, sizeof(tbl[i].tuple.v6.dip)); - memcpy(tbl[i].tuple.v6.sip, - rules_tbl[r_idx].tuple.v6.sip, + memcpy(&tbl[i].tuple.v6.sip, + &rules_tbl[r_idx].tuple.v6.sip, sizeof(tbl[i].tuple.v6.sip)); } else { tbl[i].tuple.v4.dip = rules_tbl[i % @@ -472,8 +472,8 @@ print_result(const union rte_ipsec_sad_key *key, void *res) v4 = &key->v4; v6 = &key->v6; spi = (config.ipv6 == 0) ? v4->spi : v6->spi; - dip = (config.ipv6 == 0) ? &v4->dip : (const void *)v6->dip; - sip = (config.ipv6 == 0) ? &v4->sip : (const void *)v6->sip; + dip = (config.ipv6 == 0) ? &v4->dip : (const void *)&v6->dip; + sip = (config.ipv6 == 0) ? &v4->sip : (const void *)&v6->sip; if (res == NULL) { printf("TUPLE: "); @@ -500,8 +500,8 @@ print_result(const union rte_ipsec_sad_key *key, void *res) v4 = &rule->tuple.v4; v6 = &rule->tuple.v6; spi = (config.ipv6 == 0) ? v4->spi : v6->spi; - dip = (config.ipv6 == 0) ? &v4->dip : (const void *)v6->dip; - sip = (config.ipv6 == 0) ? &v4->sip : (const void *)v6->sip; + dip = (config.ipv6 == 0) ? &v4->dip : (const void *)&v6->dip; + sip = (config.ipv6 == 0) ? &v4->sip : (const void *)&v6->sip; printf("\n\tpoints to RULE ID %zu ", RTE_PTR_DIFF(res, rules_tbl)/sizeof(struct rule)); print_tuple(af, spi, dip, sip); diff --git a/app/test/test_ipsec_sad.c b/app/test/test_ipsec_sad.c index 7534f16f89d0..79ea8ee915dd 100644 --- a/app/test/test_ipsec_sad.c +++ b/app/test/test_ipsec_sad.c @@ -212,7 +212,7 @@ test_add_invalid(void) { int status; struct rte_ipsec_sadv4_key tuple_v4 = {10, 20, 30}; - struct rte_ipsec_sadv6_key tuple_v6 = {10, {20, }, {30, } }; + struct rte_ipsec_sadv6_key tuple_v6 = {10, {.a = {20, }}, {.a = {30, }} }; status = __test_add_invalid(0, (union rte_ipsec_sad_key *)&tuple_v4); if (status != TEST_SUCCESS) @@ -271,8 +271,8 @@ test_delete_invalid(void) { int status; struct rte_ipsec_sadv4_key tuple_v4 = {SPI, DIP, SIP}; - struct rte_ipsec_sadv6_key tuple_v6 = {SPI, {0xbe, 0xef, }, - {0xf0, 0x0d, } }; + struct rte_ipsec_sadv6_key tuple_v6 = { + SPI, {.a = {0xbe, 0xef, }}, {.a = {0xf0, 0x0d, }} }; status = __test_delete_invalid(0, (union rte_ipsec_sad_key *)&tuple_v4); if (status != TEST_SUCCESS) @@ -329,7 +329,7 @@ test_lookup_invalid(void) { int status; struct rte_ipsec_sadv4_key tuple_v4 = {10, 20, 30}; - struct rte_ipsec_sadv6_key tuple_v6 = {10, {20, }, {30, } }; + struct rte_ipsec_sadv6_key tuple_v6 = {10, {.a = {20, }}, {.a = {30, }} }; status = __test_lookup_invalid(0, (union rte_ipsec_sad_key *)&tuple_v4); @@ -405,10 +405,10 @@ test_lookup_basic(void) int status; struct rte_ipsec_sadv4_key tuple_v4 = {SPI, DIP, SIP}; struct rte_ipsec_sadv4_key tuple_v4_1 = {SPI, BAD, BAD}; - struct rte_ipsec_sadv6_key tuple_v6 = {SPI, {0xbe, 0xef, }, - {0xf0, 0x0d, } }; - struct rte_ipsec_sadv6_key tuple_v6_1 = {SPI, {0x0b, 0xad, }, - {0x0b, 0xad, } }; + struct rte_ipsec_sadv6_key tuple_v6 = { + SPI, {.a = {0xbe, 0xef, }}, {.a = {0xf0, 0x0d, }} }; + struct rte_ipsec_sadv6_key tuple_v6_1 = { + SPI, {.a = {0x0b, 0xad, }}, {.a = {0x0b, 0xad, }} }; status = __test_lookup_basic(0, (union rte_ipsec_sad_key *)&tuple_v4, (union rte_ipsec_sad_key *)&tuple_v4_1); @@ -654,14 +654,14 @@ test_lookup_adv(void) struct rte_ipsec_sadv4_key tuple_v4_3 = {BAD, DIP, SIP}; /* key to install*/ - struct rte_ipsec_sadv6_key tuple_v6 = {SPI, {0xbe, 0xef, }, - {0xf0, 0x0d, } }; - struct rte_ipsec_sadv6_key tuple_v6_1 = {SPI, {0xbe, 0xef, }, - {0x0b, 0xad, } }; - struct rte_ipsec_sadv6_key tuple_v6_2 = {SPI, {0x0b, 0xad, }, - {0xf0, 0x0d, } }; - struct rte_ipsec_sadv6_key tuple_v6_3 = {BAD, {0xbe, 0xef, }, - {0xf0, 0x0d, } }; + struct rte_ipsec_sadv6_key tuple_v6 = { + SPI, {.a = {0xbe, 0xef, }}, {.a = {0xf0, 0x0d, }} }; + struct rte_ipsec_sadv6_key tuple_v6_1 = { + SPI, {.a = {0xbe, 0xef, }}, {.a = {0x0b, 0xad, }} }; + struct rte_ipsec_sadv6_key tuple_v6_2 = { + SPI, {.a = {0x0b, 0xad, }}, {.a = {0xf0, 0x0d, }} }; + struct rte_ipsec_sadv6_key tuple_v6_3 = { + BAD, {.a = {0xbe, 0xef, }}, {.a = {0xf0, 0x0d, }} }; const union rte_ipsec_sad_key *key_arr[] = { (union rte_ipsec_sad_key *)&tuple_v4, @@ -852,12 +852,12 @@ test_lookup_order(void) struct rte_ipsec_sadv4_key tuple_v4_1 = {SPI, DIP, BAD}; struct rte_ipsec_sadv4_key tuple_v4_2 = {SPI, BAD, SIP}; /* key to install*/ - struct rte_ipsec_sadv6_key tuple_v6 = {SPI, {0xbe, 0xef, }, - {0xf0, 0x0d, } }; - struct rte_ipsec_sadv6_key tuple_v6_1 = {SPI, {0xbe, 0xef, }, - {0x0b, 0xad, } }; - struct rte_ipsec_sadv6_key tuple_v6_2 = {SPI, {0x0b, 0xad, }, - {0xf0, 0x0d, } }; + struct rte_ipsec_sadv6_key tuple_v6 = { + SPI, {.a = {0xbe, 0xef, }}, {.a = {0xf0, 0x0d, }} }; + struct rte_ipsec_sadv6_key tuple_v6_1 = { + SPI, {.a = {0xbe, 0xef, }}, {.a = {0x0b, 0xad, }} }; + struct rte_ipsec_sadv6_key tuple_v6_2 = { + SPI, {.a = {0x0b, 0xad, }}, {.a = {0xf0, 0x0d, }} }; status = __test_lookup_order(0, (union rte_ipsec_sad_key *)&tuple_v4, (union rte_ipsec_sad_key *)&tuple_v4_1, diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index fcccb22593d8..838e22b44444 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -74,8 +74,6 @@ Deprecation Notices - ``struct tcp6_flow_key`` hash - ``struct rte_ipv6_tuple`` - ipsec - - ``struct rte_ipsec_sadv6_key`` * net, ethdev: The flow item ``RTE_FLOW_ITEM_TYPE_VXLAN_GPE`` is replaced with ``RTE_FLOW_ITEM_TYPE_VXLAN``. diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index 3eb43ba8520f..debaf99e4a71 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -93,6 +93,8 @@ API Changes ``uint8_t[16]`` parameter. * pipeline: ``rte_table_action_ipv6_header`` and ``rte_table_action_nat_params`` were modified to use ``rte_ipv6_addr`` structures instead of ``uint8_t[16]`` fields. +* ipsec: ``rte_ipsec_sadv6_key`` was modified to use ``rte_ipv6_addr`` structures instead of + ``uint8_t[16]`` fields. ABI Changes ----------- diff --git a/examples/ipsec-secgw/sad.h b/examples/ipsec-secgw/sad.h index fdb1d2ef1790..4108abb9e698 100644 --- a/examples/ipsec-secgw/sad.h +++ b/examples/ipsec-secgw/sad.h @@ -9,6 +9,8 @@ #include #include +#include "ipsec.h" + #define SA_CACHE_SZ 128 #define SPI2IDX(spi, mask) ((spi) & (mask)) @@ -39,8 +41,8 @@ cmp_sa_key(struct ipsec_sa *sa, int is_v4, struct rte_ipv4_hdr *ipv4, (sa->dst.ip.ip4 == ipv4->dst_addr)) || /* IPv6 check */ (!is_v4 && (sa_type == IP6_TUNNEL) && - (!memcmp(sa->src.ip.ip6.ip6, &ipv6->src_addr, 16)) && - (!memcmp(sa->dst.ip.ip6.ip6, &ipv6->dst_addr, 16)))) + (!memcmp(&sa->src.ip.ip6.ip6, &ipv6->src_addr, 16)) && + (!memcmp(&sa->dst.ip.ip6.ip6, &ipv6->dst_addr, 16)))) return 1; return 0; @@ -130,9 +132,9 @@ sad_lookup(struct ipsec_sad *sad, struct rte_mbuf *pkts[], } } v6[nb_v6].spi = esp->spi; - memcpy(v6[nb_v6].dip, &ipv6->dst_addr, + memcpy(&v6[nb_v6].dip, &ipv6->dst_addr, sizeof(ipv6->dst_addr)); - memcpy(v6[nb_v6].sip, &ipv6->src_addr, + memcpy(&v6[nb_v6].sip, &ipv6->src_addr, sizeof(ipv6->src_addr)); keys_v6[nb_v6] = (const union rte_ipsec_sad_key *) &v6[nb_v6]; diff --git a/lib/ipsec/rte_ipsec_sad.h b/lib/ipsec/rte_ipsec_sad.h index 0adf89d9310c..035ae4f3b3eb 100644 --- a/lib/ipsec/rte_ipsec_sad.h +++ b/lib/ipsec/rte_ipsec_sad.h @@ -6,8 +6,9 @@ #ifndef _RTE_IPSEC_SAD_H_ #define _RTE_IPSEC_SAD_H_ -#include +#include +#include /** * @file rte_ipsec_sad.h @@ -38,8 +39,8 @@ struct rte_ipsec_sadv4_key { struct rte_ipsec_sadv6_key { uint32_t spi; - uint8_t dip[16]; - uint8_t sip[16]; + struct rte_ipv6_addr dip; + struct rte_ipv6_addr sip; }; union rte_ipsec_sad_key { -- 2.46.1