summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2016-08-31 12:57:31 +0000
committermpi <mpi@openbsd.org>2016-08-31 12:57:31 +0000
commit6a2ee11aa21725bb4cdef90dcde7b2006ee496bb (patch)
treea8f27657c15ad60ce2de28bf9cd07a7936d79c34
parentremove ym, wss, and sea drivers (diff)
downloadwireguard-openbsd-6a2ee11aa21725bb4cdef90dcde7b2006ee496bb.tar.xz
wireguard-openbsd-6a2ee11aa21725bb4cdef90dcde7b2006ee496bb.zip
Remove the 'client' global and make it per-ifp.
ok krw@
-rw-r--r--sbin/dhclient/bpf.c4
-rw-r--r--sbin/dhclient/clparse.c3
-rw-r--r--sbin/dhclient/dhclient.c43
-rw-r--r--sbin/dhclient/dhcpd.h6
-rw-r--r--sbin/dhclient/dispatch.c3
-rw-r--r--sbin/dhclient/options.c6
6 files changed, 45 insertions, 20 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c
index 74dc0b1c72e..9d1f6051cad 100644
--- a/sbin/dhclient/bpf.c
+++ b/sbin/dhclient/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.43 2016/08/23 09:26:02 mpi Exp $ */
+/* $OpenBSD: bpf.c,v 1.44 2016/08/31 12:57:31 mpi Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -259,6 +259,7 @@ if_register_receive(struct interface_info *ifi)
ssize_t
send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to)
{
+ struct client_state *client = ifi->client;
struct sockaddr_in dest;
struct ether_header eh;
struct ip ip;
@@ -336,6 +337,7 @@ ssize_t
receive_packet(struct interface_info *ifi, struct sockaddr_in *from,
struct ether_addr *hfrom)
{
+ struct client_state *client = ifi->client;
int length = 0, offset = 0;
struct bpf_hdr hdr;
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index 70728a8a385..e5c4c0c955f 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.98 2016/08/23 09:26:02 mpi Exp $ */
+/* $OpenBSD: clparse.c,v 1.99 2016/08/31 12:57:31 mpi Exp $ */
/* Parser for dhclient config and lease files. */
@@ -463,6 +463,7 @@ parse_interface_declaration(FILE *cfile, struct interface_info *ifi)
void
parse_client_lease_statement(FILE *cfile, int is_static, struct interface_info *ifi)
{
+ struct client_state *client = ifi->client;
struct client_lease *lease, *lp, *pl;
struct option_data *opt1, *opt2;
int token;
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 499f4a68622..a056c205793 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.381 2016/08/23 09:26:02 mpi Exp $ */
+/* $OpenBSD: dhclient.c,v 1.382 2016/08/31 12:57:31 mpi Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -112,7 +112,6 @@ const struct in_addr inaddr_any = { INADDR_ANY };
const struct in_addr inaddr_broadcast = { INADDR_BROADCAST };
struct interface_info *ifi;
-struct client_state *client;
struct client_config *config;
struct imsgbuf *unpriv_ibuf;
@@ -231,6 +230,7 @@ get_ifa(char *cp, int n)
void
routehandler(void)
{
+ struct client_state *client = ifi->client;
char ntoabuf[INET_ADDRSTRLEN];
struct in_addr a, b;
ssize_t n;
@@ -538,11 +538,11 @@ main(int argc, char *argv[])
error("config calloc");
TAILQ_INIT(&config->reject_list);
- client = calloc(1, sizeof(struct client_state));
- if (client == NULL)
+ ifi->client = calloc(1, sizeof(struct client_state));
+ if (ifi->client == NULL)
error("client calloc");
- TAILQ_INIT(&client->leases);
- TAILQ_INIT(&client->offered_leases);
+ TAILQ_INIT(&ifi->client->leases);
+ TAILQ_INIT(&ifi->client->offered_leases);
read_client_conf(ifi);
@@ -647,13 +647,13 @@ main(int argc, char *argv[])
}
setproctitle("%s", ifi->name);
- time(&client->startup_time);
+ time(&ifi->client->startup_time);
if (ifi->linkstat) {
- client->state = S_REBOOTING;
+ ifi->client->state = S_REBOOTING;
state_reboot();
} else {
- client->state = S_PREBOOT;
+ ifi->client->state = S_PREBOOT;
state_preboot();
}
@@ -677,6 +677,7 @@ usage(void)
void
state_preboot(void)
{
+ struct client_state *client = ifi->client;
static int preamble;
time_t cur_time;
int interval;
@@ -720,6 +721,7 @@ state_preboot(void)
void
state_reboot(void)
{
+ struct client_state *client = ifi->client;
char ifname[IF_NAMESIZE];
struct client_lease *lp;
struct option_data *opt;
@@ -795,6 +797,8 @@ state_reboot(void)
void
state_init(void)
{
+ struct client_state *client = ifi->client;
+
client->xid = arc4random();
make_discover(client->active);
@@ -813,6 +817,7 @@ state_init(void)
void
state_selecting(void)
{
+ struct client_state *client = ifi->client;
struct client_lease *lease, *picked;
cancel_timeout();
@@ -901,6 +906,7 @@ state_selecting(void)
void
dhcpack(struct in_addr client_addr, struct option_data *options, char *info)
{
+ struct client_state *client = ifi->client;
struct client_lease *lease;
if (client->state != S_REBOOTING &&
@@ -938,6 +944,7 @@ dhcpack(struct in_addr client_addr, struct option_data *options, char *info)
void
bind_lease(void)
{
+ struct client_state *client = ifi->client;
struct in_addr gateway, mask;
struct option_data *options, *opt;
struct client_lease *lease, *pl;
@@ -1086,6 +1093,7 @@ newlease:
void
state_bound(void)
{
+ struct client_state *client = ifi->client;
struct option_data *opt;
struct in_addr *dest;
@@ -1110,6 +1118,7 @@ state_bound(void)
void
dhcpoffer(struct in_addr client_addr, struct option_data *options, char *info)
{
+ struct client_state *client = ifi->client;
struct client_lease *lease, *lp;
time_t stop_selecting;
@@ -1198,6 +1207,7 @@ addressinuse(struct in_addr address, char *ifname)
struct client_lease *
packet_to_lease(struct in_addr client_addr, struct option_data *options)
{
+ struct client_state *client = ifi->client;
char ifname[IF_NAMESIZE];
struct client_lease *lease;
char *pretty, *buf;
@@ -1330,6 +1340,8 @@ packet_to_lease(struct in_addr client_addr, struct option_data *options)
void
dhcpnak(struct in_addr client_addr, struct option_data *options, char *info)
{
+ struct client_state *client = ifi->client;
+
if (client->state != S_REBOOTING &&
client->state != S_REQUESTING &&
client->state != S_RENEWING &&
@@ -1372,6 +1384,7 @@ dhcpnak(struct in_addr client_addr, struct option_data *options, char *info)
void
send_discover(void)
{
+ struct client_state *client = ifi->client;
time_t cur_time;
ssize_t rslt;
int interval;
@@ -1436,6 +1449,7 @@ send_discover(void)
void
state_panic(void)
{
+ struct client_state *client = ifi->client;
char ifname[IF_NAMESIZE];
struct client_lease *lp;
time_t cur_time;
@@ -1479,6 +1493,7 @@ state_panic(void)
void
send_request(void)
{
+ struct client_state *client = ifi->client;
struct sockaddr_in destination;
struct in_addr from;
time_t cur_time;
@@ -1591,6 +1606,7 @@ send_decline(void)
void
make_discover(struct client_lease *lease)
{
+ struct client_state *client = ifi->client;
struct option_data options[256];
struct dhcp_packet *packet = &client->bootrequest_packet;
unsigned char discover = DHCPDISCOVER;
@@ -1627,7 +1643,7 @@ make_discover(struct client_lease *lease)
}
/* Set up the option buffer to fit in a minimal UDP packet. */
- i = cons_options(options);
+ i = cons_options(ifi, options);
if (i == -1 || packet->options[i] != DHO_END)
error("options do not fit in DHCPDISCOVER packet.");
client->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1;
@@ -1654,6 +1670,7 @@ make_discover(struct client_lease *lease)
void
make_request(struct client_lease * lease)
{
+ struct client_state *client = ifi->client;
struct option_data options[256];
struct dhcp_packet *packet = &client->bootrequest_packet;
unsigned char request = DHCPREQUEST;
@@ -1698,7 +1715,7 @@ make_request(struct client_lease * lease)
}
/* Set up the option buffer to fit in a minimal UDP packet. */
- i = cons_options(options);
+ i = cons_options(ifi, options);
if (i == -1 || packet->options[i] != DHO_END)
error("options do not fit in DHCPREQUEST packet.");
client->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1;
@@ -1735,6 +1752,7 @@ make_request(struct client_lease * lease)
void
make_decline(struct client_lease *lease)
{
+ struct client_state *client = ifi->client;
struct option_data options[256];
struct dhcp_packet *packet = &client->bootrequest_packet;
unsigned char decline = DHCPDECLINE;
@@ -1766,7 +1784,7 @@ make_decline(struct client_lease *lease)
}
/* Set up the option buffer to fit in a minimal UDP packet. */
- i = cons_options(options);
+ i = cons_options(ifi, options);
if (i == -1 || packet->options[i] != DHO_END)
error("options do not fit in DHCPDECLINE packet.");
client->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1;
@@ -1812,6 +1830,7 @@ free_client_lease(struct client_lease *lease)
void
rewrite_client_leases(void)
{
+ struct client_state *client = ifi->client;
struct client_lease *lp;
char *leasestr;
time_t cur_time;
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 3472f167a4c..dea464e2c26 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.156 2016/08/23 09:26:02 mpi Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.157 2016/08/31 12:57:31 mpi Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -145,6 +145,7 @@ struct interface_info {
struct ether_addr hw_address;
char name[IFNAMSIZ];
char ssid[33];
+ struct client_state *client;
int bfdesc; /* bpf - reading & broadcast writing*/
int ufdesc; /* udp - unicast writing */
unsigned char *rbuf;
@@ -172,7 +173,6 @@ struct dhcp_timeout {
/* External definitions. */
-extern struct client_state *client;
extern struct client_config *config;
extern struct imsgbuf *unpriv_ibuf;
extern struct in_addr deleting;
@@ -181,7 +181,7 @@ extern struct in_addr active_addr;
extern volatile sig_atomic_t quit;
/* options.c */
-int cons_options(struct option_data *);
+int cons_options(struct interface_info *, struct option_data *);
char *pretty_print_option(unsigned int, struct option_data *, int);
int pretty_print_string(unsigned char *, size_t, unsigned char *, size_t, int);
int pretty_print_classless_routes(unsigned char *, size_t, unsigned char *,
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index ac0ee601016..ffc40edde87 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.107 2016/08/23 09:26:02 mpi Exp $ */
+/* $OpenBSD: dispatch.c,v 1.108 2016/08/31 12:57:31 mpi Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -119,6 +119,7 @@ get_hw_address(struct interface_info *ifi)
void
dispatch(struct interface_info *ifi)
{
+ struct client_state *client = ifi->client;
int count, to_msec;
struct pollfd fds[3];
time_t cur_time, howlong;
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index 95790e5171c..c14630ea47c 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.76 2016/08/23 09:26:02 mpi Exp $ */
+/* $OpenBSD: options.c,v 1.77 2016/08/31 12:57:31 mpi Exp $ */
/* DHCP options parsing and reassembly. */
@@ -159,8 +159,9 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer,
* to see if it's DHO_END to decide if all the options were copied.
*/
int
-cons_options(struct option_data *options)
+cons_options(struct interface_info *ifi, struct option_data *options)
{
+ struct client_state *client = ifi->client;
unsigned char *buf = client->bootrequest_packet.options;
int buflen = 576 - DHCP_FIXED_LEN;
int ix, incr, length, bufix, code, lastopt = -1;
@@ -648,6 +649,7 @@ void
do_packet(struct interface_info *ifi, unsigned int from_port,
struct in_addr from, struct ether_addr *hfrom)
{
+ struct client_state *client = ifi->client;
struct dhcp_packet *packet = &client->packet;
struct option_data options[256];
struct reject_elem *ap;