From c6e3af30133e3ba7ccea2118e410bc54b978fe26 Mon Sep 17 00:00:00 2001 From: Acee Date: Thu, 15 Jun 2023 17:50:24 -0400 Subject: [PATCH] ospfd: Add config callbacks and suppress hello during config load. Signed-off-by: Acee --- ospfd/ospf_main.c | 29 +++++++++++++++++++++++++++++ ospfd/ospf_packet.c | 10 ++++++++++ ospfd/ospfd.c | 2 ++ ospfd/ospfd.h | 3 +++ 4 files changed, 44 insertions(+) diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 1f476a7e3d..536bd592d2 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -134,6 +134,32 @@ FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT, .n_yang_modules = array_size(ospfd_yang_modules), ); +/** Max wait time for config to load before accepting hellos */ +#define OSPF_PRE_CONFIG_MAX_WAIT_SECONDS 600 + +static void ospf_config_finish(struct event *t) +{ + zlog_err("OSPF configuration end timer expired after %d seconds.", + OSPF_PRE_CONFIG_MAX_WAIT_SECONDS); +} + +static void ospf_config_start(void) +{ + EVENT_OFF(t_ospf_cfg); + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("ospfd config start callback received."); + event_add_timer(master, ospf_config_finish, NULL, + OSPF_PRE_CONFIG_MAX_WAIT_SECONDS, &t_ospf_cfg); +} + +static void ospf_config_end(void) +{ + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("ospfd config end callback received."); + + EVENT_OFF(t_ospf_cfg); +} + /* OSPFd main routine. */ int main(int argc, char **argv) { @@ -193,6 +219,9 @@ int main(int argc, char **argv) access_list_init(); prefix_list_init(); + /* Configuration processing callback initialization. */ + cmd_init_config_callbacks(ospf_config_start, ospf_config_end); + /* OSPFd inits. */ ospf_if_init(); ospf_zebra_init(master, ospf_instance); diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index d010b8b6e6..105c04c7a1 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -3682,6 +3682,16 @@ static void ospf_hello_send_sub(struct ospf_interface *oi, in_addr_t addr) struct ospf_packet *op; uint16_t length = OSPF_HEADER_SIZE; + /* Check if config is still being processed */ + if (event_is_scheduled(t_ospf_cfg)) { + if (IS_DEBUG_OSPF_PACKET(0, SEND)) + zlog_debug( + "Suppressing hello to %pI4 on %s during config load", + &(addr), IF_NAME(oi)); + + return; + } + op = ospf_packet_new(oi->ifp->mtu); /* Prepare OSPF common header. */ diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 51e937f42c..053907f209 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -61,6 +61,8 @@ unsigned short ospf_instance; extern struct zclient *zclient; +/* OSPF config processing timer thread */ +struct event *t_ospf_cfg; static void ospf_remove_vls_through_area(struct ospf *, struct ospf_area *); static void ospf_network_free(struct ospf *, struct ospf_network *); diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 36936b16f4..860140cb76 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -70,6 +70,9 @@ /* Default socket buffer size */ #define OSPF_DEFAULT_SOCK_BUFSIZE (8 * 1024 * 1024) +/* OSPF config processing timer thread */ +extern struct event *t_ospf_cfg; + struct ospf_external { unsigned short instance; struct route_table *external_info; -- 2.39.5