Skip to content

Commit

Permalink
zebra: Properly unregister hook on shutdown
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
donaldsharp committed Dec 11, 2023
1 parent c783d5b commit 7cabd93
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ void zebra_finalize(struct event *dummy)

zebra_mpls_terminate();

zebra_pw_terminate();

ns_terminate();
frr_fini();
exit(0);
Expand Down
18 changes: 14 additions & 4 deletions zebra/zebra_pw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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",
Expand Down Expand Up @@ -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();
}
5 changes: 3 additions & 2 deletions zebra/zebra_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions zebra/zebra_vrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 */

Expand Down

0 comments on commit 7cabd93

Please sign in to comment.