blob: ca04716ed8fde79f33c898f96d64450b697ce7bc [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{
30 src->interface.fesi_cover = FIB_NODE_INDEX_INVALID;
31 src->interface.fesi_sibling = FIB_NODE_INDEX_INVALID;
32}
33
34static void
35fib_entry_src_interface_path_swap (fib_entry_src_t *src,
36 const fib_entry_t *entry,
37 fib_path_list_flags_t pl_flags,
38 const fib_route_path_t *paths)
39{
40 ip_adjacency_t *adj;
41
42 src->fes_pl = fib_path_list_create(pl_flags, paths);
43
44 /*
45 * this is a hack to get the entry's prefix into the glean adjacnecy
46 * so that it is available for fast retreival in the switch path.
47 */
48 if (!(FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags))
49 {
50 adj = adj_get(fib_path_list_get_adj(
51 src->fes_pl,
52 fib_entry_get_default_chain_type(entry)));
53
Neale Ranns5899fde2016-10-12 13:51:05 +010054 if (IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010055 {
56 /*
57 * the connected prefix will link to a glean on a non-p2p
58 * interface.
59 */
60 adj->sub_type.glean.receive_addr = entry->fe_prefix.fp_addr;
61 }
62 }
63}
64
65/*
66 * Source activate.
67 * Called when the source is teh new longer best source on the entry
68 */
69static int
70fib_entry_src_interface_activate (fib_entry_src_t *src,
71 const fib_entry_t *fib_entry)
72{
73 fib_entry_t *cover;
74
75 if (FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags)
76 {
77 /*
78 * Track the covering attached/connected cover. This is so that
79 * during an attached export of the cover, this local prefix is
80 * also exported
81 */
82 src->interface.fesi_cover =
83 fib_table_get_less_specific(fib_entry->fe_fib_index,
84 &fib_entry->fe_prefix);
85
86 ASSERT(FIB_NODE_INDEX_INVALID != src->interface.fesi_cover);
87
88 cover = fib_entry_get(src->interface.fesi_cover);
89
90 src->interface.fesi_sibling =
91 fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
92 }
93
94 return (!0);
95}
96
97
98/*
99 * Source Deactivate.
100 * Called when the source is no longer best source on the entry
101 */
102static void
103fib_entry_src_interface_deactivate (fib_entry_src_t *src,
104 const fib_entry_t *fib_entry)
105{
106 fib_entry_t *cover;
107
108 /*
109 * remove the depednecy on the covering entry
110 */
111 if (FIB_NODE_INDEX_INVALID != src->interface.fesi_cover)
112 {
113 cover = fib_entry_get(src->interface.fesi_cover);
114
115 fib_entry_cover_untrack(cover, src->interface.fesi_sibling);
116
117 src->interface.fesi_cover = FIB_NODE_INDEX_INVALID;
118 }
119}
120
121static fib_entry_src_cover_res_t
122fib_entry_src_interface_cover_change (fib_entry_src_t *src,
123 const fib_entry_t *fib_entry)
124{
125 fib_entry_src_cover_res_t res = {
126 .install = !0,
127 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
128 };
129
130 if (FIB_NODE_INDEX_INVALID == src->interface.fesi_cover)
131 {
132 /*
133 * not tracking the cover. surprised we got poked?
134 */
135 return (res);
136 }
137
138 /*
139 * this function is called when this entry's cover has a more specific
140 * entry inserted benaeth it. That does not necessarily mean that this
141 * entry is covered by the new prefix. check that
142 */
143 if (src->rr.fesr_cover != fib_table_get_less_specific(fib_entry->fe_fib_index,
144 &fib_entry->fe_prefix))
145 {
146 fib_entry_src_interface_deactivate(src, fib_entry);
147 fib_entry_src_interface_activate(src, fib_entry);
148 }
149 return (res);
150}
151
152static void
153fib_entry_src_interface_installed (fib_entry_src_t *src,
154 const fib_entry_t *fib_entry)
155{
156 /*
157 * The interface source now rules! poke our cover to get exported
158 */
159 fib_entry_t *cover;
160
161 if (FIB_NODE_INDEX_INVALID != src->interface.fesi_cover)
162 {
163 cover = fib_entry_get(src->interface.fesi_cover);
164
165 fib_attached_export_covered_added(cover,
166 fib_entry_get_index(fib_entry));
167 }
168}
169
170static u8*
171fib_entry_src_interface_format (fib_entry_src_t *src,
172 u8* s)
173{
174 return (format(s, "cover:%d", src->interface.fesi_cover));
175}
176
177const static fib_entry_src_vft_t interface_src_vft = {
178 .fesv_init = fib_entry_src_interface_init,
179 .fesv_path_swap = fib_entry_src_interface_path_swap,
180 .fesv_activate = fib_entry_src_interface_activate,
181 .fesv_deactivate = fib_entry_src_interface_deactivate,
182 .fesv_format = fib_entry_src_interface_format,
183 .fesv_installed = fib_entry_src_interface_installed,
184 .fesv_cover_change = fib_entry_src_interface_cover_change,
185 /*
186 * not concerned about updates to the cover. the cover will
187 * decide to export or not
188 */
189};
190
191void
192fib_entry_src_interface_register (void)
193{
194 fib_entry_src_register(FIB_SOURCE_INTERFACE, &interface_src_vft);
195}