From ce27a13e90885de3a830e4ec78afc9efeadae42e Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Sat, 6 Nov 2021 01:22:07 +0300 Subject: lib: fix vrf deletion when the last interface is deleted Currently, we automatically delete an inactive VRF when its last interface is deleted. This code introduces a couple of crashes because of the following problems: - vrf_delete is called before calling if_del hook, so daemons may try to dereference an ifp->vrf pointer which is freed - in if_terminate, we continue to use the VRF in the loop condition after the last interface is deleted This check is needed only when the interface is deleted by the user, because if the interface is deleted by the system, VRF must still exist in the system. Move the check to appropriate places to fix crashes. Signed-off-by: Igor Ryzhov --- ospfd/ospf_interface.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ospfd/ospf_interface.c') diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 60e109ea80..ccfeddfc66 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -971,11 +971,14 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf, static void ospf_vl_if_delete(struct ospf_vl_data *vl_data) { struct interface *ifp = vl_data->vl_oi->ifp; + struct vrf *vrf = ifp->vrf; vl_data->vl_oi->address->u.prefix4.s_addr = INADDR_ANY; vl_data->vl_oi->address->prefixlen = 0; ospf_if_free(vl_data->vl_oi); if_delete(&ifp); + if (!vrf_is_enabled(vrf)) + vrf_delete(vrf); vlink_count--; } -- cgit v1.2.3