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