Line data Source code
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_16_t *ip4_fib_16s;
21 :
22 : void
23 830 : ip4_fib_16_table_init (ip4_fib_16_t *fib)
24 : {
25 830 : ip4_mtrie_16_init(&fib->mtrie);
26 830 : }
27 :
28 : void
29 252 : ip4_fib_16_table_free (ip4_fib_16_t *fib)
30 : {
31 252 : ip4_mtrie_16_free(&fib->mtrie);
32 252 : }
33 :
34 : /*
35 : * ip4_fib_16_table_lookup_exact_match
36 : *
37 : * Exact match prefix lookup
38 : */
39 : fib_node_index_t
40 190295 : ip4_fib_16_table_lookup_exact_match (const ip4_fib_16_t *fib,
41 : const ip4_address_t *addr,
42 : u32 len)
43 : {
44 190295 : return (ip4_fib_hash_table_lookup_exact_match(&fib->hash, addr, len));
45 : }
46 :
47 : /*
48 : * ip4_fib_16_table_lookup_adj
49 : *
50 : * Longest prefix match
51 : */
52 : index_t
53 100 : ip4_fib_16_table_lookup_lb (ip4_fib_16_t *fib,
54 : const ip4_address_t *addr)
55 : {
56 100 : return (ip4_fib_hash_table_lookup_lb(&fib->hash, addr));
57 : }
58 :
59 : /*
60 : * ip4_fib_16_table_lookup
61 : *
62 : * Longest prefix match
63 : */
64 : fib_node_index_t
65 118111 : ip4_fib_16_table_lookup (const ip4_fib_16_t *fib,
66 : const ip4_address_t *addr,
67 : u32 len)
68 : {
69 118111 : return (ip4_fib_hash_table_lookup(&fib->hash, addr, len));
70 : }
71 :
72 : void
73 21954 : ip4_fib_16_table_entry_insert (ip4_fib_16_t *fib,
74 : const ip4_address_t *addr,
75 : u32 len,
76 : fib_node_index_t fib_entry_index)
77 : {
78 21954 : return (ip4_fib_hash_table_entry_insert(&fib->hash, addr, len, fib_entry_index));
79 : }
80 :
81 : void
82 15812 : ip4_fib_16_table_entry_remove (ip4_fib_16_t *fib,
83 : const ip4_address_t *addr,
84 : u32 len)
85 : {
86 15812 : return (ip4_fib_hash_table_entry_remove(&fib->hash, addr, len));
87 : }
88 :
89 : void
90 21662 : ip4_fib_16_table_fwding_dpo_update (ip4_fib_16_t *fib,
91 : const ip4_address_t *addr,
92 : u32 len,
93 : const dpo_id_t *dpo)
94 : {
95 21662 : ip4_mtrie_16_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
96 21662 : }
97 :
98 : void
99 15505 : ip4_fib_16_table_fwding_dpo_remove (ip4_fib_16_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 15505 : cover_prefix = fib_entry_get_prefix(cover_index);
114 15505 : cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
115 :
116 15505 : ip4_mtrie_16_route_del(&fib->mtrie,
117 : addr, len, dpo->dpoi_index,
118 15505 : cover_prefix->fp_len,
119 : cover_dpo->dpoi_index);
120 15505 : }
121 :
122 : void
123 3169 : ip4_fib_16_table_walk (ip4_fib_16_t *fib,
124 : fib_table_walk_fn_t fn,
125 : void *ctx)
126 : {
127 3169 : ip4_fib_hash_table_walk(&fib->hash, fn, ctx);
128 3169 : }
129 :
130 : void
131 56 : ip4_fib_16_table_sub_tree_walk (ip4_fib_16_t *fib,
132 : const fib_prefix_t *root,
133 : fib_table_walk_fn_t fn,
134 : void *ctx)
135 : {
136 56 : ip4_fib_hash_table_sub_tree_walk(&fib->hash, root, fn, ctx);
137 56 : }
|