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 #include <rte_compat.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define RTE_FIB6_IPV6_ADDR_SIZE 16 27 /** Maximum depth value possible for IPv6 FIB. */ 28 #define RTE_FIB6_MAXDEPTH 128 29 30 struct rte_fib6; 31 struct rte_rib6; 32 33 /** Type of FIB struct */ 34 enum rte_fib6_type { 35 RTE_FIB6_DUMMY, /**< RIB6 tree based FIB */ 36 RTE_FIB6_TRIE /**< TRIE based fib */ 37 }; 38 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); 47 48 enum rte_fib6_op { 49 RTE_FIB6_ADD, 50 RTE_FIB6_DEL, 51 }; 52 53 /** Size of nexthop (1 << nh_sz) bits for TRIE based FIB */ 54 enum rte_fib_trie_nh_sz { 55 RTE_FIB6_TRIE_2B = 1, 56 RTE_FIB6_TRIE_4B, 57 RTE_FIB6_TRIE_8B 58 }; 59 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 */ 66 }; 67 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 */ 72 uint64_t default_nh; 73 int max_routes; 74 union { 75 struct { 76 enum rte_fib_trie_nh_sz nh_sz; 77 uint32_t num_tbl8; 78 } trie; 79 }; 80 }; 81 82 /** 83 * Create FIB 84 * 85 * @param name 86 * FIB name 87 * @param socket_id 88 * NUMA socket ID for FIB table memory allocation 89 * @param conf 90 * Structure containing the configuration 91 * @return 92 * Handle to FIB object on success 93 * NULL otherwise with rte_errno set to an appropriate values. 94 */ 95 struct rte_fib6 * 96 rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf); 97 98 /** 99 * Find an existing FIB object and return a pointer to it. 100 * 101 * @param name 102 * Name of the fib object as passed to rte_fib6_create() 103 * @return 104 * Pointer to fib object or NULL if object not found with rte_errno 105 * set appropriately. Possible rte_errno values include: 106 * - ENOENT - required entry not available to return. 107 */ 108 struct rte_fib6 * 109 rte_fib6_find_existing(const char *name); 110 111 /** 112 * Free an FIB object. 113 * 114 * @param fib 115 * FIB object handle 116 * @return 117 * None 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 othervise 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 othervise 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