From 7cabd9361ca981c9f1becae2505d6fc35e32bd5f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 11 Dec 2023 15:22:07 -0500 Subject: [PATCH] zebra: Properly unregister hook on shutdown the zebra pseudo wire code was registering a callback per vrf. These callbacks are not per vrf based. They are vrf agnostic so this was a mistake. Modify the code to on startup register once and on shutdown unregister once. Finally rename the zebra_pw_init and zebra_pw_exit functions to more properly reflect when they are called. Signed-off-by: Donald Sharp --- zebra/main.c | 2 ++ zebra/zebra_pw.c | 18 ++++++++++++++---- zebra/zebra_pw.h | 5 +++-- zebra/zebra_vrf.c | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/zebra/main.c b/zebra/main.c index 1efb27db06..2e5f8c48f4 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -234,6 +234,8 @@ void zebra_finalize(struct event *dummy) zebra_mpls_terminate(); + zebra_pw_terminate(); + ns_terminate(); frr_fini(); exit(0); diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index f76bf747d6..deed3b6ad3 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -377,15 +377,18 @@ static int zebra_pw_client_close(struct zserv *client) return 0; } -void zebra_pw_init(struct zebra_vrf *zvrf) +static void zebra_pw_init(void) +{ + hook_register(zserv_client_close, zebra_pw_client_close); +} + +void zebra_pw_init_vrf(struct zebra_vrf *zvrf) { RB_INIT(zebra_pw_head, &zvrf->pseudowires); RB_INIT(zebra_static_pw_head, &zvrf->static_pseudowires); - - hook_register(zserv_client_close, zebra_pw_client_close); } -void zebra_pw_exit(struct zebra_vrf *zvrf) +void zebra_pw_exit_vrf(struct zebra_vrf *zvrf) { struct zebra_pw *pw; @@ -396,6 +399,11 @@ void zebra_pw_exit(struct zebra_vrf *zvrf) } } +void zebra_pw_terminate(void) +{ + hook_unregister(zserv_client_close, zebra_pw_client_close); +} + DEFUN_NOSH (pseudowire_if, pseudowire_if_cmd, "pseudowire IFNAME", @@ -837,4 +845,6 @@ void zebra_pw_vty_init(void) install_element(VIEW_NODE, &show_pseudowires_cmd); install_element(VIEW_NODE, &show_pseudowires_detail_cmd); + + zebra_pw_init(); } diff --git a/zebra/zebra_pw.h b/zebra/zebra_pw.h index a41afc920b..431d663f7c 100644 --- a/zebra/zebra_pw.h +++ b/zebra/zebra_pw.h @@ -60,8 +60,9 @@ void zebra_pw_change(struct zebra_pw *, ifindex_t, int, int, union g_addr *, struct zebra_pw *zebra_pw_find(struct zebra_vrf *, const char *); void zebra_pw_update(struct zebra_pw *); void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus); -void zebra_pw_init(struct zebra_vrf *); -void zebra_pw_exit(struct zebra_vrf *); +void zebra_pw_init_vrf(struct zebra_vrf *); +void zebra_pw_exit_vrf(struct zebra_vrf *); +void zebra_pw_terminate(void); void zebra_pw_vty_init(void); #ifdef __cplusplus diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 2adae61f54..92982f25c8 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -195,7 +195,7 @@ static int zebra_vrf_disable(struct vrf *vrf) /* Cleanup Vxlan, MPLS and PW tables. */ zebra_vxlan_cleanup_tables(zvrf); zebra_mpls_cleanup_tables(zvrf); - zebra_pw_exit(zvrf); + zebra_pw_exit_vrf(zvrf); /* Remove link-local IPv4 addresses created for BGP unnumbered peering. */ @@ -376,7 +376,7 @@ struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf) zebra_vxlan_init_tables(zvrf); zebra_mpls_init_tables(zvrf); - zebra_pw_init(zvrf); + zebra_pw_init_vrf(zvrf); zvrf->table_id = rt_table_main_id; /* by default table ID is default one */ -- 2.39.5