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 B66CF45B09; Thu, 10 Oct 2024 21:42:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6F10740A8B; Thu, 10 Oct 2024 21:42:47 +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 ECD524042F for ; Thu, 10 Oct 2024 21:42:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728589365; 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=3bvz+elgueLkg8C8VKuGoi1G+cy9qlUcTRnXQhzU0JM=; b=UI12gnFoQqIbMMIROmaNINekvy7+OijVy2dk2tH3K61d/jQh9I+Lws8BafIIEQKAvWXsH/ IAjE+klb3CmCVnDU6V0g4DyKXaurqc05tJ8J+o4G+y4qinBdWd78y+tgpqJXV99KlQlbkQ j6Jh+rzbdzydxTMsGHikRFw/CWLBgJ4= Received: from mx-prod-mc-02.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-594-IQOi_XB1MI2Mv-xQCkJZ7Q-1; Thu, 10 Oct 2024 15:42:42 -0400 X-MC-Unique: IQOi_XB1MI2Mv-xQCkJZ7Q-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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 749941955EA7; Thu, 10 Oct 2024 19:42:41 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.39.208.7]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B630919560AA; Thu, 10 Oct 2024 19:42:39 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Vladimir Medvedkin , Bruce Richardson Subject: [PATCH dpdk v3 07/17] fib6,rib6,lpm6: use ipv6 utils Date: Thu, 10 Oct 2024 21:41:37 +0200 Message-ID: <20241010194148.1877659-8-rjarry@redhat.com> In-Reply-To: <20241010194148.1877659-1-rjarry@redhat.com> References: <20240821162516.610624-17-rjarry@redhat.com> <20241010194148.1877659-1-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 Replace duplicated and/or private functions by utilities from rte_ip6.h. Mark rib6 functions that deal with ipv6 addresses as deprecated. Signed-off-by: Robin Jarry --- Notes: v3: - replace rte_ipv6_addr_cpy with direct assignments app/test/test_fib6.c | 9 +++++--- app/test/test_rib6.c | 2 +- lib/fib/trie.c | 22 ++++++------------- lib/lpm/rte_lpm6.c | 32 ++++----------------------- lib/rib/rte_rib6.c | 51 ++++++++++++++------------------------------ lib/rib/rte_rib6.h | 8 +++++++ 6 files changed, 42 insertions(+), 82 deletions(-) diff --git a/app/test/test_fib6.c b/app/test/test_fib6.c index d8149e028e4f..8853adeaac7c 100644 --- a/app/test/test_fib6.c +++ b/app/test/test_fib6.c @@ -278,9 +278,12 @@ check_fib(struct rte_fib6 *fib) int ret; for (i = 0; i < RTE_FIB6_MAXDEPTH; i++) { - for (j = 0; j < RTE_FIB6_IPV6_ADDR_SIZE; j++) { - ip_arr[i].a[j] = ip_add.a[j] | - ~get_msk_part(RTE_FIB6_MAXDEPTH - i, j); + ip_arr[i] = ip_add; + j = (RTE_FIB6_MAXDEPTH - i) / CHAR_BIT; + if (j < RTE_FIB6_IPV6_ADDR_SIZE) { + ip_arr[i].a[j] |= UINT8_MAX >> ((RTE_FIB6_MAXDEPTH - i) % CHAR_BIT); + for (j++; j < RTE_FIB6_IPV6_ADDR_SIZE; j++) + ip_arr[i].a[j] = 0xff; } } diff --git a/app/test/test_rib6.c b/app/test/test_rib6.c index 6a3445297cb1..ba54a3794ea7 100644 --- a/app/test/test_rib6.c +++ b/app/test/test_rib6.c @@ -215,7 +215,7 @@ test_get_fn(void) /* check the return values */ ret = rte_rib6_get_ip(node, &ip_ret); - RTE_TEST_ASSERT((ret == 0) && (rte_rib6_is_equal(ip_ret.a, ip.a)), + RTE_TEST_ASSERT((ret == 0) && (rte_ipv6_addr_eq(&ip_ret, &ip)), "Failed to get proper node ip\n"); ret = rte_rib6_get_depth(node, &depth_ret); RTE_TEST_ASSERT((ret == 0) && (depth_ret == depth), diff --git a/lib/fib/trie.c b/lib/fib/trie.c index 0b459b3749b9..b0d80c3db815 100644 --- a/lib/fib/trie.c +++ b/lib/fib/trie.c @@ -451,14 +451,6 @@ get_nxt_net(struct rte_ipv6_addr *ip, uint8_t depth) } } -static int -v6_addr_is_zero(const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE]) -{ - uint8_t ip_addr[RTE_FIB6_IPV6_ADDR_SIZE] = {0}; - - return rte_rib6_is_equal(ip, ip_addr); -} - static int modify_dp(struct rte_trie_tbl *dp, struct rte_rib6 *rib, const struct rte_ipv6_addr *ip, @@ -481,7 +473,7 @@ modify_dp(struct rte_trie_tbl *dp, struct rte_rib6 *rib, if (tmp_depth == depth) continue; rte_rib6_get_ip(tmp, &redge); - if (rte_rib6_is_equal(ledge.a, redge.a)) { + if (rte_ipv6_addr_eq(&ledge, &redge)) { get_nxt_net(&ledge, tmp_depth); continue; } @@ -494,13 +486,13 @@ modify_dp(struct rte_trie_tbl *dp, struct rte_rib6 *rib, * we got to the end of address space * and wrapped around */ - if (v6_addr_is_zero(ledge.a)) + if (rte_ipv6_addr_is_unspec(&ledge)) break; } else { redge = *ip; get_nxt_net(&redge, depth); - if (rte_rib6_is_equal(ledge.a, redge.a) && - !v6_addr_is_zero(ledge.a)) + if (rte_ipv6_addr_eq(&ledge, &redge) && + !rte_ipv6_addr_is_unspec(&ledge)) break; ret = install_to_dp(dp, &ledge, &redge, next_hop); @@ -522,7 +514,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, struct rte_rib6_node *node; struct rte_rib6_node *parent; struct rte_ipv6_addr ip_masked; - int i, ret = 0; + int ret = 0; uint64_t par_nh, node_nh; uint8_t tmp_depth, depth_diff = 0, parent_depth = 24; @@ -534,8 +526,8 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, rib = rte_fib6_get_rib(fib); RTE_ASSERT(rib); - for (i = 0; i < RTE_FIB6_IPV6_ADDR_SIZE; i++) - ip_masked.a[i] = ip->a[i] & get_msk_part(depth, i); + ip_masked = *ip; + rte_ipv6_addr_mask(&ip_masked, depth); if (depth > 24) { tmp = rte_rib6_get_nxt(rib, &ip_masked, diff --git a/lib/lpm/rte_lpm6.c b/lib/lpm/rte_lpm6.c index b03221d013c5..1d5577f263b1 100644 --- a/lib/lpm/rte_lpm6.c +++ b/lib/lpm/rte_lpm6.c @@ -111,30 +111,6 @@ struct rte_lpm6 { /**< LPM tbl8 table. */ }; -/* - * Takes an array of uint8_t (IPv6 address) and masks it using the depth. - * It leaves untouched one bit per unit in the depth variable - * and set the rest to 0. - */ -static inline void -ip6_mask_addr(uint8_t *ip, uint8_t depth) -{ - int16_t part_depth, mask; - int i; - - part_depth = depth; - - for (i = 0; i < RTE_LPM6_IPV6_ADDR_SIZE; i++) { - if (part_depth < BYTE_SIZE && part_depth >= 0) { - mask = (uint16_t)(~(UINT8_MAX >> part_depth)); - ip[i] = (uint8_t)(ip[i] & mask); - } else if (part_depth < 0) - ip[i] = 0; - - part_depth -= BYTE_SIZE; - } -} - /* * LPM6 rule hash function * @@ -861,7 +837,7 @@ rte_lpm6_add(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth /* Copy the IP and mask it to avoid modifying user's input data. */ masked_ip = *ip; - ip6_mask_addr(masked_ip.a, depth); + rte_ipv6_addr_mask(&masked_ip, depth); /* Simulate adding a new route */ int ret = simulate_add(lpm, &masked_ip, depth); @@ -1022,7 +998,7 @@ rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, u /* Copy the IP and mask it to avoid modifying user's input data. */ masked_ip = *ip; - ip6_mask_addr(masked_ip.a, depth); + rte_ipv6_addr_mask(&masked_ip, depth); return rule_find(lpm, &masked_ip, depth, next_hop); } @@ -1072,7 +1048,7 @@ rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm, for (i = 0; i < n; i++) { masked_ip = ips[i]; - ip6_mask_addr(masked_ip.a, depths[i]); + rte_ipv6_addr_mask(&masked_ip, depths[i]); rule_delete(lpm, &masked_ip, depths[i]); } @@ -1297,7 +1273,7 @@ rte_lpm6_delete(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t de /* Copy the IP and mask it to avoid modifying user's input data. */ masked_ip = *ip; - ip6_mask_addr(masked_ip.a, depth); + rte_ipv6_addr_mask(&masked_ip, depth); /* Delete the rule from the rule table. */ ret = rule_delete(lpm, &masked_ip, depth); diff --git a/lib/rib/rte_rib6.c b/lib/rib/rte_rib6.c index d0b11b777697..75175c6aaf98 100644 --- a/lib/rib/rte_rib6.c +++ b/lib/rib/rte_rib6.c @@ -62,22 +62,6 @@ is_right_node(const struct rte_rib6_node *node) return node->parent->right == node; } -/* - * Check if ip1 is covered by ip2/depth prefix - */ -static inline bool -is_covered(const uint8_t ip1[RTE_RIB6_IPV6_ADDR_SIZE], - const uint8_t ip2[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth) -{ - int i; - - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - if ((ip1[i] ^ ip2[i]) & get_msk_part(depth, i)) - return false; - - return true; -} - static inline int get_dir(const struct rte_ipv6_addr *ip, uint8_t depth) { @@ -144,7 +128,7 @@ rte_rib6_lookup(struct rte_rib6 *rib, } cur = rib->tree; - while ((cur != NULL) && is_covered(ip->a, cur->ip.a, cur->depth)) { + while ((cur != NULL) && rte_ipv6_addr_eq_prefix(ip, &cur->ip, cur->depth)) { if (is_valid_node(cur)) prev = cur; cur = get_nxt_node(cur, ip); @@ -173,7 +157,6 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib, { struct rte_rib6_node *cur; struct rte_ipv6_addr tmp_ip; - int i; if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) { rte_errno = EINVAL; @@ -181,16 +164,16 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib, } cur = rib->tree; - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - tmp_ip.a[i] = ip->a[i] & get_msk_part(depth, i); + tmp_ip = *ip; + rte_ipv6_addr_mask(&tmp_ip, depth); while (cur != NULL) { - if (rte_rib6_is_equal(cur->ip.a, tmp_ip.a) && + if (rte_ipv6_addr_eq(&cur->ip, &tmp_ip) && (cur->depth == depth) && is_valid_node(cur)) return cur; - if (!(is_covered(tmp_ip.a, cur->ip.a, cur->depth)) || + if (!rte_ipv6_addr_eq_prefix(&tmp_ip, &cur->ip, cur->depth) || (cur->depth >= depth)) break; @@ -212,15 +195,14 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, { struct rte_rib6_node *tmp, *prev = NULL; struct rte_ipv6_addr tmp_ip; - int i; if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) { rte_errno = EINVAL; return NULL; } - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - tmp_ip.a[i] = ip->a[i] & get_msk_part(depth, i); + tmp_ip = *ip; + rte_ipv6_addr_mask(&tmp_ip, depth); if (last == NULL) { tmp = rib->tree; @@ -232,7 +214,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, (tmp->parent->right == NULL))) { tmp = tmp->parent; if (is_valid_node(tmp) && - (is_covered(tmp->ip.a, tmp_ip.a, depth) && + (rte_ipv6_addr_eq_prefix(&tmp->ip, &tmp_ip, depth) && (tmp->depth > depth))) return tmp; } @@ -240,7 +222,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, } while (tmp) { if (is_valid_node(tmp) && - (is_covered(tmp->ip.a, tmp_ip.a, depth) && + (rte_ipv6_addr_eq_prefix(&tmp->ip, &tmp_ip, depth) && (tmp->depth > depth))) { prev = tmp; if (flag == RTE_RIB6_GET_NXT_COVER) @@ -304,8 +286,8 @@ rte_rib6_insert(struct rte_rib6 *rib, tmp = &rib->tree; - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - tmp_ip.a[i] = ip->a[i] & get_msk_part(depth, i); + tmp_ip = *ip; + rte_ipv6_addr_mask(&tmp_ip, depth); new_node = rte_rib6_lookup_exact(rib, &tmp_ip, depth); if (new_node != NULL) { @@ -340,15 +322,14 @@ rte_rib6_insert(struct rte_rib6 *rib, * but node with proper search criteria is found. * Validate intermediate node and return. */ - if (rte_rib6_is_equal(tmp_ip.a, (*tmp)->ip.a) && - (depth == (*tmp)->depth)) { + if (rte_ipv6_addr_eq(&tmp_ip, &(*tmp)->ip) && (depth == (*tmp)->depth)) { node_free(rib, new_node); (*tmp)->flag |= RTE_RIB_VALID_NODE; ++rib->cur_routes; return *tmp; } - if (!is_covered(tmp_ip.a, (*tmp)->ip.a, (*tmp)->depth) || + if (!rte_ipv6_addr_eq_prefix(&tmp_ip, &(*tmp)->ip, (*tmp)->depth) || ((*tmp)->depth >= depth)) { break; } @@ -372,10 +353,10 @@ rte_rib6_insert(struct rte_rib6 *rib, common_depth = RTE_MIN(d, common_depth); - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - common_prefix.a[i] = tmp_ip.a[i] & get_msk_part(common_depth, i); + common_prefix = tmp_ip; + rte_ipv6_addr_mask(&common_prefix, common_depth); - if (rte_rib6_is_equal(common_prefix.a, tmp_ip.a) && + if (rte_ipv6_addr_eq(&common_prefix, &tmp_ip) && (common_depth == depth)) { /* insert as a parent */ if (get_dir(&(*tmp)->ip, depth)) diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h index 47dcb6d15183..ec62fdafecb6 100644 --- a/lib/rib/rte_rib6.h +++ b/lib/rib/rte_rib6.h @@ -57,6 +57,9 @@ struct rte_rib6_conf { * @param src * pointer from where to copy */ +static inline void rte_rib6_copy_addr(uint8_t *dst, const uint8_t *src) + __rte_deprecated_msg("use direct struct assignment"); + static inline void rte_rib6_copy_addr(uint8_t *dst, const uint8_t *src) { @@ -77,6 +80,9 @@ rte_rib6_copy_addr(uint8_t *dst, const uint8_t *src) * 1 if equal * 0 otherwise */ +static inline int rte_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2) + __rte_deprecated_msg("use rte_ipv6_addr_eq"); + static inline int rte_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2) { int i; @@ -101,6 +107,8 @@ rte_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2) { * @return * 8-bit chunk of the 128-bit IPv6 mask */ +static inline uint8_t get_msk_part(uint8_t depth, int byte) __rte_deprecated; + static inline uint8_t get_msk_part(uint8_t depth, int byte) { uint8_t part; -- 2.46.2