diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-02-07 10:08:07 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-02-07 10:08:07 +0000 |
commit | f0597a31a0e019728c416731216dda32a52356e9 (patch) | |
tree | d1d739de3705c20599b865d7c63bd0c84b8ff200 | |
parent | 09efeca3dd36b11a41e0d602b80612a310ad9111 (diff) |
Add support for interface-mtu (option 26).
Original request+diff from matthew@
ok dlg@
-rw-r--r-- | sbin/dhclient/dhclient.c | 14 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 43 | ||||
-rw-r--r-- | sbin/dhclient/privsep.c | 10 | ||||
-rw-r--r-- | sbin/dhclient/privsep.h | 8 |
4 files changed, 71 insertions, 4 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index e13e1599543..4bba00a1524 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.356 2015/02/07 02:07:32 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.357 2015/02/07 10:08:06 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -913,6 +913,18 @@ bind_lease(void) /* Deleting the addresses also clears out arp entries. */ delete_addresses(); flush_routes(); + + opt = &options[DHO_INTERFACE_MTU]; + if (opt->len == sizeof(u_int16_t)) { + u_int16_t mtu; + memcpy(&mtu, opt->data, sizeof(mtu)); + mtu = ntohs(mtu); + /* "The minimum legal value for the MTU is 68." */ + if (mtu < 68) + warning("mtu size %u < 68: ignored", mtu); + else + set_interface_mtu(mtu); + } opt = &options[DHO_SUBNET_MASK]; if (opt->len == sizeof(mask)) diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index a19575a1873..98d624159c8 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.72 2015/02/07 02:07:32 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.73 2015/02/07 10:08:06 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -364,6 +364,47 @@ priv_delete_address(struct imsg_delete_address *imsg) } /* + * [priv_]set_interface_mtu is the equivalent of + * + * ifconfig <if> mtu <mtu> + */ +void +set_interface_mtu(int mtu) +{ + struct imsg_set_interface_mtu imsg; + int rslt; + + memset(&imsg, 0, sizeof(imsg)); + + imsg.mtu = mtu; + + rslt = imsg_compose(unpriv_ibuf, IMSG_SET_INTERFACE_MTU, 0, 0, -1, + &imsg, sizeof(imsg)); + if (rslt == -1) + warning("set_interface_mtu: imsg_compose: %s", strerror(errno)); + + flush_unpriv_ibuf("set_interface_mtu"); +} + +void +priv_set_interface_mtu(struct imsg_set_interface_mtu *imsg) +{ + struct ifreq ifr; + int s; + + memset(&ifr, 0, sizeof(ifr)); + + strlcpy(ifr.ifr_name, ifi->name, sizeof(ifr.ifr_name)); + ifr.ifr_mtu = imsg->mtu; + + if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) + error("socket open failed: %s", strerror(errno)); + if (ioctl(s, SIOCSIFMTU, &ifr) < 0) + warning("SIOCSIFMTU failed (%d): %s", imsg->mtu, strerror(errno)); + close(s); +} + +/* * [priv_]add_address is the equivalent of * * ifconfig <if> inet <addr> netmask <mask> broadcast <addr> diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c index 56f83ea2764..3c0b5203b9f 100644 --- a/sbin/dhclient/privsep.c +++ b/sbin/dhclient/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.38 2015/02/06 09:16:06 reyk Exp $ */ +/* $OpenBSD: privsep.c,v 1.39 2015/02/07 10:08:06 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -69,6 +69,14 @@ dispatch_imsg(struct imsgbuf *ibuf) priv_add_route(imsg.data); break; + case IMSG_SET_INTERFACE_MTU: + if (imsg.hdr.len != IMSG_HEADER_SIZE + + sizeof(struct imsg_set_interface_mtu)) + warning("bad IMSG_SET_INTERFACE_MTU"); + else + priv_set_interface_mtu(imsg.data); + break; + case IMSG_HUP: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_hup)) diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h index a394fe02fcf..34bcb64cd3a 100644 --- a/sbin/dhclient/privsep.h +++ b/sbin/dhclient/privsep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.h,v 1.26 2015/02/06 09:16:06 reyk Exp $ */ +/* $OpenBSD: privsep.h,v 1.27 2015/02/07 10:08:06 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -26,6 +26,7 @@ enum imsg_code { IMSG_ADD_ADDRESS, IMSG_FLUSH_ROUTES, IMSG_ADD_ROUTE, + IMSG_SET_INTERFACE_MTU, IMSG_HUP, IMSG_WRITE_RESOLV_CONF, IMSG_WRITE_OPTION_DB @@ -52,6 +53,10 @@ struct imsg_add_route { int flags; }; +struct imsg_set_interface_mtu { + int mtu; +}; + struct imsg_hup { struct in_addr addr; }; @@ -62,6 +67,7 @@ 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_cleanup(struct imsg_hup *); +void priv_set_interface_mtu(struct imsg_set_interface_mtu *); void priv_write_resolv_conf(struct imsg *); void priv_write_option_db(struct imsg *); void priv_write_file(char *, int, mode_t, uid_t, gid_t, u_int8_t *, size_t); |