[PATCH dpdk v2 07/16] fib6,rib6,lpm6: use ipv6 utils
Robin Jarry
rjarry at redhat.com
Tue Oct 1 10:17:19 CEST 2024
Replace duplicated and/or private functions by some of the previously
introduced utility functions.
Mark rib6 functions that deal with ipv6 addresses as deprecated.
Signed-off-by: Robin Jarry <rjarry at redhat.com>
---
app/test/test_fib6.c | 9 +++--
app/test/test_rib6.c | 2 +-
examples/ipsec-secgw/ipsec_lpm_neon.h | 2 +-
lib/fib/trie.c | 30 ++++++--------
lib/lpm/rte_lpm6.c | 51 +++++-------------------
lib/rib/rte_rib6.c | 57 +++++++++------------------
lib/rib/rte_rib6.h | 8 ++++
7 files changed, 56 insertions(+), 103 deletions(-)
diff --git a/app/test/test_fib6.c b/app/test/test_fib6.c
index c3b947d789bb..7134c4d335cd 100644
--- a/app/test/test_fib6.c
+++ b/app/test/test_fib6.c
@@ -279,9 +279,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);
+ rte_ipv6_addr_cpy(&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 f3b6f1474348..33288f9c26d6 100644
--- a/app/test/test_rib6.c
+++ b/app/test/test_rib6.c
@@ -217,7 +217,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/examples/ipsec-secgw/ipsec_lpm_neon.h b/examples/ipsec-secgw/ipsec_lpm_neon.h
index 865b9624a86e..62b4260843a3 100644
--- a/examples/ipsec-secgw/ipsec_lpm_neon.h
+++ b/examples/ipsec-secgw/ipsec_lpm_neon.h
@@ -144,7 +144,7 @@ route6_pkts_neon(struct rt_ctx *rt_ctx, struct rte_mbuf **pkts, int nb_rx)
* required to get the hop
*/
ipv6_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1);
- memcpy(&dst_ip6[lpm_pkts], &ipv6_hdr->dst_addr, 16);
+ rte_ipv6_addr_cpy(&dst_ip6[lpm_pkts], &ipv6_hdr->dst_addr);
lpm_pkts++;
}
}
diff --git a/lib/fib/trie.c b/lib/fib/trie.c
index bd0c7ec63b7f..8a69702eabb2 100644
--- a/lib/fib/trie.c
+++ b/lib/fib/trie.c
@@ -367,7 +367,7 @@ install_to_dp(struct rte_trie_tbl *dp, const struct rte_ipv6_addr *ledge,
struct rte_ipv6_addr redge;
/* decrement redge by 1*/
- rte_rib6_copy_addr(redge.a, r->a);
+ rte_ipv6_addr_cpy(&redge, r);
for (i = 15; i >= 0; i--) {
redge.a[i]--;
if (redge.a[i] != 0xff)
@@ -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,
@@ -472,7 +464,7 @@ modify_dp(struct rte_trie_tbl *dp, struct rte_rib6 *rib,
if (next_hop > get_max_nh(dp->nh_sz))
return -EINVAL;
- rte_rib6_copy_addr(ledge.a, ip->a);
+ rte_ipv6_addr_cpy(&ledge, ip);
do {
tmp = rte_rib6_get_nxt(rib, ip, depth, tmp,
RTE_RIB6_GET_NXT_COVER);
@@ -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;
}
@@ -489,18 +481,18 @@ modify_dp(struct rte_trie_tbl *dp, struct rte_rib6 *rib,
if (ret != 0)
return ret;
get_nxt_net(&redge, tmp_depth);
- rte_rib6_copy_addr(ledge.a, redge.a);
+ rte_ipv6_addr_cpy(&ledge, &redge);
/*
* 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 {
- rte_rib6_copy_addr(redge.a, ip->a);
+ rte_ipv6_addr_cpy(&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);
+ rte_ipv6_addr_cpy(&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 d3f1c8485f5f..642b02b32cc2 100644
--- a/lib/lpm/rte_lpm6.c
+++ b/lib/lpm/rte_lpm6.c
@@ -111,37 +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;
- }
-}
-
-/* copy ipv6 address */
-static inline void
-ip6_copy_addr(uint8_t *dst, const uint8_t *src)
-{
- rte_memcpy(dst, src, RTE_LPM6_IPV6_ADDR_SIZE);
-}
-
/*
* LPM6 rule hash function
*
@@ -215,7 +184,7 @@ tbl8_available(struct rte_lpm6 *lpm)
static inline void
rule_key_init(struct rte_lpm6_rule_key *key, const struct rte_ipv6_addr *ip, uint8_t depth)
{
- ip6_copy_addr(key->ip.a, ip->a);
+ rte_ipv6_addr_cpy(&key->ip, ip);
key->depth = depth;
}
@@ -867,8 +836,8 @@ rte_lpm6_add(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth
return -EINVAL;
/* Copy the IP and mask it to avoid modifying user's input data. */
- ip6_copy_addr(masked_ip.a, ip->a);
- ip6_mask_addr(masked_ip.a, depth);
+ rte_ipv6_addr_cpy(&masked_ip, ip);
+ rte_ipv6_addr_mask(&masked_ip, depth);
/* Simulate adding a new route */
int ret = simulate_add(lpm, &masked_ip, depth);
@@ -1028,8 +997,8 @@ rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, u
return -EINVAL;
/* Copy the IP and mask it to avoid modifying user's input data. */
- ip6_copy_addr(masked_ip.a, ip->a);
- ip6_mask_addr(masked_ip.a, depth);
+ rte_ipv6_addr_cpy(&masked_ip, ip);
+ rte_ipv6_addr_mask(&masked_ip, depth);
return rule_find(lpm, &masked_ip, depth, next_hop);
}
@@ -1078,8 +1047,8 @@ rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm,
return -EINVAL;
for (i = 0; i < n; i++) {
- ip6_copy_addr(masked_ip.a, ips[i].a);
- ip6_mask_addr(masked_ip.a, depths[i]);
+ rte_ipv6_addr_cpy(&masked_ip, &ips[i]);
+ rte_ipv6_addr_mask(&masked_ip, depths[i]);
rule_delete(lpm, &masked_ip, depths[i]);
}
@@ -1168,7 +1137,7 @@ rule_find_less_specific(struct rte_lpm6 *lpm, struct rte_ipv6_addr *ip, uint8_t
ret = rule_find_with_key(lpm, &rule_key, &next_hop);
if (ret) {
rule->depth = depth;
- ip6_copy_addr(rule->ip.a, rule_key.ip.a);
+ rte_ipv6_addr_cpy(&rule->ip, &rule_key.ip);
rule->next_hop = next_hop;
return 1;
}
@@ -1302,8 +1271,8 @@ rte_lpm6_delete(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t de
return -EINVAL;
/* Copy the IP and mask it to avoid modifying user's input data. */
- ip6_copy_addr(masked_ip.a, ip->a);
- ip6_mask_addr(masked_ip.a, depth);
+ rte_ipv6_addr_cpy(&masked_ip, ip);
+ 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 a1ac418eb87a..ec46c865ddf7 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);
+ rte_ipv6_addr_cpy(&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);
+ rte_ipv6_addr_cpy(&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);
+ rte_ipv6_addr_cpy(&tmp_ip, ip);
+ rte_ipv6_addr_mask(&tmp_ip, depth);
new_node = rte_rib6_lookup_exact(rib, &tmp_ip, depth);
if (new_node != NULL) {
@@ -321,7 +303,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.a, tmp_ip.a);
+ rte_ipv6_addr_cpy(&new_node->ip, &tmp_ip);
new_node->depth = depth;
new_node->flag = RTE_RIB_VALID_NODE;
@@ -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);
+ rte_ipv6_addr_cpy(&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))
@@ -393,7 +374,7 @@ rte_rib6_insert(struct rte_rib6 *rib,
rte_errno = ENOMEM;
return NULL;
}
- rte_rib6_copy_addr(common_node->ip.a, common_prefix.a);
+ rte_ipv6_addr_cpy(&common_node->ip, &common_prefix);
common_node->depth = common_depth;
common_node->flag = 0;
common_node->parent = (*tmp)->parent;
@@ -420,7 +401,7 @@ rte_rib6_get_ip(const struct rte_rib6_node *node,
rte_errno = EINVAL;
return -1;
}
- rte_rib6_copy_addr(ip->a, node->ip.a);
+ rte_ipv6_addr_cpy(ip, &node->ip);
return 0;
}
diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h
index 47dcb6d15183..fcf4169ca790 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("replaced by rte_ipv6_addr_cpy");
+
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("replaced by 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.1
More information about the dev
mailing list