git: ea980c17f48e - stable/13 - if_clone: correctly destroy a clone from a different vnet

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Thu, 10 Oct 2024 10:03:24 UTC
The branch stable/13 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=ea980c17f48e9307504d7567d8f2b37dc3181588

commit ea980c17f48e9307504d7567d8f2b37dc3181588
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-01-25 05:07:16 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-10-10 10:00:48 +0000

    if_clone: correctly destroy a clone from a different vnet
    
    Try to live with cruel reality fact - if_vmove doesn't move an
    interface from previous vnet cloning infrastructure to the new
    one.  Let's admit this as design feature and make it work better.
    
    * Delete two blocks of code that would fallback to vnet0, if a
      cloner isn't found.  They didn't do any good job and also whole
      idea of treating vnet0 as special one is wrong.
    * When deleting a cloned interface, lookup its cloner using it's
      home vnet.
    
    With this change simple sequence works correctly:
    
      ifconfig foo0 create
      jail -c name=jj persist vnet vnet.interface=foo0
      jexec jj ifconfig foo0 destroy
    
    Differential revision:  https://reviews.freebsd.org/D33942
    
    (cherry picked from commit 6d1808f051a5f8e3b546442b9bcab3d03f04ef8a)
---
 sys/net/if_clone.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c
index 803d9b1f307a..98d2f4564db8 100644
--- a/sys/net/if_clone.c
+++ b/sys/net/if_clone.c
@@ -197,15 +197,6 @@ ifc_create_ifp(const char *name, struct ifc_data *ifd,
 	LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
 		if (ifc->ifc_match(ifc, name))
 			break;
-#ifdef VIMAGE
-	if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
-		CURVNET_SET_QUIET(vnet0);
-		LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
-			if (ifc->ifc_match(ifc, name))
-				break;
-		CURVNET_RESTORE();
-	}
-#endif
 	IF_CLONERS_UNLOCK();
 
 	if (ifc == NULL)
@@ -289,22 +280,15 @@ if_clone_destroy(const char *name)
 		return (ENXIO);
 
 	/* Find the cloner for this interface */
+	CURVNET_SET_QUIET(ifp->if_home_vnet);
 	IF_CLONERS_LOCK();
 	LIST_FOREACH(ifc, &V_if_cloners, ifc_list) {
 		if (strcmp(ifc->ifc_name, ifp->if_dname) == 0) {
 			break;
 		}
 	}
-#ifdef VIMAGE
-	if (ifc == NULL && !IS_DEFAULT_VNET(curvnet)) {
-		CURVNET_SET_QUIET(vnet0);
-		LIST_FOREACH(ifc, &V_if_cloners, ifc_list)
-			if (ifc->ifc_match(ifc, name))
-				break;
-		CURVNET_RESTORE();
-	}
-#endif
 	IF_CLONERS_UNLOCK();
+	CURVNET_RESTORE();
 	if (ifc == NULL) {
 		if_rele(ifp);
 		return (EINVAL);