FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
fib_entry_src_interpose.c
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 #include <vlib/vlib.h>
17 #include <vnet/ip/format.h>
18 #include <vnet/ip/lookup.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/dpo/drop_dpo.h>
21 
22 #include "fib_entry_src.h"
23 #include "fib_entry_src_rr.h"
24 #include "fib_entry_cover.h"
25 #include "fib_entry.h"
26 #include "fib_table.h"
27 
28 /*
29  * Source initialisation Function
30  */
31 static void
33 {
34  src->u.interpose.fesi_cover = FIB_NODE_INDEX_INVALID;
35  src->u.interpose.fesi_sibling = FIB_NODE_INDEX_INVALID;
36 }
37 
38 /*
39  * Source deinitialisation Function
40  */
41 static void
43 {
44  ASSERT(src->u.interpose.fesi_cover == FIB_NODE_INDEX_INVALID);
45 
46  src->u.interpose.fesi_cover = FIB_NODE_INDEX_INVALID;
47  src->u.interpose.fesi_sibling = FIB_NODE_INDEX_INVALID;
48 
49  dpo_reset(&src->u.interpose.fesi_dpo);
50 }
51 
52 static fib_entry_src_t *
54  const fib_entry_t *fib_entry)
55 {
56  fib_entry_src_t *next_src, *best_src = NULL;
57  fib_source_t source;
58 
59  FOR_EACH_SRC_ADDED(fib_entry, next_src, source,
60  ({
61  /*
62  * skip to the next best source after this one
63  */
64  switch (fib_source_cmp(source, src->fes_src))
65  {
66  case FIB_SOURCE_CMP_BETTER:
67  case FIB_SOURCE_CMP_EQUAL:
68  continue;
69  case FIB_SOURCE_CMP_WORSE:
70  best_src = next_src;
71  goto out;
72  }
73  }));
74  out:
75  return (best_src);
76 }
77 
78 /*
79  * Source activation. Called when the source is the new best source on the entry
80  */
81 static int
83  const fib_entry_t *fib_entry)
84 {
85  fib_entry_src_t *best_src;
86  fib_node_index_t old_pl;
87  fib_entry_t *cover;
88 
89  old_pl = src->fes_pl;
90  src->fes_pl = FIB_NODE_INDEX_INVALID;
91 
92  /*
93  * The goal here is to find a path-list that will contribute forwarding
94  * for the entry.
95  * First check this entry for other sources that have a path-list
96  */
97  best_src = fib_entry_src_rr_get_next_best(src, fib_entry);
98 
99  if (NULL != best_src)
100  {
101  const fib_entry_src_vft_t *vft;
102 
104  vft = fib_entry_src_get_vft(best_src);
105  /*
106  * there is another source for this entry. activate it so it
107  * can provide forwarding
108  */
109  if (NULL != vft->fesv_activate)
110  {
111  if (vft->fesv_activate(best_src, fib_entry))
112  {
113  /*
114  * next best source activated ok, use its path list
115  */
116  src->fes_pl = best_src->fes_pl;
117  }
118  else
119  {
120  /*
121  * the best source won't install so will use a drop
122  */
123  dpo_proto_t dproto;
124 
125  dproto = fib_proto_to_dpo(fib_entry->fe_prefix.fp_proto);
126 
127  src->fes_pl =
130  drop_dpo_get(dproto));
131  }
132  }
133  else
134  {
135  /*
136  * next best source does not require activation, use its path list
137  */
138  src->fes_pl = best_src->fes_pl;
139  }
140  }
141  else
142  {
143  /*
144  * find the covering prefix. become a dependent thereof.
145  * for IP there should always be a cover, though it may be the default route.
146  * For MPLS there is never a cover.
147  */
148  if (FIB_PROTOCOL_MPLS == fib_entry->fe_prefix.fp_proto)
149  {
152  NULL);
153  }
154  else
155  {
156  src->u.interpose.fesi_cover =
158  &fib_entry->fe_prefix);
159 
160  ASSERT(FIB_NODE_INDEX_INVALID != src->u.interpose.fesi_cover);
161 
162  cover = fib_entry_get(src->u.interpose.fesi_cover);
163 
164  src->u.interpose.fesi_sibling =
165  fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
166 
167  /*
168  * if the cover is attached then install an attached-host path
169  * (like an adj-fib). Otherwise inherit the forwarding from the cover
170  */
172  {
173  fib_entry_src_rr_resolve_via_connected(src, fib_entry, cover);
174  }
175  else
176  {
177  fib_entry_src_rr_use_covers_pl(src, fib_entry, cover);
178  }
179  }
180  }
181 
182  fib_path_list_unlock(old_pl);
183  fib_path_list_lock(src->fes_pl);
184 
185  /*
186  * return go for install
187  */
188  return (!0);
189 }
190 
191 /**
192  * Source Deactivate.
193  * Called when the source is no longer best source on the entry
194  */
195 static void
197  const fib_entry_t *fib_entry)
198 {
199  fib_entry_t *cover;
200 
201  if (FIB_NODE_INDEX_INVALID != src->u.interpose.fesi_cover)
202  {
203  /*
204  * remove the dependency on the covering entry, if that's
205  * what was contributing the path-list
206  */
207  cover = fib_entry_get(src->u.interpose.fesi_cover);
208  fib_entry_cover_untrack(cover, src->u.interpose.fesi_sibling);
209  src->u.interpose.fesi_cover = FIB_NODE_INDEX_INVALID;
210  }
211  else
212  {
213  fib_entry_src_t *best_src;
214 
215  best_src = fib_entry_src_rr_get_next_best(src, fib_entry);
216 
217  if (best_src)
218  {
220  /*
221  * there is another source for this entry. activate it so it
222  * can provide forwarding
223  */
224  FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, best_src, fesv_deactivate,
225  (best_src, fib_entry));
226  }
227  }
228 
229  fib_path_list_unlock(src->fes_pl);
230  src->fes_pl = FIB_NODE_INDEX_INVALID;
231  src->fes_entry_flags &= ~FIB_ENTRY_FLAGS_RR_INHERITED;
232 }
233 
234 static int
236  const fib_entry_t *fib_entry)
237 {
239  return (fib_entry_src_interpose_activate(src, fib_entry));
240 }
241 
244  const fib_entry_t *fib_entry)
245 {
247  .install = !0,
248  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
249  };
250 
251  if (FIB_NODE_INDEX_INVALID == src->u.interpose.fesi_cover)
252  {
253  /*
254  * the source may be added, but it is not active
255  * if it is not tracking the cover.
256  */
257  return (res);
258  }
259 
260  /*
261  * this function is called when this entry's cover has a more specific
262  * entry inserted beneath it. That does not necessarily mean that this
263  * entry is covered by the new prefix. check that
264  */
265  if (src->u.interpose.fesi_cover !=
267  &fib_entry->fe_prefix))
268  {
271 
272  /*
273  * dependent children need to re-resolve to the new forwarding info
274  */
276  }
277  return (res);
278 }
279 
280 static void
282  const fib_entry_t *entry,
285  const dpo_id_t *dpo)
286 {
287  dpo_copy(&src->u.interpose.fesi_dpo, dpo);
288 }
289 
290 static void
292 {
293  dpo_reset(&src->u.interpose.fesi_dpo);
294 }
295 
296 static void
298  const fib_entry_t *fib_entry,
299  const void *data)
300 {
301  const dpo_id_t *dpo = data;
302 
303  dpo_copy(&src->u.interpose.fesi_dpo, dpo);
304 }
305 
306 /**
307  * Contribute forwarding to interpose in the chain
308  */
310  const fib_entry_t *fib_entry)
311 {
312  return (&src->u.interpose.fesi_dpo);
313 }
314 
315 static void
317  const fib_entry_t *fib_entry,
318  fib_entry_src_t *copy_src)
319 {
320  copy_src->u.interpose.fesi_cover = orig_src->u.interpose.fesi_cover;
321 
322  if (FIB_NODE_INDEX_INVALID != copy_src->u.interpose.fesi_cover)
323  {
324  fib_entry_t *cover;
325 
326  cover = fib_entry_get(orig_src->u.interpose.fesi_cover);
327  copy_src->u.interpose.fesi_sibling =
328  fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
329  }
330 
331  dpo_copy(&copy_src->u.interpose.fesi_dpo,
332  &orig_src->u.interpose.fesi_dpo);
333 }
334 
335 static void
337  const fib_entry_t *fib_entry,
338  fib_entry_flag_t new_flags)
339 {
340  if (!(new_flags & FIB_ENTRY_FLAG_INTERPOSE))
341  {
342  /*
343  * stop tracking the source contributing forwarding
344  * and reset the interposer DPO
345  */
348  }
349 }
350 
351 static u8*
353  u8* s)
354 {
355  s = format(s, " cover:%d interpose:\n%U%U",
356  src->u.interpose.fesi_cover,
358  format_dpo_id, &src->u.interpose.fesi_dpo, 8);
359 
360  return (s);
361 }
362 
365  .fesv_deinit = fib_entry_src_interpose_deinit,
366  .fesv_activate = fib_entry_src_interpose_activate,
367  .fesv_reactivate = fib_entry_src_interpose_reactivate,
368  .fesv_deactivate = fib_entry_src_interpose_deactivate,
369  .fesv_cover_change = fib_entry_src_interpose_cover_change,
370  .fesv_cover_update = fib_entry_src_rr_cover_update,
371  .fesv_format = fib_entry_src_interpose_format,
372  .fesv_add = fib_entry_src_interpose_add,
373  .fesv_remove = fib_entry_src_interpose_remove,
374  .fesv_contribute_interpose = fib_entry_src_interpose_contribute,
375  .fesv_set_data = fib_entry_src_interpose_set_data,
376  .fesv_copy = fib_entry_src_interpose_copy,
377  .fesv_flags_change = fib_entry_src_interpose_flag_change,
378 };
379 
380 void
382 {
385 }
vlib.h
fib_entry_get_flags_i
fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry)
Definition: fib_entry_src.c:1887
fib_entry_src_t_::u
union fib_entry_src_t_::@292 u
Source specific info.
fib_entry.h
adj.h
FIB_PATH_LIST_FLAG_DROP
@ FIB_PATH_LIST_FLAG_DROP
Definition: fib_path_list.h:82
fib_entry_src_cover_res_t_
Result from a cover update/change.
Definition: fib_entry_src.h:91
FIB_NODE_BW_REASON_FLAG_NONE
@ FIB_NODE_BW_REASON_FLAG_NONE
Definition: fib_node.h:155
fib_entry_t_
An entry in a FIB table.
Definition: fib_entry.h:305
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
fib_entry_src_get_vft
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
fib_entry_src_interpose_activate
static int fib_entry_src_interpose_activate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interpose.c:82
FIB_ENTRY_FLAG_ATTACHED
@ FIB_ENTRY_FLAG_ATTACHED
Definition: fib_entry.h:114
fib_entry_src_t_
Information related to the source of a FIB entry.
Definition: fib_entry.h:197
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_table.h
fib_entry_src_interpose_remove
static void fib_entry_src_interpose_remove(fib_entry_src_t *src)
Definition: fib_entry_src_interpose.c:291
fib_entry_src_rr_resolve_via_connected
void fib_entry_src_rr_resolve_via_connected(fib_entry_src_t *src, const fib_entry_t *fib_entry, const fib_entry_t *cover)
Definition: fib_entry_src_rr.c:35
fib_source_cmp
fib_source_priority_cmp_t fib_source_cmp(fib_source_t s1, fib_source_t s2)
Definition: fib_source.c:76
FIB_ENTRY_SRC_VFT_INVOKE
#define FIB_ENTRY_SRC_VFT_INVOKE(_fe, esrc, func, args)
Definition: fib_entry_src.h:229
interpose_src_vft
const static fib_entry_src_vft_t interpose_src_vft
Definition: fib_entry_src_interpose.c:363
fib_entry_src_t_::interpose
struct fib_entry_src_t_::@292::@294 interpose
FIB_ENTRY_FLAG_INTERPOSE
@ FIB_ENTRY_FLAG_INTERPOSE
Definition: fib_entry.h:123
drop_dpo.h
FIB_NODE_BW_REASON_FLAG_EVALUATE
@ FIB_NODE_BW_REASON_FLAG_EVALUATE
Definition: fib_node.h:157
fib_path_list_unlock
void fib_path_list_unlock(fib_node_index_t path_list_index)
Definition: fib_path_list.c:1357
fib_entry_src.h
fib_entry_src_vft_t_
Virtual function table each FIB entry source will register.
Definition: fib_entry_src.h:195
fib_entry_flag_t
enum fib_entry_flag_t_ fib_entry_flag_t
fib_entry_src_interpose_contribute
const dpo_id_t * fib_entry_src_interpose_contribute(const fib_entry_src_t *src, const fib_entry_t *fib_entry)
Contribute forwarding to interpose in the chain.
Definition: fib_entry_src_interpose.c:309
fib_entry_src_interpose_init
static void fib_entry_src_interpose_init(fib_entry_src_t *src)
Definition: fib_entry_src_interpose.c:32
fib_entry_t_::fe_fib_index
u32 fe_fib_index
The index of the FIB table this entry is in.
Definition: fib_entry.h:318
format.h
fib_entry_cover.h
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
fib_entry_get_index
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:63
fib_entry_src_interpose_flag_change
static void fib_entry_src_interpose_flag_change(fib_entry_src_t *src, const fib_entry_t *fib_entry, fib_entry_flag_t new_flags)
Definition: fib_entry_src_interpose.c:336
fib_entry_src_rr_get_next_best
static fib_entry_src_t * fib_entry_src_rr_get_next_best(const fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interpose.c:53
src
vl_api_address_t src
Definition: gre.api:54
FIB_SOURCE_BH_INTERPOSE
@ FIB_SOURCE_BH_INTERPOSE
interpose
Definition: fib_source.h:223
fib_proto_to_dpo
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:343
format_dpo_id
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject.
Definition: dpo.c:150
fib_entry_src_interpose_set_data
static void fib_entry_src_interpose_set_data(fib_entry_src_t *src, const fib_entry_t *fib_entry, const void *data)
Definition: fib_entry_src_interpose.c:297
data
u8 data[128]
Definition: ipsec_types.api:95
fib_entry_src_rr_use_covers_pl
void fib_entry_src_rr_use_covers_pl(fib_entry_src_t *src, const fib_entry_t *fib_entry, const fib_entry_t *cover)
Definition: fib_entry_src_rr.c:91
FIB_ENTRY_FLAGS_RR_INHERITED
#define FIB_ENTRY_FLAGS_RR_INHERITED
Definition: fib_entry_src_rr.h:24
fib_path_list_create_special
fib_node_index_t fib_path_list_create_special(dpo_proto_t nh_proto, fib_path_list_flags_t flags, const dpo_id_t *dpo)
Definition: fib_path_list.c:774
dpo_copy
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:264
fib_entry_get
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
fib_entry_src_rr_cover_update
fib_entry_src_cover_res_t fib_entry_src_rr_cover_update(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_rr.c:256
FIB_PROTOCOL_MPLS
@ FIB_PROTOCOL_MPLS
Definition: fib_types.h:38
DPO_PROTO_MPLS
@ DPO_PROTO_MPLS
Definition: dpo.h:66
FOR_EACH_SRC_ADDED
#define FOR_EACH_SRC_ADDED(_entry, _src, _source, action)
Definition: fib_entry_src.h:218
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
fib_entry_cover_untrack
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
Definition: fib_entry_cover.c:45
fib_entry_src_cover_res_t_::bw_reason
fib_node_bw_reason_flag_t bw_reason
Definition: fib_entry_src.h:93
fib_entry_cover_track
u32 fib_entry_cover_track(fib_entry_t *cover, fib_node_index_t covered)
Definition: fib_entry_cover.c:22
fib_path_list_lock
void fib_path_list_lock(fib_node_index_t path_list_index)
Definition: fib_path_list.c:1344
drop_dpo_get
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
fib_entry_src_vft_t_::fesv_init
fib_entry_src_init_t fesv_init
Definition: fib_entry_src.h:196
fib_entry_t_::fe_prefix
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:314
u8
unsigned char u8
Definition: types.h:56
fib_entry_src_interpose_cover_change
static fib_entry_src_cover_res_t fib_entry_src_interpose_cover_change(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interpose.c:243
lookup.h
fib_entry_src_t_::fes_flags
fib_entry_src_flag_t fes_flags
Flags on the source.
Definition: fib_entry.h:221
fib_entry_src_vft_t_::fesv_activate
fib_entry_src_activate_t fesv_activate
Definition: fib_entry_src.h:198
fib_entry_src_interpose_register
void fib_entry_src_interpose_register(void)
Definition: fib_entry_src_interpose.c:381
fib_table_get_less_specific
fib_node_index_t fib_table_get_less_specific(u32 fib_index, const fib_prefix_t *prefix)
Get the less specific (covering) prefix.
Definition: fib_table.c:133
fib_entry_src_interpose_format
static u8 * fib_entry_src_interpose_format(fib_entry_src_t *src, u8 *s)
Definition: fib_entry_src_interpose.c:352
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
fib_source_t
enum fib_source_t_ fib_source_t
The different sources that can create a route.
fib_entry_src_behaviour_register
void fib_entry_src_behaviour_register(fib_source_behaviour_t bh, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:61
fib_entry_src_interpose_reactivate
static int fib_entry_src_interpose_reactivate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interpose.c:235
fib_entry_src_cover_res_t_::install
u16 install
Definition: fib_entry_src.h:92
fib_entry_src_interpose_add
static void fib_entry_src_interpose_add(fib_entry_src_t *src, const fib_entry_t *entry, fib_entry_flag_t flags, dpo_proto_t proto, const dpo_id_t *dpo)
Definition: fib_entry_src_interpose.c:281
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
fib_entry_src_interpose_copy
static void fib_entry_src_interpose_copy(const fib_entry_src_t *orig_src, const fib_entry_t *fib_entry, fib_entry_src_t *copy_src)
Definition: fib_entry_src_interpose.c:316
fib_entry_src_rr.h
fib_entry_src_t_::fes_pl
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:206
fib_entry_src_interpose_deinit
static void fib_entry_src_interpose_deinit(fib_entry_src_t *src)
Definition: fib_entry_src_interpose.c:42
dpo_reset
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:234
fib_entry_src_interpose_deactivate
static void fib_entry_src_interpose_deactivate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Source Deactivate.
Definition: fib_entry_src_interpose.c:196
FIB_ENTRY_SRC_FLAG_CONTRIBUTING
@ FIB_ENTRY_SRC_FLAG_CONTRIBUTING
Definition: fib_entry.h:179
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105