Replace all address size and max depth macros with common ones from rte_ip6.h. Mark the old symbols as deprecated.
Signed-off-by: Robin Jarry <rja...@redhat.com> --- Notes: v3: - replace memcpy() with direct struct assignments - restore RTE_FIB6_IPV6_ADDR_SIZE, RTE_FIB6_MAXDEPTH, TRIE_MAX_DEPTH, RTE_LPM6_MAX_DEPTH, RTE_LPM6_IPV6_ADDR_SIZE, RTE_RIB6_IPV6_ADDR_SIZE and mark them as RTE_DEPRECATED() - replace string initializers with RTE_IPV6() app/test/test_fib6.c | 50 ++++++++++++++++++------------------- examples/l3fwd-graph/main.c | 4 +-- lib/fib/rte_fib6.c | 6 ++--- lib/fib/rte_fib6.h | 5 ++-- lib/fib/trie.c | 6 ++--- lib/fib/trie.h | 3 ++- lib/lpm/rte_lpm6.c | 10 ++++---- lib/lpm/rte_lpm6.h | 5 ++-- lib/node/ip6_lookup.c | 2 +- lib/rib/rte_rib6.c | 11 ++++---- lib/rib/rte_rib6.h | 6 ++--- 11 files changed, 55 insertions(+), 53 deletions(-) diff --git a/app/test/test_fib6.c b/app/test/test_fib6.c index 8853adeaac7c..79220a88b112 100644 --- a/app/test/test_fib6.c +++ b/app/test/test_fib6.c @@ -170,13 +170,13 @@ test_add_del_invalid(void) fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config); RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n"); - /* rte_fib6_add: depth > RTE_FIB6_MAXDEPTH */ - ret = rte_fib6_add(fib, &ip, RTE_FIB6_MAXDEPTH + 1, nh); + /* rte_fib6_add: depth > RTE_IPV6_MAX_DEPTH */ + ret = rte_fib6_add(fib, &ip, RTE_IPV6_MAX_DEPTH + 1, nh); RTE_TEST_ASSERT(ret < 0, "Call succeeded with invalid parameters\n"); - /* rte_fib6_delete: depth > RTE_FIB6_MAXDEPTH */ - ret = rte_fib6_delete(fib, &ip, RTE_FIB6_MAXDEPTH + 1); + /* rte_fib6_delete: depth > RTE_IPV6_MAX_DEPTH */ + ret = rte_fib6_delete(fib, &ip, RTE_IPV6_MAX_DEPTH + 1); RTE_TEST_ASSERT(ret < 0, "Call succeeded with invalid parameters\n"); @@ -216,18 +216,18 @@ lookup_and_check_asc(struct rte_fib6 *fib, struct rte_ipv6_addr *ip_missing, uint64_t def_nh, uint32_t n) { - uint64_t nh_arr[RTE_FIB6_MAXDEPTH]; + uint64_t nh_arr[RTE_IPV6_MAX_DEPTH]; int ret; uint32_t i = 0; - ret = rte_fib6_lookup_bulk(fib, ip_arr, nh_arr, RTE_FIB6_MAXDEPTH); + ret = rte_fib6_lookup_bulk(fib, ip_arr, nh_arr, RTE_IPV6_MAX_DEPTH); RTE_TEST_ASSERT(ret == 0, "Failed to lookup\n"); - for (; i <= RTE_FIB6_MAXDEPTH - n; i++) + for (; i <= RTE_IPV6_MAX_DEPTH - n; i++) RTE_TEST_ASSERT(nh_arr[i] == n, "Failed to get proper nexthop\n"); - for (; i < RTE_FIB6_MAXDEPTH; i++) + for (; i < RTE_IPV6_MAX_DEPTH; i++) RTE_TEST_ASSERT(nh_arr[i] == --n, "Failed to get proper nexthop\n"); @@ -244,18 +244,18 @@ lookup_and_check_desc(struct rte_fib6 *fib, struct rte_ipv6_addr *ip_missing, uint64_t def_nh, uint32_t n) { - uint64_t nh_arr[RTE_FIB6_MAXDEPTH]; + uint64_t nh_arr[RTE_IPV6_MAX_DEPTH]; int ret; uint32_t i = 0; - ret = rte_fib6_lookup_bulk(fib, ip_arr, nh_arr, RTE_FIB6_MAXDEPTH); + ret = rte_fib6_lookup_bulk(fib, ip_arr, nh_arr, RTE_IPV6_MAX_DEPTH); RTE_TEST_ASSERT(ret == 0, "Failed to lookup\n"); for (; i < n; i++) - RTE_TEST_ASSERT(nh_arr[i] == RTE_FIB6_MAXDEPTH - i, + RTE_TEST_ASSERT(nh_arr[i] == RTE_IPV6_MAX_DEPTH - i, "Failed to get proper nexthop\n"); - for (; i < RTE_FIB6_MAXDEPTH; i++) + for (; i < RTE_IPV6_MAX_DEPTH; i++) RTE_TEST_ASSERT(nh_arr[i] == def_nh, "Failed to get proper nexthop\n"); @@ -270,19 +270,19 @@ static int check_fib(struct rte_fib6 *fib) { uint64_t def_nh = 100; - struct rte_ipv6_addr ip_arr[RTE_FIB6_MAXDEPTH]; + struct rte_ipv6_addr ip_arr[RTE_IPV6_MAX_DEPTH]; struct rte_ipv6_addr ip_add = RTE_IPV6(0x8000, 0, 0, 0, 0, 0, 0, 0); struct rte_ipv6_addr ip_missing = RTE_IPV6(0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff); uint32_t i, j; int ret; - for (i = 0; i < RTE_FIB6_MAXDEPTH; i++) { + for (i = 0; i < RTE_IPV6_MAX_DEPTH; i++) { 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++) + j = (RTE_IPV6_MAX_DEPTH - i) / CHAR_BIT; + if (j < RTE_IPV6_ADDR_SIZE) { + ip_arr[i].a[j] |= UINT8_MAX >> ((RTE_IPV6_MAX_DEPTH - i) % CHAR_BIT); + for (j++; j < RTE_IPV6_ADDR_SIZE; j++) ip_arr[i].a[j] = 0xff; } } @@ -290,7 +290,7 @@ check_fib(struct rte_fib6 *fib) ret = lookup_and_check_desc(fib, ip_arr, &ip_missing, def_nh, 0); RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n"); - for (i = 1; i <= RTE_FIB6_MAXDEPTH; i++) { + for (i = 1; i <= RTE_IPV6_MAX_DEPTH; i++) { ret = rte_fib6_add(fib, &ip_add, i, i); RTE_TEST_ASSERT(ret == 0, "Failed to add a route\n"); ret = lookup_and_check_asc(fib, ip_arr, &ip_missing, def_nh, i); @@ -298,7 +298,7 @@ check_fib(struct rte_fib6 *fib) "Lookup and check fails\n"); } - for (i = RTE_FIB6_MAXDEPTH; i > 1; i--) { + for (i = RTE_IPV6_MAX_DEPTH; i > 1; i--) { ret = rte_fib6_delete(fib, &ip_add, i); RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n"); ret = lookup_and_check_asc(fib, ip_arr, &ip_missing, @@ -313,9 +313,9 @@ check_fib(struct rte_fib6 *fib) RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n"); - for (i = 0; i < RTE_FIB6_MAXDEPTH; i++) { - ret = rte_fib6_add(fib, &ip_add, RTE_FIB6_MAXDEPTH - i, - RTE_FIB6_MAXDEPTH - i); + for (i = 0; i < RTE_IPV6_MAX_DEPTH; i++) { + ret = rte_fib6_add(fib, &ip_add, RTE_IPV6_MAX_DEPTH - i, + RTE_IPV6_MAX_DEPTH - i); RTE_TEST_ASSERT(ret == 0, "Failed to add a route\n"); ret = lookup_and_check_desc(fib, ip_arr, &ip_missing, def_nh, i + 1); @@ -323,11 +323,11 @@ check_fib(struct rte_fib6 *fib) "Lookup and check fails\n"); } - for (i = 1; i <= RTE_FIB6_MAXDEPTH; i++) { + for (i = 1; i <= RTE_IPV6_MAX_DEPTH; i++) { ret = rte_fib6_delete(fib, &ip_add, i); RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n"); ret = lookup_and_check_desc(fib, ip_arr, &ip_missing, def_nh, - RTE_FIB6_MAXDEPTH - i); + RTE_IPV6_MAX_DEPTH - i); RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n"); } diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c index a13dc011380d..9bda0ab633e1 100644 --- a/examples/l3fwd-graph/main.c +++ b/examples/l3fwd-graph/main.c @@ -151,7 +151,7 @@ struct ipv4_l3fwd_lpm_route { }; struct ipv6_l3fwd_lpm_route { - uint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; + uint8_t ip[RTE_IPV6_ADDR_SIZE]; uint8_t depth; uint8_t if_out; }; @@ -1371,7 +1371,7 @@ main(int argc, char **argv) dst_port = ipv6_l3fwd_lpm_route_array[i].if_out; - memcpy(in6.s6_addr, ipv6_l3fwd_lpm_route_array[i].ip, RTE_LPM6_IPV6_ADDR_SIZE); + memcpy(in6.s6_addr, ipv6_l3fwd_lpm_route_array[i].ip, RTE_IPV6_ADDR_SIZE); snprintf(route_str, sizeof(route_str), "%s / %d (%d)", inet_ntop(AF_INET6, &in6, abuf, sizeof(abuf)), ipv6_l3fwd_lpm_route_array[i].depth, diff --git a/lib/fib/rte_fib6.c b/lib/fib/rte_fib6.c index d95cac79cbb5..9c7d4fde433a 100644 --- a/lib/fib/rte_fib6.c +++ b/lib/fib/rte_fib6.c @@ -71,7 +71,7 @@ dummy_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, uint8_t depth, uint64_t next_hop, int op) { struct rte_rib6_node *node; - if ((fib == NULL) || (depth > RTE_FIB6_MAXDEPTH)) + if ((fib == NULL) || (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; node = rte_rib6_lookup_exact(fib->rib, ip, depth); @@ -123,7 +123,7 @@ rte_fib6_add(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, uint8_t depth, uint64_t next_hop) { if ((fib == NULL) || (ip == NULL) || (fib->modify == NULL) || - (depth > RTE_FIB6_MAXDEPTH)) + (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; return fib->modify(fib, ip, depth, next_hop, RTE_FIB6_ADD); } @@ -133,7 +133,7 @@ rte_fib6_delete(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, uint8_t depth) { if ((fib == NULL) || (ip == NULL) || (fib->modify == NULL) || - (depth > RTE_FIB6_MAXDEPTH)) + (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; return fib->modify(fib, ip, depth, 0, RTE_FIB6_DEL); } diff --git a/lib/fib/rte_fib6.h b/lib/fib/rte_fib6.h index d26a0c7c0b77..21f0492374d9 100644 --- a/lib/fib/rte_fib6.h +++ b/lib/fib/rte_fib6.h @@ -17,15 +17,16 @@ #include <stdint.h> +#include <rte_common.h> #include <rte_ip6.h> #ifdef __cplusplus extern "C" { #endif -#define RTE_FIB6_IPV6_ADDR_SIZE 16 +#define RTE_FIB6_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_FIB6_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE) /** Maximum depth value possible for IPv6 FIB. */ -#define RTE_FIB6_MAXDEPTH 128 +#define RTE_FIB6_MAXDEPTH (RTE_DEPRECATED(RTE_FIB6_MAXDEPTH) RTE_IPV6_MAX_DEPTH) struct rte_fib6; struct rte_rib6; diff --git a/lib/fib/trie.c b/lib/fib/trie.c index b0d80c3db815..ee9c2395414d 100644 --- a/lib/fib/trie.c +++ b/lib/fib/trie.c @@ -350,9 +350,9 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, return ret; } -#define IPV6_MAX_IDX (RTE_FIB6_IPV6_ADDR_SIZE - 1) +#define IPV6_MAX_IDX (RTE_IPV6_ADDR_SIZE - 1) #define TBL24_BYTES 3 -#define TBL8_LEN (RTE_FIB6_IPV6_ADDR_SIZE - TBL24_BYTES) +#define TBL8_LEN (RTE_IPV6_ADDR_SIZE - TBL24_BYTES) static int install_to_dp(struct rte_trie_tbl *dp, const struct rte_ipv6_addr *ledge, @@ -518,7 +518,7 @@ trie_modify(struct rte_fib6 *fib, const struct rte_ipv6_addr *ip, uint64_t par_nh, node_nh; uint8_t tmp_depth, depth_diff = 0, parent_depth = 24; - if ((fib == NULL) || (ip == NULL) || (depth > RTE_FIB6_MAXDEPTH)) + if ((fib == NULL) || (ip == NULL) || (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; dp = rte_fib6_get_dp(fib); diff --git a/lib/fib/trie.h b/lib/fib/trie.h index 6e235edaf89c..6004ec49ce7c 100644 --- a/lib/fib/trie.h +++ b/lib/fib/trie.h @@ -8,6 +8,7 @@ #include <stdalign.h> +#include <rte_common.h> #include <rte_fib6.h> /** @@ -18,7 +19,7 @@ /* @internal Total number of tbl24 entries. */ #define TRIE_TBL24_NUM_ENT (1 << 24) /* Maximum depth value possible for IPv6 LPM. */ -#define TRIE_MAX_DEPTH 128 +#define TRIE_MAX_DEPTH (RTE_DEPRECATED(TRIE_MAX_DEPTH) RTE_IPV6_MAX_DEPTH) /* @internal Number of entries in a tbl8 group. */ #define TRIE_TBL8_GRP_NUM_ENT 256ULL /* @internal Total number of tbl8 groups in the tbl8. */ diff --git a/lib/lpm/rte_lpm6.c b/lib/lpm/rte_lpm6.c index 1d5577f263b1..8beb394c4701 100644 --- a/lib/lpm/rte_lpm6.c +++ b/lib/lpm/rte_lpm6.c @@ -802,7 +802,7 @@ simulate_add(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *masked_ip, uint8_ * Inspect one by one the rest of the bytes until * the process is completed. */ - for (i = ADD_FIRST_BYTE; i < RTE_LPM6_IPV6_ADDR_SIZE && ret == 1; i++) { + for (i = ADD_FIRST_BYTE; i < RTE_IPV6_ADDR_SIZE && ret == 1; i++) { tbl = tbl_next; ret = simulate_add_step(lpm, tbl, &tbl_next, masked_ip, 1, (uint8_t)(i + 1), depth, &need_tbl_nb); @@ -832,7 +832,7 @@ rte_lpm6_add(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth int i; /* Check user arguments. */ - if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) + if ((lpm == NULL) || (depth < 1) || (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; /* Copy the IP and mask it to avoid modifying user's input data. */ @@ -861,7 +861,7 @@ rte_lpm6_add(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t depth * Inspect one by one the rest of the bytes until * the process is completed. */ - for (i = ADD_FIRST_BYTE; i < RTE_LPM6_IPV6_ADDR_SIZE && status == 1; i++) { + for (i = ADD_FIRST_BYTE; i < RTE_IPV6_ADDR_SIZE && status == 1; i++) { tbl = tbl_next; status = add_step(lpm, tbl, tbl_next_num, &tbl_next, &tbl_next_num, &masked_ip, 1, (uint8_t)(i + 1), @@ -993,7 +993,7 @@ rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, u /* Check user arguments. */ if ((lpm == NULL) || next_hop == NULL || ip == NULL || - (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) + (depth < 1) || (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; /* Copy the IP and mask it to avoid modifying user's input data. */ @@ -1268,7 +1268,7 @@ rte_lpm6_delete(struct rte_lpm6 *lpm, const struct rte_ipv6_addr *ip, uint8_t de struct rte_lpm6_tbl_entry *from, *to; /* Check input arguments. */ - if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) + if ((lpm == NULL) || (depth < 1) || (depth > RTE_IPV6_MAX_DEPTH)) return -EINVAL; /* Copy the IP and mask it to avoid modifying user's input data. */ diff --git a/lib/lpm/rte_lpm6.h b/lib/lpm/rte_lpm6.h index 87392194237c..d7ebe9245c8e 100644 --- a/lib/lpm/rte_lpm6.h +++ b/lib/lpm/rte_lpm6.h @@ -9,6 +9,7 @@ * RTE Longest Prefix Match for IPv6 (LPM6) */ +#include <rte_common.h> #include <rte_ip6.h> #include <stdint.h> @@ -18,8 +19,8 @@ extern "C" { #endif -#define RTE_LPM6_MAX_DEPTH 128 -#define RTE_LPM6_IPV6_ADDR_SIZE 16 +#define RTE_LPM6_MAX_DEPTH (RTE_DEPRECATED(RTE_LPM6_MAX_DEPTH) RTE_IPV6_MAX_DEPTH) +#define RTE_LPM6_IPV6_ADDR_SIZE (RTE_DEPRECATED(RTE_LPM6_IPV6_ADDR_SIZE) RTE_IPV6_ADDR_SIZE) /** Max number of characters in LPM name. */ #define RTE_LPM6_NAMESIZE 32 diff --git a/lib/node/ip6_lookup.c b/lib/node/ip6_lookup.c index f291ef74832b..faaea5085938 100644 --- a/lib/node/ip6_lookup.c +++ b/lib/node/ip6_lookup.c @@ -267,7 +267,7 @@ rte_node_ip6_route_add(const uint8_t *ip, uint8_t depth, uint16_t next_hop, uint32_t val; int ret; - memcpy(in6.s6_addr, ip, RTE_LPM6_IPV6_ADDR_SIZE); + memcpy(in6.s6_addr, ip, RTE_IPV6_ADDR_SIZE); inet_ntop(AF_INET6, &in6, abuf, sizeof(abuf)); /* Embedded next node id into 24 bit next hop */ val = ((next_node << 16) | next_hop) & ((1ull << 24) - 1); diff --git a/lib/rib/rte_rib6.c b/lib/rib/rte_rib6.c index 75175c6aaf98..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 @@ -89,7 +88,7 @@ static inline struct rte_rib6_node * get_nxt_node(struct rte_rib6_node *node, 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; @@ -158,7 +157,7 @@ rte_rib6_lookup_exact(struct rte_rib6 *rib, struct rte_rib6_node *cur; 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; } @@ -196,7 +195,7 @@ rte_rib6_get_nxt(struct rte_rib6 *rib, struct rte_rib6_node *tmp, *prev = NULL; 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; } @@ -279,7 +278,7 @@ rte_rib6_insert(struct rte_rib6 *rib, 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; } @@ -341,7 +340,7 @@ rte_rib6_insert(struct rte_rib6 *rib, /* 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++) { + 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; diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h index ec62fdafecb6..a60756f798d8 100644 --- a/lib/rib/rte_rib6.h +++ b/lib/rib/rte_rib6.h @@ -22,7 +22,7 @@ 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 @@ -65,7 +65,7 @@ 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); } /** @@ -89,7 +89,7 @@ rte_rib6_is_equal(const uint8_t *ip1, const uint8_t *ip2) { 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; } -- 2.46.2