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 #ifndef __FIB_ENTRY_SRC_H__
17 #define __FIB_ENTRY_SRC_H__
19 #include "fib_entry.h"
20 #include "fib_path_list.h"
21 #include "fib_internal.h"
27 #define FIB_ENTRY_DBG(_e, _fmt, _args...) \
30 __tmp = format(__tmp, "e:[%d:%U", \
31 fib_entry_get_index(_e), \
32 format_ip46_address, \
33 &_e->fe_prefix.fp_addr, \
35 __tmp = format(__tmp, "/%d]:", \
36 _e->fe_prefix.fp_len); \
37 __tmp = format(__tmp, _fmt, ##_args); \
38 clib_warning("%s", __tmp); \
42 #define FIB_ENTRY_DBG(_e, _fmt, _args...)
46 * Source initialisation Function
48 typedef void (*fib_entry_src_init_t)(fib_entry_src_t *src);
51 * Source deinitialisation Function
53 typedef void (*fib_entry_src_deinit_t)(fib_entry_src_t *src);
56 * Source activation. Called when the source is the new best source on the entry.
57 * Return non-zero if the entry can now install, 0 otherwise
59 typedef int (*fib_entry_src_activate_t)(fib_entry_src_t *src,
60 const fib_entry_t *fib_entry);
63 * Source re-activation. Called when the source is updated and remains
66 typedef int (*fib_entry_src_reactivate_t)(fib_entry_src_t *src,
67 const fib_entry_t *fib_entry);
71 * Called when the source is no longer best source on the entry
73 typedef void (*fib_entry_src_deactivate_t)(fib_entry_src_t *src,
74 const fib_entry_t *fib_entry);
78 * Called when the source is added to the entry
80 typedef void (*fib_entry_src_add_t)(fib_entry_src_t *src,
81 const fib_entry_t *entry,
82 fib_entry_flag_t flags,
89 typedef void (*fib_entry_src_remove_t)(fib_entry_src_t *src);
92 * Result from a cover update/change
94 typedef struct fib_entry_src_cover_res_t_ {
96 fib_node_bw_reason_flag_t bw_reason;
97 } fib_entry_src_cover_res_t;
100 * Cover changed. the source should re-evaluate its cover.
102 typedef fib_entry_src_cover_res_t (*fib_entry_src_cover_change_t)(
103 fib_entry_src_t *src,
104 const fib_entry_t *fib_entry);
107 * Cover updated. The cover the source has, has updated (i.e. its forwarding)
108 * the source may need to re-evaluate.
110 typedef fib_entry_src_cover_res_t (*fib_entry_src_cover_update_t)(
111 fib_entry_src_t *src,
112 const fib_entry_t *fib_entry);
115 * Forwarding updated. Notification that the forwarding information for the
116 * entry has been updated. This notification is sent to all sources, not just
119 typedef void (*fib_entry_src_fwd_update_t)(fib_entry_src_t *src,
120 const fib_entry_t *fib_entry,
121 fib_source_t best_source);
124 * Installed. Notification that the source is now installed as
125 * the entry's forwarding source.
127 typedef void (*fib_entry_src_installed_t)(fib_entry_src_t *src,
128 const fib_entry_t *fib_entry);
133 typedef u8* (*fib_entry_src_format_t)(fib_entry_src_t *src,
138 * the source is adding a new path
140 typedef void (*fib_entry_src_path_add_t)(fib_entry_src_t *src,
141 const fib_entry_t *fib_entry,
142 fib_path_list_flags_t pl_flags,
143 const fib_route_path_t *path);
147 * the source is remoinvg a path
149 typedef void (*fib_entry_src_path_remove_t)(fib_entry_src_t *src,
150 fib_path_list_flags_t pl_flags,
151 const fib_route_path_t *path);
154 * Source path replace/swap
155 * the source is providing a new set of paths
157 typedef void (*fib_entry_src_path_swap_t)(fib_entry_src_t *src,
158 const fib_entry_t *fib_entry,
159 fib_path_list_flags_t pl_flags,
160 const fib_route_path_t *path);
163 * Set source specific opaque data
165 typedef void (*fib_entry_src_set_data_t)(fib_entry_src_t *src,
166 const fib_entry_t *fib_entry,
170 * Get source specific opaque data
172 typedef const void* (*fib_entry_src_get_data_t)(fib_entry_src_t *src,
173 const fib_entry_t *fib_entry);
176 * Contribute forwarding to interpose inthe chain
178 typedef const dpo_id_t* (*fib_entry_src_contribute_interpose_t)(const fib_entry_src_t *src,
179 const fib_entry_t *fib_entry);
182 * The fib entry flags for this source are changing
184 typedef void (*fib_entry_src_flag_change_t)(fib_entry_src_t *src,
185 const fib_entry_t *fib_entry,
186 fib_entry_flag_t new_flags);
189 * The fib entry flags for this source are changing
191 typedef void (*fib_entry_src_copy_t)(const fib_entry_src_t *orig_src,
192 const fib_entry_t *fib_entry,
193 fib_entry_src_t *copy_src);
196 * Virtual function table each FIB entry source will register
198 typedef struct fib_entry_src_vft_t_ {
199 fib_entry_src_init_t fesv_init;
200 fib_entry_src_deinit_t fesv_deinit;
201 fib_entry_src_activate_t fesv_activate;
202 fib_entry_src_deactivate_t fesv_deactivate;
203 fib_entry_src_reactivate_t fesv_reactivate;
204 fib_entry_src_add_t fesv_add;
205 fib_entry_src_remove_t fesv_remove;
206 fib_entry_src_path_swap_t fesv_path_swap;
207 fib_entry_src_path_add_t fesv_path_add;
208 fib_entry_src_path_remove_t fesv_path_remove;
209 fib_entry_src_cover_change_t fesv_cover_change;
210 fib_entry_src_cover_update_t fesv_cover_update;
211 fib_entry_src_format_t fesv_format;
212 fib_entry_src_installed_t fesv_installed;
213 fib_entry_src_fwd_update_t fesv_fwd_update;
214 fib_entry_src_get_data_t fesv_get_data;
215 fib_entry_src_set_data_t fesv_set_data;
216 fib_entry_src_contribute_interpose_t fesv_contribute_interpose;
217 fib_entry_src_flag_change_t fesv_flags_change;
218 fib_entry_src_copy_t fesv_copy;
219 } fib_entry_src_vft_t;
221 #define FOR_EACH_SRC_ADDED(_entry, _src, _source, action) \
223 vec_foreach(_src, (_entry)->fe_srcs) \
225 if (_src->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED) { \
226 _source = (_src)->fes_src; \
232 #define FIB_ENTRY_SRC_VFT_INVOKE(esrc, func, args) \
234 const fib_entry_src_vft_t *_vft; \
235 _vft = fib_entry_src_get_vft(esrc); \
240 #define FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, func, args) \
242 const fib_entry_src_vft_t *_vft; \
243 _vft = fib_entry_src_get_vft(esrc); \
245 return (_vft->func args); \
248 #define FIB_ENTRY_SRC_VFT_EXISTS(esrc, func) \
250 const fib_entry_src_vft_t *_vft; \
251 _vft = fib_entry_src_get_vft(esrc); \
255 extern const fib_entry_src_vft_t*fib_entry_src_get_vft(
256 const fib_entry_src_t *esrc);
258 extern u8* fib_entry_src_format(fib_entry_t *entry,
262 extern void fib_entry_src_register(fib_source_t source,
263 const fib_entry_src_vft_t *vft);
265 extern fib_entry_src_cover_res_t fib_entry_src_action_cover_change(
267 fib_entry_src_t *esrc);
269 extern fib_entry_src_cover_res_t fib_entry_src_action_cover_update(
270 fib_entry_t *fib_entry,
271 fib_entry_src_t *esrc);
273 extern void fib_entry_src_action_activate(fib_entry_t *fib_entry,
274 fib_source_t source);
276 extern void fib_entry_src_action_deactivate(fib_entry_t *fib_entry,
277 fib_source_t source);
278 extern void fib_entry_src_action_reactivate(fib_entry_t *fib_entry,
279 fib_source_t source);
281 extern fib_entry_t* fib_entry_src_action_add(fib_entry_t *fib_entry,
283 fib_entry_flag_t flags,
284 const dpo_id_t *dpo);
285 extern fib_entry_t* fib_entry_src_action_update(fib_entry_t *fib_entry,
287 fib_entry_flag_t flags,
288 const dpo_id_t *dpo);
290 extern fib_entry_src_flag_t fib_entry_src_action_remove(fib_entry_t *fib_entry,
291 fib_source_t source);
292 extern fib_entry_src_flag_t
293 fib_entry_src_action_remove_or_update_inherit(fib_entry_t *fib_entry,
294 fib_source_t source);
296 extern void fib_entry_src_action_install(fib_entry_t *fib_entry,
297 fib_source_t source);
299 extern void fib_entry_src_action_uninstall(fib_entry_t *fib_entry);
301 extern fib_entry_t* fib_entry_src_action_path_add(fib_entry_t *fib_entry,
303 fib_entry_flag_t flags,
304 const fib_route_path_t *path);
306 extern fib_entry_t* fib_entry_src_action_path_swap(fib_entry_t *fib_entry,
308 fib_entry_flag_t flags,
309 const fib_route_path_t *path);
311 extern fib_entry_src_flag_t fib_entry_src_action_path_remove(fib_entry_t *fib_entry,
313 const fib_route_path_t *path);
315 extern void fib_entry_src_action_installed(const fib_entry_t *fib_entry,
316 fib_source_t source);
317 extern void fib_entry_src_inherit (const fib_entry_t *cover,
318 fib_entry_t *covered);
320 extern fib_forward_chain_type_t fib_entry_get_default_chain_type(
321 const fib_entry_t *fib_entry);
322 extern fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry);
324 extern fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags(
325 fib_entry_flag_t eflags);
327 extern fib_forward_chain_type_t fib_entry_chain_type_fixup(const fib_entry_t *entry,
328 fib_forward_chain_type_t fct);
330 extern void fib_entry_src_mk_lb (fib_entry_t *fib_entry,
331 const fib_entry_src_t *esrc,
332 fib_forward_chain_type_t fct,
335 extern fib_protocol_t fib_entry_get_proto(const fib_entry_t * fib_entry);
336 extern dpo_proto_t fib_entry_get_dpo_proto(const fib_entry_t * fib_entry);
338 extern void fib_entry_source_change(fib_entry_t *fib_entry,
339 fib_source_t old_source,
340 fib_source_t new_source);
343 * Per-source registration. declared here so we save a separate .h file for each
345 extern void fib_entry_src_default_register(void);
346 extern void fib_entry_src_rr_register(void);
347 extern void fib_entry_src_interface_register(void);
348 extern void fib_entry_src_interpose_register(void);
349 extern void fib_entry_src_default_route_register(void);
350 extern void fib_entry_src_special_register(void);
351 extern void fib_entry_src_api_register(void);
352 extern void fib_entry_src_adj_register(void);
353 extern void fib_entry_src_mpls_register(void);
354 extern void fib_entry_src_lisp_register(void);
356 extern void fib_entry_src_module_init(void);