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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/fib/fib_table.h>
17 #include <vnet/fib/fib_entry.h>
18 #include <vnet/fib/ip4_fib.h>
20 ip4_fib_8_t *ip4_fib_8s;
23 ip4_fib_8_table_init (ip4_fib_8_t *fib)
25 ip4_mtrie_8_init(&fib->mtrie);
29 ip4_fib_8_table_free (ip4_fib_8_t *fib)
31 ip4_mtrie_8_free(&fib->mtrie);
35 * ip4_fib_8_table_lookup_exact_match
37 * Exact match prefix lookup
40 ip4_fib_8_table_lookup_exact_match (const ip4_fib_8_t *fib,
41 const ip4_address_t *addr,
44 return (ip4_fib_hash_table_lookup_exact_match(&fib->hash, addr, len));
48 * ip4_fib_8_table_lookup_adj
50 * Longest prefix match
53 ip4_fib_8_table_lookup_lb (ip4_fib_8_t *fib,
54 const ip4_address_t *addr)
56 return (ip4_fib_hash_table_lookup_lb(&fib->hash, addr));
60 * ip4_fib_8_table_lookup
62 * Longest prefix match
65 ip4_fib_8_table_lookup (const ip4_fib_8_t *fib,
66 const ip4_address_t *addr,
69 return (ip4_fib_hash_table_lookup(&fib->hash, addr, len));
73 ip4_fib_8_table_entry_insert (ip4_fib_8_t *fib,
74 const ip4_address_t *addr,
76 fib_node_index_t fib_entry_index)
78 return (ip4_fib_hash_table_entry_insert(&fib->hash, addr, len, fib_entry_index));
82 ip4_fib_8_table_entry_remove (ip4_fib_8_t *fib,
83 const ip4_address_t *addr,
86 return (ip4_fib_hash_table_entry_remove(&fib->hash, addr, len));
90 ip4_fib_8_table_fwding_dpo_update (ip4_fib_8_t *fib,
91 const ip4_address_t *addr,
95 ip4_mtrie_8_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
99 ip4_fib_8_table_fwding_dpo_remove (ip4_fib_8_t *fib,
100 const ip4_address_t *addr,
105 const fib_prefix_t *cover_prefix;
106 const dpo_id_t *cover_dpo;
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
113 cover_prefix = fib_entry_get_prefix(cover_index);
114 cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
116 ip4_mtrie_8_route_del(&fib->mtrie,
117 addr, len, dpo->dpoi_index,
118 cover_prefix->fp_len,
119 cover_dpo->dpoi_index);
123 ip4_fib_8_table_walk (ip4_fib_8_t *fib,
124 fib_table_walk_fn_t fn,
127 ip4_fib_hash_table_walk(&fib->hash, fn, ctx);
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,
136 ip4_fib_hash_table_sub_tree_walk(&fib->hash, root, fn, ctx);