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 | #include <vnet/fib/fib_table.h> |
| 17 | #include <vnet/fib/fib_entry.h> |
| 18 | #include <vnet/fib/ip4_fib.h> |
| 19 | |
| 20 | ip4_fib_8_t *ip4_fib_8s; |
| 21 | |
| 22 | void |
| 23 | ip4_fib_8_table_init (ip4_fib_8_t *fib) |
| 24 | { |
| 25 | ip4_mtrie_8_init(&fib->mtrie); |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | ip4_fib_8_table_free (ip4_fib_8_t *fib) |
| 30 | { |
| 31 | ip4_mtrie_8_free(&fib->mtrie); |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * ip4_fib_8_table_lookup_exact_match |
| 36 | * |
| 37 | * Exact match prefix lookup |
| 38 | */ |
| 39 | fib_node_index_t |
| 40 | ip4_fib_8_table_lookup_exact_match (const ip4_fib_8_t *fib, |
| 41 | const ip4_address_t *addr, |
| 42 | u32 len) |
| 43 | { |
| 44 | return (ip4_fib_hash_table_lookup_exact_match(&fib->hash, addr, len)); |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * ip4_fib_8_table_lookup_adj |
| 49 | * |
| 50 | * Longest prefix match |
| 51 | */ |
| 52 | index_t |
| 53 | ip4_fib_8_table_lookup_lb (ip4_fib_8_t *fib, |
| 54 | const ip4_address_t *addr) |
| 55 | { |
| 56 | return (ip4_fib_hash_table_lookup_lb(&fib->hash, addr)); |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * ip4_fib_8_table_lookup |
| 61 | * |
| 62 | * Longest prefix match |
| 63 | */ |
| 64 | fib_node_index_t |
| 65 | ip4_fib_8_table_lookup (const ip4_fib_8_t *fib, |
| 66 | const ip4_address_t *addr, |
| 67 | u32 len) |
| 68 | { |
| 69 | return (ip4_fib_hash_table_lookup(&fib->hash, addr, len)); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | ip4_fib_8_table_entry_insert (ip4_fib_8_t *fib, |
| 74 | const ip4_address_t *addr, |
| 75 | u32 len, |
| 76 | fib_node_index_t fib_entry_index) |
| 77 | { |
| 78 | return (ip4_fib_hash_table_entry_insert(&fib->hash, addr, len, fib_entry_index)); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | ip4_fib_8_table_entry_remove (ip4_fib_8_t *fib, |
| 83 | const ip4_address_t *addr, |
| 84 | u32 len) |
| 85 | { |
| 86 | return (ip4_fib_hash_table_entry_remove(&fib->hash, addr, len)); |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | ip4_fib_8_table_fwding_dpo_update (ip4_fib_8_t *fib, |
| 91 | const ip4_address_t *addr, |
| 92 | u32 len, |
| 93 | const dpo_id_t *dpo) |
| 94 | { |
| 95 | ip4_mtrie_8_route_add(&fib->mtrie, addr, len, dpo->dpoi_index); |
| 96 | } |
| 97 | |
| 98 | void |
| 99 | ip4_fib_8_table_fwding_dpo_remove (ip4_fib_8_t *fib, |
| 100 | const ip4_address_t *addr, |
| 101 | u32 len, |
| 102 | const dpo_id_t *dpo, |
| 103 | u32 cover_index) |
| 104 | { |
| 105 | const fib_prefix_t *cover_prefix; |
| 106 | const dpo_id_t *cover_dpo; |
| 107 | |
| 108 | /* |
| 109 | * We need to pass the MTRIE the LB index and address length of the |
| 110 | * covering prefix, so it can fill the plys with the correct replacement |
| 111 | * for the entry being removed |
| 112 | */ |
| 113 | cover_prefix = fib_entry_get_prefix(cover_index); |
| 114 | cover_dpo = fib_entry_contribute_ip_forwarding(cover_index); |
| 115 | |
| 116 | ip4_mtrie_8_route_del(&fib->mtrie, |
| 117 | addr, len, dpo->dpoi_index, |
| 118 | cover_prefix->fp_len, |
| 119 | cover_dpo->dpoi_index); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | ip4_fib_8_table_walk (ip4_fib_8_t *fib, |
| 124 | fib_table_walk_fn_t fn, |
| 125 | void *ctx) |
| 126 | { |
| 127 | ip4_fib_hash_table_walk(&fib->hash, fn, ctx); |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | ip4_fib_8_table_sub_tree_walk (ip4_fib_8_t *fib, |
| 132 | const fib_prefix_t *root, |
| 133 | fib_table_walk_fn_t fn, |
| 134 | void *ctx) |
| 135 | { |
| 136 | ip4_fib_hash_table_sub_tree_walk(&fib->hash, root, fn, ctx); |
| 137 | } |