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 0992D45834; Wed, 21 Aug 2024 18:28:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0E1ED42831; Wed, 21 Aug 2024 18:28:04 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id ADC8A427CD for ; Wed, 21 Aug 2024 18:28:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724257682; 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=UAU9S9irfqRanmYS+5Xj6udEsiw5e0U/5ZpzrgFzpqY=; b=HAuPDuSNksFB5AlmkzDAv8VgqrE6OjLoxXrN/TZf9pwiwPag9CYVWawy+3OW18+3rY3dEn v1aZYjdLiit3Ustzygxx5E8ZUzwPJc5JAZ8lm/rp2Scgsm5Kxk7l2rKLYSQqN8Vw/apzJL wgIsoUSE4aJZiEpDY/HDEMK62/gueCY= 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-605-SUP1aewHN4e_8a3MUVid_g-1; Wed, 21 Aug 2024 12:27:56 -0400 X-MC-Unique: SUP1aewHN4e_8a3MUVid_g-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37FC81895CDE; Wed, 21 Aug 2024 16:27:40 +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 8403518FFC5C; Wed, 21 Aug 2024 16:27:03 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Konstantin Ananyev , Vladimir Medvedkin , Radu Nicolau , Akhil Goyal Subject: [PATCH dpdk v1 10/15] ipsec: use ipv6 addr struct Date: Wed, 21 Aug 2024 18:25:27 +0200 Message-ID: <20240821162516.610624-27-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 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 --- app/test-sad/main.c | 24 ++++++++++----------- app/test/test_ipsec_sad.c | 44 +++++++++++++++++++------------------- examples/ipsec-secgw/sad.h | 10 +++++---- lib/ipsec/rte_ipsec_sad.h | 7 +++--- 4 files changed, 44 insertions(+), 41 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/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.0