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
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
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 extern struct zclient
*zclient
;
51 * ospf_bfd_reg_dereg_nbr - Register/Deregister a neighbor with BFD through
52 * zebra for starting/stopping the monitoring of
53 * the neighbor rechahability.
56 ospf_bfd_reg_dereg_nbr (struct ospf_neighbor
*nbr
, int command
)
58 struct ospf_interface
*oi
= nbr
->oi
;
59 struct interface
*ifp
= oi
->ifp
;
60 struct ospf_if_params
*params
;
61 struct bfd_info
*bfd_info
;
63 /* Check if BFD is enabled */
64 params
= IF_DEF_PARAMS (ifp
);
66 /* Check if BFD is enabled */
67 if (!params
->bfd_info
)
69 bfd_info
= (struct bfd_info
*)params
->bfd_info
;
71 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
72 zlog_debug ("%s nbr (%s) with BFD",
73 bfd_get_command_dbg_str(command
),
74 inet_ntoa (nbr
->src
));
76 bfd_peer_sendmsg (zclient
, bfd_info
, AF_INET
,
77 &nbr
->src
, NULL
, ifp
->name
, 0, 0, command
, 0);
81 * ospf_bfd_trigger_event - Neighbor is registered/deregistered with BFD when
82 * neighbor state is changed to/from 2way.
85 ospf_bfd_trigger_event(struct ospf_neighbor
*nbr
, int old_state
, int state
)
87 if ((old_state
< NSM_TwoWay
) && (state
>= NSM_TwoWay
))
88 ospf_bfd_reg_dereg_nbr(nbr
, ZEBRA_BFD_DEST_REGISTER
);
89 else if ((old_state
>= NSM_TwoWay
) && (state
< NSM_TwoWay
))
90 ospf_bfd_reg_dereg_nbr(nbr
, ZEBRA_BFD_DEST_DEREGISTER
);
94 * ospf_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
95 * with a interface with BFD through
96 * zebra for starting/stopping the monitoring of
97 * the neighbor rechahability.
100 ospf_bfd_reg_dereg_all_nbr (struct interface
*ifp
, int command
)
102 struct ospf_interface
*oi
;
103 struct route_table
*nbrs
;
104 struct ospf_neighbor
*nbr
;
105 struct route_node
*irn
;
106 struct route_node
*nrn
;
108 for (irn
= route_top (IF_OIFS (ifp
)); irn
; irn
= route_next (irn
))
110 if ((oi
= irn
->info
) == NULL
)
113 if ((nbrs
= oi
->nbrs
) == NULL
)
116 for (nrn
= route_top (nbrs
); nrn
; nrn
= route_next (nrn
))
118 if ((nbr
= nrn
->info
) == NULL
|| nbr
== oi
->nbr_self
)
121 if (nbr
->state
< NSM_TwoWay
)
124 ospf_bfd_reg_dereg_nbr(nbr
, command
);
132 * ospf_bfd_nbr_replay - Replay all the neighbors that have BFD enabled
136 ospf_bfd_nbr_replay (int command
, struct zclient
*client
, zebra_size_t length
)
138 struct listnode
*inode
, *node
, *onode
;
140 struct ospf_interface
*oi
;
141 struct route_table
*nbrs
;
142 struct route_node
*rn
;
143 struct ospf_neighbor
*nbr
;
144 struct ospf_if_params
*params
;
146 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
148 zlog_debug("Zebra: BFD Dest replay request");
151 /* Replay the neighbor, if BFD is enabled in BGP */
152 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, onode
, ospf
))
154 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, inode
, oi
))
156 if ((nbrs
= oi
->nbrs
) == NULL
)
159 params
= IF_DEF_PARAMS (oi
->ifp
);
160 if (!params
->bfd_info
)
163 for (rn
= route_top (nbrs
); rn
; rn
= route_next (rn
))
165 if ((nbr
= rn
->info
) == NULL
|| nbr
== oi
->nbr_self
)
168 if (nbr
->state
< NSM_TwoWay
)
171 if (IS_DEBUG_OSPF(zebra
, ZEBRA_INTERFACE
))
172 zlog_debug ("Replaying nbr (%s) to BFD", inet_ntoa (nbr
->src
));
174 ospf_bfd_reg_dereg_nbr(nbr
, ZEBRA_BFD_DEST_UPDATE
);
182 * ospf_bfd_interface_dest_down - Find the neighbor for which the BFD status
183 * has changed and bring down the neighbor
187 ospf_bfd_interface_dest_down (int command
, struct zclient
*zclient
,
190 struct interface
*ifp
;
191 struct ospf_interface
*oi
;
192 struct ospf_if_params
*params
;
193 struct ospf_neighbor
*nbr
;
194 struct route_node
*node
;
197 ifp
= bfd_get_peer_info (zclient
->ibuf
, &p
, NULL
);
199 if ((ifp
== NULL
) || (p
.family
!= AF_INET
))
202 if (IS_DEBUG_OSPF (zebra
, ZEBRA_INTERFACE
))
205 prefix2str(&p
, buf
, sizeof(buf
));
206 zlog_debug("Zebra: interface %s bfd destination %s down", ifp
->name
, buf
);
209 params
= IF_DEF_PARAMS (ifp
);
210 if (!params
->bfd_info
)
213 for (node
= route_top (IF_OIFS (ifp
)); node
; node
= route_next (node
))
215 if ((oi
= node
->info
) == NULL
)
218 nbr
= ospf_nbr_lookup_by_addr (oi
->nbrs
, &p
.u
.prefix4
);
222 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
223 zlog_debug ("NSM[%s:%s]: BFD Down",
224 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->address
.u
.prefix4
));
226 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_InactivityTimer
);
233 * ospf_bfd_write_config - Write the interface BFD configuration.
236 ospf_bfd_write_config(struct vty
*vty
, struct ospf_if_params
*params
)
239 struct bfd_info
*bfd_info
;
241 if (!params
->bfd_info
)
244 bfd_info
= (struct bfd_info
*)params
->bfd_info
;
246 if (CHECK_FLAG(bfd_info
->flags
, BFD_FLAG_PARAM_CFG
))
247 vty_out (vty
, " ip ospf bfd %d %d %d%s",
248 bfd_info
->detect_mult
, bfd_info
->required_min_rx
,
249 bfd_info
->desired_min_tx
, VTY_NEWLINE
);
251 vty_out (vty
, " ip ospf bfd%s", VTY_NEWLINE
);
256 * ospf_bfd_if_param_set - Set the configured BFD paramter values for
260 ospf_bfd_if_param_set (struct interface
*ifp
, u_int32_t min_rx
,
261 u_int32_t min_tx
, u_int8_t detect_mult
, int defaults
)
263 struct ospf_if_params
*params
;
266 params
= IF_DEF_PARAMS (ifp
);
268 bfd_set_param(&(params
->bfd_info
), min_rx
, min_tx
, detect_mult
,
271 ospf_bfd_reg_dereg_all_nbr(ifp
, command
);
279 "OSPF interface commands\n"
280 "Enables BFD support\n")
282 struct interface
*ifp
= (struct interface
*) vty
->index
;
285 ospf_bfd_if_param_set (ifp
, BFD_DEF_MIN_RX
, BFD_DEF_MIN_TX
,
286 BFD_DEF_DETECT_MULT
, 1);
291 DEFUN (ip_ospf_bfd_param
,
292 ip_ospf_bfd_param_cmd
,
293 "ip ospf bfd " BFD_CMD_DETECT_MULT_RANGE BFD_CMD_MIN_RX_RANGE BFD_CMD_MIN_TX_RANGE
,
295 "OSPF interface commands\n"
296 "Enables BFD support\n"
297 "Detect Multiplier\n"
298 "Required min receive interval\n"
299 "Desired min transmit interval\n")
301 struct interface
*ifp
= (struct interface
*) vty
->index
;
309 if ((ret
= bfd_validate_param (vty
, argv
[0], argv
[1], argv
[2], &dm_val
,
310 &rx_val
, &tx_val
)) != CMD_SUCCESS
)
313 ospf_bfd_if_param_set (ifp
, rx_val
, tx_val
, dm_val
, 0);
318 DEFUN (no_ip_ospf_bfd
,
323 "OSPF interface commands\n"
324 "Disables BFD support\n")
326 struct interface
*ifp
= (struct interface
*)vty
->index
;
327 struct ospf_if_params
*params
;
331 params
= IF_DEF_PARAMS (ifp
);
332 if (params
->bfd_info
)
334 ospf_bfd_reg_dereg_all_nbr(ifp
, ZEBRA_BFD_DEST_DEREGISTER
);
335 bfd_info_free(&(params
->bfd_info
));
344 /* Initialize BFD client functions */
345 zclient
->interface_bfd_dest_down
= ospf_bfd_interface_dest_down
;
346 zclient
->bfd_dest_replay
= ospf_bfd_nbr_replay
;
348 /* Install BFD command */
349 install_element (INTERFACE_NODE
, &ip_ospf_bfd_cmd
);
350 install_element (INTERFACE_NODE
, &ip_ospf_bfd_param_cmd
);
351 install_element (INTERFACE_NODE
, &no_ip_ospf_bfd_cmd
);