summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-06-18 21:08:15 +0000
committerkrw <krw@openbsd.org>2017-06-18 21:08:15 +0000
commit8b6a415aff35ea2940738b5e8468f30e665082cf (patch)
tree2528858ad5b4b6363a82063a9bdb8c8f8f0f09ef
parentDon't write input if ICANON is enabled. Also, write one byte at a time. (diff)
downloadwireguard-openbsd-8b6a415aff35ea2940738b5e8468f30e665082cf.tar.xz
wireguard-openbsd-8b6a415aff35ea2940738b5e8468f30e665082cf.zip
Move the timeout information into struct interface_info with
the rest of the dhcp state. One less struct (dhcp_timeout) to worry about, one less field (ifi) to keep track of.
-rw-r--r--sbin/dhclient/dhclient.c14
-rw-r--r--sbin/dhclient/dhcpd.h13
-rw-r--r--sbin/dhclient/dispatch.c30
3 files changed, 24 insertions, 33 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 468fdfd256c..d9f27578cfe 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.436 2017/06/18 17:01:46 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.437 2017/06/18 21:08:15 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -404,7 +404,7 @@ routehandler(struct interface_info *ifi)
ftruncate(fileno(optionDB), 0);
}
/* No need to wait for anything but link. */
- cancel_timeout();
+ cancel_timeout(ifi);
}
}
break;
@@ -752,7 +752,7 @@ state_reboot(struct interface_info *ifi)
char ifname[IF_NAMESIZE];
time_t cur_time;
- cancel_timeout();
+ cancel_timeout(ifi);
deleting.s_addr = INADDR_ANY;
adding.s_addr = INADDR_ANY;
@@ -810,7 +810,7 @@ state_selecting(struct interface_info *ifi)
{
struct option_data *option;
- cancel_timeout();
+ cancel_timeout(ifi);
if (ifi->offer == NULL) {
state_panic(ifi);
@@ -941,7 +941,7 @@ dhcpack(struct interface_info *ifi, struct option_data *options, char *info)
ifi->offer->ssid_len = ifi->ssid_len;
/* Stop resending DHCPREQUEST. */
- cancel_timeout();
+ cancel_timeout(ifi);
bind_lease(ifi);
}
@@ -977,7 +977,7 @@ dhcpnak(struct interface_info *ifi, struct option_data *options, char *info)
ifi->active = NULL;
/* Stop sending DHCPREQUEST packets. */
- cancel_timeout();
+ cancel_timeout(ifi);
ifi->state = S_INIT;
state_init(ifi);
@@ -1451,7 +1451,7 @@ send_request(struct interface_info *ifi)
if (ifi->state == S_REBOOTING && interval >
config->reboot_timeout) {
ifi->state = S_INIT;
- cancel_timeout();
+ cancel_timeout(ifi);
state_init(ifi);
return;
}
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 0cdcd566661..890e01dd469 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.188 2017/06/18 17:01:46 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.189 2017/06/18 21:08:15 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -119,6 +119,7 @@ struct client_config {
char *server_name;
};
+
struct interface_info {
struct ether_addr hw_address;
char name[IFNAMSIZ];
@@ -144,6 +145,8 @@ struct interface_info {
struct dhcp_packet sent_packet;
int sent_packet_length;
u_int32_t xid;
+ time_t timeout;
+ void (*timeout_func)(struct interface_info *);
u_int16_t secs;
time_t first_sending;
time_t startup_time;
@@ -156,12 +159,6 @@ struct interface_info {
TAILQ_HEAD(_leases, client_lease) leases;
};
-struct dhcp_timeout {
- time_t when;
- void (*func)(struct interface_info *);
- struct interface_info *ifi;
-};
-
#define _PATH_RESOLV_CONF "/etc/resolv.conf"
#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases"
@@ -215,7 +212,7 @@ ssize_t receive_packet(struct interface_info *, struct sockaddr_in *,
void dispatch(struct interface_info *);
void set_timeout(time_t, void (*)(struct interface_info *),
struct interface_info *);
-void cancel_timeout(void);
+void cancel_timeout(struct interface_info *);
void interface_link_forceup(char *);
int interface_status(struct interface_info *);
int get_rdomain(char *);
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index 62308ec073c..57ed6b2230e 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.123 2017/06/18 17:01:46 krw Exp $ */
+/* $OpenBSD: dispatch.c,v 1.124 2017/06/18 21:08:15 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -70,8 +70,6 @@
#include "privsep.h"
-struct dhcp_timeout timeout;
-
void packethandler(struct interface_info *ifi);
void sendhup(struct client_lease *);
@@ -124,16 +122,14 @@ dispatch(struct interface_info *ifi)
struct pollfd fds[3];
time_t cur_time, howlong;
void (*func)(struct interface_info *);
- struct interface_info *arg;
while (quit == 0) {
- if (timeout.func) {
+ if (ifi->timeout_func) {
time(&cur_time);
- if (timeout.when <= cur_time) {
- func = timeout.func;
- arg = timeout.ifi;
- cancel_timeout();
- (*(func))(arg);
+ if (ifi->timeout <= cur_time) {
+ func = ifi->timeout_func;
+ cancel_timeout(ifi);
+ (*(func))(ifi);
continue;
}
/*
@@ -142,7 +138,7 @@ dispatch(struct interface_info *ifi)
* int for poll, while not polling with a
* negative timeout and blocking indefinitely.
*/
- howlong = timeout.when - cur_time;
+ howlong = ifi->timeout - cur_time;
if (howlong > INT_MAX / 1000)
howlong = INT_MAX / 1000;
to_msec = howlong * 1000;
@@ -283,17 +279,15 @@ void
set_timeout(time_t secs, void (*where)(struct interface_info *),
struct interface_info *ifi)
{
- timeout.when = time(NULL) + secs;
- timeout.func = where;
- timeout.ifi = ifi;
+ ifi->timeout = time(NULL) + secs;
+ ifi->timeout_func = where;
}
void
-cancel_timeout(void)
+cancel_timeout(struct interface_info *ifi)
{
- timeout.when = 0;
- timeout.func = NULL;
- timeout.ifi = NULL;
+ ifi->timeout = 0;
+ ifi->timeout_func = NULL;
}
int