Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Aug 2007 15:16:33 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124728 for review
Message-ID:  <200708051516.l75FGX8B012045@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124728

Change 124728 by zec@zec_tpx32 on 2007/08/05 15:15:59

	ifnet renaming when roaming from one vnet to another:
	
	- when returning to home vnet (the one where it was attached
	for the first time) always restore the original name in form
	of ("%s%d", if_dname, if_dunit);
	
	- otherwise, find the lowest unit number allowing the ifnet
	to be attached as ("eth%d", unit), unless
	
	- the request from userland included another name to be given
	to the ifnet, in which case set if_xname to this name;
	
	- return the new ifnet name to the userland properly.

Affected files ...

.. //depot/projects/vimage/src/sys/kern/kern_vimage.c#33 edit

Differences ...

==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#33 (text+ko) ====

@@ -268,7 +268,9 @@
 
 /*
  * Move the interface to another vnet. The interface can be specified either
- * by ifp argument, or by name contained in vi_req if NULL is passed as ifp.
+ * by ifp argument, or by name contained in vi_req->vi_chroot if NULL is
+ * passed as ifp.  The interface will be renamed to vi_req->vi_parent_name
+ * if vi_req->vi_parent_name is not an empty string (uff ugly ugly)...
  * Similary, the target vnet can be specified either by vnet argument or
  * by name. If vnet name equals to "-" or vi_req is set to NULL the
  * interface is moved to the parent vnet.
@@ -359,6 +361,41 @@
 		if_grow();
 	ifnet_byindex(ifp->if_index) = ifp;
 
+	/* Rename the ifnet */
+	if (new_vnet == ifp->if_home_vnet) {
+		/* always restore the original name on return to home vnet */
+		snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", ifp->if_dname,
+		    ifp->if_dunit);
+	} else {
+		if (vi_req  && strlen(vi_req->vi_parent_name) > 0) {
+			snprintf(ifp->if_xname, IFNAMSIZ, "%s",
+			    vi_req->vi_parent_name);
+		} else {
+			int unit = 0;
+			struct ifnet *iter;
+
+			switch (ifp->if_type) {
+				case IFT_ETHER:
+				case IFT_L2VLAN:
+					do {
+						snprintf(ifp->if_xname,
+						    IFNAMSIZ, "eth%d", unit);
+						TAILQ_FOREACH(iter, &V_ifnet,
+						    if_link)
+							if (strcmp(
+							    ifp->if_xname,
+							    iter->if_xname)
+							    == 0)
+								break;
+						unit++;
+					} while (iter);
+					break;
+				default:
+					break;
+			}
+		}
+	}
+
 	switch (ifp->if_type) {
 	case IFT_ETHER:
 	case IFT_L2VLAN:
@@ -371,8 +408,7 @@
 	getmicrotime(&ifp->if_lastchange);
 
 	if (vi_req != NULL)
-		sprintf(vi_req->vi_chroot, "%s%d",
-			ifp->if_dname, ifp->if_dunit);
+		sprintf(vi_req->vi_chroot, "%s", ifp->if_xname);
 
 	CURVNET_RESTORE();
 	return (0);



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