FD.io VPP  v21.06-3-gbb25fbf28
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 {
50  src->fes_pl = FIB_NODE_INDEX_INVALID;
51  ASSERT(src->u.interface.fesi_sibling == ~0);
52 }
53 
54 static int
56  const fib_entry_t *local)
57 {
59  adj_index_t ai;
60 
62 
63  if (NULL == src)
64  {
65  /*
66  * The cover is not an interface source, no work
67  */
68  return 0;
69  }
70 
71  ai = fib_path_list_get_adj(src->fes_pl,
73 
74  if (INDEX_INVALID != ai)
75  {
76  ip_adjacency_t *adj;
77 
78  adj = adj_get(ai);
79 
81  {
82  /*
83  * the connected prefix will link to a glean on a non-p2p
84  * interface.
85  * Ensure we are updating with a host in the connected's subnet
86  */
87  if (fib_prefix_is_cover(&adj->sub_type.glean.rx_pfx,
88  &local->fe_prefix))
89  {
90  adj->sub_type.glean.rx_pfx.fp_addr = local->fe_prefix.fp_addr;
91  return (1);
92  }
93  }
94  }
95 
96  return (0);
97 }
98 
99 static walk_rc_t
101  fib_node_index_t covered,
102  void *ctx)
103 {
105  return (WALK_STOP);
106 
107  return (WALK_CONTINUE);
108 }
109 
110 static void
112  const fib_entry_t *entry,
113  fib_path_list_flags_t pl_flags,
114  const fib_route_path_t *paths)
115 {
116  src->fes_pl = fib_path_list_create(pl_flags, paths);
117 }
118 
119 /*
120  * Source activate.
121  * Called when the source is teh new longer best source on the entry
122  */
123 static int
125  const fib_entry_t *fib_entry)
126 {
127  fib_entry_t *cover;
128 
129  if (FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags)
130  {
131  /*
132  * Track the covering attached/connected cover. This is so that
133  * during an attached export of the cover, this local prefix is
134  * also exported
135  */
136  src->u.interface.fesi_cover =
138  &fib_entry->fe_prefix);
139 
140  ASSERT(FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover);
141 
142  cover = fib_entry_get(src->u.interface.fesi_cover);
143 
144  src->u.interface.fesi_sibling =
145  fib_entry_cover_track(cover, fib_entry_get_index(fib_entry));
146 
147  fib_entry_src_interface_update_glean(cover, fib_entry);
148  }
149 
150  return (!0);
151 }
152 
153 
154 /*
155  * Source Deactivate.
156  * Called when the source is no longer best source on the entry
157  */
158 static void
160  const fib_entry_t *fib_entry)
161 {
162  fib_entry_t *cover;
163 
164  /*
165  * remove the dependency on the covering entry
166  */
167  if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
168  {
169  cover = fib_entry_get(src->u.interface.fesi_cover);
170 
171  fib_entry_cover_untrack(cover, src->u.interface.fesi_sibling);
172 
173  src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID;
174  src->u.interface.fesi_sibling = ~0;
175 
176  fib_entry_cover_walk(cover,
178  NULL);
179  }
180 }
181 
184  const fib_entry_t *fib_entry)
185 {
187  .install = !0,
188  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
189  };
190 
191  if (FIB_NODE_INDEX_INVALID == src->u.interface.fesi_cover)
192  {
193  /*
194  * not tracking the cover. surprised we got poked?
195  */
196  return (res);
197  }
198 
199  /*
200  * this function is called when this entry's cover has a more specific
201  * entry inserted benaeth it. That does not necessarily mean that this
202  * entry is covered by the new prefix. check that
203  */
204  if (src->u.interface.fesi_cover !=
206  &fib_entry->fe_prefix))
207  {
210  }
211  return (res);
212 }
213 
214 static void
216  const fib_entry_t *fib_entry)
217 {
218  /*
219  * The interface source now rules! poke our cover to get exported
220  */
221  fib_entry_t *cover;
222 
223  if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover)
224  {
225  cover = fib_entry_get(src->u.interface.fesi_cover);
226 
228  fib_entry_get_index(fib_entry));
229  }
230 }
231 
232 static u8*
234  u8* s)
235 {
236  return (format(s, " cover:%d", src->u.interface.fesi_cover));
237 }
238 
241  .fesv_add = fib_entry_src_interface_add,
242  .fesv_remove = fib_entry_src_interface_remove,
243  .fesv_path_swap = fib_entry_src_interface_path_swap,
244  .fesv_activate = fib_entry_src_interface_activate,
245  .fesv_deactivate = fib_entry_src_interface_deactivate,
246  .fesv_format = fib_entry_src_interface_format,
247  .fesv_installed = fib_entry_src_interface_installed,
248  .fesv_cover_change = fib_entry_src_interface_cover_change,
249  /*
250  * not concerned about updates to the cover. the cover will
251  * decide to export or not
252  */
253 };
254 
255 void
257 {
260 }
fib_entry.h
fib_entry_src_cover_res_t_
Result from a cover update/change.
Definition: fib_entry_src.h:91
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
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_interface_deactivate
static void fib_entry_src_interface_deactivate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interface.c:159
IP_LOOKUP_NEXT_GLEAN
@ IP_LOOKUP_NEXT_GLEAN
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: adj.h:68
fib_entry_src_t_
Information related to the source of a FIB entry.
Definition: fib_entry.h:197
paths
paths
Definition: map.api:460
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_table.h
fib_entry_src_interface_remove
static void fib_entry_src_interface_remove(fib_entry_src_t *src)
Definition: fib_entry_src_interface.c:48
fib_entry_cover_walk
void fib_entry_cover_walk(fib_entry_t *cover, fib_entry_covered_walk_t walk, void *args)
Definition: fib_entry_cover.c:87
FIB_SOURCE_BH_INTERFACE
@ FIB_SOURCE_BH_INTERFACE
cover tracking w/ glean management
Definition: fib_source.h:221
fib_path_list_flags_t
enum fib_path_list_flags_t_ fib_path_list_flags_t
fib_entry_src_interface_update_glean
static int fib_entry_src_interface_update_glean(fib_entry_t *cover, const fib_entry_t *local)
Definition: fib_entry_src_interface.c:55
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_src_find
fib_entry_src_t * fib_entry_src_find(const fib_entry_t *fib_entry, fib_source_t source)
Definition: fib_entry_src.c:131
fib_entry_flag_t
enum fib_entry_flag_t_ fib_entry_flag_t
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
fib_path_list_get_adj
adj_index_t fib_path_list_get_adj(fib_node_index_t path_list_index, fib_forward_chain_type_t type)
Definition: fib_path_list.c:1242
FIB_SOURCE_INTERFACE
@ FIB_SOURCE_INTERFACE
Route added as a result of interface configuration.
Definition: fib_source.h:59
ip_adjacency_t_::lookup_next_index
ip_lookup_next_t lookup_next_index
Next hop after ip4-lookup.
Definition: adj.h:337
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
interface_src_vft
const static fib_entry_src_vft_t interface_src_vft
Definition: fib_entry_src_interface.c:239
src
vl_api_address_t src
Definition: gre.api:54
ip_adjacency_t_
IP unicast adjacency.
Definition: adj.h:235
fib_entry_src_interface_path_swap
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)
Definition: fib_entry_src_interface.c:111
FIB_ENTRY_FLAG_LOCAL
@ FIB_ENTRY_FLAG_LOCAL
Definition: fib_entry.h:117
fib_entry_get_default_chain_type
fib_forward_chain_type_t fib_entry_get_default_chain_type(const fib_entry_t *fib_entry)
Definition: fib_entry.c:81
fib_entry_src_interface_update_glean_walk
static walk_rc_t fib_entry_src_interface_update_glean_walk(fib_entry_t *cover, fib_node_index_t covered, void *ctx)
Definition: fib_entry_src_interface.c:100
fib_prefix_t_::fp_addr
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:225
fib_attached_export_covered_added
void fib_attached_export_covered_added(fib_entry_t *cover, fib_node_index_t covered)
Definition: fib_attached_export.c:398
fib_entry_src_interface_init
static void fib_entry_src_interface_init(fib_entry_src_t *src)
Source initialisation Function.
Definition: fib_entry_src_interface.c:28
ip_adjacency_t_::glean
struct ip_adjacency_t_::@144::@147 glean
IP_LOOKUP_NEXT_GLEAN.
ip_adjacency_t_::sub_type
union ip_adjacency_t_::@144 sub_type
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
fib_path_list.h
fib_entry_get
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
fib_entry_src_interface_installed
static void fib_entry_src_interface_installed(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interface.c:215
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
fib_entry_src_interface_add
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)
Definition: fib_entry_src_interface.c:35
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
fib_prefix_is_cover
int fib_prefix_is_cover(const fib_prefix_t *p1, const fib_prefix_t *p2)
Compare two prefixes for covering relationship.
Definition: fib_types.c:212
fib_entry_cover_untrack
void fib_entry_cover_untrack(fib_entry_t *cover, u32 tracked_index)
Definition: fib_entry_cover.c:45
fib_entry_cover_track
u32 fib_entry_cover_track(fib_entry_t *cover, fib_node_index_t covered)
Definition: fib_entry_cover.c:22
adj_index_t
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
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_interface_register
void fib_entry_src_interface_register(void)
Definition: fib_entry_src_interface.c:256
fib_entry_src_interface_format
static u8 * fib_entry_src_interface_format(fib_entry_src_t *src, u8 *s)
Definition: fib_entry_src_interface.c:233
fib_internal.h
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
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_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_interface_activate
static int fib_entry_src_interface_activate(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interface.c:124
fib_entry_src_cover_res_t_::install
u16 install
Definition: fib_entry_src.h:92
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
fib_path_list_create
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
Definition: fib_path_list.c:682
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
fib_entry_src_flags_2_path_list_flags
fib_path_list_flags_t fib_entry_src_flags_2_path_list_flags(fib_entry_flag_t eflags)
Definition: fib_entry_src.c:1550
adj_get
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:470
fib_attached_export.h
WALK_STOP
@ WALK_STOP
Definition: interface_funcs.h:173
fib_entry_src_interface_cover_change
static fib_entry_src_cover_res_t fib_entry_src_interface_cover_change(fib_entry_src_t *src, const fib_entry_t *fib_entry)
Definition: fib_entry_src_interface.c:183
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105