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
This commit is contained in:
Rink Springer 2009-10-21 11:10:34 +00:00
parent 32ae24b7d7
commit c8c45602aa

View File

@ -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]);
}
}
if (!variable_get(VAR_NONINTERACTIVE))
msgConfirm("No network devices available!");
return (NULL);
}
devs = deviceFind(variable_get(VAR_NETWORK_DEVICE), DEVICE_TYPE_NETWORK);
cnt = deviceCount(devs);
if (!cnt) {
msgConfirm("No network devices available!");
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];
}