Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef __FIB_TABLE_H__ |
| 17 | #define __FIB_TABLE_H__ |
| 18 | |
| 19 | #include <vnet/ip/ip.h> |
| 20 | #include <vnet/adj/adj.h> |
| 21 | #include <vnet/fib/fib_entry.h> |
| 22 | #include <vnet/mpls/mpls.h> |
| 23 | #include <vnet/mpls/packet.h> |
| 24 | |
| 25 | /** |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 26 | * Flags for the source data |
| 27 | */ |
| 28 | typedef enum fib_table_attribute_t_ { |
| 29 | /** |
| 30 | * Marker. Add new values after this one. |
| 31 | */ |
| 32 | FIB_TABLE_ATTRIBUTE_FIRST, |
| 33 | /** |
| 34 | * the table is for IP6 link local addresses |
| 35 | */ |
| 36 | FIB_TABLE_ATTRIBUTE_IP6_LL = FIB_TABLE_ATTRIBUTE_FIRST, |
| 37 | /** |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 38 | * the table is currently resync-ing |
| 39 | */ |
| 40 | FIB_TABLE_ATTRIBUTE_RESYNC, |
| 41 | /** |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 42 | * Marker. add new entries before this one. |
| 43 | */ |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 44 | FIB_TABLE_ATTRIBUTE_LAST = FIB_TABLE_ATTRIBUTE_RESYNC, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 45 | } fib_table_attribute_t; |
| 46 | |
| 47 | #define FIB_TABLE_ATTRIBUTE_MAX (FIB_TABLE_ATTRIBUTE_LAST+1) |
| 48 | |
| 49 | #define FIB_TABLE_ATTRIBUTES { \ |
| 50 | [FIB_TABLE_ATTRIBUTE_IP6_LL] = "ip6-ll", \ |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 51 | [FIB_TABLE_ATTRIBUTE_RESYNC] = "resync", \ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | #define FOR_EACH_FIB_TABLE_ATTRIBUTE(_item) \ |
| 55 | for (_item = FIB_TABLE_ATTRIBUTE_FIRST; \ |
| 56 | _item < FIB_TABLE_ATTRIBUTE_MAX; \ |
| 57 | _item++) |
| 58 | |
| 59 | typedef enum fib_table_flags_t_ { |
| 60 | FIB_TABLE_FLAG_NONE = 0, |
| 61 | FIB_TABLE_FLAG_IP6_LL = (1 << FIB_TABLE_ATTRIBUTE_IP6_LL), |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 62 | FIB_TABLE_FLAG_RESYNC = (1 << FIB_TABLE_ATTRIBUTE_RESYNC), |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 63 | } __attribute__ ((packed)) fib_table_flags_t; |
| 64 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 65 | extern u8* format_fib_table_flags(u8 *s, va_list *args); |
| 66 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 67 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 68 | * @brief |
| 69 | * A protocol Independent FIB table |
| 70 | */ |
| 71 | typedef struct fib_table_t_ |
| 72 | { |
| 73 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 74 | * Which protocol this table serves. Used to switch on the union above. |
| 75 | */ |
| 76 | fib_protocol_t ft_proto; |
| 77 | |
| 78 | /** |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 79 | * Table flags |
| 80 | */ |
| 81 | fib_table_flags_t ft_flags; |
| 82 | |
| 83 | /** |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 84 | * per-source number of locks on the table |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 85 | */ |
Miklos Tirpak | 4a94cd2 | 2019-12-20 11:55:43 +0100 | [diff] [blame] | 86 | u32 *ft_locks; |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 87 | u32 ft_total_locks; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Table ID (hash key) for this FIB. |
| 91 | */ |
| 92 | u32 ft_table_id; |
| 93 | |
| 94 | /** |
| 95 | * Index into FIB vector. |
| 96 | */ |
| 97 | fib_node_index_t ft_index; |
| 98 | |
| 99 | /** |
| 100 | * flow hash configuration |
| 101 | */ |
| 102 | u32 ft_flow_hash_config; |
| 103 | |
| 104 | /** |
| 105 | * Per-source route counters |
| 106 | */ |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 107 | u32 *ft_src_route_counts; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Total route counters |
| 111 | */ |
| 112 | u32 ft_total_route_counts; |
| 113 | |
| 114 | /** |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 115 | * Epoch - number of resyncs performed |
| 116 | */ |
| 117 | u32 ft_epoch; |
| 118 | |
| 119 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 120 | * Table description |
| 121 | */ |
| 122 | u8* ft_desc; |
| 123 | } fib_table_t; |
| 124 | |
| 125 | /** |
| 126 | * @brief |
| 127 | * Format the description/name of the table |
| 128 | */ |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 129 | extern u8* format_fib_table_name(u8* s, va_list *ap); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * @brief |
| 133 | * Perfom a longest prefix match in the non-forwarding table |
| 134 | * |
| 135 | * @param fib_index |
| 136 | * The index of the FIB |
| 137 | * |
| 138 | * @param prefix |
| 139 | * The prefix to lookup |
| 140 | * |
| 141 | * @return |
| 142 | * The index of the fib_entry_t for the best match, which may be the default route |
| 143 | */ |
| 144 | extern fib_node_index_t fib_table_lookup(u32 fib_index, |
| 145 | const fib_prefix_t *prefix); |
| 146 | |
| 147 | /** |
| 148 | * @brief |
| 149 | * Perfom an exact match in the non-forwarding table |
| 150 | * |
| 151 | * @param fib_index |
| 152 | * The index of the FIB |
| 153 | * |
| 154 | * @param prefix |
| 155 | * The prefix to lookup |
| 156 | * |
| 157 | * @return |
| 158 | * The index of the fib_entry_t for the exact match, or INVALID |
| 159 | * is there is no match. |
| 160 | */ |
| 161 | extern fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, |
| 162 | const fib_prefix_t *prefix); |
| 163 | |
| 164 | /** |
| 165 | * @brief |
| 166 | * Get the less specific (covering) prefix |
| 167 | * |
| 168 | * @param fib_index |
| 169 | * The index of the FIB |
| 170 | * |
| 171 | * @param prefix |
| 172 | * The prefix to lookup |
| 173 | * |
| 174 | * @return |
| 175 | * The index of the less specific fib_entry_t. |
| 176 | */ |
| 177 | extern fib_node_index_t fib_table_get_less_specific(u32 fib_index, |
| 178 | const fib_prefix_t *prefix); |
| 179 | |
| 180 | /** |
| 181 | * @brief |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 182 | * Add a 'special' entry to the FIB. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 183 | * A special entry is an entry that the FIB is not expect to resolve |
| 184 | * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 185 | * Instead the will link to a DPO valid for the source and/or the flags. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 186 | * This add is reference counting per-source. So n 'removes' are required |
| 187 | * for n 'adds', if the entry is no longer required. |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 188 | * If the source needs to provide non-default forwarding use: |
| 189 | * fib_table_entry_special_dpo_add() |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 190 | * |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 191 | * @param fib_index |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 192 | * The index of the FIB |
| 193 | * |
| 194 | * @param prefix |
| 195 | * The prefix to add |
| 196 | * |
| 197 | * @param source |
| 198 | * The ID of the client/source adding the entry. |
| 199 | * |
| 200 | * @param flags |
| 201 | * Flags for the entry. |
| 202 | * |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 203 | * @return |
| 204 | * the index of the fib_entry_t that is created (or exists already). |
| 205 | */ |
| 206 | extern fib_node_index_t fib_table_entry_special_add(u32 fib_index, |
| 207 | const fib_prefix_t *prefix, |
| 208 | fib_source_t source, |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 209 | fib_entry_flag_t flags); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * @brief |
| 213 | * Add a 'special' entry to the FIB that links to the DPO passed |
| 214 | * A special entry is an entry that the FIB is not expect to resolve |
| 215 | * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). |
| 216 | * Instead the client/source provides the DPO to link to. |
| 217 | * This add is reference counting per-source. So n 'removes' are required |
| 218 | * for n 'adds', if the entry is no longer required. |
| 219 | * |
| 220 | * @param fib_index |
| 221 | * The index of the FIB |
| 222 | * |
| 223 | * @param prefix |
| 224 | * The prefix to add |
| 225 | * |
| 226 | * @param source |
| 227 | * The ID of the client/source adding the entry. |
| 228 | * |
| 229 | * @param flags |
| 230 | * Flags for the entry. |
| 231 | * |
| 232 | * @param dpo |
| 233 | * The DPO to link to. |
| 234 | * |
| 235 | * @return |
| 236 | * the index of the fib_entry_t that is created (or existed already). |
| 237 | */ |
| 238 | extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, |
| 239 | const fib_prefix_t *prefix, |
| 240 | fib_source_t source, |
| 241 | fib_entry_flag_t stype, |
| 242 | const dpo_id_t *dpo); |
| 243 | |
| 244 | /** |
| 245 | * @brief |
| 246 | * Update a 'special' entry to the FIB that links to the DPO passed |
| 247 | * A special entry is an entry that the FIB is not expect to resolve |
| 248 | * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup). |
| 249 | * Instead the client/source provides the DPO to link to. |
| 250 | * Special entries are add/remove reference counted per-source. So n |
| 251 | * 'removes' are required for n 'adds', if the entry is no longer required. |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 252 | * An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add' |
| 253 | * is therefore assumed to act on the reference instance of that add. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 254 | * |
| 255 | * @param fib_entry_index |
| 256 | * The index of the FIB entry to update |
| 257 | * |
| 258 | * @param source |
| 259 | * The ID of the client/source adding the entry. |
| 260 | * |
| 261 | * @param flags |
| 262 | * Flags for the entry. |
| 263 | * |
| 264 | * @param dpo |
| 265 | * The DPO to link to. |
| 266 | * |
| 267 | * @return |
| 268 | * the index of the fib_entry_t that is created (or existed already). |
| 269 | */ |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 270 | extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index, |
| 271 | const fib_prefix_t *prefix, |
| 272 | fib_source_t source, |
| 273 | fib_entry_flag_t stype, |
| 274 | const dpo_id_t *dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * @brief |
| 278 | * Remove a 'special' entry from the FIB. |
| 279 | * This add is reference counting per-source. So n 'removes' are required |
| 280 | * for n 'adds', if the entry is no longer required. |
| 281 | * |
| 282 | * @param fib_index |
| 283 | * The index of the FIB |
| 284 | * |
| 285 | * @param prefix |
| 286 | * The prefix to remove |
| 287 | * |
| 288 | * @param source |
| 289 | * The ID of the client/source adding the entry. |
| 290 | * |
| 291 | */ |
| 292 | extern void fib_table_entry_special_remove(u32 fib_index, |
| 293 | const fib_prefix_t *prefix, |
| 294 | fib_source_t source); |
| 295 | |
| 296 | /** |
| 297 | * @brief |
| 298 | * Add one path to an entry (aka route) in the FIB. If the entry does not |
| 299 | * exist, it will be created. |
| 300 | * See the documentation for fib_route_path_t for more descirptions of |
| 301 | * the path parameters. |
| 302 | * |
| 303 | * @param fib_index |
| 304 | * The index of the FIB |
| 305 | * |
| 306 | * @param prefix |
| 307 | * The prefix for the entry to add |
| 308 | * |
| 309 | * @param source |
| 310 | * The ID of the client/source adding the entry. |
| 311 | * |
| 312 | * @param flags |
| 313 | * Flags for the entry. |
| 314 | * |
| 315 | * @paran next_hop_proto |
| 316 | * The protocol of the next hop. This cannot be derived in the event that |
| 317 | * the next hop is all zeros. |
| 318 | * |
| 319 | * @param next_hop |
| 320 | * The address of the next-hop. |
| 321 | * |
| 322 | * @param sw_if_index |
| 323 | * The index of the interface. |
| 324 | * |
| 325 | * @param next_hop_fib_index, |
| 326 | * The fib index of the next-hop for recursive resolution |
| 327 | * |
| 328 | * @param next_hop_weight |
| 329 | * [un]equal cost path weight |
| 330 | * |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 331 | * @param next_hop_label_stack |
| 332 | * The path's out-going label stack. NULL is there is none. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 333 | * |
| 334 | * @param pf |
| 335 | * Flags for the path |
| 336 | * |
| 337 | * @return |
| 338 | * the index of the fib_entry_t that is created (or existed already). |
| 339 | */ |
| 340 | extern fib_node_index_t fib_table_entry_path_add(u32 fib_index, |
| 341 | const fib_prefix_t *prefix, |
| 342 | fib_source_t source, |
| 343 | fib_entry_flag_t flags, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 344 | dpo_proto_t next_hop_proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 345 | const ip46_address_t *next_hop, |
| 346 | u32 next_hop_sw_if_index, |
| 347 | u32 next_hop_fib_index, |
| 348 | u32 next_hop_weight, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 349 | fib_mpls_label_t *next_hop_label_stack, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 350 | fib_route_path_flags_t pf); |
| 351 | /** |
| 352 | * @brief |
| 353 | * Add n paths to an entry (aka route) in the FIB. If the entry does not |
| 354 | * exist, it will be created. |
| 355 | * See the documentation for fib_route_path_t for more descirptions of |
| 356 | * the path parameters. |
| 357 | * |
| 358 | * @param fib_index |
| 359 | * The index of the FIB |
| 360 | * |
| 361 | * @param prefix |
| 362 | * The prefix for the entry to add |
| 363 | * |
| 364 | * @param source |
| 365 | * The ID of the client/source adding the entry. |
| 366 | * |
| 367 | * @param flags |
| 368 | * Flags for the entry. |
| 369 | * |
| 370 | * @param rpaths |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 371 | * A vector of paths. Not const since they may be modified. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 372 | * |
| 373 | * @return |
| 374 | * the index of the fib_entry_t that is created (or existed already). |
| 375 | */ |
| 376 | extern fib_node_index_t fib_table_entry_path_add2(u32 fib_index, |
| 377 | const fib_prefix_t *prefix, |
| 378 | fib_source_t source, |
| 379 | fib_entry_flag_t flags, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 380 | fib_route_path_t *rpath); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * @brief |
| 384 | * remove one path to an entry (aka route) in the FIB. If this is the entry's |
| 385 | * last path, then the entry will be removed, unless it has other sources. |
| 386 | * See the documentation for fib_route_path_t for more descirptions of |
| 387 | * the path parameters. |
| 388 | * |
| 389 | * @param fib_index |
| 390 | * The index of the FIB |
| 391 | * |
| 392 | * @param prefix |
| 393 | * The prefix for the entry to add |
| 394 | * |
| 395 | * @param source |
| 396 | * The ID of the client/source adding the entry. |
| 397 | * |
| 398 | * @paran next_hop_proto |
| 399 | * The protocol of the next hop. This cannot be derived in the event that |
| 400 | * the next hop is all zeros. |
| 401 | * |
| 402 | * @param next_hop |
| 403 | * The address of the next-hop. |
| 404 | * |
| 405 | * @param sw_if_index |
| 406 | * The index of the interface. |
| 407 | * |
| 408 | * @param next_hop_fib_index, |
| 409 | * The fib index of the next-hop for recursive resolution |
| 410 | * |
| 411 | * @param next_hop_weight |
| 412 | * [un]equal cost path weight |
| 413 | * |
| 414 | * @param pf |
| 415 | * Flags for the path |
| 416 | */ |
| 417 | extern void fib_table_entry_path_remove(u32 fib_index, |
| 418 | const fib_prefix_t *prefix, |
| 419 | fib_source_t source, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 420 | dpo_proto_t next_hop_proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 421 | const ip46_address_t *next_hop, |
| 422 | u32 next_hop_sw_if_index, |
| 423 | u32 next_hop_fib_index, |
| 424 | u32 next_hop_weight, |
| 425 | fib_route_path_flags_t pf); |
| 426 | |
| 427 | /** |
| 428 | * @brief |
| 429 | * Remove n paths to an entry (aka route) in the FIB. If this is the entry's |
| 430 | * last path, then the entry will be removed, unless it has other sources. |
| 431 | * See the documentation for fib_route_path_t for more descirptions of |
| 432 | * the path parameters. |
| 433 | * |
| 434 | * @param fib_index |
| 435 | * The index of the FIB |
| 436 | * |
| 437 | * @param prefix |
| 438 | * The prefix for the entry to add |
| 439 | * |
| 440 | * @param source |
| 441 | * The ID of the client/source adding the entry. |
| 442 | * |
| 443 | * @param rpaths |
| 444 | * A vector of paths. |
| 445 | */ |
| 446 | extern void fib_table_entry_path_remove2(u32 fib_index, |
| 447 | const fib_prefix_t *prefix, |
| 448 | fib_source_t source, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 449 | fib_route_path_t *paths); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 450 | |
| 451 | /** |
| 452 | * @brief |
| 453 | * Update an entry to have a new set of paths. If the entry does not |
| 454 | * exist, it will be created. |
| 455 | * The difference between an 'path-add' and an update, is that path-add is |
| 456 | * an incremental addition of paths, whereas an update is a wholesale swap. |
| 457 | * |
| 458 | * @param fib_index |
| 459 | * The index of the FIB |
| 460 | * |
| 461 | * @param prefix |
| 462 | * The prefix for the entry to add |
| 463 | * |
| 464 | * @param source |
| 465 | * The ID of the client/source adding the entry. |
| 466 | * |
| 467 | * @param rpaths |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 468 | * A vector of paths. Not const since they may be modified. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 469 | * |
| 470 | * @return |
| 471 | * the index of the fib_entry_t that is created (or existed already). |
| 472 | */ |
| 473 | extern fib_node_index_t fib_table_entry_update(u32 fib_index, |
| 474 | const fib_prefix_t *prefix, |
| 475 | fib_source_t source, |
| 476 | fib_entry_flag_t flags, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 477 | fib_route_path_t *paths); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 478 | |
| 479 | /** |
| 480 | * @brief |
| 481 | * Update the entry to have just one path. If the entry does not |
| 482 | * exist, it will be created. |
| 483 | * See the documentation for fib_route_path_t for more descirptions of |
| 484 | * the path parameters. |
| 485 | * |
| 486 | * @param fib_index |
| 487 | * The index of the FIB |
| 488 | * |
| 489 | * @param prefix |
| 490 | * The prefix for the entry to add |
| 491 | * |
| 492 | * @param source |
| 493 | * The ID of the client/source adding the entry. |
| 494 | * |
| 495 | * @param flags |
| 496 | * Flags for the entry. |
| 497 | * |
| 498 | * @paran next_hop_proto |
| 499 | * The protocol of the next hop. This cannot be derived in the event that |
| 500 | * the next hop is all zeros. |
| 501 | * |
| 502 | * @param next_hop |
| 503 | * The address of the next-hop. |
| 504 | * |
| 505 | * @param sw_if_index |
| 506 | * The index of the interface. |
| 507 | * |
| 508 | * @param next_hop_fib_index, |
| 509 | * The fib index of the next-hop for recursive resolution |
| 510 | * |
| 511 | * @param next_hop_weight |
| 512 | * [un]equal cost path weight |
| 513 | * |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 514 | * @param next_hop_label_stack |
| 515 | * The path's out-going label stack. NULL is there is none. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 516 | * |
| 517 | * @param pf |
| 518 | * Flags for the path |
| 519 | * |
| 520 | * @return |
| 521 | * the index of the fib_entry_t that is created (or existed already). |
| 522 | */ |
| 523 | extern fib_node_index_t fib_table_entry_update_one_path(u32 fib_index, |
| 524 | const fib_prefix_t *prefix, |
| 525 | fib_source_t source, |
| 526 | fib_entry_flag_t flags, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 527 | dpo_proto_t next_hop_proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 528 | const ip46_address_t *next_hop, |
| 529 | u32 next_hop_sw_if_index, |
| 530 | u32 next_hop_fib_index, |
| 531 | u32 next_hop_weight, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 532 | fib_mpls_label_t *next_hop_label_stack, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 533 | fib_route_path_flags_t pf); |
| 534 | |
| 535 | /** |
| 536 | * @brief |
| 537 | * Add a MPLS local label for the prefix/route. If the entry does not |
| 538 | * exist, it will be created. In theory more than one local label can be |
| 539 | * added, but this is not yet supported. |
| 540 | * |
| 541 | * @param fib_index |
| 542 | * The index of the FIB |
| 543 | * |
| 544 | * @param prefix |
| 545 | * The prefix for the entry to which to add the label |
| 546 | * |
| 547 | * @param label |
| 548 | * The MPLS label to add |
| 549 | * |
| 550 | * @return |
| 551 | * the index of the fib_entry_t that is created (or existed already). |
| 552 | */ |
| 553 | extern fib_node_index_t fib_table_entry_local_label_add(u32 fib_index, |
| 554 | const fib_prefix_t *prefix, |
| 555 | mpls_label_t label); |
| 556 | /** |
| 557 | * @brief |
| 558 | * remove a MPLS local label for the prefix/route. |
| 559 | * |
| 560 | * @param fib_index |
| 561 | * The index of the FIB |
| 562 | * |
| 563 | * @param prefix |
| 564 | * The prefix for the entry to which to add the label |
| 565 | * |
| 566 | * @param label |
| 567 | * The MPLS label to add |
| 568 | */ |
| 569 | extern void fib_table_entry_local_label_remove(u32 fib_index, |
| 570 | const fib_prefix_t *prefix, |
| 571 | mpls_label_t label); |
| 572 | |
| 573 | /** |
| 574 | * @brief |
| 575 | * Delete a FIB entry. If the entry has no more sources, then it is |
| 576 | * removed from the table. |
| 577 | * |
| 578 | * @param fib_index |
| 579 | * The index of the FIB |
| 580 | * |
| 581 | * @param prefix |
| 582 | * The prefix for the entry to remove |
| 583 | * |
| 584 | * @param source |
| 585 | * The ID of the client/source adding the entry. |
| 586 | */ |
| 587 | extern void fib_table_entry_delete(u32 fib_index, |
| 588 | const fib_prefix_t *prefix, |
| 589 | fib_source_t source); |
| 590 | |
| 591 | /** |
| 592 | * @brief |
| 593 | * Delete a FIB entry. If the entry has no more sources, then it is |
| 594 | * removed from the table. |
| 595 | * |
| 596 | * @param entry_index |
| 597 | * The index of the FIB entry |
| 598 | * |
| 599 | * @param source |
| 600 | * The ID of the client/source adding the entry. |
| 601 | */ |
| 602 | extern void fib_table_entry_delete_index(fib_node_index_t entry_index, |
| 603 | fib_source_t source); |
| 604 | |
| 605 | /** |
| 606 | * @brief |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 607 | * Return the stats index for a FIB entry |
| 608 | * @param fib_index |
| 609 | * The table's FIB index |
| 610 | * @param prefix |
| 611 | * The entry's prefix's |
| 612 | */ |
| 613 | extern u32 fib_table_entry_get_stats_index(u32 fib_index, |
| 614 | const fib_prefix_t *prefix); |
| 615 | |
| 616 | /** |
| 617 | * @brief |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 618 | * Flush all entries from a table for the source |
| 619 | * |
| 620 | * @param fib_index |
| 621 | * The index of the FIB |
| 622 | * |
| 623 | * @paran proto |
| 624 | * The protocol of the entries in the table |
| 625 | * |
| 626 | * @param source |
| 627 | * the source to flush |
| 628 | */ |
| 629 | extern void fib_table_flush(u32 fib_index, |
| 630 | fib_protocol_t proto, |
| 631 | fib_source_t source); |
| 632 | |
| 633 | /** |
| 634 | * @brief |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 635 | * Resync all entries from a table for the source |
| 636 | * this is the mark part of the mark and sweep algorithm. |
| 637 | * All entries in this FIB that are sourced by 'source' are marked |
| 638 | * as stale. |
| 639 | * |
| 640 | * @param fib_index |
| 641 | * The index of the FIB |
| 642 | * |
| 643 | * @paran proto |
| 644 | * The protocol of the entries in the table |
| 645 | * |
| 646 | * @param source |
| 647 | * the source to flush |
| 648 | */ |
| 649 | extern void fib_table_mark(u32 fib_index, |
| 650 | fib_protocol_t proto, |
| 651 | fib_source_t source); |
| 652 | |
| 653 | /** |
| 654 | * @brief |
| 655 | * Signal that the table has converged, i.e. all updates are complete. |
| 656 | * this is the sweep part of the mark and sweep algorithm. |
| 657 | * All entries in this FIB that are sourced by 'source' and marked |
| 658 | * as stale are flushed. |
| 659 | * |
| 660 | * @param fib_index |
| 661 | * The index of the FIB |
| 662 | * |
| 663 | * @paran proto |
| 664 | * The protocol of the entries in the table |
| 665 | * |
| 666 | * @param source |
| 667 | * the source to flush |
| 668 | */ |
| 669 | extern void fib_table_sweep(u32 fib_index, |
| 670 | fib_protocol_t proto, |
| 671 | fib_source_t source); |
| 672 | |
| 673 | /** |
| 674 | * @brief |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 675 | * Get the index of the FIB bound to the interface |
| 676 | * |
| 677 | * @paran proto |
| 678 | * The protocol of the FIB (and thus the entries therein) |
| 679 | * |
| 680 | * @param sw_if_index |
| 681 | * The interface index |
| 682 | * |
| 683 | * @return fib_index |
| 684 | * The index of the FIB |
| 685 | */ |
| 686 | extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, |
| 687 | u32 sw_if_index); |
| 688 | |
| 689 | /** |
| 690 | * @brief |
| 691 | * Get the Table-ID of the FIB bound to the interface |
| 692 | * |
| 693 | * @paran proto |
| 694 | * The protocol of the FIB (and thus the entries therein) |
| 695 | * |
| 696 | * @param sw_if_index |
| 697 | * The interface index |
| 698 | * |
| 699 | * @return fib_index |
| 700 | * The tableID of the FIB |
| 701 | */ |
| 702 | extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto, |
| 703 | u32 sw_if_index); |
| 704 | |
| 705 | /** |
| 706 | * @brief |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 707 | * Get the Table-ID of the FIB from protocol and index |
| 708 | * |
| 709 | * @param fib_index |
| 710 | * The FIB index |
| 711 | * |
| 712 | * @paran proto |
| 713 | * The protocol of the FIB (and thus the entries therein) |
| 714 | * |
| 715 | * @return fib_index |
| 716 | * The tableID of the FIB |
| 717 | */ |
| 718 | extern u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto); |
| 719 | |
| 720 | /** |
| 721 | * @brief |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 722 | * Get the index of the FIB for a Table-ID. This DOES NOT create the |
| 723 | * FIB if it does not exist. |
| 724 | * |
| 725 | * @paran proto |
| 726 | * The protocol of the FIB (and thus the entries therein) |
| 727 | * |
| 728 | * @param table-id |
| 729 | * The Table-ID |
| 730 | * |
| 731 | * @return fib_index |
| 732 | * The index of the FIB, which may be INVALID. |
| 733 | */ |
| 734 | extern u32 fib_table_find(fib_protocol_t proto, u32 table_id); |
| 735 | |
| 736 | |
| 737 | /** |
| 738 | * @brief |
| 739 | * Get the index of the FIB for a Table-ID. This DOES create the |
| 740 | * FIB if it does not exist. |
| 741 | * |
| 742 | * @paran proto |
| 743 | * The protocol of the FIB (and thus the entries therein) |
| 744 | * |
| 745 | * @param table-id |
| 746 | * The Table-ID |
| 747 | * |
| 748 | * @return fib_index |
| 749 | * The index of the FIB |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 750 | * |
| 751 | * @param source |
| 752 | * The ID of the client/source. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 753 | */ |
| 754 | extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 755 | u32 table_id, |
| 756 | fib_source_t source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 757 | |
| 758 | /** |
| 759 | * @brief |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 760 | * Get the index of the FIB for a Table-ID. This DOES create the |
| 761 | * FIB if it does not exist. |
| 762 | * |
| 763 | * @paran proto |
| 764 | * The protocol of the FIB (and thus the entries therein) |
| 765 | * |
| 766 | * @param table-id |
| 767 | * The Table-ID |
| 768 | * |
| 769 | * @return fib_index |
| 770 | * The index of the FIB |
| 771 | * |
| 772 | * @param source |
| 773 | * The ID of the client/source. |
| 774 | * |
| 775 | * @param name |
| 776 | * The client is choosing the name they want the table to have |
| 777 | */ |
| 778 | extern u32 fib_table_find_or_create_and_lock_w_name(fib_protocol_t proto, |
| 779 | u32 table_id, |
| 780 | fib_source_t source, |
| 781 | const u8 *name); |
| 782 | |
| 783 | /** |
| 784 | * @brief |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 785 | * Create a new table with no table ID. This means it does not get |
| 786 | * added to the hash-table and so can only be found by using the index returned. |
| 787 | * |
| 788 | * @paran proto |
| 789 | * The protocol of the FIB (and thus the entries therein) |
| 790 | * |
| 791 | * @param fmt |
| 792 | * A string to describe the table |
| 793 | * |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 794 | * @param source |
| 795 | * The ID of the client/source. |
| 796 | * |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 797 | * @return fib_index |
| 798 | * The index of the FIB |
| 799 | */ |
| 800 | extern u32 fib_table_create_and_lock(fib_protocol_t proto, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 801 | fib_source_t source, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 802 | const char *const fmt, |
| 803 | ...); |
| 804 | |
| 805 | /** |
| 806 | * @brief |
| 807 | * Get the flow hash configured used by the table |
| 808 | * |
| 809 | * @param fib_index |
| 810 | * The index of the FIB |
| 811 | * |
| 812 | * @paran proto |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 813 | * The protocol the packets the flow hash will be calculated for. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 814 | * |
| 815 | * @return The flow hash config |
| 816 | */ |
| 817 | extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index, |
| 818 | fib_protocol_t proto); |
| 819 | |
| 820 | /** |
| 821 | * @brief |
Neale Ranns | 41da54f | 2017-05-02 10:15:19 -0700 | [diff] [blame] | 822 | * Get the flow hash configured used by the protocol |
| 823 | * |
| 824 | * @paran proto |
| 825 | * The protocol of the FIB (and thus the entries therein) |
| 826 | * |
| 827 | * @return The flow hash config |
| 828 | */ |
| 829 | extern flow_hash_config_t fib_table_get_default_flow_hash_config(fib_protocol_t proto); |
| 830 | |
| 831 | /** |
| 832 | * @brief |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 833 | * Set the flow hash configured used by the table |
| 834 | * |
| 835 | * @param fib_index |
| 836 | * The index of the FIB |
| 837 | * |
| 838 | * @paran proto |
| 839 | * The protocol of the FIB (and thus the entries therein) |
| 840 | * |
| 841 | * @param hash_config |
| 842 | * The flow-hash config to set |
| 843 | * |
| 844 | * @return none |
| 845 | */ |
| 846 | extern void fib_table_set_flow_hash_config(u32 fib_index, |
| 847 | fib_protocol_t proto, |
| 848 | flow_hash_config_t hash_config); |
| 849 | |
| 850 | /** |
| 851 | * @brief |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 852 | * Take a reference counting lock on the table |
| 853 | * |
| 854 | * @param fib_index |
| 855 | * The index of the FIB |
| 856 | * |
| 857 | * @paran proto |
| 858 | * The protocol of the FIB (and thus the entries therein) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 859 | * |
| 860 | * @param source |
| 861 | * The ID of the client/source. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 862 | */ |
| 863 | extern void fib_table_unlock(u32 fib_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 864 | fib_protocol_t proto, |
| 865 | fib_source_t source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 866 | |
| 867 | /** |
| 868 | * @brief |
| 869 | * Release a reference counting lock on the table. When the last lock |
| 870 | * has gone. the FIB is deleted. |
| 871 | * |
| 872 | * @param fib_index |
| 873 | * The index of the FIB |
| 874 | * |
| 875 | * @paran proto |
| 876 | * The protocol of the FIB (and thus the entries therein) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 877 | * |
| 878 | * @param source |
| 879 | * The ID of the client/source. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 880 | */ |
| 881 | extern void fib_table_lock(u32 fib_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 882 | fib_protocol_t proto, |
| 883 | fib_source_t source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 884 | |
| 885 | /** |
| 886 | * @brief |
| 887 | * Return the number of entries in the FIB added by a given source. |
| 888 | * |
| 889 | * @param fib_index |
| 890 | * The index of the FIB |
| 891 | * |
| 892 | * @paran proto |
| 893 | * The protocol of the FIB (and thus the entries therein) |
| 894 | * |
| 895 | * @return number of sourced entries. |
| 896 | */ |
| 897 | extern u32 fib_table_get_num_entries(u32 fib_index, |
| 898 | fib_protocol_t proto, |
| 899 | fib_source_t source); |
| 900 | |
| 901 | /** |
| 902 | * @brief |
| 903 | * Get a pointer to a FIB table |
| 904 | */ |
| 905 | extern fib_table_t *fib_table_get(fib_node_index_t index, |
| 906 | fib_protocol_t proto); |
| 907 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 908 | /** |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 909 | * @brief return code controlling how a table walk proceeds |
| 910 | */ |
| 911 | typedef enum fib_table_walk_rc_t_ |
| 912 | { |
| 913 | /** |
| 914 | * Continue on to the next entry |
| 915 | */ |
| 916 | FIB_TABLE_WALK_CONTINUE, |
| 917 | /** |
| 918 | * Do no traverse down this sub-tree |
| 919 | */ |
| 920 | FIB_TABLE_WALK_SUB_TREE_STOP, |
| 921 | /** |
| 922 | * Stop the walk completely |
| 923 | */ |
| 924 | FIB_TABLE_WALK_STOP, |
| 925 | } fib_table_walk_rc_t; |
| 926 | |
| 927 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 928 | * @brief Call back function when walking entries in a FIB table |
| 929 | */ |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 930 | typedef fib_table_walk_rc_t (*fib_table_walk_fn_t)(fib_node_index_t fei, |
| 931 | void *ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 932 | |
| 933 | /** |
| 934 | * @brief Walk all entries in a FIB table |
| 935 | * N.B: This is NOT safe to deletes. If you need to delete walk the whole |
| 936 | * table and store elements in a vector, then delete the elements |
| 937 | */ |
| 938 | extern void fib_table_walk(u32 fib_index, |
| 939 | fib_protocol_t proto, |
| 940 | fib_table_walk_fn_t fn, |
| 941 | void *ctx); |
| 942 | |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 943 | /** |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 944 | * @brief Walk all entries in a sub-tree FIB table. The 'root' paraneter |
| 945 | * is the prefix at the root of the sub-tree. |
| 946 | * N.B: This is NOT safe to deletes. If you need to delete walk the whole |
| 947 | * table and store elements in a vector, then delete the elements |
| 948 | */ |
| 949 | extern void fib_table_sub_tree_walk(u32 fib_index, |
| 950 | fib_protocol_t proto, |
| 951 | const fib_prefix_t *root, |
| 952 | fib_table_walk_fn_t fn, |
| 953 | void *ctx); |
| 954 | |
| 955 | /** |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 956 | * @brief format (display) the memory used by the FIB tables |
| 957 | */ |
| 958 | extern u8 *format_fib_table_memory(u8 *s, va_list *args); |
| 959 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 960 | /** |
| 961 | * Debug function |
| 962 | */ |
| 963 | #ifdef CLIB_DEBUG |
| 964 | extern void fib_table_assert_empty(const fib_table_t *fib_table); |
| 965 | #endif |
| 966 | |
| 967 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 968 | #endif |