1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Vladimir Medvedkin <[email protected]> 3 * Copyright(c) 2019 Intel Corporation 4 */ 5 6 #ifndef _RTE_FIB6_H_ 7 #define _RTE_FIB6_H_ 8 9 /** 10 * @file 11 * 12 * RTE FIB6 library. 13 * 14 * FIB (Forwarding information base) implementation 15 * for IPv6 Longest Prefix Match 16 */ 17 18 #include <stdint.h> 19 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define RTE_FIB6_IPV6_ADDR_SIZE 16 26 /** Maximum depth value possible for IPv6 FIB. */ 27 #define RTE_FIB6_MAXDEPTH 128 28 29 struct rte_fib6; 30 struct rte_rib6; 31 32 /** Type of FIB struct */ 33 enum rte_fib6_type { 34 RTE_FIB6_DUMMY, /**< RIB6 tree based FIB */ 35 RTE_FIB6_TRIE /**< TRIE based fib */ 36 }; 37 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); 46 47 enum rte_fib6_op { 48 RTE_FIB6_ADD, 49 RTE_FIB6_DEL, 50 }; 51 52 /** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */ 53 enum rte_fib_trie_nh_sz { 54 RTE_FIB6_TRIE_2B = 1, 55 RTE_FIB6_TRIE_4B, 56 RTE_FIB6_TRIE_8B 57 }; 58 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 */ 65 }; 66 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 */ 71 uint64_t default_nh; 72 int max_routes; 73 /** Size of the node extension in the internal RIB struct */ 74 unsigned int rib_ext_sz; 75 union { 76 struct { 77 enum rte_fib_trie_nh_sz nh_sz; 78 uint32_t num_tbl8; 79 } trie; 80 }; 81 }; 82 83 /** 84 * Create FIB 85 * 86 * @param name 87 * FIB name 88 * @param socket_id 89 * NUMA socket ID for FIB table memory allocation 90 * @param conf 91 * Structure containing the configuration 92 * @return 93 * Handle to FIB object on success 94 * NULL otherwise with rte_errno set to an appropriate values. 95 */ 96 struct rte_fib6 * 97 rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf); 98 99 /** 100 * Find an existing FIB object and return a pointer to it. 101 * 102 * @param name 103 * Name of the fib object as passed to rte_fib6_create() 104 * @return 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. 108 */ 109 struct rte_fib6 * 110 rte_fib6_find_existing(const char *name); 111 112 /** 113 * Free an FIB object. 114 * 115 * @param fib 116 * FIB object handle 117 * @return 118 * None 119 */ 120 void 121 rte_fib6_free(struct rte_fib6 *fib); 122 123 /** 124 * Add a route to the FIB. 125 * 126 * @param fib 127 * FIB object handle 128 * @param ip 129 * IPv6 prefix address to be added to the FIB 130 * @param depth 131 * Prefix length 132 * @param next_hop 133 * Next hop to be added to the FIB 134 * @return 135 * 0 on success, negative value otherwise 136 */ 137 int 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); 140 141 /** 142 * Delete a rule from the FIB. 143 * 144 * @param fib 145 * FIB object handle 146 * @param ip 147 * IPv6 prefix address to be deleted from the FIB 148 * @param depth 149 * Prefix length 150 * @return 151 * 0 on success, negative value otherwise 152 */ 153 int 154 rte_fib6_delete(struct rte_fib6 *fib, 155 const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth); 156 157 /** 158 * Lookup multiple IP addresses in the FIB. 159 * 160 * @param fib 161 * FIB object handle 162 * @param ips 163 * Array of IPv6s to be looked up in the FIB 164 * @param next_hops 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. 169 * @param n 170 * Number of elements in ips (and next_hops) array to lookup. 171 * @return 172 * -EINVAL for incorrect arguments, otherwise 0 173 */ 174 int 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); 178 179 /** 180 * Get pointer to the dataplane specific struct 181 * 182 * @param fib 183 * FIB6 object handle 184 * @return 185 * Pointer on the dataplane struct on success 186 * NULL otherwise 187 */ 188 void * 189 rte_fib6_get_dp(struct rte_fib6 *fib); 190 191 /** 192 * Get pointer to the RIB6 193 * 194 * @param fib 195 * FIB object handle 196 * @return 197 * Pointer on the RIB6 on success 198 * NULL otherwise 199 */ 200 struct rte_rib6 * 201 rte_fib6_get_rib(struct rte_fib6 *fib); 202 203 /** 204 * Set lookup function based on type 205 * 206 * @param fib 207 * FIB object handle 208 * @param type 209 * type of lookup function 210 * 211 * @return 212 * 0 on success 213 * -EINVAL on failure 214 */ 215 int 216 rte_fib6_select_lookup(struct rte_fib6 *fib, enum rte_fib6_lookup_type type); 217 218 #ifdef __cplusplus 219 } 220 #endif 221 222 #endif /* _RTE_FIB6_H_ */ 223