]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_bfd.c
Merge pull request #9703 from donaldsharp/splitup_bgp_gr
[mirror_frr.git] / pimd / pim_bfd.c
1 /*
2 * pim_bfd.c: PIM BFD handling routines
3 *
4 * Copyright (C) 2017 Cumulus Networks, Inc.
5 * Chirag Shah
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
23 #include <zebra.h>
24
25 #include "lib/json.h"
26 #include "command.h"
27 #include "vty.h"
28 #include "zclient.h"
29
30 #include "pim_instance.h"
31 #include "pim_neighbor.h"
32 #include "pim_cmd.h"
33 #include "pim_vty.h"
34 #include "pim_iface.h"
35 #include "pim_bfd.h"
36 #include "bfd.h"
37 #include "pimd.h"
38 #include "pim_zebra.h"
39
40 /*
41 * pim_bfd_write_config - Write the interface BFD configuration.
42 */
43 void pim_bfd_write_config(struct vty *vty, struct interface *ifp)
44 {
45 struct pim_interface *pim_ifp = ifp->info;
46
47 if (!pim_ifp || !pim_ifp->bfd_config.enabled)
48 return;
49
50 #if HAVE_BFDD == 0
51 if (pim_ifp->bfd_config.detection_multiplier != BFD_DEF_DETECT_MULT
52 || pim_ifp->bfd_config.min_rx != BFD_DEF_MIN_RX
53 || pim_ifp->bfd_config.min_tx != BFD_DEF_MIN_TX)
54 vty_out(vty, " ip pim bfd %d %d %d\n",
55 pim_ifp->bfd_config.detection_multiplier,
56 pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx);
57 else
58 #endif /* ! HAVE_BFDD */
59 vty_out(vty, " ip pim bfd\n");
60
61 if (pim_ifp->bfd_config.profile)
62 vty_out(vty, " ip pim bfd profile %s\n",
63 pim_ifp->bfd_config.profile);
64 }
65
66 static void pim_neighbor_bfd_cb(struct bfd_session_params *bsp,
67 const struct bfd_session_status *bss, void *arg)
68 {
69 struct pim_neighbor *nbr = arg;
70
71 if (PIM_DEBUG_PIM_TRACE) {
72 zlog_debug("%s: status %s old_status %s", __func__,
73 bfd_get_status_str(bss->state),
74 bfd_get_status_str(bss->previous_state));
75 }
76
77 if (bss->state == BFD_STATUS_DOWN
78 && bss->previous_state == BFD_STATUS_UP)
79 pim_neighbor_delete(nbr->interface, nbr, "BFD Session Expired");
80 }
81
82 /*
83 * pim_bfd_info_nbr_create - Create/update BFD information for a neighbor.
84 */
85 void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp,
86 struct pim_neighbor *neigh)
87 {
88 /* Check if Pim Interface BFD is enabled */
89 if (!pim_ifp || !pim_ifp->bfd_config.enabled)
90 return;
91
92 if (neigh->bfd_session == NULL)
93 neigh->bfd_session = bfd_sess_new(pim_neighbor_bfd_cb, neigh);
94
95 bfd_sess_set_timers(
96 neigh->bfd_session, pim_ifp->bfd_config.detection_multiplier,
97 pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx);
98 bfd_sess_set_ipv4_addrs(neigh->bfd_session, NULL, &neigh->source_addr);
99 bfd_sess_set_interface(neigh->bfd_session, neigh->interface->name);
100 bfd_sess_set_vrf(neigh->bfd_session, neigh->interface->vrf->vrf_id);
101 bfd_sess_set_profile(neigh->bfd_session, pim_ifp->bfd_config.profile);
102 bfd_sess_install(neigh->bfd_session);
103 }
104
105 /*
106 * pim_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
107 * with a interface with BFD through
108 * zebra for starting/stopping the monitoring of
109 * the neighbor rechahability.
110 */
111 void pim_bfd_reg_dereg_all_nbr(struct interface *ifp)
112 {
113 struct pim_interface *pim_ifp = NULL;
114 struct listnode *node = NULL;
115 struct pim_neighbor *neigh = NULL;
116
117 pim_ifp = ifp->info;
118 if (!pim_ifp)
119 return;
120
121 for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
122 if (pim_ifp->bfd_config.enabled)
123 pim_bfd_info_nbr_create(pim_ifp, neigh);
124 else
125 bfd_sess_free(&neigh->bfd_session);
126 }
127 }
128
129 void pim_bfd_init(void)
130 {
131 bfd_protocol_integration_init(pim_zebra_zclient_get(), router->master);
132 }