2 * ospf6_bfd.c: IPv6 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 "ospf6_message.h"
39 #include "ospf6_neighbor.h"
40 #include "ospf6_interface.h"
41 #include "ospf6_route.h"
42 #include "ospf6_zebra.h"
43 #include "ospf6_bfd.h"
45 extern struct zclient
*zclient
;
48 * ospf6_bfd_info_free - Free BFD info structure
50 void ospf6_bfd_info_free(void **bfd_info
)
52 bfd_info_free((struct bfd_info
**)bfd_info
);
56 * ospf6_bfd_show_info - Show BFD info structure
58 void ospf6_bfd_show_info(struct vty
*vty
, void *bfd_info
, int param_only
,
59 json_object
*json_obj
, bool use_json
)
62 bfd_show_param(vty
, bfd_info
, 1, 0, 0, NULL
);
64 bfd_show_info(vty
, bfd_info
, 0, 1, use_json
, json_obj
);
68 * ospf6_bfd_reg_dereg_nbr - Register/Deregister a neighbor with BFD through
69 * zebra for starting/stopping the monitoring of
70 * the neighbor rechahability.
72 void ospf6_bfd_reg_dereg_nbr(struct ospf6_neighbor
*on
, int command
)
74 struct ospf6_interface
*oi
= on
->ospf6_if
;
75 struct interface
*ifp
= oi
->interface
;
76 struct bfd_info
*bfd_info
;
80 if (!oi
->bfd_info
|| !on
->bfd_info
)
82 bfd_info
= (struct bfd_info
*)oi
->bfd_info
;
84 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
85 inet_ntop(AF_INET6
, &on
->linklocal_addr
, src
, sizeof(src
));
86 zlog_debug("%s nbr (%s) with BFD",
87 bfd_get_command_dbg_str(command
), src
);
90 cbit
= CHECK_FLAG(bfd_info
->flags
, BFD_FLAG_BFD_CBIT_ON
);
92 bfd_peer_sendmsg(zclient
, bfd_info
, AF_INET6
, &on
->linklocal_addr
,
93 on
->ospf6_if
->linklocal_addr
, ifp
->name
, 0, 0, cbit
,
94 command
, 0, ifp
->vrf_id
);
96 if (command
== ZEBRA_BFD_DEST_DEREGISTER
)
97 bfd_info_free((struct bfd_info
**)&on
->bfd_info
);
101 * ospf6_bfd_trigger_event - Neighbor is registered/deregistered with BFD when
102 * neighbor state is changed to/from 2way.
104 void ospf6_bfd_trigger_event(struct ospf6_neighbor
*on
, int old_state
,
107 if ((old_state
< OSPF6_NEIGHBOR_TWOWAY
)
108 && (state
>= OSPF6_NEIGHBOR_TWOWAY
))
109 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_REGISTER
);
110 else if ((old_state
>= OSPF6_NEIGHBOR_TWOWAY
)
111 && (state
< OSPF6_NEIGHBOR_TWOWAY
))
112 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_DEREGISTER
);
116 * ospf6_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
117 * with a interface with BFD through
118 * zebra for starting/stopping the monitoring of
119 * the neighbor rechahability.
121 static void ospf6_bfd_reg_dereg_all_nbr(struct ospf6_interface
*oi
, int command
)
123 struct ospf6_neighbor
*on
;
124 struct listnode
*node
;
126 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
127 if (command
== ZEBRA_BFD_DEST_REGISTER
)
128 ospf6_bfd_info_nbr_create(oi
, on
);
130 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
) {
131 if (command
== ZEBRA_BFD_DEST_DEREGISTER
)
133 (struct bfd_info
**)&on
->bfd_info
);
137 ospf6_bfd_reg_dereg_nbr(on
, command
);
142 * ospf6_bfd_nbr_replay - Replay all the neighbors that have BFD enabled
145 static int ospf6_bfd_nbr_replay(ZAPI_CALLBACK_ARGS
)
147 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
148 struct listnode
*node
;
149 struct interface
*ifp
;
150 struct ospf6_interface
*oi
;
151 struct ospf6_neighbor
*on
;
154 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
155 zlog_debug("Zebra: BFD Dest replay request");
157 /* Send the client registration */
158 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
, vrf_id
);
160 /* Replay the neighbor, if BFD is enabled on the interface*/
161 FOR_ALL_INTERFACES (vrf
, ifp
) {
162 oi
= (struct ospf6_interface
*)ifp
->info
;
164 if (!oi
|| !oi
->bfd_info
)
167 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
168 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
171 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
172 inet_ntop(AF_INET6
, &on
->linklocal_addr
, dst
,
174 zlog_debug("Replaying nbr (%s) to BFD", dst
);
177 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_UPDATE
);
184 * ospf6_bfd_interface_dest_update - Find the neighbor for which the BFD status
185 * has changed and bring down the neighbor
186 * connectivity if BFD down is received.
188 static int ospf6_bfd_interface_dest_update(ZAPI_CALLBACK_ARGS
)
190 struct interface
*ifp
;
191 struct ospf6_interface
*oi
;
192 struct ospf6_neighbor
*on
;
195 struct listnode
*node
, *nnode
;
199 struct bfd_info
*bfd_info
;
202 ifp
= bfd_get_peer_info(zclient
->ibuf
, &dp
, &sp
, &status
,
205 if ((ifp
== NULL
) || (dp
.family
!= AF_INET6
))
208 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
209 zlog_debug("Zebra: interface %s bfd destination %pFX %s",
210 ifp
->name
, &dp
, bfd_get_status_str(status
));
213 oi
= (struct ospf6_interface
*)ifp
->info
;
214 if (!oi
|| !oi
->bfd_info
)
217 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
218 if (memcmp(&(on
->linklocal_addr
), &dp
.u
.prefix6
,
219 sizeof(struct in6_addr
)))
222 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
)) {
223 inet_ntop(AF_INET6
, &on
->linklocal_addr
, dst
,
225 zlog_debug("[%s:%s]: BFD %s", ifp
->name
, dst
,
226 bfd_get_status_str(status
));
232 bfd_info
= (struct bfd_info
*)on
->bfd_info
;
233 if (bfd_info
->status
== status
)
236 old_status
= bfd_info
->status
;
237 BFD_SET_CLIENT_STATUS(bfd_info
->status
, status
);
239 bfd_info
->last_update
= tv
.tv_sec
;
241 if ((status
== BFD_STATUS_DOWN
)
242 && (old_status
== BFD_STATUS_UP
)) {
243 THREAD_OFF(on
->inactivity_timer
);
244 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
252 * ospf6_bfd_info_nbr_create - Create/update BFD information for a neighbor.
254 void ospf6_bfd_info_nbr_create(struct ospf6_interface
*oi
,
255 struct ospf6_neighbor
*on
)
257 struct bfd_info
*oi_bfd_info
;
258 struct bfd_info
*on_bfd_info
;
263 oi_bfd_info
= (struct bfd_info
*)oi
->bfd_info
;
266 on
->bfd_info
= bfd_info_create();
268 on_bfd_info
= (struct bfd_info
*)on
->bfd_info
;
269 on_bfd_info
->detect_mult
= oi_bfd_info
->detect_mult
;
270 on_bfd_info
->desired_min_tx
= oi_bfd_info
->desired_min_tx
;
271 on_bfd_info
->required_min_rx
= oi_bfd_info
->required_min_rx
;
275 * ospf6_bfd_write_config - Write the interface BFD configuration.
277 void ospf6_bfd_write_config(struct vty
*vty
, struct ospf6_interface
*oi
)
280 struct bfd_info
*bfd_info
;
281 #endif /* ! HAVE_BFDD */
287 bfd_info
= (struct bfd_info
*)oi
->bfd_info
;
289 if (CHECK_FLAG(bfd_info
->flags
, BFD_FLAG_PARAM_CFG
))
290 vty_out(vty
, " ipv6 ospf6 bfd %d %d %d\n",
291 bfd_info
->detect_mult
, bfd_info
->required_min_rx
,
292 bfd_info
->desired_min_tx
);
294 #endif /* ! HAVE_BFDD */
295 vty_out(vty
, " ipv6 ospf6 bfd\n");
299 * ospf6_bfd_if_param_set - Set the configured BFD paramter values for
302 static void ospf6_bfd_if_param_set(struct ospf6_interface
*oi
, uint32_t min_rx
,
303 uint32_t min_tx
, uint8_t detect_mult
,
308 bfd_set_param((struct bfd_info
**)&(oi
->bfd_info
), min_rx
, min_tx
,
309 detect_mult
, NULL
, defaults
, &command
);
311 ospf6_bfd_reg_dereg_all_nbr(oi
, command
);
314 DEFUN (ipv6_ospf6_bfd
,
319 "Enables BFD support\n"
322 VTY_DECLVAR_CONTEXT(interface
, ifp
);
323 struct ospf6_interface
*oi
;
326 oi
= (struct ospf6_interface
*)ifp
->info
;
328 oi
= ospf6_interface_create(ifp
);
331 ospf6_bfd_if_param_set(oi
, BFD_DEF_MIN_RX
, BFD_DEF_MIN_TX
,
332 BFD_DEF_DETECT_MULT
, 1);
340 #endif /* HAVE_BFDD */
341 ipv6_ospf6_bfd_param
,
342 ipv6_ospf6_bfd_param_cmd
,
343 "ipv6 ospf6 bfd (2-255) (50-60000) (50-60000)",
346 "Enables BFD support\n"
347 "Detect Multiplier\n"
348 "Required min receive interval\n"
349 "Desired min transmit interval\n")
351 VTY_DECLVAR_CONTEXT(interface
, ifp
);
353 int idx_number_2
= 4;
354 int idx_number_3
= 5;
355 struct ospf6_interface
*oi
;
363 oi
= (struct ospf6_interface
*)ifp
->info
;
365 oi
= ospf6_interface_create(ifp
);
368 if ((ret
= bfd_validate_param(
369 vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
,
370 argv
[idx_number_3
]->arg
, &dm_val
, &rx_val
, &tx_val
))
374 ospf6_bfd_if_param_set(oi
, rx_val
, tx_val
, dm_val
, 0);
379 DEFUN (no_ipv6_ospf6_bfd
,
380 no_ipv6_ospf6_bfd_cmd
,
385 "Disables BFD support\n"
388 VTY_DECLVAR_CONTEXT(interface
, ifp
);
389 struct ospf6_interface
*oi
;
392 oi
= (struct ospf6_interface
*)ifp
->info
;
394 oi
= ospf6_interface_create(ifp
);
398 ospf6_bfd_reg_dereg_all_nbr(oi
, ZEBRA_BFD_DEST_DEREGISTER
);
399 bfd_info_free((struct bfd_info
**)&(oi
->bfd_info
));
405 void ospf6_bfd_init(void)
409 /* Initialize BFD client functions */
410 zclient
->interface_bfd_dest_update
= ospf6_bfd_interface_dest_update
;
411 zclient
->bfd_dest_replay
= ospf6_bfd_nbr_replay
;
413 /* Install BFD command */
414 install_element(INTERFACE_NODE
, &ipv6_ospf6_bfd_cmd
);
415 install_element(INTERFACE_NODE
, &ipv6_ospf6_bfd_param_cmd
);
416 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_bfd_cmd
);