From 1f7be0d242dbff4c4b49ddd6d157ac7eabf9b931 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Fri, 16 Apr 2021 16:17:31 -0300 Subject: [PATCH] ospf6d: add support for BFD profiles Allow user to pre configure BFD sessions using profiles. Signed-off-by: Rafael Zalamena --- ospf6d/ospf6_bfd.c | 51 ++++++++++++++++++++++++++++++++++------ ospf6d/ospf6_interface.c | 3 +++ ospf6d/ospf6_interface.h | 1 + 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c index 0ef5d597ed..ba8c398dee 100644 --- a/ospf6d/ospf6_bfd.c +++ b/ospf6d/ospf6_bfd.c @@ -164,18 +164,22 @@ void ospf6_bfd_write_config(struct vty *vty, struct ospf6_interface *oi) else #endif /* ! HAVE_BFDD */ vty_out(vty, " ipv6 ospf6 bfd\n"); + + if (oi->bfd_config.profile) + vty_out(vty, " ipv6 ospf6 bfd profile %s\n", + oi->bfd_config.profile); } -DEFUN (ipv6_ospf6_bfd, - ipv6_ospf6_bfd_cmd, - "ipv6 ospf6 bfd", - IP6_STR - OSPF6_STR - "Enables BFD support\n" - ) +DEFUN(ipv6_ospf6_bfd, ipv6_ospf6_bfd_cmd, + "ipv6 ospf6 bfd [profile BFDPROF]", + IP6_STR OSPF6_STR + "Enables BFD support\n" + "BFD Profile selection\n" + "BFD Profile name\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; + int prof_idx = 4; assert(ifp); oi = (struct ospf6_interface *)ifp->info; @@ -187,7 +191,39 @@ DEFUN (ipv6_ospf6_bfd, oi->bfd_config.min_rx = BFD_DEF_MIN_RX; oi->bfd_config.min_tx = BFD_DEF_MIN_TX; oi->bfd_config.enabled = true; + if (argc > prof_idx) { + XFREE(MTYPE_TMP, oi->bfd_config.profile); + oi->bfd_config.profile = + XSTRDUP(MTYPE_TMP, argv[prof_idx]->arg); + } + + ospf6_bfd_reg_dereg_all_nbr(oi, true); + + return CMD_SUCCESS; +} + +DEFUN(no_ipv6_ospf6_bfd_profile, no_ipv6_ospf6_bfd_profile_cmd, + "no ipv6 ospf6 bfd profile [BFDPROF]", + NO_STR IP6_STR OSPF6_STR + "BFD support\n" + "BFD Profile selection\n" + "BFD Profile name\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi; + assert(ifp); + + oi = (struct ospf6_interface *)ifp->info; + if (oi == NULL) + oi = ospf6_interface_create(ifp); + assert(oi); + + /* BFD not enabled, nothing to do. */ + if (!oi->bfd_config.enabled) + return CMD_SUCCESS; + /* Remove profile and apply new configuration. */ + XFREE(MTYPE_TMP, oi->bfd_config.profile); ospf6_bfd_reg_dereg_all_nbr(oi, true); return CMD_SUCCESS; @@ -263,5 +299,6 @@ void ospf6_bfd_init(void) /* Install BFD command */ install_element(INTERFACE_NODE, &ipv6_ospf6_bfd_cmd); install_element(INTERFACE_NODE, &ipv6_ospf6_bfd_param_cmd); + install_element(INTERFACE_NODE, &no_ipv6_ospf6_bfd_profile_cmd); install_element(INTERFACE_NODE, &no_ipv6_ospf6_bfd_cmd); } diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 60ead06f3e..f3af8b308f 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -275,6 +275,9 @@ void ospf6_interface_delete(struct ospf6_interface *oi) /* disable from area list if possible */ ospf6_area_interface_delete(oi); + /* Free BFD allocated data. */ + XFREE(MTYPE_TMP, oi->bfd_config.profile); + XFREE(MTYPE_OSPF6_IF, oi); } diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h index 49a9c2bba6..a45a841406 100644 --- a/ospf6d/ospf6_interface.h +++ b/ospf6d/ospf6_interface.h @@ -124,6 +124,7 @@ struct ospf6_interface { uint8_t detection_multiplier; uint32_t min_rx; uint32_t min_tx; + char *profile; } bfd_config; /* Statistics Fields */ -- 2.39.5