From: Robin Jarry <rjarry@redhat.com>
To: dev@dpdk.org, Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Subject: [PATCH dpdk v4 07/17] rib6: use IPv6 address structure and utils
Date: Fri, 18 Oct 2024 11:17:24 +0200 [thread overview]
Message-ID: <20241018091734.64601-8-rjarry@redhat.com> (raw)
In-Reply-To: <20241018091734.64601-1-rjarry@redhat.com>
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 <rjarry@redhat.com>
---
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 <stdio.h>
#include <stdint.h>
#include <stdlib.h>
-#include <rte_ip.h>
+#include <rte_ip6.h>
#include <rte_rib6.h>
#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 <rte_memcpy.h>
#include <rte_common.h>
+#include <rte_ip6.h>
#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
next prev parent reply other threads:[~2024-10-18 9:18 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 16:25 [PATCH dpdk v1 00/15] IPv6 APIs overhaul Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 01/15] net: split raw checksum functions in separate header Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 02/15] net: split ipv6 symbols " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 03/15] net: add structure for ipv6 addresses Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 04/15] net: use ipv6 structure for header addresses Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 05/15] fib6,rib6,lpm6: use ipv6 addr struct Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 06/15] net: add ipv6 address utilities Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 07/15] fib6,rib6,lpm6: use ipv6 utils Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 08/15] graph,node: use ipv6 addr struct and utils Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 09/15] pipeline: use ipv6 addr struct Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 10/15] ipsec: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 11/15] thash: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 12/15] gro: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 13/15] rte_flow: " Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 14/15] rib6,fib6,lpm6: remove duplicate constants Robin Jarry
2024-08-21 16:25 ` [PATCH dpdk v1 15/15] net: add utilities for well known ipv6 address types Robin Jarry
2024-08-21 22:28 ` [PATCH dpdk v1 00/15] IPv6 APIs overhaul Morten Brørup
2024-08-22 14:13 ` Stephen Hemminger
2024-08-22 15:13 ` Morten Brørup
2024-08-22 15:27 ` Robin Jarry
2024-08-22 18:41 ` Morten Brørup
2024-08-22 15:14 ` Robin Jarry
2024-08-22 15:16 ` Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 00/16] " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 01/16] net: split raw checksum functions in separate header Robin Jarry
2024-10-03 23:12 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 02/16] net: split ipv6 symbols " Robin Jarry
2024-10-03 23:15 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 03/16] net: add structure for ipv6 addresses Robin Jarry
2024-10-03 23:18 ` Stephen Hemminger
2024-10-04 11:59 ` Robin Jarry
2024-10-06 8:18 ` Morten Brørup
2024-10-10 20:08 ` Robin Jarry
2024-10-11 12:37 ` Morten Brørup
2024-10-11 17:02 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 04/16] net: use ipv6 structure for header addresses Robin Jarry
2024-10-03 23:20 ` Stephen Hemminger
2024-10-04 18:01 ` Ferruh Yigit
2024-10-04 20:04 ` Robin Jarry
2024-10-06 21:03 ` Ferruh Yigit
2024-10-01 8:17 ` [PATCH dpdk v2 05/16] fib6,rib6,lpm6: use ipv6 addr struct Robin Jarry
2024-10-03 23:21 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 06/16] net: add ipv6 address utilities Robin Jarry
2024-10-01 15:35 ` Stephen Hemminger
2024-10-03 23:22 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 07/16] fib6,rib6,lpm6: use ipv6 utils Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 08/16] graph,node: use ipv6 addr struct and utils Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 09/16] pipeline: use ipv6 addr struct Robin Jarry
2024-10-03 23:23 ` Stephen Hemminger
2024-10-04 11:55 ` Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 10/16] ipsec: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 11/16] thash: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 12/16] gro: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 13/16] rte_flow: " Robin Jarry
2024-10-01 8:17 ` [PATCH dpdk v2 14/16] rib6,fib6,lpm6: remove duplicate constants Robin Jarry
2024-10-03 23:12 ` Stephen Hemminger
2024-10-04 11:54 ` Robin Jarry
2024-10-04 16:16 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 15/16] net: add utilities for well known ipv6 address types Robin Jarry
2024-10-03 23:24 ` Stephen Hemminger
2024-10-01 8:17 ` [PATCH dpdk v2 16/16] ipv6: add function to check ipv6 version Robin Jarry
2024-10-06 9:02 ` Morten Brørup
2024-10-10 20:00 ` Robin Jarry
2024-10-11 12:05 ` Morten Brørup
2024-10-10 15:26 ` Konstantin Ananyev
2024-10-06 9:04 ` [PATCH dpdk v2 00/16] IPv6 APIs overhaul Morten Brørup
2024-10-10 15:27 ` Konstantin Ananyev
2024-10-10 19:41 ` [PATCH dpdk v3 00/17] " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 01/17] net: split raw checksum functions in separate header Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 02/17] net: split ipv6 symbols " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 03/17] net: add structure for ipv6 addresses Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 04/17] net: add ipv6 address utilities Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 05/17] net: use struct rte_ipv6_addr for header addresses Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 06/17] fib6,rib6,lpm6: use struct rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 07/17] fib6,rib6,lpm6: use ipv6 utils Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 08/17] rib6,fib6,lpm6: remove duplicate constants Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 09/17] cmdline: replace in6_addr with rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 10/17] graph,node: use struct rte_ipv6_addr and utils Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 11/17] pipeline: use struct rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 12/17] ipsec, security: use struct rte_ipv6_addr and utils Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 13/17] thash: use struct rte_ipv6_addr Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 14/17] gro: " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 15/17] rte_flow: " Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 16/17] net: add utilities for well known ipv6 address types Robin Jarry
2024-10-10 19:41 ` [PATCH dpdk v3 17/17] ipv6: add function to check ipv6 version Robin Jarry
2024-10-15 17:12 ` Stephen Hemminger
2024-10-17 13:52 ` [PATCH dpdk v3 00/17] IPv6 APIs overhaul David Marchand
2024-10-17 18:03 ` Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 01/17] net: split raw checksum functions in separate header Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 02/17] net: split IPv4 and IPv6 symbols in separate headers Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 03/17] net: add IPv6 address structure and utils Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 04/17] net: use IPv6 structure for packet headers Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 05/17] lpm6: use IPv6 address structure and utils Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 06/17] fib6: " Robin Jarry
2024-10-18 9:17 ` Robin Jarry [this message]
2024-10-18 9:17 ` [PATCH dpdk v4 08/17] cmdline: use IPv6 address structure Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 09/17] node: use IPv6 address structure and utils Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 10/17] pipeline: use IPv6 structures Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 11/17] ipsec: use IPv6 address structure Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 12/17] security: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 13/17] hash: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 14/17] gro: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 15/17] flow: " Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 16/17] net: add utilities for well known IPv6 address types Robin Jarry
2024-10-18 9:17 ` [PATCH dpdk v4 17/17] net: add function to check IPv6 version Robin Jarry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241018091734.64601-8-rjarry@redhat.com \
--to=rjarry@redhat.com \
--cc=dev@dpdk.org \
--cc=vladimir.medvedkin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).