FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
fib_entry_src_interface.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_internal.h"
20 #include "fib_table.h"
21 #include "fib_entry_cover.h"
22 #include "fib_attached_export.h"
23 
24 /**
25  * Source initialisation Function
26  */
27 static void
29 {
30  src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
31  src->u.interface.fesi_sibling = FIB_NODE_INDEX_INVALID;
32 }
33 
34 static void
36  const fib_entry_t *entry,
39  const dpo_id_t *dpo)
40 {
42  proto,
44  dpo);
45 }
46 
47 static void
49 {
51 }
52 
53 static void
55  const fib_entry_t *entry,
56  fib_path_list_flags_t pl_flags,
57  const fib_route_path_t *paths)
58 {
59  fib_node_index_t fib_entry_index;
60  ip_adjacency_t *adj;
61 
62  fib_entry_index = fib_entry_get_index(entry);
63  src->fes_pl = fib_path_list_create(pl_flags, paths);
64 
65  /*
66  * this is a hack to get the entry's prefix into the glean adjacency
67  * so that it is available for fast retrieval in the switch path.
68  */
70  {
71  adj_index_t ai;
72 
73  ai = fib_path_list_get_adj(src->fes_pl,
75  fib_entry_get(fib_entry_index)));
76  if (INDEX_INVALID != ai)
77  {
78  adj = adj_get(ai);
79 
81  {
82  /*
83  * the connected prefix will link to a glean on a non-p2p
84  * u.interface.
85  */
86  adj->sub_type.glean.receive_addr = entry->fe_prefix.fp_addr;
87  }
88  }
89  }
90 }
91 
92 /*
93  * Source activate.
94  * Called when the source is teh new longer best source on the entry
95  */
96 static int
98  const fib_entry_t *fib_entry)
99 {
100  fib_entry_t *cover;
101 
103  {
104  /*
105  * Track the covering attached/connected cover. This is so that
106  * during an attached export of the cover, this local prefix is
107  * also exported
108  */
109  src->u.interface.fesi_cover =
111  &fib_entry->fe_prefix);
112 
113  ASSERT(FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover);
114 
115  cover = fib_entry_get(src->u.interface.fesi_cover);
116 
117  src->u.interface.fesi_sibling =
118  fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
119  }
120 
121  return (!0);
122 }
123 
124 
125 /*
126  * Source Deactivate.
127  * Called when the source is no longer best source on the entry
128  */
129 static void
131  const fib_entry_t *fib_entry)
132 {
133  fib_entry_t *cover;
134 
135  /*
136  * remove the dependency on the covering entry
137  */
138  if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
139  {
140  cover = fib_entry_get(src->u.interface.fesi_cover);
141 
142  fib_entry_cover_untrack(cover, src->u.interface.fesi_sibling);
143 
144  src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
145  }
146 }
147 
150  const fib_entry_t *fib_entry)
151 {
153  .install = !0,
154  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
155  };
156 
157  if (FIB_NODE_INDEX_INVALID == src->u.interface.fesi_cover)
158  {
159  /*
160  * not tracking the cover. surprised we got poked?
161  */
162  return (res);
163  }
164 
165  /*
166  * this function is called when this entry's cover has a more specific
167  * entry inserted benaeth it. That does not necessarily mean that this
168  * entry is covered by the new prefix. check that
169  */
170  if (src->u.interface.fesi_cover !=
172  &fib_entry->fe_prefix))
173  {
174  fib_entry_src_interface_deactivate(src, fib_entry);
175  fib_entry_src_interface_activate(src, fib_entry);
176  }
177  return (res);
178 }
179 
180 static void
182  const fib_entry_t *fib_entry)
183 {
184  /*
185  * The interface source now rules! poke our cover to get exported
186  */
187  fib_entry_t *cover;
188 
189  if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
190  {
191  cover = fib_entry_get(src->u.interface.fesi_cover);
192 
194  fib_entry_get_index(fib_entry));
195  }
196 }
197 
198 static u8*
200  u8* s)
201 {
202  return (format(s, " cover:%d", src->u.interface.fesi_cover));
203 }
204 
205 const static fib_entry_src_vft_t interface_src_vft = {
207  .fesv_add = fib_entry_src_interface_add,
208  .fesv_remove = fib_entry_src_interface_remove,
209  .fesv_path_swap = fib_entry_src_interface_path_swap,
210  .fesv_activate = fib_entry_src_interface_activate,
211  .fesv_deactivate = fib_entry_src_interface_deactivate,
212  .fesv_format = fib_entry_src_interface_format,
213  .fesv_installed = fib_entry_src_interface_installed,
214  .fesv_cover_change = fib_entry_src_interface_cover_change,
215  /*
216  * not concerned about updates to the cover. the cover will
217  * decide to export or not
218  */
219 };
220 
221 void
223 {
225  &interface_src_vft);
226 }
struct ip_adjacency_t_::@149::@152 glean
IP_LOOKUP_NEXT_GLEAN.
fib_entry_src_init_t fesv_init
An entry in a FIB table.
Definition: fib_entry.h:305
static void fib_entry_src_interface_remove(fib_entry_src_t *src)
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:103
A representation of a path as described by a route producer.
Definition: fib_types.h:490
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
adj_index_t fib_path_list_get_adj(fib_node_index_t path_list_index, fib_forward_chain_type_t type)
Virtual function table each FIB entry source will register.
IP unicast adjacency.
Definition: adj.h:227
Information related to the source of a FIB entry.
Definition: fib_entry.h:197
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)
static fib_entry_src_cover_res_t fib_entry_src_interface_cover_change(fib_entry_src_t *src, const fib_entry_t *fib_entry)
vl_api_address_t src
Definition: gre.api:54
Result from a cover update/change.
Definition: fib_entry_src.h:91
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u32 fe_fib_index
The index of the FIB table this entry is in.
Definition: fib_entry.h:318
unsigned char u8
Definition: types.h:56
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)
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:459
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:63
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 install
Definition: fib_entry_src.h:92
union ip_adjacency_t_::@149 sub_type
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
Definition: fib_entry.h:117
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
vl_api_ip_proto_t proto
Definition: acl_types.api:50
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: adj.h:68
static int fib_entry_src_interface_activate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags(fib_entry_flag_t eflags)
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
enum fib_entry_flag_t_ fib_entry_flag_t
vl_api_fib_path_t paths[n_paths]
Definition: ip.api:146
fib_entry_flag_t fes_entry_flags
Flags the source contributes to the entry.
Definition: fib_entry.h:211
#define ASSERT(truth)
static void fib_entry_src_interface_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)
fib_forward_chain_type_t fib_entry_get_default_chain_type(const fib_entry_t *fib_entry)
Definition: fib_entry.c:81
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:206
static void fib_entry_src_interface_init(fib_entry_src_t *src)
Source initialisation Function.
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
union fib_entry_src_t_::@275 u
Source specific info.
struct fib_entry_src_t_::@275::@279 interface
ip_lookup_next_t lookup_next_index
Next hop after ip4-lookup.
Definition: adj.h:329
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
static void fib_entry_src_interface_installed(fib_entry_src_t *src, const fib_entry_t *fib_entry)
static void fib_entry_src_interface_deactivate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
enum fib_path_list_flags_t_ fib_path_list_flags_t
void fib_entry_src_behaviour_register(fib_source_behaviour_t bh, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:61
static void fib_entry_src_interface_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)
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:314
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
cover tracking w/ glean management
Definition: fib_source.h:216
static u8 * fib_entry_src_interface_format(fib_entry_src_t *src, u8 *s)
void fib_entry_src_interface_register(void)