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 92C3E45B68; Fri, 18 Oct 2024 11:18:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A8A0D40DD3; Fri, 18 Oct 2024 11:18:17 +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 BC49F40B9A for ; Fri, 18 Oct 2024 11:18:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729243092; 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=VHQEVhqlBfc+q48MJ5t3rNTLa0uqN5Ub3cTNISeZLt0=; b=IlUOAzGcYV+tfnRZVE///Xf647Fllrrqwj8Axm6EwpJK4uBVcP85F09PFjDenqpIN3PldO jitNK6RpmziU4OyK7Wmr3dH5rCnOylwDz28Ao0hPksrpZQX4amzzyw0j/wLDpowOT7S3NC K6ipja+F8m6pd6gjBBj99b+jqW22rD0= 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-637-dhHaAaKxPC6G06enzFx5hg-1; Fri, 18 Oct 2024 05:18:10 -0400 X-MC-Unique: dhHaAaKxPC6G06enzFx5hg-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 D4A2219560B8; Fri, 18 Oct 2024 09:18:09 +0000 (UTC) Received: from ringo.redhat.com (unknown [10.39.208.23]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6B4D19560AD; Fri, 18 Oct 2024 09:18:08 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org, Vladimir Medvedkin Subject: [PATCH dpdk v4 07/17] rib6: use IPv6 address structure and utils Date: Fri, 18 Oct 2024 11:17:24 +0200 Message-ID: <20241018091734.64601-8-rjarry@redhat.com> In-Reply-To: <20241018091734.64601-1-rjarry@redhat.com> References: <20240821162516.610624-17-rjarry@redhat.com> <20241018091734.64601-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 ad-hoc uint8_t[16] array types in the API of rte_rib6 with rte_ipv6_addr structures. Replace duplicate functions and macros with common ones from rte_ip6.h. Update all code accordingly. Signed-off-by: Robin Jarry --- app/test/test_rib6.c | 55 ++++++------ doc/guides/rel_notes/deprecation.rst | 7 -- doc/guides/rel_notes/release_24_11.rst | 11 +++ lib/fib/rte_fib6.c | 8 +- lib/fib/trie.c | 16 ++-- lib/rib/meson.build | 2 +- lib/rib/rte_rib6.c | 112 ++++++++++--------------- lib/rib/rte_rib6.h | 27 ++++-- 8 files changed, 113 insertions(+), 125 deletions(-) diff --git a/app/test/test_rib6.c b/app/test/test_rib6.c index 33596fddb4e5..ba54a3794ea7 100644 --- a/app/test/test_rib6.c +++ b/app/test/test_rib6.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include "test.h" @@ -118,14 +118,14 @@ test_insert_invalid(void) struct rte_rib6 *rib = NULL; struct rte_rib6_node *node, *node1; struct rte_rib6_conf config; - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE] = {0}; + struct rte_ipv6_addr ip = {0}; uint8_t depth = 24; config.max_nodes = MAX_RULES; config.ext_sz = 0; /* rte_rib6_insert: rib == NULL */ - node = rte_rib6_insert(NULL, ip, depth); + node = rte_rib6_insert(NULL, &ip, depth); RTE_TEST_ASSERT(node == NULL, "Call succeeded with invalid parameters\n"); @@ -134,14 +134,14 @@ test_insert_invalid(void) RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n"); /* rte_rib6_insert: depth > MAX_DEPTH */ - node = rte_rib6_insert(rib, ip, MAX_DEPTH + 1); + node = rte_rib6_insert(rib, &ip, MAX_DEPTH + 1); RTE_TEST_ASSERT(node == NULL, "Call succeeded with invalid parameters\n"); /* insert the same ip/depth twice*/ - node = rte_rib6_insert(rib, ip, depth); + node = rte_rib6_insert(rib, &ip, depth); RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n"); - node1 = rte_rib6_insert(rib, ip, depth); + node1 = rte_rib6_insert(rib, &ip, depth); RTE_TEST_ASSERT(node1 == NULL, "Call succeeded with invalid parameters\n"); @@ -162,9 +162,8 @@ test_get_fn(void) struct rte_rib6_node *node; struct rte_rib6_conf config; void *ext; - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE] = {192, 0, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0}; - uint8_t ip_ret[RTE_RIB6_IPV6_ADDR_SIZE]; + struct rte_ipv6_addr ip = RTE_IPV6(0xc000, 0x0200, 0, 0, 0, 0, 0, 0); + struct rte_ipv6_addr ip_ret; uint64_t nh_set = 10; uint64_t nh_ret; uint8_t depth = 24; @@ -177,11 +176,11 @@ test_get_fn(void) rib = rte_rib6_create(__func__, SOCKET_ID_ANY, &config); RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n"); - node = rte_rib6_insert(rib, ip, depth); + node = rte_rib6_insert(rib, &ip, depth); RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n"); /* test rte_rib6_get_ip() with incorrect args */ - ret = rte_rib6_get_ip(NULL, ip_ret); + ret = rte_rib6_get_ip(NULL, &ip_ret); RTE_TEST_ASSERT(ret < 0, "Call succeeded with invalid parameters\n"); ret = rte_rib6_get_ip(node, NULL); @@ -215,8 +214,8 @@ test_get_fn(void) "Call succeeded with invalid parameters\n"); /* check the return values */ - ret = rte_rib6_get_ip(node, ip_ret); - RTE_TEST_ASSERT((ret == 0) && (rte_rib6_is_equal(ip_ret, ip)), + ret = rte_rib6_get_ip(node, &ip_ret); + 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), @@ -243,8 +242,7 @@ test_basic(void) struct rte_rib6_node *node; struct rte_rib6_conf config; - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE] = {192, 0, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0}; + struct rte_ipv6_addr ip = RTE_IPV6(0xc000, 0x0200, 0, 0, 0, 0, 0, 0); uint64_t next_hop_add = 10; uint64_t next_hop_return; uint8_t depth = 24; @@ -256,21 +254,21 @@ test_basic(void) rib = rte_rib6_create(__func__, SOCKET_ID_ANY, &config); RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n"); - node = rte_rib6_insert(rib, ip, depth); + node = rte_rib6_insert(rib, &ip, depth); RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n"); status = rte_rib6_set_nh(node, next_hop_add); RTE_TEST_ASSERT(status == 0, "Failed to set rte_rib_node field\n"); - node = rte_rib6_lookup(rib, ip); + node = rte_rib6_lookup(rib, &ip); RTE_TEST_ASSERT(node != NULL, "Failed to lookup\n"); status = rte_rib6_get_nh(node, &next_hop_return); RTE_TEST_ASSERT((status == 0) && (next_hop_add == next_hop_return), "Failed to get proper nexthop\n"); - node = rte_rib6_lookup_exact(rib, ip, depth); + node = rte_rib6_lookup_exact(rib, &ip, depth); RTE_TEST_ASSERT(node != NULL, "Failed to lookup\n"); @@ -278,12 +276,12 @@ test_basic(void) RTE_TEST_ASSERT((status == 0) && (next_hop_add == next_hop_return), "Failed to get proper nexthop\n"); - rte_rib6_remove(rib, ip, depth); + rte_rib6_remove(rib, &ip, depth); - node = rte_rib6_lookup(rib, ip); + node = rte_rib6_lookup(rib, &ip); RTE_TEST_ASSERT(node == NULL, "Lookup returns non existent rule\n"); - node = rte_rib6_lookup_exact(rib, ip, depth); + node = rte_rib6_lookup_exact(rib, &ip, depth); RTE_TEST_ASSERT(node == NULL, "Lookup returns non existent rule\n"); @@ -299,12 +297,9 @@ test_tree_traversal(void) struct rte_rib6_node *node; struct rte_rib6_conf config; - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE] = {10, 0, 2, 130, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0}; - uint8_t ip1[RTE_RIB6_IPV6_ADDR_SIZE] = {10, 0, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0}; - uint8_t ip2[RTE_RIB6_IPV6_ADDR_SIZE] = {10, 0, 2, 130, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 80}; + struct rte_ipv6_addr ip = RTE_IPV6(0x0a00, 0x0282, 0, 0, 0, 0, 0, 0); + struct rte_ipv6_addr ip1 = RTE_IPV6(0x0a00, 0x0200, 0, 0, 0, 0, 0, 0); + struct rte_ipv6_addr ip2 = RTE_IPV6(0x0a00, 0x0282, 0, 0, 0, 0, 0, 0x0050); uint8_t depth = 126; config.max_nodes = MAX_RULES; @@ -313,13 +308,13 @@ test_tree_traversal(void) rib = rte_rib6_create(__func__, SOCKET_ID_ANY, &config); RTE_TEST_ASSERT(rib != NULL, "Failed to create RIB\n"); - node = rte_rib6_insert(rib, ip1, depth); + node = rte_rib6_insert(rib, &ip1, depth); RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n"); - node = rte_rib6_insert(rib, ip2, depth); + node = rte_rib6_insert(rib, &ip2, depth); RTE_TEST_ASSERT(node != NULL, "Failed to insert rule\n"); node = NULL; - node = rte_rib6_get_nxt(rib, ip, 32, node, RTE_RIB6_GET_NXT_ALL); + node = rte_rib6_get_nxt(rib, &ip, 32, node, RTE_RIB6_GET_NXT_ALL); RTE_TEST_ASSERT(node != NULL, "Failed to get rib_node\n"); rte_rib6_free(rib); diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 582d54aece2f..735542d7a1e2 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -80,13 +80,6 @@ Deprecation Notices - ``rte_node_ip6_route_add()`` pipeline - ``struct rte_table_action_ipv6_header`` - rib - - ``rte_rib6_lookup()`` - - ``rte_rib6_lookup_exact()`` - - ``rte_rib6_get_nxt()`` - - ``rte_rib6_insert()`` - - ``rte_rib6_remove()`` - - ``rte_rib6_get_ip()`` * 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 aada0df483c8..40045b32ef08 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -304,6 +304,17 @@ API Changes - ``struct rte_ipv6_hdr`` table - ``struct rte_table_lpm_ipv6_key`` + rib + - ``rte_rib6_get_ip()`` + - ``rte_rib6_get_nxt()`` + - ``rte_rib6_insert()`` + - ``rte_rib6_lookup()`` + - ``rte_rib6_lookup_exact()`` + - ``rte_rib6_remove()`` + - ``RTE_RIB6_IPV6_ADDR_SIZE`` (deprecated, replace with ``RTE_IPV6_ADDR_SIZE``) + - ``get_msk_part()`` (deprecated) + - ``rte_rib6_copy_addr()`` (deprecated, replaced with direct structure assignments) + - ``rte_rib6_is_equal()`` (deprecated, replaced with ``rte_ipv6_addr_eq()``) ABI Changes diff --git a/lib/fib/rte_fib6.c b/lib/fib/rte_fib6.c index ef334da67cc4..9c7d4fde433a 100644 --- a/lib/fib/rte_fib6.c +++ b/lib/fib/rte_fib6.c @@ -58,7 +58,7 @@ dummy_lookup(void *fib_p, const struct rte_ipv6_addr *ips, struct rte_rib6_node *node; for (i = 0; i < n; i++) { - node = rte_rib6_lookup(fib->rib, ips[i].a); + node = rte_rib6_lookup(fib->rib, &ips[i]); if (node != NULL) rte_rib6_get_nh(node, &next_hops[i]); else @@ -74,19 +74,19 @@ dummy_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, if ((fib == NULL) || (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; - node = rte_rib6_lookup_exact(fib->rib, ip->a, depth); + node = rte_rib6_lookup_exact(fib->rib, ip, depth); switch (op) { case RTE_FIB6_ADD: if (node == NULL) - node = rte_rib6_insert(fib->rib, ip->a, depth); + node = rte_rib6_insert(fib->rib, ip, depth); if (node == NULL) return -rte_errno; return rte_rib6_set_nh(node, next_hop); case RTE_FIB6_DEL: if (node == NULL) return -ENOENT; - rte_rib6_remove(fib->rib, ip->a, depth); + rte_rib6_remove(fib->rib, ip, depth); return 0; } return -EINVAL; diff --git a/lib/fib/trie.c b/lib/fib/trie.c index 6bb46541feee..4893f6c63615 100644 --- a/lib/fib/trie.c +++ b/lib/fib/trie.c @@ -468,13 +468,13 @@ modify_dp(struct rte_trie_tbl *dp, struct rte_rib6 *rib, ledge = *ip; do { - tmp = rte_rib6_get_nxt(rib, ip->a, depth, tmp, + tmp = rte_rib6_get_nxt(rib, ip, depth, tmp, RTE_RIB6_GET_NXT_COVER); if (tmp != NULL) { rte_rib6_get_depth(tmp, &tmp_depth); if (tmp_depth == depth) continue; - rte_rib6_get_ip(tmp, redge.a); + rte_rib6_get_ip(tmp, &redge); if (rte_ipv6_addr_eq(&ledge, &redge)) { get_nxt_net(&ledge, tmp_depth); continue; @@ -532,11 +532,11 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, rte_ipv6_addr_mask(&ip_masked, depth); if (depth > 24) { - tmp = rte_rib6_get_nxt(rib, ip_masked.a, + tmp = rte_rib6_get_nxt(rib, &ip_masked, RTE_ALIGN_FLOOR(depth, 8), NULL, RTE_RIB6_GET_NXT_COVER); if (tmp == NULL) { - tmp = rte_rib6_lookup(rib, ip->a); + tmp = rte_rib6_lookup(rib, ip); if (tmp != NULL) { rte_rib6_get_depth(tmp, &tmp_depth); parent_depth = RTE_MAX(tmp_depth, 24); @@ -546,7 +546,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, depth_diff = depth_diff >> 3; } } - node = rte_rib6_lookup_exact(rib, ip_masked.a, depth); + node = rte_rib6_lookup_exact(rib, &ip_masked, depth); switch (op) { case RTE_FIB6_ADD: if (node != NULL) { @@ -563,7 +563,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, dp->number_tbl8s - depth_diff)) return -ENOSPC; - node = rte_rib6_insert(rib, ip_masked.a, depth); + node = rte_rib6_insert(rib, &ip_masked, depth); if (node == NULL) return -rte_errno; rte_rib6_set_nh(node, next_hop); @@ -575,7 +575,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, } ret = modify_dp(dp, rib, &ip_masked, depth, next_hop); if (ret != 0) { - rte_rib6_remove(rib, ip_masked.a, depth); + rte_rib6_remove(rib, &ip_masked, depth); return ret; } @@ -597,7 +597,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, if (ret != 0) return ret; - rte_rib6_remove(rib, ip->a, depth); + rte_rib6_remove(rib, ip, depth); dp->rsvd_tbl8s -= depth_diff; return 0; diff --git a/lib/rib/meson.build b/lib/rib/meson.build index 7bacbb453592..e98f70848189 100644 --- a/lib/rib/meson.build +++ b/lib/rib/meson.build @@ -4,4 +4,4 @@ sources = files('rte_rib.c', 'rte_rib6.c') headers = files('rte_rib.h', 'rte_rib6.h') -deps += ['mempool'] +deps += ['net', 'mempool'] diff --git a/lib/rib/rte_rib6.c b/lib/rib/rte_rib6.c index 89c8390c63be..84c47fed6d1f 100644 --- a/lib/rib/rte_rib6.c +++ b/lib/rib/rte_rib6.c @@ -20,7 +20,6 @@ #include "rib_log.h" #define RTE_RIB_VALID_NODE 1 -#define RIB6_MAXDEPTH 128 /* Maximum length of a RIB6 name. */ #define RTE_RIB6_NAMESIZE 64 @@ -35,7 +34,7 @@ struct rte_rib6_node { struct rte_rib6_node *right; struct rte_rib6_node *parent; uint64_t nh; - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]; + struct rte_ipv6_addr ip; uint8_t depth; uint8_t flag; uint64_t ext[]; @@ -62,24 +61,8 @@ 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 uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth) +get_dir(const struct rte_ipv6_addr *ip, uint8_t depth) { uint8_t index, msk; @@ -98,14 +81,14 @@ get_dir(const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth) */ msk = 1 << (7 - (depth & 7)); - return (ip[index] & msk) != 0; + return (ip->a[index] & msk) != 0; } static inline struct rte_rib6_node * get_nxt_node(struct rte_rib6_node *node, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]) + const struct rte_ipv6_addr *ip) { - if (node->depth == RIB6_MAXDEPTH) + if (node->depth == RTE_IPV6_MAX_DEPTH) return NULL; return (get_dir(ip, node->depth)) ? node->right : node->left; @@ -133,7 +116,7 @@ node_free(struct rte_rib6 *rib, struct rte_rib6_node *ent) struct rte_rib6_node * rte_rib6_lookup(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]) + const struct rte_ipv6_addr *ip) { struct rte_rib6_node *cur; struct rte_rib6_node *prev = NULL; @@ -144,7 +127,7 @@ rte_rib6_lookup(struct rte_rib6 *rib, } cur = rib->tree; - while ((cur != NULL) && is_covered(ip, cur->ip, 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); @@ -169,32 +152,31 @@ rte_rib6_lookup_parent(struct rte_rib6_node *ent) struct rte_rib6_node * rte_rib6_lookup_exact(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth) + const struct rte_ipv6_addr *ip, uint8_t depth) { struct rte_rib6_node *cur; - uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE]; - int i; + struct rte_ipv6_addr tmp_ip; - if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) { + if (unlikely(rib == NULL || ip == NULL || depth > RTE_IPV6_MAX_DEPTH)) { rte_errno = EINVAL; return NULL; } cur = rib->tree; - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - tmp_ip[i] = ip[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, tmp_ip) && + if (rte_ipv6_addr_eq(&cur->ip, &tmp_ip) && (cur->depth == depth) && is_valid_node(cur)) return cur; - if (!(is_covered(tmp_ip, cur->ip, cur->depth)) || + if (!rte_ipv6_addr_eq_prefix(&tmp_ip, &cur->ip, cur->depth) || (cur->depth >= depth)) break; - cur = get_nxt_node(cur, tmp_ip); + cur = get_nxt_node(cur, &tmp_ip); } return NULL; @@ -207,32 +189,31 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib, */ struct rte_rib6_node * rte_rib6_get_nxt(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], + const struct rte_ipv6_addr *ip, uint8_t depth, struct rte_rib6_node *last, int flag) { struct rte_rib6_node *tmp, *prev = NULL; - uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE]; - int i; + struct rte_ipv6_addr tmp_ip; - if (unlikely(rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH)) { + if (unlikely(rib == NULL || ip == NULL || depth > RTE_IPV6_MAX_DEPTH)) { rte_errno = EINVAL; return NULL; } - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - tmp_ip[i] = ip[i] & get_msk_part(depth, i); + tmp_ip = *ip; + rte_ipv6_addr_mask(&tmp_ip, depth); if (last == NULL) { tmp = rib->tree; while ((tmp) && (tmp->depth < depth)) - tmp = get_nxt_node(tmp, tmp_ip); + tmp = get_nxt_node(tmp, &tmp_ip); } else { tmp = last; while ((tmp->parent != NULL) && (is_right_node(tmp) || (tmp->parent->right == NULL))) { tmp = tmp->parent; if (is_valid_node(tmp) && - (is_covered(tmp->ip, tmp_ip, depth) && + (rte_ipv6_addr_eq_prefix(&tmp->ip, &tmp_ip, depth) && (tmp->depth > depth))) return tmp; } @@ -240,7 +221,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, } while (tmp) { if (is_valid_node(tmp) && - (is_covered(tmp->ip, tmp_ip, depth) && + (rte_ipv6_addr_eq_prefix(&tmp->ip, &tmp_ip, depth) && (tmp->depth > depth))) { prev = tmp; if (flag == RTE_RIB6_GET_NXT_COVER) @@ -253,7 +234,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, void rte_rib6_remove(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth) + const struct rte_ipv6_addr *ip, uint8_t depth) { struct rte_rib6_node *cur, *prev, *child; @@ -286,28 +267,28 @@ rte_rib6_remove(struct rte_rib6 *rib, struct rte_rib6_node * rte_rib6_insert(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth) + const struct rte_ipv6_addr *ip, uint8_t depth) { struct rte_rib6_node **tmp; struct rte_rib6_node *prev = NULL; struct rte_rib6_node *new_node = NULL; struct rte_rib6_node *common_node = NULL; - uint8_t common_prefix[RTE_RIB6_IPV6_ADDR_SIZE]; - uint8_t tmp_ip[RTE_RIB6_IPV6_ADDR_SIZE]; + struct rte_ipv6_addr common_prefix; + struct rte_ipv6_addr tmp_ip; int i, d; uint8_t common_depth, ip_xor; - if (unlikely((rib == NULL || ip == NULL || depth > RIB6_MAXDEPTH))) { + if (unlikely((rib == NULL || ip == NULL || depth > RTE_IPV6_MAX_DEPTH))) { rte_errno = EINVAL; return NULL; } tmp = &rib->tree; - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) - tmp_ip[i] = ip[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); + new_node = rte_rib6_lookup_exact(rib, &tmp_ip, depth); if (new_node != NULL) { rte_errno = EEXIST; return NULL; @@ -321,7 +302,7 @@ rte_rib6_insert(struct rte_rib6 *rib, new_node->left = NULL; new_node->right = NULL; new_node->parent = NULL; - rte_rib6_copy_addr(new_node->ip, tmp_ip); + new_node->ip = tmp_ip; new_node->depth = depth; new_node->flag = RTE_RIB_VALID_NODE; @@ -340,28 +321,27 @@ 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, (*tmp)->ip) && - (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, (*tmp)->ip, (*tmp)->depth) || + if (!rte_ipv6_addr_eq_prefix(&tmp_ip, &(*tmp)->ip, (*tmp)->depth) || ((*tmp)->depth >= depth)) { break; } prev = *tmp; - tmp = (get_dir(tmp_ip, (*tmp)->depth)) ? &(*tmp)->right : + tmp = (get_dir(&tmp_ip, (*tmp)->depth)) ? &(*tmp)->right : &(*tmp)->left; } /* closest node found, new_node should be inserted in the middle */ common_depth = RTE_MIN(depth, (*tmp)->depth); - for (i = 0, d = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) { - ip_xor = tmp_ip[i] ^ (*tmp)->ip[i]; + for (i = 0, d = 0; i < RTE_IPV6_ADDR_SIZE; i++) { + ip_xor = tmp_ip.a[i] ^ (*tmp)->ip.a[i]; if (ip_xor == 0) d += 8; else { @@ -372,13 +352,13 @@ 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[i] = tmp_ip[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, tmp_ip) && + if (rte_ipv6_addr_eq(&common_prefix, &tmp_ip) && (common_depth == depth)) { /* insert as a parent */ - if (get_dir((*tmp)->ip, depth)) + if (get_dir(&(*tmp)->ip, depth)) new_node->right = *tmp; else new_node->left = *tmp; @@ -393,13 +373,13 @@ rte_rib6_insert(struct rte_rib6 *rib, rte_errno = ENOMEM; return NULL; } - rte_rib6_copy_addr(common_node->ip, common_prefix); + common_node->ip = common_prefix; common_node->depth = common_depth; common_node->flag = 0; common_node->parent = (*tmp)->parent; new_node->parent = common_node; (*tmp)->parent = common_node; - if (get_dir((*tmp)->ip, common_depth) == 1) { + if (get_dir(&(*tmp)->ip, common_depth) == 1) { common_node->left = new_node; common_node->right = *tmp; } else { @@ -414,13 +394,13 @@ rte_rib6_insert(struct rte_rib6 *rib, int rte_rib6_get_ip(const struct rte_rib6_node *node, - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]) + struct rte_ipv6_addr *ip) { if (unlikely(node == NULL || ip == NULL)) { rte_errno = EINVAL; return -1; } - rte_rib6_copy_addr(ip, node->ip); + *ip = node->ip; return 0; } @@ -604,7 +584,7 @@ rte_rib6_free(struct rte_rib6 *rib) while ((tmp = rte_rib6_get_nxt(rib, 0, 0, tmp, RTE_RIB6_GET_NXT_ALL)) != NULL) - rte_rib6_remove(rib, tmp->ip, tmp->depth); + rte_rib6_remove(rib, &tmp->ip, tmp->depth); rte_mempool_free(rib->node_pool); diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h index 775286f965f2..a60756f798d8 100644 --- a/lib/rib/rte_rib6.h +++ b/lib/rib/rte_rib6.h @@ -16,12 +16,13 @@ #include #include +#include #ifdef __cplusplus extern "C" { #endif -#define RTE_RIB6_IPV6_ADDR_SIZE 16 +#define RTE_RIB6_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_RIB6_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE) /** * rte_rib6_get_nxt() flags @@ -56,12 +57,15 @@ 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) { if ((dst == NULL) || (src == NULL)) return; - rte_memcpy(dst, src, RTE_RIB6_IPV6_ADDR_SIZE); + rte_memcpy(dst, src, RTE_IPV6_ADDR_SIZE); } /** @@ -76,13 +80,16 @@ 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; if ((ip1 == NULL) || (ip2 == NULL)) return 0; - for (i = 0; i < RTE_RIB6_IPV6_ADDR_SIZE; i++) { + for (i = 0; i < RTE_IPV6_ADDR_SIZE; i++) { if (ip1[i] != ip2[i]) return 0; } @@ -100,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; @@ -124,7 +133,7 @@ get_msk_part(uint8_t depth, int byte) { */ struct rte_rib6_node * rte_rib6_lookup(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]); + const struct rte_ipv6_addr *ip); /** * Lookup less specific route into the RIB structure @@ -154,7 +163,7 @@ rte_rib6_lookup_parent(struct rte_rib6_node *ent); */ struct rte_rib6_node * rte_rib6_lookup_exact(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth); + const struct rte_ipv6_addr *ip, uint8_t depth); /** * Retrieve next more specific prefix from the RIB @@ -181,7 +190,7 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib, */ struct rte_rib6_node * rte_rib6_get_nxt(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], + const struct rte_ipv6_addr *ip, uint8_t depth, struct rte_rib6_node *last, int flag); /** @@ -196,7 +205,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, */ void rte_rib6_remove(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth); + const struct rte_ipv6_addr *ip, uint8_t depth); /** * Insert prefix into the RIB @@ -213,7 +222,7 @@ rte_rib6_remove(struct rte_rib6 *rib, */ struct rte_rib6_node * rte_rib6_insert(struct rte_rib6 *rib, - const uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE], uint8_t depth); + const struct rte_ipv6_addr *ip, uint8_t depth); /** * Get an ip from rte_rib6_node @@ -228,7 +237,7 @@ rte_rib6_insert(struct rte_rib6 *rib, */ int rte_rib6_get_ip(const struct rte_rib6_node *node, - uint8_t ip[RTE_RIB6_IPV6_ADDR_SIZE]); + struct rte_ipv6_addr *ip); /** * Get a depth from rte_rib6_node -- 2.47.0