Merge pull request #14985 from donaldsharp/zebra_delete_memory_problems

Zebra delete memory problems
This commit is contained in:
Donatas Abraitis 2023-12-12 16:31:52 +02:00 committed by GitHub
commit f17cd4587d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 9 deletions

View File

@ -502,12 +502,19 @@ void ns_init_management(ns_id_t default_ns_id, ns_id_t internal_ns)
void ns_terminate(void) void ns_terminate(void)
{ {
struct ns *ns; struct ns *ns;
struct ns_map_nsid *ns_map;
while (!RB_EMPTY(ns_head, &ns_tree)) { while (!RB_EMPTY(ns_head, &ns_tree)) {
ns = RB_ROOT(ns_head, &ns_tree); ns = RB_ROOT(ns_head, &ns_tree);
ns_delete(ns); ns_delete(ns);
} }
while (!RB_EMPTY(ns_map_nsid_head, &ns_map_nsid_list)) {
ns_map = RB_ROOT(ns_map_nsid_head, &ns_map_nsid_list);
RB_REMOVE(ns_map_nsid_head, &ns_map_nsid_list, ns_map);
XFREE(MTYPE_NS, ns_map);
}
} }
int ns_switch_to_netns(const char *name) int ns_switch_to_netns(const char *name)

View File

@ -302,6 +302,11 @@ void label_manager_init(void)
install_element(CONFIG_NODE, &mpls_label_dynamic_block_cmd); install_element(CONFIG_NODE, &mpls_label_dynamic_block_cmd);
} }
void label_manager_terminate(void)
{
list_delete(&lbl_mgr.lc_list);
}
/* alloc and fill a label chunk */ /* alloc and fill a label chunk */
struct label_manager_chunk * struct label_manager_chunk *
create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,

View File

@ -105,6 +105,8 @@ struct label_manager {
}; };
void label_manager_init(void); void label_manager_init(void);
void label_manager_terminate(void);
struct label_manager_chunk * struct label_manager_chunk *
assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
uint8_t keep, uint32_t size, uint32_t base); uint8_t keep, uint32_t size, uint32_t base);

View File

@ -234,6 +234,10 @@ void zebra_finalize(struct event *dummy)
zebra_mpls_terminate(); zebra_mpls_terminate();
zebra_pw_terminate();
label_manager_terminate();
ns_terminate(); ns_terminate();
frr_fini(); frr_fini();
exit(0); exit(0);

View File

@ -377,15 +377,18 @@ static int zebra_pw_client_close(struct zserv *client)
return 0; return 0;
} }
void zebra_pw_init(struct zebra_vrf *zvrf) static void zebra_pw_init(void)
{ {
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); hook_register(zserv_client_close, zebra_pw_client_close);
} }
void zebra_pw_exit(struct zebra_vrf *zvrf) 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);
}
void zebra_pw_exit_vrf(struct zebra_vrf *zvrf)
{ {
struct zebra_pw *pw; 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, DEFUN_NOSH (pseudowire_if,
pseudowire_if_cmd, pseudowire_if_cmd,
"pseudowire IFNAME", "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_cmd);
install_element(VIEW_NODE, &show_pseudowires_detail_cmd); install_element(VIEW_NODE, &show_pseudowires_detail_cmd);
zebra_pw_init();
} }

View File

@ -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 *); struct zebra_pw *zebra_pw_find(struct zebra_vrf *, const char *);
void zebra_pw_update(struct zebra_pw *); void zebra_pw_update(struct zebra_pw *);
void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus); void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus);
void zebra_pw_init(struct zebra_vrf *); void zebra_pw_init_vrf(struct zebra_vrf *);
void zebra_pw_exit(struct zebra_vrf *); void zebra_pw_exit_vrf(struct zebra_vrf *);
void zebra_pw_terminate(void);
void zebra_pw_vty_init(void); void zebra_pw_vty_init(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -195,7 +195,7 @@ static int zebra_vrf_disable(struct vrf *vrf)
/* Cleanup Vxlan, MPLS and PW tables. */ /* Cleanup Vxlan, MPLS and PW tables. */
zebra_vxlan_cleanup_tables(zvrf); zebra_vxlan_cleanup_tables(zvrf);
zebra_mpls_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. /* 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_vxlan_init_tables(zvrf);
zebra_mpls_init_tables(zvrf); zebra_mpls_init_tables(zvrf);
zebra_pw_init(zvrf); zebra_pw_init_vrf(zvrf);
zvrf->table_id = rt_table_main_id; zvrf->table_id = rt_table_main_id;
/* by default table ID is default one */ /* by default table ID is default one */