summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2008-05-26 03:11:48 +0000
committerderaadt <deraadt@openbsd.org>2008-05-26 03:11:48 +0000
commit50c0c4828c48d180bd9100e76d6a1c66a5e77e4d (patch)
tree6012f60df27e57de8070eb883072ee278c1c2667
parentexplain why, even though we support "sticky" block sizes, setting block (diff)
downloadwireguard-openbsd-50c0c4828c48d180bd9100e76d6a1c66a5e77e4d.tar.xz
wireguard-openbsd-50c0c4828c48d180bd9100e76d6a1c66a5e77e4d.zip
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
-rw-r--r--sbin/dhclient/dhclient.c32
-rw-r--r--sbin/dhclient/dhcpd.h3
-rw-r--r--sbin/dhclient/dispatch.c20
3 files changed, 30 insertions, 25 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 15dfcf1b1e5..dbeea0631aa 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.118 2008/05/09 05:19:14 reyk Exp $ */
+/* $OpenBSD: dhclient.c,v 1.119 2008/05/26 03:11:48 deraadt Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -319,25 +319,27 @@ main(int argc, char *argv[])
read_client_conf();
- if (!(ifi->linkstat = interface_link_status(ifi->name))) {
- fprintf(stderr, "%s: no link ...", ifi->name);
- if (config->link_timeout == 0) {
+ if (interface_status(ifi->name) == 0) {
+ interface_link_forceup(ifi->name);
+ /* Give it up to 4 seconds of silent grace to find link */
+ i = -4;
+ } else
+ i = 0;
+
+ while (!(ifi->linkstat = interface_link_status(ifi->name))) {
+ if (i == 0)
+ fprintf(stderr, "%s: no link ...", ifi->name);
+ else if (i > 0)
+ fprintf(stderr, ".");
+ fflush(stderr);
+ if (++i > config->link_timeout) {
fprintf(stderr, " sleeping\n");
goto dispatch;
}
- fflush(stderr);
sleep(1);
- while (!(ifi->linkstat = interface_link_status(ifi->name))) {
- fprintf(stderr, ".");
- fflush(stderr);
- if (++i > config->link_timeout) {
- fprintf(stderr, " sleeping\n");
- goto dispatch;
- }
- sleep(1);
- }
- fprintf(stderr, " got link\n");
}
+ if (i >= 0)
+ fprintf(stderr, " got link\n");
dispatch:
if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1)
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index b3427c5f16c..1f16add560c 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.66 2008/05/09 05:19:14 reyk Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.67 2008/05/26 03:11:48 deraadt Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -255,6 +255,7 @@ void got_one(void);
void add_timeout(time_t, void (*)(void));
void cancel_timeout(void (*)(void));
int interface_link_status(char *);
+int interface_status(char *);
int interface_link_forceup(char *);
void interface_link_forcedown(char *);
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);
}