]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: fix interface nb stale pointers 8426/head
authorIgor Ryzhov <iryzhov@nfware.com>
Thu, 8 Apr 2021 12:43:07 +0000 (15:43 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Mon, 12 Apr 2021 07:56:04 +0000 (10:56 +0300)
The first change in this commit is the processing of the VRF termination.
When we terminate the VRF, we should not delete the underlying interfaces,
because there may be pointers to them in the northbound configuration. We
should move them to the default VRF instead.

Because of the first change, the VRF interface itself is also not deleted
when deleting the VRF. It should be handled in netlink_link_change. This
is done by the second change.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
lib/if.c
zebra/if_netlink.c

index 629ef4e70878b3e401392304cf31eb5d6fb6eddc..f8a693d8f3053d7ab5037d3b4571185da9fda1bf 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -1056,15 +1056,30 @@ struct connected *connected_get_linklocal(struct interface *ifp)
 void if_terminate(struct vrf *vrf)
 {
        struct interface *ifp;
+       bool delete;
+
+       /*
+        * If the default VRF is being terminated or has
+        * already been terminated it means that
+        * the program is shutting down and we need to
+        * delete all the interfaces. Otherwise, we only
+        * need to move VRF's interfaces to the default VRF.
+        */
+       delete = vrf_is_backend_netns() || vrf->vrf_id == VRF_DEFAULT
+                || !vrf_lookup_by_id(VRF_DEFAULT);
 
        while (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
                ifp = RB_ROOT(if_name_head, &vrf->ifaces_by_name);
 
-               if (ifp->node) {
-                       ifp->node->info = NULL;
-                       route_unlock_node(ifp->node);
+               if (delete) {
+                       if (ifp->node) {
+                               ifp->node->info = NULL;
+                               route_unlock_node(ifp->node);
+                       }
+                       if_delete(&ifp);
+               } else {
+                       if_update_to_new_vrf(ifp, VRF_DEFAULT);
                }
-               if_delete(&ifp);
        }
 }
 
index af2c2516071d7e60874381f0fb6ff552d74200c8..6aaf9d94f3664a9f37aa415953c2b89658548abc 100644 (file)
@@ -1661,8 +1661,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                else if (IS_ZEBRA_IF_VXLAN(ifp))
                        zebra_l2_vxlanif_del(ifp);
 
-               if (!IS_ZEBRA_IF_VRF(ifp))
-                       if_delete_update(ifp);
+               if_delete_update(ifp);
        }
 
        return 0;