blob: 88154ef90be3b4c9cd3102a5e85a16c6c8d0e88e [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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 "fib_entry.h"
17#include "fib_entry_src.h"
18#include "fib_path_list.h"
19#include "fib_internal.h"
20#include "fib_table.h"
21#include "fib_entry_cover.h"
22#include "fib_attached_export.h"
23
24/**
25 * Source initialisation Function
26 */
27static void
28fib_entry_src_interface_init (fib_entry_src_t *src)
29{
Neale Ranns2303cb12018-02-21 04:57:17 -080030 src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
31 src->u.interface.fesi_sibling = FIB_NODE_INDEX_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010032}
33
34static void
Neale Ranns9a69a602017-03-26 10:56:33 -070035fib_entry_src_interface_add (fib_entry_src_t *src,
36 const fib_entry_t *entry,
37 fib_entry_flag_t flags,
Neale Rannsda78f952017-05-24 09:15:43 -070038 dpo_proto_t proto,
Neale Ranns9a69a602017-03-26 10:56:33 -070039 const dpo_id_t *dpo)
40{
41 src->fes_pl = fib_path_list_create_special(
42 proto,
43 fib_entry_src_flags_2_path_list_flags(flags),
44 dpo);
45}
46
47static void
48fib_entry_src_interface_remove (fib_entry_src_t *src)
49{
50 src->fes_pl = FIB_NODE_INDEX_INVALID;
51}
52
53static void
Neale Ranns0bfe5d82016-08-25 15:29:12 +010054fib_entry_src_interface_path_swap (fib_entry_src_t *src,
55 const fib_entry_t *entry,
56 fib_path_list_flags_t pl_flags,
57 const fib_route_path_t *paths)
58{
59 ip_adjacency_t *adj;
60
61 src->fes_pl = fib_path_list_create(pl_flags, paths);
62
63 /*
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -070064 * this is a hack to get the entry's prefix into the glean adjacency
65 * so that it is available for fast retrieval in the switch path.
Neale Ranns0bfe5d82016-08-25 15:29:12 +010066 */
67 if (!(FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags))
68 {
Neale Ranns3fd99042019-12-16 00:53:11 +000069 adj_index_t ai;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010070
Neale Ranns3fd99042019-12-16 00:53:11 +000071 ai = fib_path_list_get_adj(src->fes_pl,
72 fib_entry_get_default_chain_type(entry));
73 if (INDEX_INVALID != ai)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010074 {
Neale Ranns3fd99042019-12-16 00:53:11 +000075 adj = adj_get(ai);
76
77 if (IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index)
78 {
79 /*
80 * the connected prefix will link to a glean on a non-p2p
81 * u.interface.
82 */
83 adj->sub_type.glean.receive_addr = entry->fe_prefix.fp_addr;
84 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +010085 }
86 }
87}
88
89/*
90 * Source activate.
91 * Called when the source is teh new longer best source on the entry
92 */
93static int
94fib_entry_src_interface_activate (fib_entry_src_t *src,
95 const fib_entry_t *fib_entry)
96{
97 fib_entry_t *cover;
98
99 if (FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags)
100 {
101 /*
102 * Track the covering attached/connected cover. This is so that
103 * during an attached export of the cover, this local prefix is
104 * also exported
105 */
Neale Ranns2303cb12018-02-21 04:57:17 -0800106 src->u.interface.fesi_cover =
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100107 fib_table_get_less_specific(fib_entry->fe_fib_index,
108 &fib_entry->fe_prefix);
109
Neale Ranns2303cb12018-02-21 04:57:17 -0800110 ASSERT(FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100111
Neale Ranns2303cb12018-02-21 04:57:17 -0800112 cover = fib_entry_get(src->u.interface.fesi_cover);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100113
Neale Ranns2303cb12018-02-21 04:57:17 -0800114 src->u.interface.fesi_sibling =
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100115 fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
116 }
117
118 return (!0);
119}
120
121
122/*
123 * Source Deactivate.
124 * Called when the source is no longer best source on the entry
125 */
126static void
127fib_entry_src_interface_deactivate (fib_entry_src_t *src,
128 const fib_entry_t *fib_entry)
129{
130 fib_entry_t *cover;
131
132 /*
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700133 * remove the dependency on the covering entry
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100134 */
Neale Ranns2303cb12018-02-21 04:57:17 -0800135 if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100136 {
Neale Ranns2303cb12018-02-21 04:57:17 -0800137 cover = fib_entry_get(src->u.interface.fesi_cover);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100138
Neale Ranns2303cb12018-02-21 04:57:17 -0800139 fib_entry_cover_untrack(cover, src->u.interface.fesi_sibling);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100140
Neale Ranns2303cb12018-02-21 04:57:17 -0800141 src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100142 }
143}
144
145static fib_entry_src_cover_res_t
146fib_entry_src_interface_cover_change (fib_entry_src_t *src,
147 const fib_entry_t *fib_entry)
148{
149 fib_entry_src_cover_res_t res = {
150 .install = !0,
151 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
152 };
153
Neale Ranns2303cb12018-02-21 04:57:17 -0800154 if (FIB_NODE_INDEX_INVALID == src->u.interface.fesi_cover)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100155 {
156 /*
157 * not tracking the cover. surprised we got poked?
158 */
159 return (res);
160 }
161
162 /*
163 * this function is called when this entry's cover has a more specific
164 * entry inserted benaeth it. That does not necessarily mean that this
165 * entry is covered by the new prefix. check that
166 */
Neale Ranns2303cb12018-02-21 04:57:17 -0800167 if (src->u.interface.fesi_cover !=
168 fib_table_get_less_specific(fib_entry->fe_fib_index,
169 &fib_entry->fe_prefix))
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100170 {
171 fib_entry_src_interface_deactivate(src, fib_entry);
172 fib_entry_src_interface_activate(src, fib_entry);
173 }
174 return (res);
175}
176
177static void
178fib_entry_src_interface_installed (fib_entry_src_t *src,
179 const fib_entry_t *fib_entry)
180{
181 /*
182 * The interface source now rules! poke our cover to get exported
183 */
184 fib_entry_t *cover;
185
Neale Ranns2303cb12018-02-21 04:57:17 -0800186 if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100187 {
Neale Ranns2303cb12018-02-21 04:57:17 -0800188 cover = fib_entry_get(src->u.interface.fesi_cover);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100189
190 fib_attached_export_covered_added(cover,
191 fib_entry_get_index(fib_entry));
192 }
193}
194
195static u8*
196fib_entry_src_interface_format (fib_entry_src_t *src,
197 u8* s)
198{
Neale Ranns2303cb12018-02-21 04:57:17 -0800199 return (format(s, " cover:%d", src->u.interface.fesi_cover));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100200}
201
202const static fib_entry_src_vft_t interface_src_vft = {
203 .fesv_init = fib_entry_src_interface_init,
Neale Ranns9a69a602017-03-26 10:56:33 -0700204 .fesv_add = fib_entry_src_interface_add,
205 .fesv_remove = fib_entry_src_interface_remove,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100206 .fesv_path_swap = fib_entry_src_interface_path_swap,
207 .fesv_activate = fib_entry_src_interface_activate,
208 .fesv_deactivate = fib_entry_src_interface_deactivate,
209 .fesv_format = fib_entry_src_interface_format,
210 .fesv_installed = fib_entry_src_interface_installed,
211 .fesv_cover_change = fib_entry_src_interface_cover_change,
212 /*
213 * not concerned about updates to the cover. the cover will
214 * decide to export or not
215 */
216};
217
218void
219fib_entry_src_interface_register (void)
220{
Neale Ranns3bab8f92019-12-04 06:11:00 +0000221 fib_entry_src_behaviour_register(FIB_SOURCE_BH_INTERFACE,
222 &interface_src_vft);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100223}