FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
fib_bfd.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 <vnet/bfd/bfd_main.h>
17 
19 #include <vnet/fib/fib_entry.h>
20 #include <vnet/fib/fib_table.h>
21 #include <vnet/fib/fib_walk.h>
22 
23 static fib_bfd_state_t
25 {
26  switch (bstate)
27  {
28  case BFD_STATE_up:
29  return (FIB_BFD_STATE_UP);
30  case BFD_STATE_down:
31  case BFD_STATE_admin_down:
32  case BFD_STATE_init:
33  return (FIB_BFD_STATE_DOWN);
34  }
35  return (FIB_BFD_STATE_DOWN);
36 }
37 
38 static void
40 {
41  /*
42  * initiate a backwalk of dependent children
43  * to notify of the state change of this entry.
44  */
46  .fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE,
47  };
49 }
50 
51 /**
52  * @brief Callback function registered with BFD module to receive notifications
53  * of the CRUD of BFD sessions
54  * would be static but for the fact it's called from the unit-tests
55  */
56 void
58  const bfd_session_t *session)
59 {
61  const bfd_udp_key_t *key;
62  fib_node_index_t fei;
63 
64  if (BFD_HOP_TYPE_MULTI != session->hop_type)
65  {
66  /*
67  * multi-hop BFD sessions attach directly to the FIB entry
68  * single-hop adj to the associate adjacency.
69  */
70  return;
71  }
72 
73  key = &session->udp.key;
74 
75  fib_prefix_t pfx = {
76  .fp_addr = key->peer_addr,
77  .fp_proto = (ip46_address_is_ip4 (&key->peer_addr) ?
80  .fp_len = (ip46_address_is_ip4 (&key->peer_addr) ?
81  32:
82  128),
83  };
84 
85  /*
86  * get the FIB entry
87  */
88  fei = fib_table_lookup_exact_match(key->fib_index, &pfx);
89 
90  switch (event)
91  {
92  case BFD_LISTEN_EVENT_CREATE:
93  /*
94  * The creation of a new session
95  */
96  if ((FIB_NODE_INDEX_INVALID != fei) &&
99  {
100  /*
101  * already got state for this entry
102  */
103  }
104  else
105  {
106  /*
107  * source and lock the entry. add the delegate
108  */
109  fei = fib_table_entry_special_add(key->fib_index,
110  &pfx,
113  fib_entry_lock(fei);
114 
117 
118  /*
119  * pretend the session is up and skip the walk.
120  * If we set it down then we get traffic loss on new children.
121  * if we walk then we lose traffic for existing children. Wait
122  * for the first BFD UP/DOWN before we let the session's state
123  * influence forwarding.
124  */
126  }
127  break;
128 
129  case BFD_LISTEN_EVENT_UPDATE:
130  /*
131  * state change up/dowm and
132  */
134 
137 
138  if (NULL != fed)
139  {
141  fib_bfd_update_walk(fei);
142  }
143  /*
144  * else
145  * no BFD state
146  */
147  break;
148 
149  case BFD_LISTEN_EVENT_DELETE:
150  /*
151  * session has been removed.
152  */
153  if (FIB_NODE_INDEX_INVALID == fei)
154  {
155  /*
156  * no FIB entry
157  */
158  }
161  {
162  /*
163  * has an associated BFD tracking delegate
164  * usource the entry and remove the BFD tracking delegate
165  */
168  fib_bfd_update_walk(fei);
169 
170  fib_table_entry_special_remove(key->fib_index,
171  &pfx,
172  FIB_SOURCE_RR);
173  fib_entry_unlock(fei);
174  }
175  /*
176  * else
177  * no BFD associated state
178  */
179  break;
180  }
181 }
182 
183 static clib_error_t *
185 {
187 
188  return (NULL);
189 }
190 
191 /* *INDENT-OFF* */
193 {
194  .runs_after = VLIB_INITS("bfd_main_init"),
195 };
196 /* *INDENT-ON* */
void fib_entry_unlock(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1642
static fib_bfd_state_t fib_bfd_bfd_state_to_fib(bfd_state_e bstate)
Definition: fib_bfd.c:24
fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: fib_table.c:97
BFD session state.
void fib_bfd_notify(bfd_listen_event_e event, const bfd_session_t *session)
Callback function registered with BFD module to receive notifications of the CRUD of BFD sessions wou...
Definition: fib_bfd.c:57
fib_bfd_state_t fd_bfd_state
BFD state.
fib_entry_delegate_t * fib_entry_delegate_find(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
vlib_main_t * vm
Definition: in2out_ed.c:1582
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a &#39;special&#39; entry from the FIB.
Definition: fib_table.c:424
void fib_walk_sync(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_back_walk_ctx_t *ctx)
Back walk all the children of a FIB node.
Definition: fib_walk.c:745
Recursive resolution source.
Definition: fib_source.h:119
Aggregate type for a prefix.
Definition: fib_types.h:203
static void fib_bfd_update_walk(fib_node_index_t fei)
Definition: fib_bfd.c:39
Definition: fib_entry.h:112
bfd_udp_key_t key
key identifying this session
Definition: bfd_udp.h:47
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
long ctx[MAX_CONNS]
Definition: main.c:144
BFD global declarations.
bfd_udp_session_t udp
Definition: bfd_main.h:241
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:405
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
bfd_state_e
Definition: bfd_protocol.h:195
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:51
Context passed between object during a back walk.
Definition: fib_node.h:208
void fib_entry_lock(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1632
#define ASSERT(truth)
bfd_hop_type_e hop_type
BFD hop type.
Definition: bfd_main.h:97
bfd_state_e local_state
session state
Definition: bfd_main.h:91
typedef key
Definition: ipsec_types.api:85
void bfd_register_listener(bfd_notify_fn_t fn)
Register a callback function to receive session notifications.
Definition: bfd_main.c:1327
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
enum fib_bfd_state_t_ fib_bfd_state_t
Distillation of the BFD session states into a go/no-go for using the associated tracked FIB entry...
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)
#define VLIB_INITS(...)
Definition: init.h:357
static clib_error_t * fib_bfd_main_init(vlib_main_t *vm)
Definition: fib_bfd.c:184
bfd_listen_event_e
Definition: bfd_main.h:253