summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-07-22 14:56:28 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-07-22 14:56:28 +0000
commit4de9d35cbf2fc1ad09b6bee12d77af60888d79ef (patch)
tree1b8df6344a379b61ebac206f667c4eee78eca679 /sbin/dhclient
parentdcde299afc055b737334395365b7ef6b2a485eb7 (diff)
Rename *_add_address to *_set_address to reflect that the
lease address replaces all current addresses. Shuffle some code from bind_lease() into set_mtu()/set_address() to shrink bind_lease().
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c23
-rw-r--r--sbin/dhclient/dhcpd.h6
-rw-r--r--sbin/dhclient/kroute.c33
-rw-r--r--sbin/dhclient/privsep.c10
-rw-r--r--sbin/dhclient/privsep.h8
5 files changed, 37 insertions, 43 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 8572c75eb3f..56d2c2539d3 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.474 2017/07/21 18:57:55 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.475 2017/07/22 14:56:27 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -935,28 +935,11 @@ bind_lease(struct interface_info *ifi)
flush_routes();
opt = &options[DHO_INTERFACE_MTU];
- if (opt->len == sizeof(uint16_t)) {
- uint16_t mtu;
- memcpy(&mtu, opt->data, sizeof(mtu));
- mtu = ntohs(mtu);
- /* "The minimum legal value for the MTU is 68." */
- if (mtu < 68)
- log_warnx("mtu size %u < 68: ignored", mtu);
- else
- set_mtu(mtu);
- }
+ set_mtu(opt);
opt = &options[DHO_SUBNET_MASK];
- if (opt->len == sizeof(mask))
- mask.s_addr = ((struct in_addr *)opt->data)->s_addr;
- else
- mask.s_addr = INADDR_ANY;
+ set_address(ifi->active->address, opt);
- /*
- * Add address and default route last, so we know when the binding
- * is done by the RTM_NEWADDR message being received.
- */
- add_address(ifi->active->address, mask);
if (options[DHO_CLASSLESS_STATIC_ROUTES].len != 0) {
add_classless_static_routes(
&options[DHO_CLASSLESS_STATIC_ROUTES],
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index a4a6a0e6f43..3431f5f5a70 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.213 2017/07/21 18:57:55 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.214 2017/07/22 14:56:27 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -237,8 +237,8 @@ void read_client_leases(char *, struct client_lease_tq *);
void delete_addresses(char *);
void delete_address(struct in_addr);
-void set_mtu(int);
-void add_address(struct in_addr, struct in_addr);
+void set_mtu(struct option_data *);
+void set_address(struct in_addr, struct option_data *);
void flush_routes(void);
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index ba9561e46a5..6bf8067cdd8 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.111 2017/07/21 18:57:55 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.112 2017/07/22 14:56:27 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -614,12 +614,20 @@ priv_delete_address(char *name, int ioctlfd, struct imsg_delete_address *imsg)
* ifconfig <if> mtu <mtu>
*/
void
-set_mtu(int mtu)
+set_mtu(struct option_data *mtu)
{
struct imsg_set_mtu imsg;
int rslt;
- imsg.mtu = mtu;
+ if (mtu->len != sizeof(uint16_t))
+ return;
+
+ memcpy(&imsg.mtu, mtu->data, sizeof(uint16_t));
+ imsg.mtu = ntohs(imsg.mtu);
+ if (imsg.mtu < 68) {
+ log_warnx("mtu size %u < 68: ignored", imsg.mtu);
+ return;
+ }
rslt = imsg_compose(unpriv_ibuf, IMSG_SET_MTU, 0, 0, -1,
&imsg, sizeof(imsg));
@@ -644,29 +652,32 @@ priv_set_mtu(char *name, int ioctlfd, struct imsg_set_mtu *imsg)
}
/*
- * [priv_]add_address is the equivalent of
+ * [priv_]set_address is the equivalent of
*
* ifconfig <if> inet <addr> netmask <mask> broadcast <addr>
*/
void
-add_address(struct in_addr addr, struct in_addr mask)
+set_address(struct in_addr addr, struct option_data *mask)
{
- struct imsg_add_address imsg;
+ struct imsg_set_address imsg;
int rslt;
imsg.addr = addr;
- imsg.mask = mask;
+ if (mask->len == sizeof(imsg.mask))
+ imsg.mask.s_addr = ((struct in_addr *)mask->data)->s_addr;
+ else
+ imsg.mask.s_addr = INADDR_ANY;
- rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ADDRESS, 0, 0, -1, &imsg,
+ rslt = imsg_compose(unpriv_ibuf, IMSG_SET_ADDRESS, 0, 0, -1, &imsg,
sizeof(imsg));
if (rslt == -1)
- log_warn("add_address: imsg_compose");
+ log_warn("set_address: imsg_compose");
- flush_unpriv_ibuf("add_address");
+ flush_unpriv_ibuf("set_address");
}
void
-priv_add_address(char *name, int ioctlfd, struct imsg_add_address *imsg)
+priv_set_address(char *name, int ioctlfd, struct imsg_set_address *imsg)
{
struct ifaliasreq ifaliasreq;
struct sockaddr_in *in;
diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c
index 2683a881883..0a5bac9fd97 100644
--- a/sbin/dhclient/privsep.c
+++ b/sbin/dhclient/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.58 2017/07/21 18:57:55 krw Exp $ */
+/* $OpenBSD: privsep.c,v 1.59 2017/07/22 14:56:27 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -58,12 +58,12 @@ dispatch_imsg(char *name, int rdomain, int ioctlfd, int routefd,
priv_delete_address(name, ioctlfd, imsg.data);
break;
- case IMSG_ADD_ADDRESS:
+ case IMSG_SET_ADDRESS:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(struct imsg_add_address))
- log_warnx("bad IMSG_ADD_ADDRESS");
+ sizeof(struct imsg_set_address))
+ log_warnx("bad IMSG_SET_ADDRESS");
else
- priv_add_address(name, ioctlfd, imsg.data);
+ priv_set_address(name, ioctlfd, imsg.data);
break;
case IMSG_FLUSH_ROUTES:
diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h
index 9368f7bd804..21f99196afa 100644
--- a/sbin/dhclient/privsep.h
+++ b/sbin/dhclient/privsep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.h,v 1.45 2017/07/21 18:57:55 krw Exp $ */
+/* $OpenBSD: privsep.h,v 1.46 2017/07/22 14:56:27 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -20,7 +20,7 @@ enum imsg_code {
IMSG_NONE,
IMSG_HUP,
IMSG_DELETE_ADDRESS,
- IMSG_ADD_ADDRESS,
+ IMSG_SET_ADDRESS,
IMSG_FLUSH_ROUTES,
IMSG_ADD_ROUTE,
IMSG_SET_MTU,
@@ -31,7 +31,7 @@ struct imsg_delete_address {
struct in_addr addr;
};
-struct imsg_add_address {
+struct imsg_set_address {
struct in_addr addr;
struct in_addr mask;
};
@@ -64,6 +64,6 @@ void write_resolv_conf(uint8_t *, size_t);
void priv_write_resolv_conf(uint8_t *, size_t);
void priv_delete_address(char *, int, struct imsg_delete_address *);
-void priv_add_address(char *, int, struct imsg_add_address *);
+void priv_set_address(char *, int, struct imsg_set_address *);
void priv_set_mtu(char *, int, struct imsg_set_mtu *);