From owner-p4-projects@FreeBSD.ORG Sun Aug 5 15:16:34 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 673CA16A420; Sun, 5 Aug 2007 15:16:34 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A23F16A418 for ; Sun, 5 Aug 2007 15:16:34 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 0F68813C45A for ; Sun, 5 Aug 2007 15:16:34 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l75FGXol012048 for ; Sun, 5 Aug 2007 15:16:33 GMT (envelope-from zec@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l75FGX8B012045 for perforce@freebsd.org; Sun, 5 Aug 2007 15:16:33 GMT (envelope-from zec@FreeBSD.org) Date: Sun, 5 Aug 2007 15:16:33 GMT Message-Id: <200708051516.l75FGX8B012045@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@FreeBSD.org using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 124728 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Aug 2007 15:16:34 -0000 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);