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
25 #define RTE_FIB6_IPV6_ADDR_SIZE 16
26 /** Maximum depth value possible for IPv6 FIB. */
27 #define RTE_FIB6_MAXDEPTH 128
32 /** Type of FIB struct */
34 RTE_FIB6_DUMMY, /**< RIB6 tree based FIB */
35 RTE_FIB6_TRIE /**< TRIE based fib */
38 /** Modify FIB function */
39 typedef int (*rte_fib6_modify_fn_t)(struct rte_fib6 *fib,
40 const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth,
41 uint64_t next_hop, int op);
42 /** FIB bulk lookup function */
43 typedef void (*rte_fib6_lookup_fn_t)(void *fib,
44 uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
45 uint64_t *next_hops, const unsigned int n);
52 /** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */
53 enum rte_fib_trie_nh_sz {
59 /** Type of lookup function implementation */
60 enum rte_fib6_lookup_type {
61 RTE_FIB6_LOOKUP_DEFAULT,
62 /**< Selects the best implementation based on the max simd bitwidth */
63 RTE_FIB6_LOOKUP_TRIE_SCALAR, /**< Scalar lookup function implementation*/
64 RTE_FIB6_LOOKUP_TRIE_VECTOR_AVX512 /**< Vector implementation using AVX512 */
67 /** FIB configuration structure */
68 struct rte_fib6_conf {
69 enum rte_fib6_type type; /**< Type of FIB struct */
70 /** Default value returned on lookup if there is no route */
73 /** Size of the node extension in the internal RIB struct */
74 unsigned int rib_ext_sz;
77 enum rte_fib_trie_nh_sz nh_sz;
89 * NUMA socket ID for FIB table memory allocation
91 * Structure containing the configuration
93 * Handle to FIB object on success
94 * NULL otherwise with rte_errno set to an appropriate values.
97 rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
100 * Find an existing FIB object and return a pointer to it.
103 * Name of the fib object as passed to rte_fib6_create()
105 * Pointer to fib object or NULL if object not found with rte_errno
106 * set appropriately. Possible rte_errno values include:
107 * - ENOENT - required entry not available to return.
110 rte_fib6_find_existing(const char *name);
113 * Free an FIB object.
121 rte_fib6_free(struct rte_fib6 *fib);
124 * Add a route to the FIB.
129 * IPv6 prefix address to be added to the FIB
133 * Next hop to be added to the FIB
135 * 0 on success, negative value otherwise
138 rte_fib6_add(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE],
139 uint8_t depth, uint64_t next_hop);
142 * Delete a rule from the FIB.
147 * IPv6 prefix address to be deleted from the FIB
151 * 0 on success, negative value otherwise
154 rte_fib6_delete(struct rte_fib6 *fib,
155 const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth);
158 * Lookup multiple IP addresses in the FIB.
163 * Array of IPv6s to be looked up in the FIB
165 * Next hop of the most specific rule found for IP.
166 * This is an array of eight byte values.
167 * If the lookup for the given IP failed, then corresponding element would
168 * contain default nexthop value configured for a FIB.
170 * Number of elements in ips (and next_hops) array to lookup.
172 * -EINVAL for incorrect arguments, otherwise 0
175 rte_fib6_lookup_bulk(struct rte_fib6 *fib,
176 uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE],
177 uint64_t *next_hops, int n);
180 * Get pointer to the dataplane specific struct
185 * Pointer on the dataplane struct on success
189 rte_fib6_get_dp(struct rte_fib6 *fib);
192 * Get pointer to the RIB6
197 * Pointer on the RIB6 on success
201 rte_fib6_get_rib(struct rte_fib6 *fib);
204 * Set lookup function based on type
209 * type of lookup function
216 rte_fib6_select_lookup(struct rte_fib6 *fib, enum rte_fib6_lookup_type type);
222 #endif /* _RTE_FIB6_H_ */