diff options
author | rink <rink@FreeBSD.org> | 2009-10-21 11:10:34 +0000 |
---|---|---|
committer | rink <rink@FreeBSD.org> | 2009-10-21 11:10:34 +0000 |
commit | c97b94656f34fdf55e60f0df440569ebf6471ba4 (patch) | |
tree | 35f07223fa82e1922d72a6fbc5aa03e36576900d /usr.sbin/sysinstall | |
parent | 418ad4a68fb7f7356533cc99ea9059eb4d0b910f (diff) | |
download | FreeBSD-src-c97b94656f34fdf55e60f0df440569ebf6471ba4.zip FreeBSD-src-c97b94656f34fdf55e60f0df440569ebf6471ba4.tar.gz |
Introduce 'netDev=ANY' support for scripted (install.cfg) installs, which results in the first ethernet interface with physical link being selected.
While here, fix a minor typo causing an 'if' to be missed.
Submitted by: randi
Diffstat (limited to 'usr.sbin/sysinstall')
-rw-r--r-- | usr.sbin/sysinstall/tcpip.c | 83 |
1 files changed, 73 insertions, 10 deletions
diff --git a/usr.sbin/sysinstall/tcpip.c b/usr.sbin/sysinstall/tcpip.c index f505a05..75a40e8 100644 --- a/usr.sbin/sysinstall/tcpip.c +++ b/usr.sbin/sysinstall/tcpip.c @@ -40,10 +40,17 @@ #include "sysinstall.h" #include <sys/param.h> #include <sys/sysctl.h> +#include <sys/types.h> #include <sys/socket.h> +#include <sys/sockio.h> + #include <netinet/in.h> +#include <net/if.h> +#include <net/if_media.h> + #include <netdb.h> #include <paths.h> +#include <ifaddrs.h> /* The help file for the TCP/IP setup screen */ #define TCP_HELPFILE "tcp" @@ -636,6 +643,51 @@ 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); + } + } + + freeifaddrs(ifap); + + return (NULL); +} + /* Get a network device */ Device * tcpDeviceSelect(void) @@ -647,27 +699,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]; } |