]>
Commit | Line | Data |
---|---|---|
c43ed2e4 DS |
1 | /** |
2 | * bgp_bfd.c: BGP BFD handling routines | |
3 | * | |
4 | * @copyright Copyright (C) 2015 Cumulus Networks, Inc. | |
5 | * | |
6 | * This file is part of GNU Zebra. | |
7 | * | |
8 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * GNU Zebra is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
896014f4 DL |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
c43ed2e4 DS |
21 | */ |
22 | ||
23 | #include <zebra.h> | |
24 | ||
25 | #include "command.h" | |
26 | #include "linklist.h" | |
27 | #include "memory.h" | |
28 | #include "prefix.h" | |
29 | #include "thread.h" | |
30 | #include "buffer.h" | |
31 | #include "stream.h" | |
32 | #include "zclient.h" | |
7f342629 | 33 | #include "bfd.h" |
856ca177 | 34 | #include "lib/json.h" |
039f3a34 DS |
35 | #include "filter.h" |
36 | ||
c43ed2e4 | 37 | #include "bgpd/bgpd.h" |
7f342629 | 38 | #include "bgp_fsm.h" |
c43ed2e4 DS |
39 | #include "bgpd/bgp_bfd.h" |
40 | #include "bgpd/bgp_debug.h" | |
41 | #include "bgpd/bgp_vty.h" | |
42 | ||
43 | extern struct zclient *zclient; | |
44 | ||
c43ed2e4 | 45 | /* |
d62a17ae | 46 | * bgp_bfd_peer_group2peer_copy - Copy the BFD information from peer group |
47 | * template | |
c43ed2e4 DS |
48 | * to peer. |
49 | */ | |
d62a17ae | 50 | void bgp_bfd_peer_group2peer_copy(struct peer *conf, struct peer *peer) |
c43ed2e4 | 51 | { |
d62a17ae | 52 | struct bfd_info *bfd_info; |
53 | struct bfd_info *conf_bfd_info; | |
7f342629 | 54 | |
d62a17ae | 55 | if (!conf->bfd_info) |
56 | return; | |
7f342629 | 57 | |
d62a17ae | 58 | conf_bfd_info = (struct bfd_info *)conf->bfd_info; |
59 | if (!peer->bfd_info) | |
60 | peer->bfd_info = bfd_info_create(); | |
c43ed2e4 | 61 | |
d62a17ae | 62 | bfd_info = (struct bfd_info *)peer->bfd_info; |
c43ed2e4 | 63 | |
d62a17ae | 64 | /* Copy BFD parameter values */ |
65 | bfd_info->required_min_rx = conf_bfd_info->required_min_rx; | |
66 | bfd_info->desired_min_tx = conf_bfd_info->desired_min_tx; | |
67 | bfd_info->detect_mult = conf_bfd_info->detect_mult; | |
68 | bfd_info->type = conf_bfd_info->type; | |
c43ed2e4 DS |
69 | } |
70 | ||
71 | /* | |
d62a17ae | 72 | * bgp_bfd_is_peer_multihop - returns whether BFD peer is multi-hop or single |
73 | * hop. | |
c43ed2e4 | 74 | */ |
d62a17ae | 75 | int bgp_bfd_is_peer_multihop(struct peer *peer) |
c43ed2e4 | 76 | { |
d62a17ae | 77 | struct bfd_info *bfd_info; |
986aa00f | 78 | |
d62a17ae | 79 | bfd_info = (struct bfd_info *)peer->bfd_info; |
986aa00f | 80 | |
d62a17ae | 81 | if (!bfd_info) |
82 | return 0; | |
986aa00f | 83 | |
d62a17ae | 84 | if ((bfd_info->type == BFD_TYPE_MULTIHOP) |
85 | || ((peer->sort == BGP_PEER_IBGP) && !peer->shared_network) | |
86 | || is_ebgp_multihop_configured(peer)) | |
87 | return 1; | |
88 | else | |
89 | return 0; | |
c43ed2e4 DS |
90 | } |
91 | ||
92 | /* | |
7f342629 DS |
93 | * bgp_bfd_peer_sendmsg - Format and send a Peer register/Unregister |
94 | * command to Zebra to be forwarded to BFD | |
c43ed2e4 | 95 | */ |
d62a17ae | 96 | static void bgp_bfd_peer_sendmsg(struct peer *peer, int command) |
c43ed2e4 | 97 | { |
d62a17ae | 98 | struct bfd_info *bfd_info; |
99 | vrf_id_t vrf_id = VRF_DEFAULT; | |
100 | int multihop; | |
101 | ||
102 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
103 | ||
104 | if (peer->bgp && (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VRF)) | |
105 | vrf_id = peer->bgp->vrf_id; | |
106 | ||
107 | if (command == ZEBRA_BFD_DEST_DEREGISTER) { | |
108 | multihop = | |
109 | CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); | |
110 | UNSET_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); | |
111 | } else { | |
112 | multihop = bgp_bfd_is_peer_multihop(peer); | |
113 | if ((command == ZEBRA_BFD_DEST_REGISTER) && multihop) | |
114 | SET_FLAG(bfd_info->flags, BFD_FLAG_BFD_TYPE_MULTIHOP); | |
115 | } | |
116 | ||
117 | if (peer->su.sa.sa_family == AF_INET) | |
118 | bfd_peer_sendmsg( | |
119 | zclient, bfd_info, AF_INET, &peer->su.sin.sin_addr, | |
120 | (peer->su_local) ? &peer->su_local->sin.sin_addr : NULL, | |
121 | (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, | |
122 | peer->ttl, multihop, command, 1, vrf_id); | |
123 | else if (peer->su.sa.sa_family == AF_INET6) | |
124 | bfd_peer_sendmsg( | |
125 | zclient, bfd_info, AF_INET6, &peer->su.sin6.sin6_addr, | |
126 | (peer->su_local) ? &peer->su_local->sin6.sin6_addr | |
127 | : NULL, | |
128 | (peer->nexthop.ifp) ? peer->nexthop.ifp->name : NULL, | |
129 | peer->ttl, multihop, command, 1, vrf_id); | |
c43ed2e4 DS |
130 | } |
131 | ||
132 | /* | |
133 | * bgp_bfd_register_peer - register a peer with BFD through zebra | |
134 | * for monitoring the peer rechahability. | |
135 | */ | |
d62a17ae | 136 | void bgp_bfd_register_peer(struct peer *peer) |
c43ed2e4 | 137 | { |
d62a17ae | 138 | struct bfd_info *bfd_info; |
c43ed2e4 | 139 | |
d62a17ae | 140 | if (!peer->bfd_info) |
141 | return; | |
142 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
c43ed2e4 | 143 | |
d62a17ae | 144 | /* Check if BFD is enabled and peer has already been registered with BFD |
145 | */ | |
146 | if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) | |
147 | return; | |
c43ed2e4 | 148 | |
d62a17ae | 149 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); |
c43ed2e4 DS |
150 | } |
151 | ||
152 | /** | |
153 | * bgp_bfd_deregister_peer - deregister a peer with BFD through zebra | |
154 | * for stopping the monitoring of the peer | |
155 | * rechahability. | |
156 | */ | |
d62a17ae | 157 | void bgp_bfd_deregister_peer(struct peer *peer) |
c43ed2e4 | 158 | { |
d62a17ae | 159 | struct bfd_info *bfd_info; |
c43ed2e4 | 160 | |
d62a17ae | 161 | if (!peer->bfd_info) |
162 | return; | |
163 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
c43ed2e4 | 164 | |
d62a17ae | 165 | /* Check if BFD is eanbled and peer has not been registered */ |
166 | if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) | |
167 | return; | |
c43ed2e4 | 168 | |
d62a17ae | 169 | bfd_info->status = BFD_STATUS_DOWN; |
170 | bfd_info->last_update = bgp_clock(); | |
5c940836 | 171 | |
d62a17ae | 172 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); |
c43ed2e4 DS |
173 | } |
174 | ||
175 | /* | |
176 | * bgp_bfd_update_peer - update peer with BFD with new BFD paramters | |
177 | * through zebra. | |
178 | */ | |
d62a17ae | 179 | static void bgp_bfd_update_peer(struct peer *peer) |
c43ed2e4 | 180 | { |
d62a17ae | 181 | struct bfd_info *bfd_info; |
c43ed2e4 | 182 | |
d62a17ae | 183 | if (!peer->bfd_info) |
184 | return; | |
185 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
c43ed2e4 | 186 | |
d62a17ae | 187 | /* Check if the peer has been registered with BFD*/ |
188 | if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) | |
189 | return; | |
c43ed2e4 | 190 | |
d62a17ae | 191 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_UPDATE); |
c43ed2e4 DS |
192 | } |
193 | ||
986aa00f | 194 | /* |
195 | * bgp_bfd_update_type - update session type with BFD through zebra. | |
196 | */ | |
d62a17ae | 197 | static void bgp_bfd_update_type(struct peer *peer) |
986aa00f | 198 | { |
d62a17ae | 199 | struct bfd_info *bfd_info; |
200 | int multihop; | |
201 | ||
202 | if (!peer->bfd_info) | |
203 | return; | |
204 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
205 | ||
206 | /* Check if the peer has been registered with BFD*/ | |
207 | if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_BFD_REG)) | |
208 | return; | |
209 | ||
210 | if (bfd_info->type == BFD_TYPE_NOT_CONFIGURED) { | |
211 | multihop = bgp_bfd_is_peer_multihop(peer); | |
212 | if ((multihop | |
213 | && !CHECK_FLAG(bfd_info->flags, | |
214 | BFD_FLAG_BFD_TYPE_MULTIHOP)) | |
c14777c6 | 215 | || (!multihop |
216 | && CHECK_FLAG(bfd_info->flags, | |
217 | BFD_FLAG_BFD_TYPE_MULTIHOP))) { | |
d62a17ae | 218 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); |
219 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); | |
220 | } | |
221 | } else { | |
222 | if ((bfd_info->type == BFD_TYPE_MULTIHOP | |
223 | && !CHECK_FLAG(bfd_info->flags, | |
224 | BFD_FLAG_BFD_TYPE_MULTIHOP)) | |
225 | || (bfd_info->type == BFD_TYPE_SINGLEHOP | |
226 | && CHECK_FLAG(bfd_info->flags, | |
227 | BFD_FLAG_BFD_TYPE_MULTIHOP))) { | |
228 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_DEREGISTER); | |
229 | bgp_bfd_peer_sendmsg(peer, ZEBRA_BFD_DEST_REGISTER); | |
230 | } | |
231 | } | |
986aa00f | 232 | } |
233 | ||
c43ed2e4 DS |
234 | /* |
235 | * bgp_bfd_dest_replay - Replay all the peers that have BFD enabled | |
236 | * to zebra | |
237 | */ | |
d62a17ae | 238 | static int bgp_bfd_dest_replay(int command, struct zclient *client, |
239 | zebra_size_t length, vrf_id_t vrf_id) | |
c43ed2e4 | 240 | { |
d62a17ae | 241 | struct listnode *mnode, *node, *nnode; |
242 | struct bgp *bgp; | |
243 | struct peer *peer; | |
c43ed2e4 | 244 | |
d62a17ae | 245 | if (BGP_DEBUG(zebra, ZEBRA)) |
246 | zlog_debug("Zebra: BFD Dest replay request"); | |
c43ed2e4 | 247 | |
d62a17ae | 248 | /* Send the client registration */ |
249 | bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); | |
055c4dfc | 250 | |
d62a17ae | 251 | /* Replay the peer, if BFD is enabled in BGP */ |
c43ed2e4 | 252 | |
d62a17ae | 253 | for (ALL_LIST_ELEMENTS_RO(bm->bgp, mnode, bgp)) |
254 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
255 | bgp_bfd_update_peer(peer); | |
256 | } | |
c43ed2e4 | 257 | |
d62a17ae | 258 | return 0; |
c43ed2e4 DS |
259 | } |
260 | ||
261 | /* | |
68fe91d6 | 262 | * bgp_bfd_peer_status_update - Update the BFD status if it has changed. Bring |
d62a17ae | 263 | * down the peer if the BFD session went down from |
264 | * * up. | |
68fe91d6 | 265 | */ |
d62a17ae | 266 | static void bgp_bfd_peer_status_update(struct peer *peer, int status) |
68fe91d6 | 267 | { |
d62a17ae | 268 | struct bfd_info *bfd_info; |
269 | int old_status; | |
68fe91d6 | 270 | |
d62a17ae | 271 | bfd_info = (struct bfd_info *)peer->bfd_info; |
68fe91d6 | 272 | |
d62a17ae | 273 | if (bfd_info->status == status) |
274 | return; | |
68fe91d6 | 275 | |
d62a17ae | 276 | old_status = bfd_info->status; |
277 | bfd_info->status = status; | |
278 | bfd_info->last_update = bgp_clock(); | |
68fe91d6 | 279 | |
d62a17ae | 280 | if ((status == BFD_STATUS_DOWN) && (old_status == BFD_STATUS_UP)) { |
281 | peer->last_reset = PEER_DOWN_BFD_DOWN; | |
282 | BGP_EVENT_ADD(peer, BGP_Stop); | |
283 | } | |
68fe91d6 | 284 | } |
285 | ||
286 | /* | |
287 | * bgp_bfd_dest_update - Find the peer for which the BFD status | |
288 | * has changed and bring down the peer | |
289 | * connectivity if the BFD session went down. | |
c43ed2e4 | 290 | */ |
d62a17ae | 291 | static int bgp_bfd_dest_update(int command, struct zclient *zclient, |
292 | zebra_size_t length, vrf_id_t vrf_id) | |
c43ed2e4 | 293 | { |
d62a17ae | 294 | struct interface *ifp; |
295 | struct prefix dp; | |
296 | struct prefix sp; | |
297 | int status; | |
298 | ||
299 | ifp = bfd_get_peer_info(zclient->ibuf, &dp, &sp, &status, vrf_id); | |
300 | ||
301 | if (BGP_DEBUG(zebra, ZEBRA)) { | |
302 | char buf[2][PREFIX2STR_BUFFER]; | |
303 | prefix2str(&dp, buf[0], sizeof(buf[0])); | |
304 | if (ifp) { | |
305 | zlog_debug( | |
306 | "Zebra: vrf %d interface %s bfd destination %s %s", | |
307 | vrf_id, ifp->name, buf[0], | |
308 | bfd_get_status_str(status)); | |
309 | } else { | |
310 | prefix2str(&sp, buf[1], sizeof(buf[1])); | |
311 | zlog_debug( | |
312 | "Zebra: vrf %d source %s bfd destination %s %s", | |
313 | vrf_id, buf[1], buf[0], | |
314 | bfd_get_status_str(status)); | |
315 | } | |
316 | } | |
317 | ||
318 | /* Bring the peer down if BFD is enabled in BGP */ | |
319 | { | |
320 | struct listnode *mnode, *node, *nnode; | |
321 | struct bgp *bgp; | |
322 | struct peer *peer; | |
323 | ||
324 | for (ALL_LIST_ELEMENTS_RO(bm->bgp, mnode, bgp)) | |
325 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
326 | if (!peer->bfd_info) | |
327 | continue; | |
328 | ||
329 | if ((dp.family == AF_INET) | |
330 | && (peer->su.sa.sa_family == AF_INET)) { | |
331 | if (dp.u.prefix4.s_addr | |
332 | != peer->su.sin.sin_addr.s_addr) | |
333 | continue; | |
334 | } else if ((dp.family == AF_INET6) | |
335 | && (peer->su.sa.sa_family | |
336 | == AF_INET6)) { | |
337 | if (memcmp(&dp.u.prefix6, | |
338 | &peer->su.sin6.sin6_addr, | |
339 | sizeof(struct in6_addr))) | |
340 | continue; | |
341 | } else | |
342 | continue; | |
343 | ||
344 | if (ifp && (ifp == peer->nexthop.ifp)) { | |
345 | bgp_bfd_peer_status_update(peer, | |
346 | status); | |
347 | } else { | |
348 | if (!peer->su_local) | |
349 | continue; | |
350 | ||
351 | if ((sp.family == AF_INET) | |
352 | && (peer->su_local->sa.sa_family | |
353 | == AF_INET)) { | |
354 | if (sp.u.prefix4.s_addr | |
355 | != peer->su_local->sin | |
356 | .sin_addr.s_addr) | |
357 | continue; | |
358 | } else if ((sp.family == AF_INET6) | |
359 | && (peer->su_local->sa | |
360 | .sa_family | |
361 | == AF_INET6)) { | |
362 | if (memcmp(&sp.u.prefix6, | |
363 | &peer->su_local->sin6 | |
364 | .sin6_addr, | |
365 | sizeof(struct | |
366 | in6_addr))) | |
367 | continue; | |
368 | } else | |
369 | continue; | |
370 | ||
371 | if ((vrf_id != VRF_DEFAULT) | |
372 | && (peer->bgp->vrf_id != vrf_id)) | |
373 | continue; | |
374 | ||
375 | bgp_bfd_peer_status_update(peer, | |
376 | status); | |
377 | } | |
378 | } | |
379 | } | |
380 | ||
381 | return 0; | |
c43ed2e4 DS |
382 | } |
383 | ||
384 | /* | |
385 | * bgp_bfd_peer_param_set - Set the configured BFD paramter values for peer. | |
386 | */ | |
d62a17ae | 387 | static int bgp_bfd_peer_param_set(struct peer *peer, u_int32_t min_rx, |
388 | u_int32_t min_tx, u_int8_t detect_mult, | |
389 | int defaults) | |
c43ed2e4 | 390 | { |
d62a17ae | 391 | struct peer_group *group; |
392 | struct listnode *node, *nnode; | |
393 | int command = 0; | |
394 | ||
395 | bfd_set_param((struct bfd_info **)&(peer->bfd_info), min_rx, min_tx, | |
396 | detect_mult, defaults, &command); | |
397 | ||
398 | if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { | |
399 | group = peer->group; | |
400 | for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { | |
401 | command = 0; | |
402 | bfd_set_param((struct bfd_info **)&(peer->bfd_info), | |
403 | min_rx, min_tx, detect_mult, defaults, | |
404 | &command); | |
405 | ||
406 | if ((peer->status == Established) | |
407 | && (command == ZEBRA_BFD_DEST_REGISTER)) | |
408 | bgp_bfd_register_peer(peer); | |
409 | else if (command == ZEBRA_BFD_DEST_UPDATE) | |
410 | bgp_bfd_update_peer(peer); | |
411 | } | |
412 | } else { | |
413 | if ((peer->status == Established) | |
414 | && (command == ZEBRA_BFD_DEST_REGISTER)) | |
415 | bgp_bfd_register_peer(peer); | |
416 | else if (command == ZEBRA_BFD_DEST_UPDATE) | |
417 | bgp_bfd_update_peer(peer); | |
418 | } | |
419 | return 0; | |
c43ed2e4 DS |
420 | } |
421 | ||
422 | /* | |
d62a17ae | 423 | * bgp_bfd_peer_param_unset - Delete the configured BFD paramter values for |
424 | * peer. | |
c43ed2e4 | 425 | */ |
d62a17ae | 426 | static int bgp_bfd_peer_param_unset(struct peer *peer) |
c43ed2e4 | 427 | { |
d62a17ae | 428 | struct peer_group *group; |
429 | struct listnode *node, *nnode; | |
430 | ||
431 | if (!peer->bfd_info) | |
432 | return 0; | |
433 | ||
434 | if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { | |
435 | bfd_info_free(&(peer->bfd_info)); | |
436 | group = peer->group; | |
437 | for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { | |
438 | bgp_bfd_deregister_peer(peer); | |
439 | bfd_info_free(&(peer->bfd_info)); | |
440 | } | |
441 | } else { | |
442 | bgp_bfd_deregister_peer(peer); | |
443 | bfd_info_free(&(peer->bfd_info)); | |
444 | } | |
445 | return 0; | |
c43ed2e4 DS |
446 | } |
447 | ||
986aa00f | 448 | /* |
d62a17ae | 449 | * bgp_bfd_peer_param_type_set - set the BFD session type (multihop or |
450 | * singlehop) | |
986aa00f | 451 | */ |
d62a17ae | 452 | static int bgp_bfd_peer_param_type_set(struct peer *peer, |
453 | enum bfd_sess_type type) | |
986aa00f | 454 | { |
d62a17ae | 455 | struct peer_group *group; |
456 | struct listnode *node, *nnode; | |
457 | int command = 0; | |
458 | struct bfd_info *bfd_info; | |
459 | ||
460 | if (!peer->bfd_info) | |
461 | bfd_set_param((struct bfd_info **)&(peer->bfd_info), | |
462 | BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, | |
463 | BFD_DEF_DETECT_MULT, 1, &command); | |
464 | ||
465 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
466 | bfd_info->type = type; | |
467 | ||
468 | if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { | |
469 | group = peer->group; | |
470 | for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { | |
471 | command = 0; | |
472 | if (!peer->bfd_info) | |
473 | bfd_set_param( | |
474 | (struct bfd_info **)&(peer->bfd_info), | |
475 | BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, | |
476 | BFD_DEF_DETECT_MULT, 1, &command); | |
477 | ||
478 | bfd_info = (struct bfd_info *)peer->bfd_info; | |
479 | bfd_info->type = type; | |
480 | ||
481 | if (peer->status == Established) { | |
482 | if (command == ZEBRA_BFD_DEST_REGISTER) | |
483 | bgp_bfd_register_peer(peer); | |
484 | else | |
485 | bgp_bfd_update_type(peer); | |
486 | } | |
487 | } | |
488 | } else { | |
489 | if (peer->status == Established) { | |
490 | if (command == ZEBRA_BFD_DEST_REGISTER) | |
491 | bgp_bfd_register_peer(peer); | |
492 | else | |
493 | bgp_bfd_update_type(peer); | |
494 | } | |
495 | } | |
496 | ||
497 | return 0; | |
986aa00f | 498 | } |
499 | ||
c43ed2e4 DS |
500 | /* |
501 | * bgp_bfd_peer_config_write - Write the peer BFD configuration. | |
502 | */ | |
d62a17ae | 503 | void bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, char *addr) |
c43ed2e4 | 504 | { |
d62a17ae | 505 | struct bfd_info *bfd_info; |
c43ed2e4 | 506 | |
d62a17ae | 507 | if (!peer->bfd_info) |
508 | return; | |
7f342629 | 509 | |
d62a17ae | 510 | bfd_info = (struct bfd_info *)peer->bfd_info; |
c43ed2e4 | 511 | |
d62a17ae | 512 | if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG)) |
513 | vty_out(vty, " neighbor %s bfd %d %d %d\n", addr, | |
514 | bfd_info->detect_mult, bfd_info->required_min_rx, | |
515 | bfd_info->desired_min_tx); | |
986aa00f | 516 | |
d62a17ae | 517 | if (bfd_info->type != BFD_TYPE_NOT_CONFIGURED) |
518 | vty_out(vty, " neighbor %s bfd %s\n", addr, | |
519 | (bfd_info->type == BFD_TYPE_MULTIHOP) ? "multihop" | |
520 | : "singlehop"); | |
986aa00f | 521 | |
d62a17ae | 522 | if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG) |
523 | && (bfd_info->type == BFD_TYPE_NOT_CONFIGURED)) | |
524 | vty_out(vty, " neighbor %s bfd\n", addr); | |
c43ed2e4 DS |
525 | } |
526 | ||
527 | /* | |
528 | * bgp_bfd_show_info - Show the peer BFD information. | |
529 | */ | |
d62a17ae | 530 | void bgp_bfd_show_info(struct vty *vty, struct peer *peer, u_char use_json, |
531 | json_object *json_neigh) | |
c43ed2e4 | 532 | { |
d62a17ae | 533 | bfd_show_info(vty, (struct bfd_info *)peer->bfd_info, |
534 | bgp_bfd_is_peer_multihop(peer), 0, use_json, json_neigh); | |
c43ed2e4 DS |
535 | } |
536 | ||
537 | DEFUN (neighbor_bfd, | |
538 | neighbor_bfd_cmd, | |
9ccf14f7 | 539 | "neighbor <A.B.C.D|X:X::X:X|WORD> bfd", |
c43ed2e4 DS |
540 | NEIGHBOR_STR |
541 | NEIGHBOR_ADDR_STR2 | |
542 | "Enables BFD support\n") | |
543 | { | |
d62a17ae | 544 | int idx_peer = 1; |
545 | struct peer *peer; | |
546 | int ret; | |
c43ed2e4 | 547 | |
d62a17ae | 548 | peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); |
549 | if (!peer) | |
550 | return CMD_WARNING_CONFIG_FAILED; | |
c43ed2e4 | 551 | |
d62a17ae | 552 | ret = bgp_bfd_peer_param_set(peer, BFD_DEF_MIN_RX, BFD_DEF_MIN_TX, |
553 | BFD_DEF_DETECT_MULT, 1); | |
554 | if (ret != 0) | |
555 | return bgp_vty_return(vty, ret); | |
c43ed2e4 | 556 | |
d62a17ae | 557 | return CMD_SUCCESS; |
c43ed2e4 DS |
558 | } |
559 | ||
560 | DEFUN (neighbor_bfd_param, | |
561 | neighbor_bfd_param_cmd, | |
9ccf14f7 | 562 | "neighbor <A.B.C.D|X:X::X:X|WORD> bfd (2-255) (50-60000) (50-60000)", |
c43ed2e4 DS |
563 | NEIGHBOR_STR |
564 | NEIGHBOR_ADDR_STR2 | |
565 | "Enables BFD support\n" | |
566 | "Detect Multiplier\n" | |
567 | "Required min receive interval\n" | |
568 | "Desired min transmit interval\n") | |
569 | { | |
d62a17ae | 570 | int idx_peer = 1; |
571 | int idx_number_1 = 3; | |
572 | int idx_number_2 = 4; | |
573 | int idx_number_3 = 5; | |
574 | struct peer *peer; | |
575 | u_int32_t rx_val; | |
576 | u_int32_t tx_val; | |
577 | u_int8_t dm_val; | |
578 | int ret; | |
579 | ||
580 | peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); | |
581 | if (!peer) | |
582 | return CMD_WARNING_CONFIG_FAILED; | |
583 | ||
584 | if ((ret = bfd_validate_param( | |
585 | vty, argv[idx_number_1]->arg, argv[idx_number_2]->arg, | |
586 | argv[idx_number_3]->arg, &dm_val, &rx_val, &tx_val)) | |
587 | != CMD_SUCCESS) | |
588 | return ret; | |
589 | ||
590 | ret = bgp_bfd_peer_param_set(peer, rx_val, tx_val, dm_val, 0); | |
591 | if (ret != 0) | |
592 | return bgp_vty_return(vty, ret); | |
593 | ||
594 | return CMD_SUCCESS; | |
c43ed2e4 DS |
595 | } |
596 | ||
986aa00f | 597 | DEFUN_HIDDEN (neighbor_bfd_type, |
598 | neighbor_bfd_type_cmd, | |
e83a9414 | 599 | "neighbor <A.B.C.D|X:X::X:X|WORD> bfd <multihop|singlehop>", |
986aa00f | 600 | NEIGHBOR_STR |
601 | NEIGHBOR_ADDR_STR2 | |
602 | "Enables BFD support\n" | |
d7fa34c1 QY |
603 | "Multihop session\n" |
604 | "Single hop session\n") | |
986aa00f | 605 | { |
d62a17ae | 606 | int idx_peer = 1; |
607 | int idx_hop = 3; | |
608 | struct peer *peer; | |
609 | enum bfd_sess_type type; | |
610 | int ret; | |
611 | ||
612 | peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); | |
613 | if (!peer) | |
614 | return CMD_WARNING_CONFIG_FAILED; | |
615 | ||
616 | if (strmatch(argv[idx_hop]->text, "singlehop")) | |
617 | type = BFD_TYPE_SINGLEHOP; | |
618 | else if (strmatch(argv[idx_hop]->text, "multihop")) | |
619 | type = BFD_TYPE_MULTIHOP; | |
620 | else | |
621 | return CMD_WARNING_CONFIG_FAILED; | |
622 | ||
623 | ret = bgp_bfd_peer_param_type_set(peer, type); | |
624 | if (ret != 0) | |
625 | return bgp_vty_return(vty, ret); | |
626 | ||
627 | return CMD_SUCCESS; | |
986aa00f | 628 | } |
629 | ||
c43ed2e4 DS |
630 | DEFUN (no_neighbor_bfd, |
631 | no_neighbor_bfd_cmd, | |
5bf15956 | 632 | "no neighbor <A.B.C.D|X:X::X:X|WORD> bfd [(2-255) (50-60000) (50-60000)]", |
c43ed2e4 DS |
633 | NO_STR |
634 | NEIGHBOR_STR | |
635 | NEIGHBOR_ADDR_STR2 | |
5bf15956 DW |
636 | "Disables BFD support\n" |
637 | "Detect Multiplier\n" | |
638 | "Required min receive interval\n" | |
639 | "Desired min transmit interval\n") | |
c43ed2e4 | 640 | { |
d62a17ae | 641 | int idx_peer = 2; |
642 | struct peer *peer; | |
643 | int ret; | |
c43ed2e4 | 644 | |
d62a17ae | 645 | peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); |
646 | if (!peer) | |
647 | return CMD_WARNING_CONFIG_FAILED; | |
c43ed2e4 | 648 | |
d62a17ae | 649 | ret = bgp_bfd_peer_param_unset(peer); |
650 | if (ret != 0) | |
651 | return bgp_vty_return(vty, ret); | |
c43ed2e4 | 652 | |
d62a17ae | 653 | return CMD_SUCCESS; |
c43ed2e4 DS |
654 | } |
655 | ||
813d4307 | 656 | |
986aa00f | 657 | DEFUN_HIDDEN (no_neighbor_bfd_type, |
658 | no_neighbor_bfd_type_cmd, | |
e83a9414 | 659 | "no neighbor <A.B.C.D|X:X::X:X|WORD> bfd <multihop|singlehop>", |
986aa00f | 660 | NO_STR |
661 | NEIGHBOR_STR | |
662 | NEIGHBOR_ADDR_STR2 | |
663 | "Disables BFD support\n" | |
3a2d747c QY |
664 | "Multihop session\n" |
665 | "Singlehop session\n") | |
986aa00f | 666 | { |
d62a17ae | 667 | int idx_peer = 2; |
668 | struct peer *peer; | |
669 | int ret; | |
986aa00f | 670 | |
d62a17ae | 671 | peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); |
672 | if (!peer) | |
673 | return CMD_WARNING_CONFIG_FAILED; | |
986aa00f | 674 | |
d62a17ae | 675 | if (!peer->bfd_info) |
676 | return 0; | |
986aa00f | 677 | |
d62a17ae | 678 | ret = bgp_bfd_peer_param_type_set(peer, BFD_TYPE_NOT_CONFIGURED); |
679 | if (ret != 0) | |
680 | return bgp_vty_return(vty, ret); | |
986aa00f | 681 | |
d62a17ae | 682 | return CMD_SUCCESS; |
986aa00f | 683 | } |
684 | ||
d62a17ae | 685 | void bgp_bfd_init(void) |
c43ed2e4 | 686 | { |
d62a17ae | 687 | bfd_gbl_init(); |
688 | ||
689 | /* Initialize BFD client functions */ | |
690 | zclient->interface_bfd_dest_update = bgp_bfd_dest_update; | |
691 | zclient->bfd_dest_replay = bgp_bfd_dest_replay; | |
692 | ||
693 | /* "neighbor bfd" commands. */ | |
694 | install_element(BGP_NODE, &neighbor_bfd_cmd); | |
695 | install_element(BGP_NODE, &neighbor_bfd_param_cmd); | |
696 | install_element(BGP_NODE, &neighbor_bfd_type_cmd); | |
697 | install_element(BGP_NODE, &no_neighbor_bfd_cmd); | |
698 | install_element(BGP_NODE, &no_neighbor_bfd_type_cmd); | |
c43ed2e4 | 699 | } |