From 9ddd39d877b98e555450def6b8fd2458e75bc570 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 30 Sep 2024 12:41:06 -0400 Subject: [PATCH] zebra: Delay some processing until after startup is finished Currently zebra starts the graceful restart timer as well as allows connections from clients before all data is read in from the kernel as well as the possiblity of allowing client connections before this happens as well. Let's move the graceful restart timer start till after this is done as well as not allowing client connections till then as well. Signed-off-by: Donald Sharp --- zebra/main.c | 64 +++++++++++++++++++++++++----------------------- zebra/rib.h | 2 ++ zebra/zebra_ns.c | 2 ++ 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/zebra/main.c b/zebra/main.c index 687da70cabce..ade29f63230c 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -54,6 +54,8 @@ #define ZEBRA_PTM_SUPPORT +char *zserv_path; + /* process id. */ pid_t pid; @@ -312,17 +314,48 @@ FRR_DAEMON_INFO(zebra, ZEBRA, ); /* clang-format on */ +void zebra_main_router_started(void) +{ + /* After we have successfully acquired the pidfile, we can be sure + * about being the only copy of zebra process, which is submitting + * changes to the FIB. + * Clean up zebra-originated routes. The requests will be sent to OS + * immediately, so originating PID in notifications from kernel + * will be equal to the current getpid(). To know about such routes, + * we have to have route_read() called before. + * If FRR is gracefully restarting, we either wait for clients + * (e.g., BGP) to signal GR is complete else we wait for specified + * duration. + */ + zrouter.startup_time = monotime(NULL); + zrouter.rib_sweep_time = 0; + zrouter.graceful_restart = zebra_di.graceful_restart; + if (!zrouter.graceful_restart) + event_add_timer(zrouter.master, rib_sweep_route, NULL, 0, NULL); + else { + int gr_cleanup_time; + + gr_cleanup_time = zebra_di.gr_cleanup_time ? zebra_di.gr_cleanup_time + : ZEBRA_GR_DEFAULT_RIB_SWEEP_TIME; + event_add_timer(zrouter.master, rib_sweep_route, NULL, gr_cleanup_time, + &zrouter.t_rib_sweep); + } + + zserv_start(zserv_path); +} + /* Main startup routine. */ int main(int argc, char **argv) { // int batch_mode = 0; - char *zserv_path = NULL; struct sockaddr_storage dummy; socklen_t dummylen; bool asic_offload = false; bool v6_with_v4_nexthop = false; bool notify_on_ack = true; + zserv_path = NULL; + vrf_configure_backend(VRF_BACKEND_VRF_LITE); frr_preinit(&zebra_di, argc, argv); @@ -473,32 +506,6 @@ int main(int argc, char **argv) */ frr_config_fork(); - /* After we have successfully acquired the pidfile, we can be sure - * about being the only copy of zebra process, which is submitting - * changes to the FIB. - * Clean up zebra-originated routes. The requests will be sent to OS - * immediately, so originating PID in notifications from kernel - * will be equal to the current getpid(). To know about such routes, - * we have to have route_read() called before. - * If FRR is gracefully restarting, we either wait for clients - * (e.g., BGP) to signal GR is complete else we wait for specified - * duration. - */ - zrouter.startup_time = monotime(NULL); - zrouter.rib_sweep_time = 0; - zrouter.graceful_restart = zebra_di.graceful_restart; - if (!zrouter.graceful_restart) - event_add_timer(zrouter.master, rib_sweep_route, NULL, 0, NULL); - else { - int gr_cleanup_time; - - gr_cleanup_time = zebra_di.gr_cleanup_time - ? zebra_di.gr_cleanup_time - : ZEBRA_GR_DEFAULT_RIB_SWEEP_TIME; - event_add_timer(zrouter.master, rib_sweep_route, NULL, - gr_cleanup_time, &zrouter.t_rib_sweep); - } - /* Needed for BSD routing socket. */ pid = getpid(); @@ -508,9 +515,6 @@ int main(int argc, char **argv) /* Start the ted module, before zserv */ zebra_opaque_start(); - /* Start Zebra API server */ - zserv_start(zserv_path); - /* Init label manager */ label_manager_init(); diff --git a/zebra/rib.h b/zebra/rib.h index 4293b5f2407a..bd558066c5d3 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -637,6 +637,8 @@ extern pid_t pid; extern uint32_t rt_table_main_id; +extern void zebra_main_router_started(void); + /* Name of hook calls */ #define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results" diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 803d8f0034c0..e665d4006455 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -123,6 +123,8 @@ void zebra_ns_startup_continue(struct zebra_dplane_ctx *ctx) vlan_read(zns); kernel_read_pbr_rules(zns); kernel_read_tc_qdisc(zns); + + zebra_main_router_started(); break; } }