1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com> 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 created by rte_fib6_create(). 117 * If fib is NULL, no operation is performed. 118 */ 119 void 120 rte_fib6_free(struct rte_fib6 *fib); 121 122 /** 123 * Add a route to the FIB. 124 * 125 * @param fib 126 * FIB object handle 127 * @param ip 128 * IPv6 prefix address to be added to the FIB 129 * @param depth 130 * Prefix length 131 * @param next_hop 132 * Next hop to be added to the FIB 133 * @return 134 * 0 on success, negative value otherwise 135 */ 136 int 137 rte_fib6_add(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], 138 uint8_t depth, uint64_t next_hop); 139 140 /** 141 * Delete a rule from the FIB. 142 * 143 * @param fib 144 * FIB object handle 145 * @param ip 146 * IPv6 prefix address to be deleted from the FIB 147 * @param depth 148 * Prefix length 149 * @return 150 * 0 on success, negative value otherwise 151 */ 152 int 153 rte_fib6_delete(struct rte_fib6 *fib, 154 const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE], uint8_t depth); 155 156 /** 157 * Lookup multiple IP addresses in the FIB. 158 * 159 * @param fib 160 * FIB object handle 161 * @param ips 162 * Array of IPv6s to be looked up in the FIB 163 * @param next_hops 164 * Next hop of the most specific rule found for IP. 165 * This is an array of eight byte values. 166 * If the lookup for the given IP failed, then corresponding element would 167 * contain default nexthop value configured for a FIB. 168 * @param n 169 * Number of elements in ips (and next_hops) array to lookup. 170 * @return 171 * -EINVAL for incorrect arguments, otherwise 0 172 */ 173 int 174 rte_fib6_lookup_bulk(struct rte_fib6 *fib, 175 uint8_t ips[][RTE_FIB6_IPV6_ADDR_SIZE], 176 uint64_t *next_hops, int n); 177 178 /** 179 * Get pointer to the dataplane specific struct 180 * 181 * @param fib 182 * FIB6 object handle 183 * @return 184 * Pointer on the dataplane struct on success 185 * NULL otherwise 186 */ 187 void * 188 rte_fib6_get_dp(struct rte_fib6 *fib); 189 190 /** 191 * Get pointer to the RIB6 192 * 193 * @param fib 194 * FIB object handle 195 * @return 196 * Pointer on the RIB6 on success 197 * NULL otherwise 198 */ 199 struct rte_rib6 * 200 rte_fib6_get_rib(struct rte_fib6 *fib); 201 202 /** 203 * Set lookup function based on type 204 * 205 * @param fib 206 * FIB object handle 207 * @param type 208 * type of lookup function 209 * 210 * @return 211 * 0 on success 212 * -EINVAL on failure 213 */ 214 int 215 rte_fib6_select_lookup(struct rte_fib6 *fib, enum rte_fib6_lookup_type type); 216 217 #ifdef __cplusplus 218 } 219 #endif 220 221 #endif /* _RTE_FIB6_H_ */ 222