FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
fib_entry_src_rr.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  * fib_entry_src_rr_resolve_via_connected
30  *
31  * Resolve via a connected cover.
32  */
33 void
35  const fib_entry_t *fib_entry,
36  const fib_entry_t *cover)
37 {
38  const fib_route_path_t path = {
40  .frp_addr = fib_entry->fe_prefix.fp_addr,
41  .frp_sw_if_index = fib_entry_get_resolving_interface(
42  fib_entry_get_index(cover)),
43  .frp_fib_index = ~0,
44  .frp_weight = 1,
45  };
46  fib_route_path_t *paths = NULL;
47  vec_add1(paths, path);
48 
49  /*
50  * since the cover is connected, the address this entry corresponds
51  * to is a peer (ARP-able for) on the interface to which the cover is
52  * connected. The fact we resolve via the cover, just means this RR
53  * source is the first SRC to use said peer. The ARP source will be along
54  * shortly to over-rule this RR source.
55  */
59 
60  vec_free(paths);
61 }
62 
63 
64 /**
65  * Source initialisation Function
66  */
67 static void
69 {
70  src->u.rr.fesr_cover = FIB_NODE_INDEX_INVALID;
71  src->u.rr.fesr_sibling = FIB_NODE_INDEX_INVALID;
72 }
73 
74 
75 /*
76  * use the path-list of the cover, unless it would form a loop.
77  * that is unless the cover is via this entry.
78  * If a loop were to form it would be a 1 level loop (i.e. X via X),
79  * and there would be 2 locks on the path-list; one since its used
80  * by the cover, and 1 from here. The first lock will go when the
81  * cover is removed, the second, and last, when the covered walk
82  * occurs during the cover's removel - this is not a place where
83  * we can handle last lock gone.
84  * In short, don't let the loop form. The usual rules of 'we must
85  * let it form so we know when it breaks' don't apply here, since
86  * the loop will break when the cover changes, and this function
87  * will be called again when that happens.
88  */
89 void
91  const fib_entry_t *fib_entry,
92  const fib_entry_t *cover)
93 {
95  dpo_proto_t proto;
96 
97  proto = fib_proto_to_dpo(fib_entry->fe_prefix.fp_proto);
98  vec_add1(entries, fib_entry_get_index(fib_entry));
99 
101  &entries))
102  {
105  drop_dpo_get(proto));
106  }
107  else
108  {
109  src->fes_pl = cover->fe_parent;
110  }
111  vec_free(entries);
112 }
113 
114 /*
115  * Source activation. Called when the source is the new best source on the entry
116  */
117 static int
119  const fib_entry_t *fib_entry)
120 {
121  fib_entry_t *cover;
122 
123  /*
124  * find the covering prefix. become a dependent thereof.
125  * for IP there should always be a cover, though it may be the default route.
126  * For MPLS there is never a cover.
127  */
128  if (FIB_PROTOCOL_MPLS == fib_entry->fe_prefix.fp_proto)
129  {
132  NULL);
134  return (!0);
135  }
136 
137  src->u.rr.fesr_cover = fib_table_get_less_specific(fib_entry->fe_fib_index,
138  &fib_entry->fe_prefix);
139 
140  ASSERT(FIB_NODE_INDEX_INVALID != src->u.rr.fesr_cover);
141 
142  cover = fib_entry_get(src->u.rr.fesr_cover);
143 
144  src->u.rr.fesr_sibling =
145  fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
146 
147  /*
148  * if the cover is attached then install an attached-host path
149  * (like an adj-fib). Otherwise inherit the forwarding from the cover
150  */
152  {
153  fib_entry_src_rr_resolve_via_connected(src, fib_entry, cover);
154  }
155  else
156  {
157  fib_entry_src_rr_use_covers_pl(src, fib_entry, cover);
158  }
160 
161  /*
162  * return go for install
163  */
164  return (!0);
165 }
166 
167 /**
168  * Source Deactivate.
169  * Called when the source is no longer best source on the entry
170  */
171 static void
173  const fib_entry_t *fib_entry)
174 {
175  fib_entry_t *cover;
176 
177  /*
178  * remove the depednecy on the covering entry
179  */
180  if (FIB_NODE_INDEX_INVALID != src->u.rr.fesr_cover)
181  {
182  cover = fib_entry_get(src->u.rr.fesr_cover);
183  fib_entry_cover_untrack(cover, src->u.rr.fesr_sibling);
184  src->u.rr.fesr_cover = FIB_NODE_INDEX_INVALID;
185  }
186 
190 }
191 
194  const fib_entry_t *fib_entry)
195 {
197  .install = !0,
198  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
199  };
200 
201  if (FIB_NODE_INDEX_INVALID == src->u.rr.fesr_cover)
202  {
203  /*
204  * the source may be added, but it is not active
205  * if it is not tracking the cover.
206  */
207  return (res);
208  }
209 
210  /*
211  * this function is called when this entry's cover has a more specific
212  * entry inserted benaeth it. That does not necessarily mean that this
213  * entry is covered by the new prefix. check that
214  */
215  if (src->u.rr.fesr_cover != fib_table_get_less_specific(fib_entry->fe_fib_index,
216  &fib_entry->fe_prefix))
217  {
218  fib_entry_src_rr_deactivate(src, fib_entry);
219  fib_entry_src_rr_activate(src, fib_entry);
220 
221  /*
222  * dependent children need to re-resolve to the new forwarding info
223  */
225  }
226  return (res);
227 }
228 
229 /*
230  * fib_entry_src_rr_cover_update
231  *
232  * This entry's cover has updated its forwarding info. This entry
233  * will need to re-inheret.
234  */
237  const fib_entry_t *fib_entry)
238 {
240  .install = !0,
241  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
242  };
243  fib_node_index_t old_path_list;
244  fib_entry_t *cover;
245 
246  if (FIB_NODE_INDEX_INVALID == src->u.rr.fesr_cover)
247  {
248  /*
249  * the source may be added, but it is not active
250  * if it is not tracking the cover.
251  */
252  return (res);
253  }
254 
255  cover = fib_entry_get(src->u.rr.fesr_cover);
256  old_path_list = src->fes_pl;
257 
258  /*
259  * if the ocver is attached then install an attached-host path
260  * (like an adj-fib). Otherwise inherit the forwarding from the cover
261  */
263  {
264  fib_entry_src_rr_resolve_via_connected(src, fib_entry, cover);
265  }
266  else
267  {
268  fib_entry_src_rr_use_covers_pl(src, fib_entry, cover);
269  }
271  fib_path_list_unlock(old_path_list);
272 
273  /*
274  * dependent children need to re-resolve to the new forwarding info
275  */
277 
278  return (res);
279 }
280 
281 static u8*
283  u8* s)
284 {
285  return (format(s, " cover:%d", src->u.rr.fesr_cover));
286 }
287 
288 const static fib_entry_src_vft_t rr_src_vft = {
290  .fesv_activate = fib_entry_src_rr_activate,
291  .fesv_deactivate = fib_entry_src_rr_deactivate,
292  .fesv_cover_change = fib_entry_src_rr_cover_change,
293  .fesv_cover_update = fib_entry_src_rr_cover_update,
294  .fesv_format = fib_entry_src_rr_format,
295 };
296 
297 void
299 {
300  fib_entry_src_register(FIB_SOURCE_RR, &rr_src_vft);
302 }
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
fib_entry_src_init_t fesv_init
Recursive resolution source.
Definition: fib_entry.h:125
vl_api_address_t src
Definition: vxlan_gbp.api:32
void fib_entry_src_rr_resolve_via_connected(fib_entry_src_t *src, const fib_entry_t *fib_entry, const fib_entry_t *cover)
An entry in a FIB table.
Definition: fib_entry.h:462
fib_node_bw_reason_flag_t bw_reason
Definition: fib_entry_src.h:93
fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry)
A representation of a path as described by a route producer.
Definition: fib_types.h:470
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
void fib_entry_src_rr_register(void)
Virtual function table each FIB entry source will register.
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
#define NULL
Definition: clib.h:58
Information related to the source of a FIB entry.
Definition: fib_entry.h:354
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)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
Result from a cover update/change.
Definition: fib_entry_src.h:91
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
dpo_proto_t frp_proto
The protocol of the address below.
Definition: fib_types.h:475
u32 fe_fib_index
The index of the FIB table this entry is in.
Definition: fib_entry.h:475
uRPF bypass/exemption.
Definition: fib_entry.h:130
Definition: fib_entry.h:277
unsigned char u8
Definition: types.h:56
fib_node_index_t fe_parent
the path-list for which this entry is a child.
Definition: fib_entry.h:499
static void fib_entry_src_rr_init(fib_entry_src_t *src)
Source initialisation Function.
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
u32 fib_entry_cover_track(fib_entry_t *cover, fib_node_index_t covered)
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:62
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 install
Definition: fib_entry_src.h:92
Definition: fib_entry.h:275
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
void fib_path_list_lock(fib_node_index_t path_list_index)
union fib_entry_src_t_::@124 u
Source specific info.
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1451
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
struct fib_entry_src_t_::@124::@125 rr
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
void fib_path_list_unlock(fib_node_index_t path_list_index)
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:50
int fib_path_list_recursive_loop_detect(fib_node_index_t path_list_index, fib_node_index_t **entry_indicies)
fib_entry_flag_t fes_entry_flags
Flags the source contributes to the entry.
Definition: fib_entry.h:368
#define ASSERT(truth)
void fib_entry_src_register(fib_source_t source, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:56
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:237
u32 entries
void fib_entry_src_rr_use_covers_pl(fib_entry_src_t *src, const fib_entry_t *fib_entry, const fib_entry_t *cover)
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:363
static int fib_entry_src_rr_activate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
#define FIB_ENTRY_FLAGS_RR_INHERITED
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
fib_entry_src_cover_res_t fib_entry_src_rr_cover_update(fib_entry_src_t *src, const fib_entry_t *fib_entry)
static void fib_entry_src_rr_deactivate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Source Deactivate.
static u8 * fib_entry_src_rr_format(fib_entry_src_t *src, u8 *s)
fib_entry_src_cover_res_t fib_entry_src_rr_cover_change(fib_entry_src_t *src, const fib_entry_t *fib_entry)
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:471
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:131
fib_entry_flag_t fib_entry_get_flags(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:301