From 6b88faa7ffadbcb159025faf114fe2e4123e8d48 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Mon, 24 Jan 2022 00:16:59 +0300 Subject: [PATCH 1/2] pimd: move iface lib initialization to a proper place Signed-off-by: Igor Ryzhov --- pimd/pim6_main.c | 3 +-- pimd/pim_iface.c | 27 +++++++++++++++++++++++---- pimd/pim_iface.h | 5 +---- pimd/pim_main.c | 3 +-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/pimd/pim6_main.c b/pimd/pim6_main.c index 02654e1cb6..3d8ebd0d86 100644 --- a/pimd/pim6_main.c +++ b/pimd/pim6_main.c @@ -178,8 +178,7 @@ int main(int argc, char **argv, char **envp) /* * Initialize zclient "update" and "lookup" sockets */ - if_zapi_callbacks(pim_ifp_create, pim_ifp_up, - pim_ifp_down, pim_ifp_destroy); + pim_iface_init(); /* TODO PIM6: next line is temporary since pim_cmd_init is disabled */ if_cmd_init(NULL); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 8b27809c7c..6727be01bc 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1521,7 +1521,7 @@ int pim_if_ifchannel_count(struct pim_interface *pim_ifp) return count; } -int pim_ifp_create(struct interface *ifp) +static int pim_ifp_create(struct interface *ifp) { struct pim_instance *pim; @@ -1589,7 +1589,7 @@ int pim_ifp_create(struct interface *ifp) return 0; } -int pim_ifp_up(struct interface *ifp) +static int pim_ifp_up(struct interface *ifp) { struct pim_interface *pim_ifp; struct pim_instance *pim; @@ -1645,7 +1645,7 @@ int pim_ifp_up(struct interface *ifp) return 0; } -int pim_ifp_down(struct interface *ifp) +static int pim_ifp_down(struct interface *ifp) { if (PIM_DEBUG_ZEBRA) { zlog_debug( @@ -1681,7 +1681,7 @@ int pim_ifp_down(struct interface *ifp) return 0; } -int pim_ifp_destroy(struct interface *ifp) +static int pim_ifp_destroy(struct interface *ifp) { struct pim_instance *pim; @@ -1702,3 +1702,22 @@ int pim_ifp_destroy(struct interface *ifp) return 0; } + +static int pim_if_new_hook(struct interface *ifp) +{ + return 0; +} + +static int pim_if_delete_hook(struct interface *ifp) +{ + return 0; +} + +void pim_iface_init(void) +{ + hook_register_prio(if_add, 0, pim_if_new_hook); + hook_register_prio(if_del, 0, pim_if_delete_hook); + + if_zapi_callbacks(pim_ifp_create, pim_ifp_up, pim_ifp_down, + pim_ifp_destroy); +} diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index f251c55e72..1ddf743619 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -259,9 +259,6 @@ bool pim_if_is_vrf_device(struct interface *ifp); int pim_if_ifchannel_count(struct pim_interface *pim_ifp); -extern int pim_ifp_create(struct interface *ifp); -extern int pim_ifp_up(struct interface *ifp); -extern int pim_ifp_down(struct interface *ifp); -extern int pim_ifp_destroy(struct interface *ifp); +void pim_iface_init(void); #endif /* PIM_IFACE_H */ diff --git a/pimd/pim_main.c b/pimd/pim_main.c index eb1cedd90d..92c34f51a1 100644 --- a/pimd/pim_main.c +++ b/pimd/pim_main.c @@ -136,8 +136,7 @@ int main(int argc, char **argv, char **envp) /* * Initialize zclient "update" and "lookup" sockets */ - if_zapi_callbacks(pim_ifp_create, pim_ifp_up, - pim_ifp_down, pim_ifp_destroy); + pim_iface_init(); pim_zebra_init(); pim_bfd_init(); pim_mlag_init(); From 3c10fb92c193d3b28537cfe138702693a382e97d Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Mon, 24 Jan 2022 00:17:48 +0300 Subject: [PATCH 2/2] pimd: fix interface info memory leak When the interface is deleted from the system, its info must be freed. Signed-off-by: Igor Ryzhov --- pimd/pim_iface.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 6727be01bc..72e04460d5 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1710,6 +1710,9 @@ static int pim_if_new_hook(struct interface *ifp) static int pim_if_delete_hook(struct interface *ifp) { + if (ifp->info) + pim_if_delete(ifp); + return 0; }