FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
fib_entry_src.h
Go to the documentation of this file.
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 #ifndef __FIB_ENTRY_SRC_H__
17 #define __FIB_ENTRY_SRC_H__
18 
19 #include "fib_entry.h"
20 #include "fib_path_list.h"
21 #include "fib_internal.h"
22 
23 /**
24  * Debug macro
25  */
27 
28 #define FIB_ENTRY_DBG(_e, _fmt, _args...) \
29 { \
30  vlib_log_debug(fib_entry_logger, \
31  "[@%d:[%U]:%U:%U]: " _fmt, \
32  fib_entry_get_index(_e), \
33  format_fib_prefix, \
34  &_e->fe_prefix, \
35  format_fib_entry_flags, \
36  fib_entry_get_flags_i(_e), \
37  format_fib_source, \
38  fib_entry_get_source_i(_e), \
39  ##_args); \
40 }
41 
42 /**
43  * Source initialisation Function
44  */
46 
47 /**
48  * Source deinitialisation Function
49  */
51 
52 /**
53  * Source activation. Called when the source is the new best source on the entry.
54  * Return non-zero if the entry can now install, 0 otherwise
55  */
57  const fib_entry_t *fib_entry);
58 
59 /**
60  * Source re-activation. Called when the source is updated and remains
61  * the best source.
62  */
64  const fib_entry_t *fib_entry);
65 
66 /**
67  * Source Deactivate.
68  * Called when the source is no longer best source on the entry
69  */
71  const fib_entry_t *fib_entry);
72 
73 /**
74  * Source Add.
75  * Called when the source is added to the entry
76  */
78  const fib_entry_t *entry,
81  const dpo_id_t *dpo);
82 
83 /**
84  * Source Remove.
85  */
87 
88 /**
89  * Result from a cover update/change
90  */
95 
96 /**
97  * Cover changed. the source should re-evaluate its cover.
98  */
101  const fib_entry_t *fib_entry);
102 
103 /**
104  * Cover updated. The cover the source has, has updated (i.e. its forwarding)
105  * the source may need to re-evaluate.
106  */
109  const fib_entry_t *fib_entry);
110 
111 /**
112  * Forwarding updated. Notification that the forwarding information for the
113  * entry has been updated. This notification is sent to all sources, not just
114  * the active best.
115  */
117  const fib_entry_t *fib_entry,
118  fib_source_t best_source);
119 
120 /**
121  * Installed. Notification that the source is now installed as
122  * the entry's forwarding source.
123  */
125  const fib_entry_t *fib_entry);
126 
127 /**
128  * format.
129  */
130 typedef u8* (*fib_entry_src_format_t)(fib_entry_src_t *src,
131  u8* s);
132 
133 /**
134  * Source path add
135  * the source is adding a new path
136  */
138  const fib_entry_t *fib_entry,
139  fib_path_list_flags_t pl_flags,
140  const fib_route_path_t *path);
141 
142 /**
143  * Source path remove
144  * the source is remoinvg a path
145  */
147  fib_path_list_flags_t pl_flags,
148  const fib_route_path_t *path);
149 
150 /**
151  * Source path replace/swap
152  * the source is providing a new set of paths
153  */
155  const fib_entry_t *fib_entry,
156  fib_path_list_flags_t pl_flags,
157  const fib_route_path_t *path);
158 
159 /**
160  * Set source specific opaque data
161  */
163  const fib_entry_t *fib_entry,
164  const void *data);
165 
166 /**
167  * Get source specific opaque data
168  */
169 typedef const void* (*fib_entry_src_get_data_t)(fib_entry_src_t *src,
170  const fib_entry_t *fib_entry);
171 
172 /**
173  * Contribute forwarding to interpose inthe chain
174  */
175 typedef const dpo_id_t* (*fib_entry_src_contribute_interpose_t)(const fib_entry_src_t *src,
176  const fib_entry_t *fib_entry);
177 
178 /**
179  * The fib entry flags for this source are changing
180  */
182  const fib_entry_t *fib_entry,
183  fib_entry_flag_t new_flags);
184 
185 /**
186  * The fib entry flags for this source are changing
187  */
188 typedef void (*fib_entry_src_copy_t)(const fib_entry_src_t *orig_src,
189  const fib_entry_t *fib_entry,
190  fib_entry_src_t *copy_src);
191 
192 /**
193  * Virtual function table each FIB entry source will register
194  */
195 typedef struct fib_entry_src_vft_t_ {
217 
218 #define FOR_EACH_SRC_ADDED(_entry, _src, _source, action) \
219 { \
220  vec_foreach(_src, (_entry)->fe_srcs) \
221  { \
222  if (_src->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED) { \
223  _source = (_src)->fes_src; \
224  action; \
225  } \
226  } \
227 }
228 
229 #define FIB_ENTRY_SRC_VFT_INVOKE(_fe, esrc, func, args) \
230 { \
231  const fib_entry_src_vft_t *_vft; \
232  fib_node_index_t _fei = fib_entry_get_index(_fe); \
233  _vft = fib_entry_src_get_vft(esrc); \
234  if (_vft->func) { \
235  (esrc)->fes_flags &= ~FIB_ENTRY_SRC_FLAG_STALE; \
236  _vft->func args; \
237  } \
238  _fe = fib_entry_get(_fei); \
239 }
240 
241 #define FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, func, args) \
242 { \
243  const fib_entry_src_vft_t *_vft; \
244  _vft = fib_entry_src_get_vft(esrc); \
245  if (_vft->func) { \
246  (esrc)->fes_flags &= ~FIB_ENTRY_SRC_FLAG_STALE; \
247  return (_vft->func args); \
248  } \
249 }
250 
251 #define FIB_ENTRY_SRC_VFT_EXISTS(esrc, func) \
252 { \
253  const fib_entry_src_vft_t *_vft; \
254  _vft = fib_entry_src_get_vft(esrc); \
255  (_vft->func); \
256 }
257 
259  const fib_entry_src_t *esrc);
260 
261 extern u8* fib_entry_src_format(fib_entry_t *entry,
262  fib_source_t source,
263  u8* s);
264 
266  const fib_entry_src_vft_t *vft);
267 
269  fib_entry_t *entry,
270  fib_entry_src_t *esrc);
271 
273  fib_entry_t *fib_entry,
274  fib_entry_src_t *esrc);
275 
276 extern void fib_entry_src_action_activate(fib_entry_t *fib_entry,
277  fib_source_t source);
278 
279 extern void fib_entry_src_action_deactivate(fib_entry_t *fib_entry,
280  fib_source_t source);
281 extern void fib_entry_src_action_reactivate(fib_entry_t *fib_entry,
282  fib_source_t source);
283 
285  fib_source_t source,
287  const dpo_id_t *dpo);
289  fib_source_t source,
291  const dpo_id_t *dpo);
292 
294  fib_source_t source);
297  fib_source_t source);
298 
299 extern void fib_entry_src_action_install(fib_entry_t *fib_entry,
300  fib_source_t source);
301 
302 extern void fib_entry_src_action_uninstall(fib_entry_t *fib_entry);
303 
305  fib_source_t source,
307  const fib_route_path_t *path);
308 
310  fib_source_t source,
312  const fib_route_path_t *path);
313 
315  fib_source_t source,
316  const fib_route_path_t *path);
317 
319  fib_source_t source);
320 extern void fib_entry_src_inherit (const fib_entry_t *cover,
321  fib_entry_t *covered);
322 
324  const fib_entry_t *fib_entry);
325 extern fib_source_t fib_entry_get_source_i(const fib_entry_t *fib_entry);
326 extern fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry);
327 
329  fib_entry_flag_t eflags);
330 
333 
334 extern void fib_entry_src_mk_lb (fib_entry_t *fib_entry,
335  const fib_entry_src_t *esrc,
337  dpo_id_t *dpo_lb);
338 
339 extern fib_protocol_t fib_entry_get_proto(const fib_entry_t * fib_entry);
340 extern dpo_proto_t fib_entry_get_dpo_proto(const fib_entry_t * fib_entry);
341 
342 extern void fib_entry_source_change(fib_entry_t *fib_entry,
343  fib_source_t old_source,
344  fib_source_t new_source);
345 
346 /*
347  * Per-source registration. declared here so we save a separate .h file for each
348  */
349 extern void fib_entry_src_default_register(void);
350 extern void fib_entry_src_rr_register(void);
351 extern void fib_entry_src_interface_register(void);
352 extern void fib_entry_src_interpose_register(void);
353 extern void fib_entry_src_drop_register(void);
354 extern void fib_entry_src_simple_register(void);
355 extern void fib_entry_src_api_register(void);
356 extern void fib_entry_src_adj_register(void);
357 extern void fib_entry_src_mpls_register(void);
358 extern void fib_entry_src_lisp_register(void);
359 
360 extern void fib_entry_src_module_init(void);
361 
362 #endif
int(* fib_entry_src_activate_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Source activation.
Definition: fib_entry_src.h:56
void(* fib_entry_src_path_add_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry, fib_path_list_flags_t pl_flags, const fib_route_path_t *path)
Source path add the source is adding a new path.
void fib_entry_src_action_install(fib_entry_t *fib_entry, fib_source_t source)
fib_source_t fib_entry_get_source_i(const fib_entry_t *fib_entry)
enum fib_source_t_ fib_source_t
The different sources that can create a route.
fib_entry_src_init_t fesv_init
void fib_entry_src_behaviour_register(fib_source_behaviour_t source, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:61
void(* fib_entry_src_deinit_t)(fib_entry_src_t *src)
Source deinitialisation Function.
Definition: fib_entry_src.h:50
void(* fib_entry_src_path_remove_t)(fib_entry_src_t *src, fib_path_list_flags_t pl_flags, const fib_route_path_t *path)
Source path remove the source is remoinvg a path.
An entry in a FIB table.
Definition: fib_entry.h:305
dpo_proto_t fib_entry_get_dpo_proto(const fib_entry_t *fib_entry)
Definition: fib_entry.c:75
fib_entry_src_set_data_t fesv_set_data
fib_node_bw_reason_flag_t bw_reason
Definition: fib_entry_src.h:93
fib_entry_src_copy_t fesv_copy
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:103
const fib_entry_src_vft_t * fib_entry_src_get_vft(const fib_entry_src_t *esrc)
Get the VFT for a given source.
Definition: fib_entry_src.c:38
A representation of a path as described by a route producer.
Definition: fib_types.h:490
fib_entry_src_cover_res_t fib_entry_src_action_cover_update(fib_entry_t *fib_entry, fib_entry_src_t *esrc)
Virtual function table each FIB entry source will register.
fib_entry_t * fib_entry_src_action_installed(fib_entry_t *fib_entry, fib_source_t source)
Information related to the source of a FIB entry.
Definition: fib_entry.h:197
fib_entry_src_cover_res_t(* fib_entry_src_cover_update_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Cover updated.
vl_api_address_t src
Definition: gre.api:54
enum fib_source_behaviour_t_ fib_source_behaviour_t
Each source has a defined behaviour that controls how entries behave that have that source...
Result from a cover update/change.
Definition: fib_entry_src.h:91
fib_entry_src_contribute_interpose_t fesv_contribute_interpose
void fib_entry_src_action_deactivate(fib_entry_t *fib_entry, fib_source_t source)
fib_entry_t * fib_entry_src_action_add(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
vl_api_fib_path_t path
Definition: mfib_types.api:34
vlib_log_class_t fib_entry_logger
Debug macro.
Definition: fib_entry.c:48
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:89
void fib_entry_src_mpls_register(void)
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
void fib_entry_src_adj_register(void)
void fib_entry_src_mk_lb(fib_entry_t *fib_entry, const fib_entry_src_t *esrc, fib_forward_chain_type_t fct, dpo_id_t *dpo_lb)
u32 vlib_log_class_t
Definition: vlib.h:51
void fib_entry_src_lisp_register(void)
fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry)
fib_entry_src_cover_update_t fesv_cover_update
void(* fib_entry_src_init_t)(fib_entry_src_t *src)
Source initialisation Function.
Definition: fib_entry_src.h:45
fib_entry_src_cover_change_t fesv_cover_change
void(* fib_entry_src_remove_t)(fib_entry_src_t *src)
Source Remove.
Definition: fib_entry_src.h:86
void(* fib_entry_src_add_t)(fib_entry_src_t *src, const fib_entry_t *entry, fib_entry_flag_t flags, dpo_proto_t proto, const dpo_id_t *dpo)
Source Add.
Definition: fib_entry_src.h:77
void fib_entry_src_simple_register(void)
u8 *(* fib_entry_src_format_t)(fib_entry_src_t *src, u8 *s)
format.
fib_entry_src_path_add_t fesv_path_add
const void *(* fib_entry_src_get_data_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Get source specific opaque data.
void(* fib_entry_src_installed_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Installed.
fib_entry_src_get_data_t fesv_get_data
void fib_entry_src_inherit(const fib_entry_t *cover, fib_entry_t *covered)
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
fib_protocol_t fib_entry_get_proto(const fib_entry_t *fib_entry)
Definition: fib_entry.c:69
void fib_entry_src_api_register(void)
u16 install
Definition: fib_entry_src.h:92
fib_entry_t * fib_entry_src_action_path_add(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *path)
fib_entry_src_flag_t fib_entry_src_action_remove_or_update_inherit(fib_entry_t *fib_entry, fib_source_t source)
void fib_entry_src_action_uninstall(fib_entry_t *fib_entry)
void fib_entry_src_drop_register(void)
void(* fib_entry_src_copy_t)(const fib_entry_src_t *orig_src, const fib_entry_t *fib_entry, fib_entry_src_t *copy_src)
The fib entry flags for this source are changing.
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
void(* fib_entry_src_deactivate_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Source Deactivate.
Definition: fib_entry_src.h:70
fib_entry_src_flag_t fib_entry_src_action_remove(fib_entry_t *fib_entry, fib_source_t source)
fib_entry_src_fwd_update_t fesv_fwd_update
vl_api_ip_proto_t proto
Definition: acl_types.api:50
fib_entry_src_deinit_t fesv_deinit
unsigned short u16
Definition: types.h:57
void fib_entry_src_interpose_register(void)
fib_entry_src_format_t fesv_format
fib_entry_src_cover_res_t(* fib_entry_src_cover_change_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Cover changed.
Definition: fib_entry_src.h:99
void fib_entry_src_default_register(void)
enum fib_node_bw_reason_flag_t_ fib_node_bw_reason_flag_t
Flags enum constructed from the reaons.
fib_entry_t * fib_entry_src_action_update(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
void fib_entry_src_rr_register(void)
fib_entry_src_remove_t fesv_remove
fib_entry_src_deactivate_t fesv_deactivate
void fib_entry_src_action_activate(fib_entry_t *fib_entry, fib_source_t source)
struct fib_entry_src_vft_t_ fib_entry_src_vft_t
Virtual function table each FIB entry source will register.
fib_entry_src_flag_change_t fesv_flags_change
enum fib_entry_flag_t_ fib_entry_flag_t
void fib_entry_src_interface_register(void)
void fib_entry_src_module_init(void)
void(* fib_entry_src_flag_change_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry, fib_entry_flag_t new_flags)
The fib entry flags for this source are changing.
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
void(* fib_entry_src_set_data_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry, const void *data)
Set source specific opaque data.
enum fib_entry_src_flag_t_ fib_entry_src_flag_t
int(* fib_entry_src_reactivate_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Source re-activation.
Definition: fib_entry_src.h:63
fib_entry_src_path_remove_t fesv_path_remove
fib_entry_src_path_swap_t fesv_path_swap
u8 * fib_entry_src_format(fib_entry_t *entry, fib_source_t source, u8 *s)
fib_entry_src_flag_t fib_entry_src_action_path_remove(fib_entry_t *fib_entry, fib_source_t source, const fib_route_path_t *path)
fib_forward_chain_type_t fib_entry_chain_type_fixup(const fib_entry_t *entry, fib_forward_chain_type_t fct)
Turn the chain type requested by the client into the one they really wanted.
fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags(fib_entry_flag_t eflags)
fib_entry_src_activate_t fesv_activate
fib_entry_t * fib_entry_src_action_path_swap(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *path)
struct fib_entry_src_cover_res_t_ fib_entry_src_cover_res_t
Result from a cover update/change.
const dpo_id_t *(* fib_entry_src_contribute_interpose_t)(const fib_entry_src_t *src, const fib_entry_t *fib_entry)
Contribute forwarding to interpose inthe chain.
fib_entry_src_add_t fesv_add
void(* fib_entry_src_fwd_update_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry, fib_source_t best_source)
Forwarding updated.
enum fib_path_list_flags_t_ fib_path_list_flags_t
void fib_entry_src_action_reactivate(fib_entry_t *fib_entry, fib_source_t source)
fib_entry_src_installed_t fesv_installed
fib_entry_src_reactivate_t fesv_reactivate
void fib_entry_source_change(fib_entry_t *fib_entry, fib_source_t old_source, fib_source_t new_source)
Definition: fib_entry.c:861
void(* fib_entry_src_path_swap_t)(fib_entry_src_t *src, const fib_entry_t *fib_entry, fib_path_list_flags_t pl_flags, const fib_route_path_t *path)
Source path replace/swap the source is providing a new set of paths.
fib_entry_src_cover_res_t fib_entry_src_action_cover_change(fib_entry_t *entry, fib_entry_src_t *esrc)
fib_forward_chain_type_t fib_entry_get_default_chain_type(const fib_entry_t *fib_entry)
Definition: fib_entry.c:81