Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Feb 2025 19:18:22 GMT
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: e0b2b8fa16a1 - stable/13 - ifnet: Make if_detach_internal() and if_vmove() void
Message-ID:  <202502061918.516JIMH5015580@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by zlei:

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

commit e0b2b8fa16a13abb1ea8326c6ff311d0d94108db
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-02-04 15:04:59 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-02-06 18:59:58 +0000

    ifnet: Make if_detach_internal() and if_vmove() void
    
    if_detach_internal() never fail since change [1]. As a consequence,
    also does its caller if_vmove(). While here, remove a stall comment.
    
    No functional change intended.
    
    This reverts commit c7bab2a7ca9a6dae79f970c6730a19b65a1ed86e.
    
    [1] a779388f8bb3 if: Protect V_ifnet in vnet_if_return()
    
    Reviewed by:    glebius
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D48820
    
    (cherry picked from commit bb0348a17974d83671becbd32ea0e4bd2ea61906)
    (cherry picked from commit 700880a13566193b853f75c87ba5c37d395f6a1e)
---
 sys/net/if.c | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/sys/net/if.c b/sys/net/if.c
index 107ff67d547a..e30e1c7e5dca 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -278,12 +278,12 @@ static int	if_getgroup(struct ifgroupreq *, struct ifnet *);
 static int	if_getgroupmembers(struct ifgroupreq *);
 static void	if_delgroups(struct ifnet *);
 static void	if_attach_internal(struct ifnet *, bool);
-static int	if_detach_internal(struct ifnet *, bool);
+static void	if_detach_internal(struct ifnet *, bool);
 static void	if_siocaddmulti(void *, int);
 static void	if_link_ifnet(struct ifnet *);
 static bool	if_unlink_ifnet(struct ifnet *, bool);
 #ifdef VIMAGE
-static int	if_vmove(struct ifnet *, struct vnet *);
+static void	if_vmove(struct ifnet *, struct vnet *);
 #endif
 
 #ifdef INET6
@@ -1137,7 +1137,7 @@ if_detach(struct ifnet *ifp)
  * on a vnet instance shutdown without this flag being set, e.g., when
  * the cloned interfaces are destoyed as first thing of teardown.
  */
-static int
+static void
 if_detach_internal(struct ifnet *ifp, bool vmove)
 {
 	struct ifaddr *ifa;
@@ -1272,8 +1272,6 @@ finish_vnet_shutdown:
 			ifp->if_afdata[dp->dom_family] = NULL;
 		}
 	}
-
-	return (0);
 }
 
 #ifdef VIMAGE
@@ -1284,20 +1282,16 @@ finish_vnet_shutdown:
  * unused if_index in target vnet and calls if_grow() if necessary,
  * and finally find an unused if_xname for the target vnet.
  */
-static int
+static void
 if_vmove(struct ifnet *ifp, struct vnet *new_vnet)
 {
 	void *old;
-	int rc;
 
 	/*
 	 * Detach from current vnet, but preserve LLADDR info, do not
 	 * mark as dead etc. so that the ifnet can be reattached later.
-	 * If we cannot find it, we lost the race to someone else.
 	 */
-	rc = if_detach_internal(ifp, true);
-	if (rc != 0)
-		return (rc);
+	if_detach_internal(ifp, true);
 
 	/*
 	 * Unlink the ifnet from ifindex_table[] in current vnet, and shrink
@@ -1336,7 +1330,6 @@ if_vmove(struct ifnet *ifp, struct vnet *new_vnet)
 	if_attach_internal(ifp, true);
 
 	CURVNET_RESTORE();
-	return (0);
 }
 
 /*
@@ -1347,7 +1340,6 @@ if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid)
 {
 	struct prison *pr;
 	struct ifnet *difp;
-	int error;
 	bool found;
 	bool shutdown;
 
@@ -1393,16 +1385,15 @@ if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid)
 	}
 
 	/* Move the interface into the child jail/vnet. */
-	error = if_vmove(ifp, pr->pr_vnet);
+	if_vmove(ifp, pr->pr_vnet);
 
-	/* Report the new if_xname back to the userland on success. */
-	if (error == 0)
-		sprintf(ifname, "%s", ifp->if_xname);
+	/* Report the new if_xname back to the userland. */
+	sprintf(ifname, "%s", ifp->if_xname);
 
 	sx_xunlock(&ifnet_detach_sxlock);
 
 	prison_free(pr);
-	return (error);
+	return (0);
 }
 
 static int
@@ -1411,7 +1402,7 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid)
 	struct prison *pr;
 	struct vnet *vnet_dst;
 	struct ifnet *ifp;
-	int error, found;
+	int found;
  	bool shutdown;
 
 	/* Try to find the prison within our visibility. */
@@ -1452,16 +1443,15 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid)
 	found = if_unlink_ifnet(ifp, true);
 	MPASS(found);
 	sx_xlock(&ifnet_detach_sxlock);
-	error = if_vmove(ifp, vnet_dst);
+	if_vmove(ifp, vnet_dst);
 	sx_xunlock(&ifnet_detach_sxlock);
 	CURVNET_RESTORE();
 
-	/* Report the new if_xname back to the userland on success. */
-	if (error == 0)
-		sprintf(ifname, "%s", ifp->if_xname);
+	/* Report the new if_xname back to the userland. */
+	sprintf(ifname, "%s", ifp->if_xname);
 
 	prison_free(pr);
-	return (error);
+	return (0);
 }
 #endif /* VIMAGE */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502061918.516JIMH5015580>