summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2013-06-09 00:30:06 +0000
committerkrw <krw@openbsd.org>2013-06-09 00:30:06 +0000
commitd18f37909efa0eb00ccec672a31a8ab3087d6c16 (patch)
tree3a4f41551d8a9fcf355d14bf07fdf44d7dfb57f5
parentKNF (diff)
downloadwireguard-openbsd-d18f37909efa0eb00ccec672a31a8ab3087d6c16.tar.xz
wireguard-openbsd-d18f37909efa0eb00ccec672a31a8ab3087d6c16.zip
Backout static/classless route handling and default route refactoring
since the former relies on the latter and the latter breaks 'egress' group populating.
-rw-r--r--sbin/dhclient/clparse.c5
-rw-r--r--sbin/dhclient/conflex.c39
-rw-r--r--sbin/dhclient/dhclient.c115
-rw-r--r--sbin/dhclient/dhcp.h3
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/kroute.c59
-rw-r--r--sbin/dhclient/privsep.c10
-rw-r--r--sbin/dhclient/privsep.h14
-rw-r--r--sbin/dhclient/tables.c4
9 files changed, 73 insertions, 180 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index f51e4148ff4..1dab99a1de1 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.58 2013/06/04 21:04:51 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.59 2013/06/09 00:30:06 krw Exp $ */
/* Parser for dhclient config and lease files. */
@@ -72,9 +72,6 @@ read_client_conf(void)
[config->requested_option_count++] = DHO_BROADCAST_ADDRESS;
config->requested_options
[config->requested_option_count++] = DHO_TIME_OFFSET;
- /* RFC 3442 says CLASSLESS_STATIC_ROUTES must be before ROUTERS! */
- config->requested_options
- [config->requested_option_count++] = DHO_CLASSLESS_STATIC_ROUTES;
config->requested_options
[config->requested_option_count++] = DHO_ROUTERS;
config->requested_options
diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c
index 60020529d45..d6be36f8c42 100644
--- a/sbin/dhclient/conflex.c
+++ b/sbin/dhclient/conflex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conflex.c,v 1.20 2013/06/04 13:00:07 krw Exp $ */
+/* $OpenBSD: conflex.c,v 1.21 2013/06/09 00:30:06 krw Exp $ */
/* Lexical scanner for dhclient config file. */
@@ -233,29 +233,34 @@ skip_to_eol(FILE *cfile)
static int
read_string(FILE *cfile)
{
- int i, c, bs;
+ int i, c, bs = 0;
- bs = i = 0;
- do {
+ for (i = 0; i < sizeof(tokbuf); i++) {
c = get_char(cfile);
- if (bs)
+ if (c == EOF) {
+ parse_warn("eof in string constant");
+ break;
+ }
+ if (bs) {
bs = 0;
- else if (c == '\\')
+ tokbuf[i] = c;
+ } else if (c == '\\')
bs = 1;
-
- if (c != '"' && c != EOF && bs == 0)
- tokbuf[i++] = c;
-
- } while (i < (sizeof(tokbuf) - 1) && c != EOF && c != '"');
-
- if (c == EOF)
- parse_warn("eof in string constant");
- else if (c != '"')
+ else if (c == '"')
+ break;
+ else
+ tokbuf[i] = c;
+ }
+ /*
+ * Normally, I'd feel guilty about this, but we're talking about
+ * strings that'll fit in a DHCP packet here.
+ */
+ if (i == sizeof(tokbuf)) {
parse_warn("string constant larger than internal buffer");
-
+ i--;
+ }
tokbuf[i] = 0;
tval = tokbuf;
-
return (TOK_STRING);
}
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 41ec4549d9c..de84208a406 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.249 2013/06/04 21:04:52 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.250 2013/06/09 00:30:06 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -108,10 +108,6 @@ struct client_lease *clone_lease(struct client_lease *);
void socket_nonblockmode(int);
void apply_ignore_list(char *);
-void add_default_route(int, struct in_addr, struct in_addr);
-void add_static_routes(int, struct option_data *);
-void add_classless_static_routes(int, struct option_data *);
-
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
@@ -792,21 +788,12 @@ bind_lease(void)
* is done by the RTM_NEWADDR message being received.
*/
add_address(ifi->name, ifi->rdomain, client->new->address, mask);
- if (options[DHO_CLASSLESS_STATIC_ROUTES].len) {
- add_classless_static_routes(ifi->rdomain,
- &options[DHO_CLASSLESS_STATIC_ROUTES]);
- } else {
- if (options[DHO_ROUTERS].len) {
- memset(&gateway, 0, sizeof(gateway));
- /* XXX Only use FIRST router address for now. */
- memcpy(&gateway.s_addr, options[DHO_ROUTERS].data,
- options[DHO_ROUTERS].len);
- add_default_route(ifi->rdomain, client->new->address,
- gateway);
- }
- if (options[DHO_STATIC_ROUTES].len)
- add_static_routes(ifi->rdomain,
- &options[DHO_STATIC_ROUTES]);
+ if (options[DHO_ROUTERS].len) {
+ memset(&gateway, 0, sizeof(gateway));
+ /* XXX Only use FIRST router address for now. */
+ memcpy(&gateway.s_addr, options[DHO_ROUTERS].data,
+ options[DHO_ROUTERS].len);
+ add_default_route(ifi->rdomain, client->new->address, gateway);
}
client->new->resolv_conf = resolv_conf_contents(
@@ -2276,91 +2263,3 @@ priv_write_file(struct imsg_write_file *imsg)
close(fd);
}
-
-/*
- * add_default_route is the equivalent of
- *
- * route -q $rdomain add default -iface $router
- *
- * or
- *
- * route -q $rdomain add default $router
- *
- * depending on the contents of the gateway parameter.
- */
-void
-add_default_route(int rdomain, struct in_addr addr, struct in_addr gateway)
-{
- struct in_addr netmask;
- int addrs;
-
- memset(&netmask, 0, sizeof(netmask));
- addrs = RTA_DST | RTA_NETMASK;
-
- /*
- * Set gateway address if and only if non-zero addr supplied. A
- * gateway address of 0 implies '-iface'.
- */
- if (bcmp(&gateway, &addr, sizeof(addr)) != 0)
- addrs |= RTA_GATEWAY;
-
- add_route(rdomain, addr, netmask, gateway, addrs);
-}
-
-void
-add_static_routes(int rdomain, struct option_data *static_routes)
-{
- struct in_addr dest, netmask, gateway;
- u_int8_t *addr;
- int i;
-
- memset(&netmask, 0, sizeof(netmask)); /* Always 0 for class addrs. */
-
- for (i = 0; (i + 7) < static_routes->len; i += 8) {
- addr = &static_routes->data[i];
- memset(&dest, 0, sizeof(dest));
- memset(&gateway, 0, sizeof(gateway));
-
- memcpy(&dest.s_addr, addr, 4);
- if (dest.s_addr == INADDR_ANY)
- continue; /* RFC 2132 says 0.0.0.0 is not allowed. */
- memcpy(&gateway.s_addr, addr+4, 4);
-
- /* XXX Order implies priority but we're ignoring that. */
- add_route(rdomain, dest, netmask, gateway,
- RTA_DST | RTA_GATEWAY);
- }
-}
-
-void add_classless_static_routes(int rdomain,
- struct option_data *classless_static_routes)
-{
- struct in_addr dest, netmask, gateway;
- int bits, bytes, i;
-
- i = 0;
- while (i < classless_static_routes->len) {
- bits = classless_static_routes->data[i];
- bytes = (bits + 7) / 8;
- i++;
-
- memset(&netmask, 0, sizeof(netmask));
- if (bits)
- netmask.s_addr = htonl(0xffffffff << (32 - bits));
-
- memset(&dest, 0, sizeof(dest));
- memcpy(&dest, &classless_static_routes->data[i], bytes);
- dest.s_addr = dest.s_addr & netmask.s_addr;
- i += bytes;
-
- memset(&gateway, 0, sizeof(gateway));
- memcpy(&gateway, &classless_static_routes->data[i], 4);
- i += 4;
-
- if (gateway.s_addr == INADDR_ANY)
- continue; /* OBSD TCP/IP doesn't support this. */
-
- add_route(rdomain, dest, netmask, gateway,
- RTA_DST | RTA_GATEWAY | RTA_NETMASK);
- }
-}
diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h
index 4b5d478c871..1e24aa6fa34 100644
--- a/sbin/dhclient/dhcp.h
+++ b/sbin/dhclient/dhcp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.h,v 1.13 2013/06/04 21:04:52 krw Exp $ */
+/* $OpenBSD: dhcp.h,v 1.14 2013/06/09 00:30:06 krw Exp $ */
/* Protocol structures. */
@@ -173,7 +173,6 @@ struct dhcp_packet {
#define DHO_NDS_SERVERS 85
#define DHO_NDS_TREE_NAME 86
#define DHO_NDS_CONTEXT 87
-#define DHO_CLASSLESS_STATIC_ROUTES 121
#define DHO_TFTP_CONFIG_FILE 144
#define DHO_VOIP_CONFIGURATION_SERVER 150
#define DHO_AUTOPROXY_SCRIPT 252
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 529299f9653..7e6da3e3661 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.118 2013/06/01 16:26:07 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.119 2013/06/09 00:30:06 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -343,4 +343,4 @@ void add_address(char *, int, struct in_addr, struct in_addr);
void flush_routes(char *, int);
-void add_route(int, struct in_addr, struct in_addr, struct in_addr, int);
+void add_default_route(int, struct in_addr, struct in_addr);
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 71e1f92916c..708aa533862 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.49 2013/06/04 21:04:53 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.50 2013/06/09 00:30:06 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -183,29 +183,26 @@ priv_flush_routes(struct imsg_flush_routes *imsg)
* depending on the contents of the gateway parameter.
*/
void
-add_route(int rdomain, struct in_addr dest, struct in_addr netmask,
- struct in_addr gateway, int addrs)
+add_default_route(int rdomain, struct in_addr addr, struct in_addr gateway)
{
- struct imsg_add_route imsg;
- int rslt;
+ struct imsg_add_default_route imsg;
+ int rslt;
memset(&imsg, 0, sizeof(imsg));
imsg.rdomain = rdomain;
- imsg.dest = dest;
+ imsg.addr = addr;
imsg.gateway = gateway;
- imsg.netmask = netmask;
- imsg.addrs = addrs;
- rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ROUTE, 0, 0, -1,
+ rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_DEFAULT_ROUTE, 0, 0, -1,
&imsg, sizeof(imsg));
if (rslt == -1)
- warning("add_route: imsg_compose: %s", strerror(errno));
+ warning("add_default_route: imsg_compose: %s", strerror(errno));
}
void
-priv_add_route(struct imsg_add_route *imsg)
+priv_add_default_route(struct imsg_add_default_route *imsg)
{
struct rt_msghdr rtm;
struct sockaddr_in dest, gateway, mask;
@@ -213,6 +210,10 @@ priv_add_route(struct imsg_add_route *imsg)
struct iovec iov[5];
int s, i, iovcnt = 0;
+ /*
+ * Add a default route via the specified address.
+ */
+
if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
error("Routing Socket open failed: %s", strerror(errno));
@@ -229,21 +230,18 @@ priv_add_route(struct imsg_add_route *imsg)
iov[iovcnt].iov_base = &rtm;
iov[iovcnt++].iov_len = sizeof(rtm);
- /* Set destination address. */
+ /* Set destination address of all zeros. */
memset(&dest, 0, sizeof(dest));
- if (imsg->addrs & RTA_DST) {
- dest.sin_len = sizeof(dest);
- dest.sin_family = AF_INET;
- dest.sin_addr.s_addr = imsg->dest.s_addr;
+ dest.sin_len = sizeof(dest);
+ dest.sin_family = AF_INET;
- rtm.rtm_addrs |= RTA_DST;
- rtm.rtm_msglen += sizeof(dest);
+ rtm.rtm_addrs |= RTA_DST;
+ rtm.rtm_msglen += sizeof(dest);
- iov[iovcnt].iov_base = &dest;
- iov[iovcnt++].iov_len = sizeof(dest);
- }
+ iov[iovcnt].iov_base = &dest;
+ iov[iovcnt++].iov_len = sizeof(dest);
/*
* Set gateway address if and only if non-zero addr supplied. A
@@ -251,7 +249,7 @@ priv_add_route(struct imsg_add_route *imsg)
*/
memset(&gateway, 0, sizeof(gateway));
- if (imsg->addrs & RTA_GATEWAY) {
+ if (bcmp(&imsg->gateway, &imsg->addr, sizeof(imsg->addr)) != 0) {
gateway.sin_len = sizeof(gateway);
gateway.sin_family = AF_INET;
gateway.sin_addr.s_addr = imsg->gateway.s_addr;
@@ -264,20 +262,17 @@ priv_add_route(struct imsg_add_route *imsg)
iov[iovcnt++].iov_len = sizeof(gateway);
}
- /* Add netmask. */
+ /* Add netmask of 0. */
memset(&mask, 0, sizeof(mask));
- if (imsg->addrs & RTA_NETMASK) {
- mask.sin_len = sizeof(mask);
- mask.sin_family = AF_INET;
- mask.sin_addr.s_addr = imsg->netmask.s_addr;
+ mask.sin_len = sizeof(mask);
+ mask.sin_family = AF_INET;
- rtm.rtm_addrs |= RTA_NETMASK;
- rtm.rtm_msglen += sizeof(mask);
+ rtm.rtm_addrs |= RTA_NETMASK;
+ rtm.rtm_msglen += sizeof(mask);
- iov[iovcnt].iov_base = &mask;
- iov[iovcnt++].iov_len = sizeof(mask);
- }
+ iov[iovcnt].iov_base = &mask;
+ iov[iovcnt++].iov_len = sizeof(mask);
/* Add our label so we can identify the route as our creation. */
if (create_route_label(&label) == 0) {
diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c
index b5497d34779..38af8edf99a 100644
--- a/sbin/dhclient/privsep.c
+++ b/sbin/dhclient/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.32 2013/06/01 16:26:07 krw Exp $ */
+/* $OpenBSD: privsep.c,v 1.33 2013/06/09 00:30:06 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -63,12 +63,12 @@ dispatch_imsg(struct imsgbuf *ibuf)
priv_flush_routes(imsg.data);
break;
- case IMSG_ADD_ROUTE:
+ case IMSG_ADD_DEFAULT_ROUTE:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(struct imsg_add_route))
- warning("bad IMSG_ADD_ROUTE");
+ sizeof(struct imsg_add_default_route))
+ warning("bad IMSG_ADD_DEFAULT_ROUTE");
else
- priv_add_route(imsg.data);
+ priv_add_default_route(imsg.data);
break;
case IMSG_HUP:
diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h
index ba3d645a53c..0e08cbd7e46 100644
--- a/sbin/dhclient/privsep.h
+++ b/sbin/dhclient/privsep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.h,v 1.19 2013/06/01 16:26:07 krw Exp $ */
+/* $OpenBSD: privsep.h,v 1.20 2013/06/09 00:30:06 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -25,7 +25,7 @@ enum imsg_code {
IMSG_DELETE_ADDRESS,
IMSG_ADD_ADDRESS,
IMSG_FLUSH_ROUTES,
- IMSG_ADD_ROUTE,
+ IMSG_ADD_DEFAULT_ROUTE,
IMSG_HUP,
IMSG_WRITE_FILE
};
@@ -49,12 +49,10 @@ struct imsg_flush_routes {
int zapzombies;
};
-struct imsg_add_route {
- struct in_addr dest;
- struct in_addr netmask;
- struct in_addr gateway;
+struct imsg_add_default_route {
int rdomain;
- int addrs;
+ struct in_addr addr;
+ struct in_addr gateway;
};
struct imsg_hup {
@@ -78,6 +76,6 @@ void dispatch_imsg(struct imsgbuf *);
void priv_delete_address(struct imsg_delete_address *);
void priv_add_address(struct imsg_add_address *);
void priv_flush_routes(struct imsg_flush_routes *);
-void priv_add_route(struct imsg_add_route *);
+void priv_add_default_route(struct imsg_add_default_route *);
void priv_cleanup(struct imsg_hup *);
void priv_write_file(struct imsg_write_file *);
diff --git a/sbin/dhclient/tables.c b/sbin/dhclient/tables.c
index 84cdabbc433..b9112334589 100644
--- a/sbin/dhclient/tables.c
+++ b/sbin/dhclient/tables.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tables.c,v 1.14 2013/06/04 21:04:53 krw Exp $ */
+/* $OpenBSD: tables.c,v 1.15 2013/06/09 00:30:06 krw Exp $ */
/* Tables of information. */
@@ -182,7 +182,7 @@ const struct option dhcp_options[256] = {
/* 118 */ { "option-118", "X" },
/* 119 */ { "option-119", "X" },
/* 120 */ { "option-120", "X" },
- /* 121 */ { "classless-static-routes", "X" },
+ /* 121 */ { "option-121", "X" },
/* 122 */ { "option-122", "X" },
/* 123 */ { "option-123", "X" },
/* 124 */ { "option-124", "X" },