]>
git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_bfd.c
2 * ospf_bfd.c: OSPF BFD handling routines
4 * @copyright Copyright (C) 2015 Cumulus Networks, Inc.
6 * This file is part of GNU Zebra.
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
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.
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
38 #include "ospf_asbr.h"
40 #include "ospf_lsdb.h"
41 #include "ospf_neighbor.h"
42 #include "ospf_interface.h"
45 #include "ospf_dump.h"
48 DEFINE_MTYPE_STATIC(OSPFD
, BFD_CONFIG
, "BFD configuration data");
51 * ospf_bfd_trigger_event - Neighbor is registered/deregistered with BFD when
52 * neighbor state is changed to/from 2way.
54 void ospf_bfd_trigger_event(struct ospf_neighbor
*nbr
, int old_state
, int state
)
56 if ((old_state
< NSM_TwoWay
) && (state
>= NSM_TwoWay
))
57 bfd_sess_install(nbr
->bfd_session
);
58 else if ((old_state
>= NSM_TwoWay
) && (state
< NSM_TwoWay
))
59 bfd_sess_uninstall(nbr
->bfd_session
);
62 static void ospf_bfd_session_change(struct bfd_session_params
*bsp
,
63 const struct bfd_session_status
*bss
,
66 struct ospf_neighbor
*nbr
= arg
;
68 /* BFD peer went down. */
69 if (bss
->state
== BFD_STATUS_DOWN
70 && bss
->previous_state
== BFD_STATUS_UP
) {
71 if (IS_DEBUG_OSPF(bfd
, BFD_LIB
))
72 zlog_debug("%s: NSM[%s:%pI4]: BFD Down", __func__
,
73 IF_NAME(nbr
->oi
), &nbr
->address
.u
.prefix4
);
75 OSPF_NSM_EVENT_SCHEDULE(nbr
, NSM_InactivityTimer
);
78 /* BFD peer went up. */
79 if (bss
->state
== BSS_UP
&& bss
->previous_state
== BSS_DOWN
)
80 if (IS_DEBUG_OSPF(bfd
, BFD_LIB
))
81 zlog_debug("%s: NSM[%s:%pI4]: BFD Up", __func__
,
82 IF_NAME(nbr
->oi
), &nbr
->address
.u
.prefix4
);
85 void ospf_neighbor_bfd_apply(struct ospf_neighbor
*nbr
)
87 struct ospf_interface
*oi
= nbr
->oi
;
88 struct ospf_if_params
*oip
= IF_DEF_PARAMS(oi
->ifp
);
90 /* BFD configuration was removed. */
91 if (oip
->bfd_config
== NULL
) {
92 bfd_sess_free(&nbr
->bfd_session
);
96 /* New BFD session. */
97 if (nbr
->bfd_session
== NULL
) {
98 nbr
->bfd_session
= bfd_sess_new(ospf_bfd_session_change
, nbr
);
99 bfd_sess_set_ipv4_addrs(nbr
->bfd_session
, NULL
, &nbr
->src
);
100 bfd_sess_set_interface(nbr
->bfd_session
, oi
->ifp
->name
);
101 bfd_sess_set_vrf(nbr
->bfd_session
, oi
->ospf
->vrf_id
);
104 /* Set new configuration. */
105 bfd_sess_set_timers(nbr
->bfd_session
,
106 oip
->bfd_config
->detection_multiplier
,
107 oip
->bfd_config
->min_rx
, oip
->bfd_config
->min_tx
);
108 bfd_sess_set_profile(nbr
->bfd_session
, oip
->bfd_config
->profile
);
110 /* Don't start sessions on down OSPF sessions. */
111 if (nbr
->state
< NSM_TwoWay
)
114 bfd_sess_install(nbr
->bfd_session
);
117 static void ospf_interface_bfd_apply(struct interface
*ifp
)
119 struct ospf_interface
*oi
;
120 struct route_table
*nbrs
;
121 struct ospf_neighbor
*nbr
;
122 struct route_node
*irn
;
123 struct route_node
*nrn
;
125 /* Iterate over all interfaces and set neighbors BFD session. */
126 for (irn
= route_top(IF_OIFS(ifp
)); irn
; irn
= route_next(irn
)) {
127 if ((oi
= irn
->info
) == NULL
)
129 if ((nbrs
= oi
->nbrs
) == NULL
)
131 for (nrn
= route_top(nbrs
); nrn
; nrn
= route_next(nrn
)) {
132 if ((nbr
= nrn
->info
) == NULL
|| nbr
== oi
->nbr_self
)
135 ospf_neighbor_bfd_apply(nbr
);
140 static void ospf_interface_enable_bfd(struct interface
*ifp
)
142 struct ospf_if_params
*oip
= IF_DEF_PARAMS(ifp
);
147 /* Allocate memory for configurations and set defaults. */
148 oip
->bfd_config
= XCALLOC(MTYPE_BFD_CONFIG
, sizeof(*oip
->bfd_config
));
149 oip
->bfd_config
->detection_multiplier
= BFD_DEF_DETECT_MULT
;
150 oip
->bfd_config
->min_rx
= BFD_DEF_MIN_RX
;
151 oip
->bfd_config
->min_tx
= BFD_DEF_MIN_TX
;
154 void ospf_interface_disable_bfd(struct interface
*ifp
,
155 struct ospf_if_params
*oip
)
157 XFREE(MTYPE_BFD_CONFIG
, oip
->bfd_config
);
158 ospf_interface_bfd_apply(ifp
);
162 * ospf_bfd_write_config - Write the interface BFD configuration.
164 void ospf_bfd_write_config(struct vty
*vty
, const struct ospf_if_params
*params
165 __attribute__((unused
)))
168 if (params
->bfd_config
->detection_multiplier
!= BFD_DEF_DETECT_MULT
169 || params
->bfd_config
->min_rx
!= BFD_DEF_MIN_RX
170 || params
->bfd_config
->min_tx
!= BFD_DEF_MIN_TX
)
171 vty_out(vty
, " ip ospf bfd %d %d %d\n",
172 params
->bfd_config
->detection_multiplier
,
173 params
->bfd_config
->min_rx
, params
->bfd_config
->min_tx
);
175 #endif /* ! HAVE_BFDD */
176 vty_out(vty
, " ip ospf bfd\n");
178 if (params
->bfd_config
->profile
[0])
179 vty_out(vty
, " ip ospf bfd profile %s\n",
180 params
->bfd_config
->profile
);
183 void ospf_interface_bfd_show(struct vty
*vty
, const struct interface
*ifp
,
184 struct json_object
*json
)
186 struct ospf_if_params
*params
= IF_DEF_PARAMS(ifp
);
187 struct bfd_configuration
*bfd_config
= params
->bfd_config
;
188 struct json_object
*json_bfd
;
190 if (bfd_config
== NULL
)
194 json_bfd
= json_object_new_object();
195 json_object_int_add(json_bfd
, "detectionMultiplier",
196 bfd_config
->detection_multiplier
);
197 json_object_int_add(json_bfd
, "rxMinInterval",
199 json_object_int_add(json_bfd
, "txMinInterval",
201 json_object_object_add(json
, "peerBfdInfo", json_bfd
);
204 " BFD: Detect Multiplier: %d, Min Rx interval: %d, Min Tx interval: %d\n",
205 bfd_config
->detection_multiplier
, bfd_config
->min_rx
,
213 "OSPF interface commands\n"
214 "Enables BFD support\n")
216 VTY_DECLVAR_CONTEXT(interface
, ifp
);
217 ospf_interface_enable_bfd(ifp
);
218 ospf_interface_bfd_apply(ifp
);
226 #endif /* HAVE_BFDD */
228 ip_ospf_bfd_param_cmd
,
229 "ip ospf bfd (2-255) (50-60000) (50-60000)",
231 "OSPF interface commands\n"
232 "Enables BFD support\n"
233 "Detect Multiplier\n"
234 "Required min receive interval\n"
235 "Desired min transmit interval\n")
237 VTY_DECLVAR_CONTEXT(interface
, ifp
);
238 struct ospf_if_params
*params
;
240 int idx_number_2
= 4;
241 int idx_number_3
= 5;
243 ospf_interface_enable_bfd(ifp
);
245 params
= IF_DEF_PARAMS(ifp
);
246 params
->bfd_config
->detection_multiplier
=
247 strtol(argv
[idx_number
]->arg
, NULL
, 10);
248 params
->bfd_config
->min_rx
= strtol(argv
[idx_number_2
]->arg
, NULL
, 10);
249 params
->bfd_config
->min_tx
= strtol(argv
[idx_number_3
]->arg
, NULL
, 10);
251 ospf_interface_bfd_apply(ifp
);
256 DEFUN (ip_ospf_bfd_prof
,
257 ip_ospf_bfd_prof_cmd
,
258 "ip ospf bfd profile BFDPROF",
260 "OSPF interface commands\n"
261 "Enables BFD support\n"
263 BFD_PROFILE_NAME_STR
)
265 VTY_DECLVAR_CONTEXT(interface
, ifp
);
266 struct ospf_if_params
*params
;
269 ospf_interface_enable_bfd(ifp
);
270 params
= IF_DEF_PARAMS(ifp
);
271 strlcpy(params
->bfd_config
->profile
, argv
[idx_prof
]->arg
,
272 sizeof(params
->bfd_config
->profile
));
273 ospf_interface_bfd_apply(ifp
);
278 DEFUN (no_ip_ospf_bfd_prof
,
279 no_ip_ospf_bfd_prof_cmd
,
280 "no ip ospf bfd profile [BFDPROF]",
283 "OSPF interface commands\n"
284 "Enables BFD support\n"
286 BFD_PROFILE_NAME_STR
)
288 VTY_DECLVAR_CONTEXT(interface
, ifp
);
289 struct ospf_if_params
*params
;
291 ospf_interface_enable_bfd(ifp
);
292 params
= IF_DEF_PARAMS(ifp
);
293 params
->bfd_config
->profile
[0] = 0;
294 ospf_interface_bfd_apply(ifp
);
299 DEFUN (no_ip_ospf_bfd
,
304 "no ip ospf bfd [(2-255) (50-60000) (50-60000)]",
305 #endif /* HAVE_BFDD */
308 "OSPF interface commands\n"
309 "Disables BFD support\n"
311 "Detect Multiplier\n"
312 "Required min receive interval\n"
313 "Desired min transmit interval\n"
314 #endif /* !HAVE_BFDD */
317 VTY_DECLVAR_CONTEXT(interface
, ifp
);
318 ospf_interface_disable_bfd(ifp
, IF_DEF_PARAMS(ifp
));
322 void ospf_bfd_init(struct thread_master
*tm
)
324 bfd_protocol_integration_init(zclient
, tm
);
326 /* Install BFD command */
327 install_element(INTERFACE_NODE
, &ip_ospf_bfd_cmd
);
328 install_element(INTERFACE_NODE
, &ip_ospf_bfd_param_cmd
);
329 install_element(INTERFACE_NODE
, &ip_ospf_bfd_prof_cmd
);
330 install_element(INTERFACE_NODE
, &no_ip_ospf_bfd_prof_cmd
);
331 install_element(INTERFACE_NODE
, &no_ip_ospf_bfd_cmd
);