Neale Ranns | d695333 | 2021-08-10 07:39:18 +0000 | [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 | * @brief The IPv4 FIB Hash table |
| 17 | */ |
| 18 | |
| 19 | #ifndef __IP4_FIB_HASH_H__ |
| 20 | #define __IP4_FIB_HASH_H__ |
| 21 | |
| 22 | #include <vlib/vlib.h> |
| 23 | #include <vnet/ip/ip.h> |
| 24 | |
| 25 | typedef struct ip4_fib_hash_t_ |
| 26 | { |
| 27 | /* Hash table for each prefix length mapping. */ |
| 28 | uword *fib_entry_by_dst_address[33]; |
| 29 | |
| 30 | /* Table ID (hash key) for this FIB. */ |
| 31 | u32 table_id; |
| 32 | } ip4_fib_hash_t; |
| 33 | |
| 34 | extern fib_node_index_t ip4_fib_hash_table_lookup(const ip4_fib_hash_t *fib, |
| 35 | const ip4_address_t *addr, |
| 36 | u32 len); |
| 37 | extern index_t ip4_fib_hash_table_lookup_lb(const ip4_fib_hash_t *fib, |
| 38 | const ip4_address_t *addr); |
| 39 | extern fib_node_index_t ip4_fib_hash_table_lookup_exact_match(const ip4_fib_hash_t *fib, |
| 40 | const ip4_address_t *addr, |
| 41 | u32 len); |
| 42 | |
| 43 | extern void ip4_fib_hash_table_entry_remove(ip4_fib_hash_t *fib, |
| 44 | const ip4_address_t *addr, |
| 45 | u32 len); |
| 46 | |
| 47 | extern void ip4_fib_hash_table_entry_insert(ip4_fib_hash_t *fib, |
| 48 | const ip4_address_t *addr, |
| 49 | u32 len, |
| 50 | fib_node_index_t fib_entry_index); |
| 51 | extern void ip4_fib_hash_table_init(ip4_fib_hash_t *fib); |
| 52 | extern void ip4_fib_hash_table_destroy(ip4_fib_hash_t *fib); |
| 53 | |
| 54 | /** |
| 55 | * @brief Walk all entries in a FIB table |
| 56 | * N.B: This is NOT safe to deletes. If you need to delete walk the whole |
| 57 | * table and store elements in a vector, then delete the elements |
| 58 | */ |
| 59 | extern void ip4_fib_hash_table_walk(ip4_fib_hash_t *fib, |
| 60 | fib_table_walk_fn_t fn, |
| 61 | void *ctx); |
| 62 | |
| 63 | /** |
| 64 | * @brief Walk all entries in a sub-tree of the FIB table |
| 65 | * N.B: This is NOT safe to deletes. If you need to delete walk the whole |
| 66 | * table and store elements in a vector, then delete the elements |
| 67 | */ |
| 68 | extern void ip4_fib_hash_table_sub_tree_walk(ip4_fib_hash_t *fib, |
| 69 | const fib_prefix_t *root, |
| 70 | fib_table_walk_fn_t fn, |
| 71 | void *ctx); |
| 72 | |
| 73 | #endif |
| 74 | |