FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
fib_entry_src_adj.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 "fib_entry.h"
17 #include "fib_entry_src.h"
18 #include "fib_path_list.h"
19 #include "fib_table.h"
20 #include "fib_entry_cover.h"
21 #include "fib_attached_export.h"
22 
23 /**
24  * Source initialisation Function
25  */
26 static void
28 {
29  src->adj.fesa_cover = FIB_NODE_INDEX_INVALID;
30  src->adj.fesa_sibling = FIB_NODE_INDEX_INVALID;
31 }
32 
33 static void
35  const fib_entry_t *entry,
36  fib_path_list_flags_t pl_flags,
37  const fib_route_path_t *paths)
38 {
39  src->fes_pl = fib_path_list_create(pl_flags, paths);
40 }
41 
42 static void
44 {
46 }
47 
48 
49 /*
50  * Source activate.
51  * Called when the source is teh new longer best source on the entry
52  */
53 static int
55  const fib_entry_t *fib_entry)
56 {
57  fib_entry_t *cover;
58 
59  /*
60  * find the covering prefix. become a dependent thereof.
61  * there should always be a cover, though it may be the default route.
62  */
63  src->adj.fesa_cover = fib_table_get_less_specific(fib_entry->fe_fib_index,
64  &fib_entry->fe_prefix);
65 
66  ASSERT(FIB_NODE_INDEX_INVALID != src->adj.fesa_cover);
67  ASSERT(fib_entry_get_index(fib_entry) != src->adj.fesa_cover);
68 
69  cover = fib_entry_get(src->adj.fesa_cover);
70 
71  ASSERT(cover != fib_entry);
72 
73  src->adj.fesa_sibling =
75  fib_entry_get_index(fib_entry));
76 
77  /*
78  * if the ocver is attached then this adj source entry can install,
79  * via the adj. otherwise install a drop.
80  * This prevents ARP/ND entries that on interface X that do not belong
81  * on X's subnet from being added to the FIB. To do so would allow
82  * nefarious gratuitous ARP requests from attracting traffic to the sender.
83  *
84  * and yes, I really do mean attached and not connected.
85  * this abomination;
86  * ip route add 10.0.0.0/24 Eth0
87  * is attached. and we want adj-fibs to install on Eth0.
88  */
90 }
91 
92 /*
93  * Source Deactivate.
94  * Called when the source is no longer best source on the entry
95  */
96 static void
98  const fib_entry_t *fib_entry)
99 {
100  fib_entry_t *cover;
101 
102  /*
103  * remove the depednecy on the covering entry
104  */
105  ASSERT(FIB_NODE_INDEX_INVALID != src->adj.fesa_cover);
106  cover = fib_entry_get(src->adj.fesa_cover);
107 
108  fib_entry_cover_untrack(cover, src->adj.fesa_sibling);
109 
110  /*
111  * tell the cover this entry no longer needs exporting
112  */
114 
115  src->adj.fesa_cover = FIB_NODE_INDEX_INVALID;
116 }
117 
118 static u8*
120  u8* s)
121 {
122  return (format(s, "cover:%d", src->adj.fesa_cover));
123 }
124 
125 static void
127  const fib_entry_t *fib_entry)
128 {
129  /*
130  * The adj source now rules! poke our cover to get exported
131  */
132  fib_entry_t *cover;
133 
134  ASSERT(FIB_NODE_INDEX_INVALID != src->adj.fesa_cover);
135  cover = fib_entry_get(src->adj.fesa_cover);
136 
138  fib_entry_get_index(fib_entry));
139 }
140 
143  const fib_entry_t *fib_entry)
144 {
146  .install = !0,
147  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
148  };
149 
150  fib_entry_src_adj_deactivate(src, fib_entry);
151 
152  res.install = fib_entry_src_adj_activate(src, fib_entry);
153 
154  if (res.install) {
155  /*
156  * ADJ fib can install
157  */
159  }
160 
161  return (res);
162 }
163 
164 /*
165  * fib_entry_src_adj_cover_update
166  */
169  const fib_entry_t *fib_entry)
170 {
171  /*
172  * the cover has updated, i.e. its forwarding or flags
173  * have changed. do'nt decativate/activate here, since this
174  * prefix is updated during the covers walk.
175  */
177  .install = !0,
178  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
179  };
180  fib_entry_t *cover;
181 
182  ASSERT(FIB_NODE_INDEX_INVALID != src->adj.fesa_cover);
183 
184  cover = fib_entry_get(src->adj.fesa_cover);
185 
187 
188  return (res);
189 }
190 
191 const static fib_entry_src_vft_t adj_src_vft = {
193  .fesv_path_swap = fib_entry_src_adj_path_swap,
194  .fesv_remove = fib_entry_src_adj_remove,
195  .fesv_activate = fib_entry_src_adj_activate,
196  .fesv_deactivate = fib_entry_src_adj_deactivate,
197  .fesv_format = fib_entry_src_adj_format,
198  .fesv_installed = fib_entry_src_adj_installed,
199  .fesv_cover_change = fib_entry_src_adj_cover_change,
200  .fesv_cover_update = fib_entry_src_adj_cover_update,
201 };
202 
203 void
205 {
206  fib_entry_src_register(FIB_SOURCE_ADJ, &adj_src_vft);
207 }
fib_entry_src_init_t fesv_init
An entry in a FIB table.
Definition: fib_entry.h:361
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:285
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
Virtual function table each FIB entry source will register.
Information related to the source of a FIB entry.
Definition: fib_entry.h:270
static fib_entry_src_cover_res_t fib_entry_src_adj_cover_change(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Result from a cover update/change.
Definition: fib_entry_src.h:87
u32 fe_fib_index
The index of the FIB table this entry is in.
Definition: fib_entry.h:374
Definition: fib_entry.h:218
static int fib_entry_src_adj_activate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
void fib_attached_export_covered_added(fib_entry_t *cover, fib_node_index_t covered)
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
static void fib_entry_src_adj_remove(fib_entry_src_t *src)
static fib_entry_src_cover_res_t fib_entry_src_adj_cover_update(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)
Adjacency source.
Definition: fib_entry.h:88
static void fib_entry_src_adj_installed(fib_entry_src_t *src, const fib_entry_t *fib_entry)
void fib_entry_src_adj_register(void)
static void fib_entry_src_adj_deactivate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
static void fib_entry_src_adj_init(fib_entry_src_t *src)
Source initialisation Function.
void fib_attached_export_covered_removed(fib_entry_t *cover, fib_node_index_t covered)
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:44
static u8 * fib_entry_src_adj_format(fib_entry_src_t *src, u8 *s)
#define ASSERT(truth)
void fib_entry_src_register(fib_source_t source, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:38
struct fib_entry_src_t_::@125::@128 adj
static void fib_entry_src_adj_path_swap(fib_entry_src_t *src, const fib_entry_t *entry, fib_path_list_flags_t pl_flags, const fib_route_path_t *paths)
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:279
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
unsigned char u8
Definition: types.h:56
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
enum fib_path_list_flags_t_ fib_path_list_flags_t
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:370
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