summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dhclient/dhclient.c43
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/kroute.c26
-rw-r--r--sbin/dhclient/privsep.c10
-rw-r--r--sbin/dhclient/privsep.h14
5 files changed, 70 insertions, 27 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index a3f4900f36c..7c98573da33 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.247 2013/05/05 16:45:01 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.248 2013/06/01 16:26:07 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -108,6 +108,8 @@ 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);
+
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
@@ -2263,3 +2265,42 @@ 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 imsg_add_route imsg;
+ int rslt;
+
+ memset(&imsg, 0, sizeof(imsg));
+
+ imsg.rdomain = rdomain;
+ imsg.dest = addr;
+ imsg.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) {
+ imsg.gateway = gateway;
+ imsg.addrs |= RTA_GATEWAY;
+ }
+
+ rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ROUTE, 0, 0, -1, &imsg,
+ sizeof(imsg));
+
+ if (rslt == -1)
+ warning("add_route: imsg_compose: %s", strerror(errno));
+}
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 522b7a3e08d..529299f9653 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.117 2013/05/05 16:45:01 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.118 2013/06/01 16:26:07 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_default_route(int, struct in_addr, struct in_addr);
+void add_route(int, struct in_addr, struct in_addr, struct in_addr, int);
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index d8aafa3c82d..7e0869c5c7d 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.47 2013/03/30 16:10:01 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.48 2013/06/01 16:26:07 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -183,26 +183,29 @@ priv_flush_routes(struct imsg_flush_routes *imsg)
* depending on the contents of the gateway parameter.
*/
void
-add_default_route(int rdomain, struct in_addr addr, struct in_addr gateway)
+add_route(int rdomain, struct in_addr dest, struct in_addr netmask,
+ struct in_addr gateway, int addrs)
{
- struct imsg_add_default_route imsg;
- int rslt;
+ struct imsg_add_route imsg;
+ int rslt;
memset(&imsg, 0, sizeof(imsg));
imsg.rdomain = rdomain;
- imsg.addr = addr;
+ imsg.dest = dest;
imsg.gateway = gateway;
+ imsg.netmask = netmask;
+ imsg.addrs = addrs;
- rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_DEFAULT_ROUTE, 0, 0, -1,
+ rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ROUTE, 0, 0, -1,
&imsg, sizeof(imsg));
if (rslt == -1)
- warning("add_default_route: imsg_compose: %s", strerror(errno));
+ warning("add_route: imsg_compose: %s", strerror(errno));
}
void
-priv_add_default_route(struct imsg_add_default_route *imsg)
+priv_add_route(struct imsg_add_route *imsg)
{
struct rt_msghdr rtm;
struct sockaddr_in dest, gateway, mask;
@@ -210,10 +213,6 @@ priv_add_default_route(struct imsg_add_default_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));
@@ -249,7 +248,7 @@ priv_add_default_route(struct imsg_add_default_route *imsg)
*/
memset(&gateway, 0, sizeof(gateway));
- if (bcmp(&imsg->gateway, &imsg->addr, sizeof(imsg->addr)) != 0) {
+ if ((imsg->addrs & RTA_GATEWAY) != 0) {
gateway.sin_len = sizeof(gateway);
gateway.sin_family = AF_INET;
gateway.sin_addr.s_addr = imsg->gateway.s_addr;
@@ -267,6 +266,7 @@ priv_add_default_route(struct imsg_add_default_route *imsg)
mask.sin_len = sizeof(mask);
mask.sin_family = AF_INET;
+ mask.sin_addr.s_addr = imsg->netmask.s_addr;
rtm.rtm_addrs |= RTA_NETMASK;
rtm.rtm_msglen += sizeof(mask);
diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c
index fa4b5ecabcb..b5497d34779 100644
--- a/sbin/dhclient/privsep.c
+++ b/sbin/dhclient/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.31 2013/03/30 16:10:01 krw Exp $ */
+/* $OpenBSD: privsep.c,v 1.32 2013/06/01 16:26:07 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_DEFAULT_ROUTE:
+ case IMSG_ADD_ROUTE:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(struct imsg_add_default_route))
- warning("bad IMSG_ADD_DEFAULT_ROUTE");
+ sizeof(struct imsg_add_route))
+ warning("bad IMSG_ADD_ROUTE");
else
- priv_add_default_route(imsg.data);
+ priv_add_route(imsg.data);
break;
case IMSG_HUP:
diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h
index 6d93f9175dd..ba3d645a53c 100644
--- a/sbin/dhclient/privsep.h
+++ b/sbin/dhclient/privsep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.h,v 1.18 2013/03/30 16:10:01 krw Exp $ */
+/* $OpenBSD: privsep.h,v 1.19 2013/06/01 16:26:07 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_DEFAULT_ROUTE,
+ IMSG_ADD_ROUTE,
IMSG_HUP,
IMSG_WRITE_FILE
};
@@ -49,10 +49,12 @@ struct imsg_flush_routes {
int zapzombies;
};
-struct imsg_add_default_route {
- int rdomain;
- struct in_addr addr;
+struct imsg_add_route {
+ struct in_addr dest;
+ struct in_addr netmask;
struct in_addr gateway;
+ int rdomain;
+ int addrs;
};
struct imsg_hup {
@@ -76,6 +78,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_default_route(struct imsg_add_default_route *);
+void priv_add_route(struct imsg_add_route *);
void priv_cleanup(struct imsg_hup *);
void priv_write_file(struct imsg_write_file *);