From owner-svn-src-stable@FreeBSD.ORG Fri May 21 23:08:54 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 435861065672; Fri, 21 May 2010 23:08:54 +0000 (UTC) (envelope-from randi@FreeBSD.org) Received: from svn.freebsd.org (unknown [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 31C078FC20; Fri, 21 May 2010 23:08:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4LN8sNo063835; Fri, 21 May 2010 23:08:54 GMT (envelope-from randi@svn.freebsd.org) Received: (from randi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4LN8sRF063833; Fri, 21 May 2010 23:08:54 GMT (envelope-from randi@svn.freebsd.org) Message-Id: <201005212308.o4LN8sRF063833@svn.freebsd.org> From: Randi Harper Date: Fri, 21 May 2010 23:08:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r208406 - stable/8/usr.sbin/sysinstall X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2010 23:08:54 -0000 Author: randi Date: Fri May 21 23:08:53 2010 New Revision: 208406 URL: http://svn.freebsd.org/changeset/base/208406 Log: MFC r198317,206995: Introduce 'netDev=ANY' support for scripted (install.cfg) installs, which results in the first ethernet interface with physical link being selected. Approved by: cperciva (mentor) Modified: stable/8/usr.sbin/sysinstall/tcpip.c Directory Properties: stable/8/usr.sbin/sysinstall/ (props changed) Modified: stable/8/usr.sbin/sysinstall/tcpip.c ============================================================================== --- stable/8/usr.sbin/sysinstall/tcpip.c Fri May 21 20:46:01 2010 (r208405) +++ stable/8/usr.sbin/sysinstall/tcpip.c Fri May 21 23:08:53 2010 (r208406) @@ -40,10 +40,17 @@ #include "sysinstall.h" #include #include +#include #include +#include + #include +#include +#include + #include #include +#include /* The help file for the TCP/IP setup screen */ #define TCP_HELPFILE "tcp" @@ -636,6 +643,53 @@ netHook(dialogMenuItem *self) return devs ? DITEM_LEAVE_MENU : DITEM_FAILURE; } +static char * +tcpDeviceScan(void) +{ + int s; + struct ifmediareq ifmr; + struct ifaddrs *ifap, *ifa; + struct if_data *ifd; + char *network_dev; + + if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) + return (NULL); + + if (getifaddrs(&ifap) < 0) + return (NULL); + + for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { + memset(&ifmr, 0, sizeof(ifmr)); + strlcpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name)); + + if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) + continue; /* some devices don't support this */ + + if ((ifmr.ifm_status & IFM_AVALID) == 0) + continue; /* not active */ + + if (IFM_TYPE(ifmr.ifm_active) != IFM_ETHER) + continue; /* not an ethernet device */ + + if (ifmr.ifm_status & IFM_ACTIVE) { + network_dev = strdup(ifa->ifa_name); + freeifaddrs(ifap); + + if (!variable_get(VAR_NONINTERACTIVE)) + msgConfirm("Using interface %s", network_dev); + + msgDebug("tcpDeviceScan found %s", network_dev); + return (network_dev); + } + } + + close(s); + + freeifaddrs(ifap); + + return (NULL); +} + /* Get a network device */ Device * tcpDeviceSelect(void) @@ -647,27 +701,38 @@ tcpDeviceSelect(void) rval = NULL; - if (variable_get(VAR_NONINTERACTIVE) && variable_get(VAR_NETWORK_DEVICE)) { + if (variable_get(VAR_NETWORK_DEVICE)) { network_dev = variable_get(VAR_NETWORK_DEVICE); + /* + * netDev can be set to several types of values. + * If netDev is set to ANY, scan all network devices + * looking for a valid link, and go with the first + * device found. netDev can also be specified as a + * comma delimited list, with each network device + * tried in order. netDev can also be set to a single + * network device. + */ + if (!strcmp(network_dev, "ANY")) + network_dev = strdup(tcpDeviceScan()); + while ((dev = strsep(&network_dev, ",")) != NULL) { devs = deviceFind(dev, DEVICE_TYPE_NETWORK); cnt = deviceCount(devs); + if (cnt) { - if (DITEM_STATUS(tcpOpenDialog(devs[0]) == DITEM_SUCCESS)) - return(devs[0]); + if (DITEM_STATUS(tcpOpenDialog(devs[0])) == DITEM_SUCCESS) + return (devs[0]); } } - } - devs = deviceFind(variable_get(VAR_NETWORK_DEVICE), DEVICE_TYPE_NETWORK); - cnt = deviceCount(devs); + if (!variable_get(VAR_NONINTERACTIVE)) + msgConfirm("No network devices available!"); - if (!cnt) { - msgConfirm("No network devices available!"); - return NULL; + return (NULL); } - else if ((!RunningAsInit) && (variable_check("NETWORK_CONFIGURED=NO") != TRUE)) { + + if ((!RunningAsInit) && (variable_check("NETWORK_CONFIGURED=NO") != TRUE)) { if (!msgYesNo("Running multi-user, assume that the network is already configured?")) return devs[0]; }