From 4e410167c094bf8c88e52f079322843fa3717d16 Mon Sep 17 00:00:00 2001 From: Acee Date: Sun, 18 Jun 2023 07:22:45 -0400 Subject: [PATCH] ospf6d: Add config callbacks to suppress hellos during config load. Add bgpd/isisd message. Signed-off-by: Acee --- ospf6d/ospf6_main.c | 29 +++++++++++++++++++++++++++++ ospf6d/ospf6_message.c | 11 +++++++++++ ospf6d/ospf6d.c | 33 +++++++++++++++++++++++++++++++++ ospf6d/ospf6d.h | 9 +++++++++ ospf6d/subdir.am | 1 + 5 files changed, 83 insertions(+) diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index fdb93475d4..932304578a 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -173,6 +173,32 @@ FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT, .n_yang_modules = array_size(ospf6d_yang_modules), ); +/* Max wait time for config to load before accepting hellos */ +#define OSPF6_PRE_CONFIG_MAX_WAIT_SECONDS 600 + +static void ospf6_config_finish(struct event *t) +{ + zlog_err("OSPF6 configuration end timer expired after %d seconds.", + OSPF6_PRE_CONFIG_MAX_WAIT_SECONDS); +} + +static void ospf6_config_start(void) +{ + if (IS_OSPF6_DEBUG_EVENT) + zlog_debug("ospf6d config start received"); + EVENT_OFF(t_ospf6_cfg); + event_add_timer(master, ospf6_config_finish, NULL, + OSPF6_PRE_CONFIG_MAX_WAIT_SECONDS, &t_ospf6_cfg); +} + +static void ospf6_config_end(void) +{ + if (IS_OSPF6_DEBUG_EVENT) + zlog_debug("ospf6d config end received"); + + EVENT_OFF(t_ospf6_cfg); +} + /* Main routine of ospf6d. Treatment of argument and starting ospf finite state machine is handled here. */ int main(int argc, char *argv[], char *envp[]) @@ -217,6 +243,9 @@ int main(int argc, char *argv[], char *envp[]) /* initialize ospf6 */ ospf6_init(master); + /* Configuration processing callback initialization. */ + cmd_init_config_callbacks(ospf6_config_start, ospf6_config_end); + frr_config_fork(); frr_run(master); diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 032988a91f..29a68c5c3d 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -2248,6 +2248,17 @@ void ospf6_hello_send(struct event *thread) if (oi->gr.hello_delay.t_grace_send) return; + /* Check if config is still being processed */ + if (event_is_scheduled(t_ospf6_cfg)) { + if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND)) + zlog_debug( + "Suppressing Hello on interface %s during config load", + oi->interface->name); + event_add_timer(master, ospf6_hello_send, oi, + oi->hello_interval, &oi->thread_send_hello); + return; + } + if (oi->state <= OSPF6_INTERFACE_DOWN) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND_HDR)) zlog_debug("Unable to send Hello on down interface %s", diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index 214007d041..d90a950d79 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -34,9 +34,16 @@ #include "lib/json.h" #include "ospf6_nssa.h" #include "ospf6_auth_trailer.h" +#include "ospf6d/ospf6d_clippy.c" DEFINE_MGROUP(OSPF6D, "ospf6d"); +/* OSPF6 config processing timer thread */ +struct event *t_ospf6_cfg; + +/* OSPF6 debug event state */ +unsigned char conf_debug_ospf6_event; + struct route_node *route_prev(struct route_node *node) { struct route_node *end; @@ -62,6 +69,7 @@ struct route_node *route_prev(struct route_node *node) } static int config_write_ospf6_debug(struct vty *vty); +static int config_write_ospf6_debug_event(struct vty *vty); static struct cmd_node debug_node = { .name = "debug", .node = DEBUG_NODE, @@ -85,6 +93,7 @@ static int config_write_ospf6_debug(struct vty *vty) config_write_ospf6_debug_nssa(vty); config_write_ospf6_debug_gr_helper(vty); config_write_ospf6_debug_auth(vty); + config_write_ospf6_debug_event(vty); return 0; } @@ -1374,6 +1383,29 @@ DEFUN(show_ipv6_ospf6_linkstate_detail, show_ipv6_ospf6_linkstate_detail_cmd, return CMD_SUCCESS; } +DEFPY(debug_ospf6_event, debug_ospf6_event_cmd, "[no] debug ospf6 event", + NO_STR DEBUG_STR OSPF6_STR "Debug OSPFv3 event function\n") +{ + if (!no) + OSPF6_DEBUG_EVENT_ON(); + else + OSPF6_DEBUG_EVENT_OFF(); + return CMD_SUCCESS; +} + +static int config_write_ospf6_debug_event(struct vty *vty) +{ + if (IS_OSPF6_DEBUG_EVENT) + vty_out(vty, "debug ospf6 event\n"); + return 0; +} + +static void install_element_ospf6_debug_event(void) +{ + install_element(ENABLE_NODE, &debug_ospf6_event_cmd); + install_element(CONFIG_NODE, &debug_ospf6_event_cmd); +} + /* Install ospf related commands. */ void ospf6_init(struct event_loop *master) { @@ -1447,6 +1479,7 @@ void ospf6_init(struct event_loop *master) VIEW_NODE, &show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd); install_element(VIEW_NODE, &show_ipv6_ospf6_database_aggr_router_cmd); + install_element_ospf6_debug_event(); install_element_ospf6_debug_auth(); ospf6_interface_auth_trailer_cmd_init(); install_element_ospf6_clear_intf_auth(); diff --git a/ospf6d/ospf6d.h b/ospf6d/ospf6d.h index 980a365265..c927ee7566 100644 --- a/ospf6d/ospf6d.h +++ b/ospf6d/ospf6d.h @@ -15,6 +15,9 @@ DECLARE_MGROUP(OSPF6D); /* global variables */ extern struct event_loop *master; +/* OSPF config processing timer thread */ +extern struct event *t_ospf6_cfg; + /* Historical for KAME. */ #ifndef IPV6_JOIN_GROUP #ifdef IPV6_ADD_MEMBERSHIP @@ -105,6 +108,12 @@ extern struct event_loop *master; extern struct zebra_privs_t ospf6d_privs; +/* Event Debug option */ +extern unsigned char conf_debug_ospf6_event; +#define OSPF6_DEBUG_EVENT_ON() (conf_debug_ospf6_event = 1) +#define OSPF6_DEBUG_EVENT_OFF() (conf_debug_ospf6_event = 0) +#define IS_OSPF6_DEBUG_EVENT (conf_debug_ospf6_event) + /* Function Prototypes */ extern struct route_node *route_prev(struct route_node *node); diff --git a/ospf6d/subdir.am b/ospf6d/subdir.am index c34db3012d..f6d27c84cd 100644 --- a/ospf6d/subdir.am +++ b/ospf6d/subdir.am @@ -75,6 +75,7 @@ ospf6d_ospf6d_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) ospf6d_ospf6d_snmp_la_LIBADD = lib/libfrrsnmp.la clippy_scan += \ + ospf6d/ospf6d.c \ ospf6d/ospf6_top.c \ ospf6d/ospf6_area.c \ ospf6d/ospf6_asbr.c \ -- 2.39.5