1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3 * Copyright(c) 2019 Intel Corporation
14 * FIB (Forwarding information base) implementation
15 * for IPv6 Longest Prefix Match
20 #include <rte_compat.h>
26 #define RTE_FIB6_IPV6_ADDR_SIZE 16
27 /** Maximum depth value possible for IPv6 FIB. */
28 #define RTE_FIB6_MAXDEPTH 128
33 /** Type of FIB struct */
35 RTE_FIB6_DUMMY, /**< RIB6 tree based FIB */
36 RTE_FIB6_TRIE /**< TRIE based fib */
39 /** Modify FIB function */
40 typedef int (*rte_fib6_modify_fn_t)(struct rte_fib6 *fib,
41 const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth,
42 uint64_t next_hop, int op);
43 /** FIB bulk lookup function */
44 typedef void (*rte_fib6_lookup_fn_t)(void *fib,
45 uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
46 uint64_t *next_hops, const unsigned int n);
53 /** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */
54 enum rte_fib_trie_nh_sz {
60 /** Type of lookup function implementation */
61 enum rte_fib6_lookup_type {
62 RTE_FIB6_LOOKUP_DEFAULT,
63 /**< Selects the best implementation based on the max simd bitwidth */
64 RTE_FIB6_LOOKUP_TRIE_SCALAR, /**< Scalar lookup function implementation*/
65 RTE_FIB6_LOOKUP_TRIE_VECTOR_AVX512 /**< Vector implementation using AVX512 */
68 /** FIB configuration structure */
69 struct rte_fib6_conf {
70 enum rte_fib6_type type; /**< Type of FIB struct */
71 /** Default value returned on lookup if there is no route */
74 /** Size of the node extension in the internal RIB struct */
75 unsigned int rib_ext_sz;
78 enum rte_fib_trie_nh_sz nh_sz;
90 * NUMA socket ID for FIB table memory allocation
92 * Structure containing the configuration
94 * Handle to FIB object on success
95 * NULL otherwise with rte_errno set to an appropriate values.
98 rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
101 * Find an existing FIB object and return a pointer to it.
104 * Name of the fib object as passed to rte_fib6_create()
106 * Pointer to fib object or NULL if object not found with rte_errno
107 * set appropriately. Possible rte_errno values include:
108 * - ENOENT - required entry not available to return.
111 rte_fib6_find_existing(const char *name);
114 * Free an FIB object.
122 rte_fib6_free(struct rte_fib6 *fib);
125 * Add a route to the FIB.
130 * IPv6 prefix address to be added to the FIB
134 * Next hop to be added to the FIB
136 * 0 on success, negative value otherwise
139 rte_fib6_add(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE],
140 uint8_t depth, uint64_t next_hop);
143 * Delete a rule from the FIB.
148 * IPv6 prefix address to be deleted from the FIB
152 * 0 on success, negative value otherwise
155 rte_fib6_delete(struct rte_fib6 *fib,
156 const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth);
159 * Lookup multiple IP addresses in the FIB.
164 * Array of IPv6s to be looked up in the FIB
166 * Next hop of the most specific rule found for IP.
167 * This is an array of eight byte values.
168 * If the lookup for the given IP failed, then corresponding element would
169 * contain default nexthop value configured for a FIB.
171 * Number of elements in ips (and next_hops) array to lookup.
173 * -EINVAL for incorrect arguments, otherwise 0
176 rte_fib6_lookup_bulk(struct rte_fib6 *fib,
177 uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
178 uint64_t *next_hops, int n);
181 * Get pointer to the dataplane specific struct
186 * Pointer on the dataplane struct on success
190 rte_fib6_get_dp(struct rte_fib6 *fib);
193 * Get pointer to the RIB6
198 * Pointer on the RIB6 on success
202 rte_fib6_get_rib(struct rte_fib6 *fib);
205 * Set lookup function based on type
210 * type of lookup function
217 rte_fib6_select_lookup(struct rte_fib6 *fib, enum rte_fib6_lookup_type type);
223 #endif /* _RTE_FIB6_H_ */