summaryrefslogtreecommitdiff
path: root/sbin/dhclient/dispatch.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-05-26 03:11:50 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-05-26 03:11:50 +0000
commit8d813c432df9889a3cf670142ee04a360cbb1164 (patch)
treed782fadcfc72288878e1e5110ece773618e43646 /sbin/dhclient/dispatch.c
parent4891b3ab6d24848f99aad7876e6f6e868587f511 (diff)
If an interface has no link at startup, try to force it up, and then
give it about 4 seconds of (silent) grace period before doing the verbose search for a link... tested by various developers who got burned a bit
Diffstat (limited to 'sbin/dhclient/dispatch.c')
-rw-r--r--sbin/dhclient/dispatch.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index 182c08c81b9..31ca87ba553 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.41 2008/05/09 05:19:14 reyk Exp $ */
+/* $OpenBSD: dispatch.c,v 1.42 2008/05/26 03:11:49 deraadt Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -51,8 +51,6 @@ struct timeout *timeouts;
static struct timeout *free_timeouts;
static int interfaces_invalidated;
-static int interface_status(void);
-
/*
* Use getifaddrs() to get a list of all the attached interfaces. For
* each interface that's of type INET and not the loopback interface,
@@ -209,7 +207,7 @@ got_one(void)
warning("receive_packet failed on %s: %s", ifi->name,
strerror(errno));
ifi->errors++;
- if ((!interface_status()) ||
+ if ((!interface_status(ifi->name)) ||
(ifi->noifmedia && ifi->errors > 20)) {
/* our interface has gone away. */
warning("Interface %s no longer appears valid.",
@@ -286,17 +284,19 @@ interface_link_forcedown(char *ifname)
}
int
-interface_status(void)
+interface_status(char *ifname)
{
- char *ifname = ifi->name;
- int ifsock = ifi->rfdesc;
struct ifreq ifr;
struct ifmediareq ifmr;
+ int sock;
+
+ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ error("Can't create socket");
/* get interface flags */
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
- if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
+ if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
warning("ioctl(SIOCGIFFLAGS) on %s: %m", ifname);
goto inactive;
}
@@ -313,7 +313,7 @@ interface_status(void)
goto active;
memset(&ifmr, 0, sizeof(ifmr));
strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
- if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
+ if (ioctl(sock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
/*
* EINVAL or ENOTTY simply means that the interface
* does not support the SIOCGIFMEDIA ioctl. We regard it alive.
@@ -331,8 +331,10 @@ interface_status(void)
goto inactive;
}
inactive:
+ close(sock);
return (0);
active:
+ close(sock);
return (1);
}