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
)
61 bfd_show_param(vty
, bfd_info
, 1, 0, 0, NULL
);
63 bfd_show_info(vty
, bfd_info
, 0, 1, 0, NULL
);
67 * ospf6_bfd_reg_dereg_nbr - Register/Deregister a neighbor with BFD through
68 * zebra for starting/stopping the monitoring of
69 * the neighbor rechahability.
71 void ospf6_bfd_reg_dereg_nbr(struct ospf6_neighbor
*on
, int command
)
73 struct ospf6_interface
*oi
= on
->ospf6_if
;
74 struct interface
*ifp
= oi
->interface
;
75 struct bfd_info
*bfd_info
;
78 if (!oi
->bfd_info
|| !on
->bfd_info
)
80 bfd_info
= (struct bfd_info
*)oi
->bfd_info
;
82 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
83 inet_ntop(AF_INET6
, &on
->linklocal_addr
, src
, sizeof(src
));
84 zlog_debug("%s nbr (%s) with BFD",
85 bfd_get_command_dbg_str(command
), src
);
88 bfd_peer_sendmsg(zclient
, bfd_info
, AF_INET6
, &on
->linklocal_addr
,
89 on
->ospf6_if
->linklocal_addr
, ifp
->name
, 0, 0, command
,
92 if (command
== ZEBRA_BFD_DEST_DEREGISTER
)
93 bfd_info_free((struct bfd_info
**)&on
->bfd_info
);
97 * ospf6_bfd_trigger_event - Neighbor is registered/deregistered with BFD when
98 * neighbor state is changed to/from 2way.
100 void ospf6_bfd_trigger_event(struct ospf6_neighbor
*on
, int old_state
,
103 if ((old_state
< OSPF6_NEIGHBOR_TWOWAY
)
104 && (state
>= OSPF6_NEIGHBOR_TWOWAY
))
105 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_REGISTER
);
106 else if ((old_state
>= OSPF6_NEIGHBOR_TWOWAY
)
107 && (state
< OSPF6_NEIGHBOR_TWOWAY
))
108 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_DEREGISTER
);
112 * ospf6_bfd_reg_dereg_all_nbr - Register/Deregister all neighbors associated
113 * with a interface with BFD through
114 * zebra for starting/stopping the monitoring of
115 * the neighbor rechahability.
117 static void ospf6_bfd_reg_dereg_all_nbr(struct ospf6_interface
*oi
, int command
)
119 struct ospf6_neighbor
*on
;
120 struct listnode
*node
;
122 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
123 if (command
== ZEBRA_BFD_DEST_REGISTER
)
124 ospf6_bfd_info_nbr_create(oi
, on
);
126 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
) {
127 if (command
== ZEBRA_BFD_DEST_DEREGISTER
)
129 (struct bfd_info
**)&on
->bfd_info
);
133 ospf6_bfd_reg_dereg_nbr(on
, command
);
138 * ospf6_bfd_nbr_replay - Replay all the neighbors that have BFD enabled
141 static int ospf6_bfd_nbr_replay(int command
, struct zclient
*zclient
,
142 zebra_size_t length
, vrf_id_t vrf_id
)
144 struct listnode
*inode
, *nnode
;
145 struct interface
*ifp
;
146 struct ospf6_interface
*oi
;
147 struct ospf6_neighbor
*on
;
150 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
151 zlog_debug("Zebra: BFD Dest replay request");
153 /* Send the client registration */
154 bfd_client_sendmsg(zclient
, ZEBRA_BFD_CLIENT_REGISTER
);
156 /* Replay the neighbor, if BFD is enabled on the interface*/
157 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), inode
, ifp
)) {
158 oi
= (struct ospf6_interface
*)ifp
->info
;
160 if (!oi
|| !oi
->bfd_info
)
163 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, nnode
, on
)) {
164 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
167 if (IS_OSPF6_DEBUG_ZEBRA(SEND
)) {
168 inet_ntop(AF_INET6
, &on
->linklocal_addr
, dst
,
170 zlog_debug("Replaying nbr (%s) to BFD", dst
);
173 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_UPDATE
);
180 * ospf6_bfd_interface_dest_update - Find the neighbor for which the BFD status
181 * has changed and bring down the neighbor
182 * connectivity if BFD down is received.
184 static int ospf6_bfd_interface_dest_update(int command
, struct zclient
*zclient
,
185 zebra_size_t length
, vrf_id_t vrf_id
)
187 struct interface
*ifp
;
188 struct ospf6_interface
*oi
;
189 struct ospf6_neighbor
*on
;
192 struct listnode
*node
, *nnode
;
196 struct bfd_info
*bfd_info
;
199 ifp
= bfd_get_peer_info(zclient
->ibuf
, &dp
, &sp
, &status
, vrf_id
);
201 if ((ifp
== NULL
) || (dp
.family
!= AF_INET6
))
204 if (IS_OSPF6_DEBUG_ZEBRA(RECV
)) {
205 char buf
[PREFIX2STR_BUFFER
];
206 prefix2str(&dp
, buf
, sizeof(buf
));
207 zlog_debug("Zebra: interface %s bfd destination %s %s",
208 ifp
->name
, buf
, bfd_get_status_str(status
));
212 oi
= (struct ospf6_interface
*)ifp
->info
;
213 if (!oi
|| !oi
->bfd_info
)
216 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
217 if (memcmp(&(on
->linklocal_addr
), &dp
.u
.prefix6
,
218 sizeof(struct in6_addr
)))
221 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
)) {
222 inet_ntop(AF_INET6
, &on
->linklocal_addr
, dst
,
224 zlog_debug("[%s:%s]: BFD %s", ifp
->name
, dst
,
225 bfd_get_status_str(status
));
231 bfd_info
= (struct bfd_info
*)on
->bfd_info
;
232 if (bfd_info
->status
== status
)
235 old_status
= bfd_info
->status
;
236 bfd_info
->status
= status
;
238 bfd_info
->last_update
= tv
.tv_sec
;
240 if ((status
== BFD_STATUS_DOWN
)
241 && (old_status
== BFD_STATUS_UP
)) {
242 THREAD_OFF(on
->inactivity_timer
);
243 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
251 * ospf6_bfd_info_nbr_create - Create/update BFD information for a neighbor.
253 void ospf6_bfd_info_nbr_create(struct ospf6_interface
*oi
,
254 struct ospf6_neighbor
*on
)
256 struct bfd_info
*oi_bfd_info
;
257 struct bfd_info
*on_bfd_info
;
262 oi_bfd_info
= (struct bfd_info
*)oi
->bfd_info
;
265 on
->bfd_info
= bfd_info_create();
267 on_bfd_info
= (struct bfd_info
*)on
->bfd_info
;
268 on_bfd_info
->detect_mult
= oi_bfd_info
->detect_mult
;
269 on_bfd_info
->desired_min_tx
= oi_bfd_info
->desired_min_tx
;
270 on_bfd_info
->required_min_rx
= oi_bfd_info
->required_min_rx
;
274 * ospf6_bfd_write_config - Write the interface BFD configuration.
276 void ospf6_bfd_write_config(struct vty
*vty
, struct ospf6_interface
*oi
)
278 struct bfd_info
*bfd_info
;
283 bfd_info
= (struct bfd_info
*)oi
->bfd_info
;
285 if (CHECK_FLAG(bfd_info
->flags
, BFD_FLAG_PARAM_CFG
))
286 vty_out(vty
, " ipv6 ospf6 bfd %d %d %d\n",
287 bfd_info
->detect_mult
, bfd_info
->required_min_rx
,
288 bfd_info
->desired_min_tx
);
290 vty_out(vty
, " ipv6 ospf6 bfd\n");
294 * ospf6_bfd_if_param_set - Set the configured BFD paramter values for
297 static void ospf6_bfd_if_param_set(struct ospf6_interface
*oi
, u_int32_t min_rx
,
298 u_int32_t min_tx
, u_int8_t detect_mult
,
303 bfd_set_param((struct bfd_info
**)&(oi
->bfd_info
), min_rx
, min_tx
,
304 detect_mult
, defaults
, &command
);
306 ospf6_bfd_reg_dereg_all_nbr(oi
, command
);
309 DEFUN (ipv6_ospf6_bfd
,
314 "Enables BFD support\n"
317 VTY_DECLVAR_CONTEXT(interface
, ifp
);
318 struct ospf6_interface
*oi
;
321 oi
= (struct ospf6_interface
*)ifp
->info
;
323 oi
= ospf6_interface_create(ifp
);
326 ospf6_bfd_if_param_set(oi
, BFD_DEF_MIN_RX
, BFD_DEF_MIN_TX
,
327 BFD_DEF_DETECT_MULT
, 1);
331 DEFUN (ipv6_ospf6_bfd_param
,
332 ipv6_ospf6_bfd_param_cmd
,
333 "ipv6 ospf6 bfd (2-255) (50-60000) (50-60000)",
336 "Enables BFD support\n"
337 "Detect Multiplier\n"
338 "Required min receive interval\n"
339 "Desired min transmit interval\n")
341 VTY_DECLVAR_CONTEXT(interface
, ifp
);
343 int idx_number_2
= 4;
344 int idx_number_3
= 5;
345 struct ospf6_interface
*oi
;
353 oi
= (struct ospf6_interface
*)ifp
->info
;
355 oi
= ospf6_interface_create(ifp
);
358 if ((ret
= bfd_validate_param(
359 vty
, argv
[idx_number
]->arg
, argv
[idx_number_2
]->arg
,
360 argv
[idx_number_3
]->arg
, &dm_val
, &rx_val
, &tx_val
))
364 ospf6_bfd_if_param_set(oi
, rx_val
, tx_val
, dm_val
, 0);
369 DEFUN (no_ipv6_ospf6_bfd
,
370 no_ipv6_ospf6_bfd_cmd
,
375 "Disables BFD support\n"
378 VTY_DECLVAR_CONTEXT(interface
, ifp
);
379 struct ospf6_interface
*oi
;
382 oi
= (struct ospf6_interface
*)ifp
->info
;
384 oi
= ospf6_interface_create(ifp
);
388 ospf6_bfd_reg_dereg_all_nbr(oi
, ZEBRA_BFD_DEST_DEREGISTER
);
389 bfd_info_free((struct bfd_info
**)&(oi
->bfd_info
));
395 void ospf6_bfd_init(void)
399 /* Initialize BFD client functions */
400 zclient
->interface_bfd_dest_update
= ospf6_bfd_interface_dest_update
;
401 zclient
->bfd_dest_replay
= ospf6_bfd_nbr_replay
;
403 /* Install BFD command */
404 install_element(INTERFACE_NODE
, &ipv6_ospf6_bfd_cmd
);
405 install_element(INTERFACE_NODE
, &ipv6_ospf6_bfd_param_cmd
);
406 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_bfd_cmd
);