diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2019-07-30 12:48:28 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2019-07-30 12:48:28 +0000 |
commit | 0cb038e4d3c82d8f6efd967e88bc50884244fee1 (patch) | |
tree | 9de157955df70fda0bb92c418a8d390eceacf23e | |
parent | b0c4777b4dd02e928b62ac0b2be79a88acd33c1d (diff) |
Use AUTOCONF4 flag. Set the flag on startup. But if the flag is
subsequently reset by ifconfig(8) then stop applying leases. If the
flag is set after being reset then get a new lease and carry on.
Clean up man page verbiage and add AUTOCONF4 description.
ok benno@, man page formatting ok ingo@
-rw-r--r-- | sbin/dhclient/dhclient.8 | 51 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 26 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 3 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 10 |
4 files changed, 59 insertions, 31 deletions
diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index f4ef921e143..e79e87df410 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.8,v 1.40 2019/07/15 11:07:00 krw Exp $ +.\" $OpenBSD: dhclient.8,v 1.41 2019/07/30 12:48:27 krw Exp $ .\" .\" Copyright (c) 1997 The Internet Software Consortium. .\" All rights reserved. @@ -35,7 +35,7 @@ .\" Enterprises. To learn more about the Internet Software Consortium, .\" see ``http://www.isc.org/isc''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. -.Dd $Mdocdate: July 15 2019 $ +.Dd $Mdocdate: July 30 2019 $ .Dt DHCLIENT 8 .Os .Sh NAME @@ -49,36 +49,32 @@ .Op Fl L Ar file .Ar interface .Sh DESCRIPTION -The Dynamic Host Configuration Protocol (DHCP) allows hosts on a TCP/IP network -to configure one or more network interfaces based on information collected from -a DHCP server. -DHCP is often used, for example, by cable modem and DSL network -providers to automate network configuration for their customers. -.Pp +.Nm +uses the Dynamic Host Configuration Protocol (DHCP), or its +predecessor BOOTP, to configure a network interface. Information typically provided via DHCP includes -address and subnet mask for the interface, -default route, +IPv4 address and subnet mask, default route, and domain name server. .Pp -To have -.Ox -configure an interface using DHCP -(or its predecessor, BOOTP) -the .Nm -utility is used. -.Nm -is run on the command line with the name of the -.Ar interface -to be configured. +can be run on the command line, or at boot time by specifying +.Sq dhcp +in the appropriate +.Xr hostname.if 5 +file. +.Pp .Nm -can also be run at boot time from -.Xr hostname.if 5 , -in which case -.Xr netstart 8 -reads the hostname files and runs +sets the +.Sy AUTOCONF4 +flag on +.Ar interface. +If the flag is later cleared by +.Xr ifconfig 8 .Nm -for each interface that is to be configured via DHCP. +will continue to obtain leases normally but it will not apply any +changes to the interface or the host until +.Xr ifconfig 8 +restores the flag. .Pp The options are as follows: .Bl -tag -width Ds @@ -270,7 +266,8 @@ database of acquired leases .Xr dhclient.leases 5 , .Xr hostname.if 5 , .Xr dhcpd 8 , -.Xr dhcrelay 8 +.Xr dhcrelay 8 , +.Xr ifconfig 8 .Sh STANDARDS .Rs .%A R. Droms diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 9c7f42202ba..51a30d29665 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.647 2019/07/24 17:53:33 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.648 2019/07/30 12:48:27 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -379,6 +379,15 @@ rtm_dispatch(struct interface_info *ifi, struct rt_msghdr *rtm) if ((rtm->rtm_flags & RTF_UP) == 0) fatalx("down"); + if ((ifm->ifm_xflags & IFXF_AUTOCONF4) == 0) + ifi->flags &= ~IFI_AUTOCONF; + else if ((ifi->flags & IFI_AUTOCONF) == 0) { + /* Get new lease when AUTOCONF4 gets set. */ + ifi->flags |= IFI_AUTOCONF; + quit = RESTART; + break; + } + oldmtu = ifi->mtu; interface_state(ifi); if (oldmtu == ifi->mtu) @@ -573,6 +582,19 @@ main(int argc, char *argv[]) interface_state(ifi); if (!LINK_STATE_IS_UP(ifi->link_state)) interface_link_forceup(ifi->name, ioctlfd); + + /* Running dhclient(8) means this interface is AUTOCONF4. */ + ifi->flags |= IFI_AUTOCONF; + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, ifi->name, sizeof(ifr.ifr_name)); + if (ioctl(ioctlfd, SIOCGIFXFLAGS, (caddr_t)&ifr) < 0) + fatal("SIOGIFXFLAGS"); + if ((ifr.ifr_flags & IFXF_AUTOCONF4) == 0) { + ifr.ifr_flags |= IFXF_AUTOCONF4; + if (ioctl(ioctlfd, SIOCSIFXFLAGS, (caddr_t)&ifr) == -1) + fatal("SIOCSIFXFLAGS"); + } + close(ioctlfd); ioctlfd = -1; @@ -958,7 +980,7 @@ bind_lease(struct interface_info *ifi) effective_proposal = NULL; propose(ifi->configured); - rslt = asprintf(&msg, "bound to %s from %s", + rslt = asprintf(&msg, "%s lease accepted from %s", inet_ntoa(ifi->active->address), (ifi->offer_src == NULL) ? "<unknown>" : ifi->offer_src); if (rslt == -1) diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 43f7e0afb39..8ea427236c7 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.281 2019/07/22 17:20:06 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.282 2019/07/30 12:48:27 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -129,6 +129,7 @@ struct interface_info { int rdomain; int flags; #define IFI_IN_CHARGE 0x01 +#define IFI_AUTOCONF 0x02 uint32_t mtu; struct dhcp_packet recv_packet; struct dhcp_packet sent_packet; diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index b85d9181903..e5952a14686 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.165 2019/07/26 14:36:26 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.166 2019/07/30 12:48:27 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -919,6 +919,14 @@ priv_propose(char *name, int ioctlfd, struct imsg_propose *imsg, char **resolv_conf, int routefd, int rdomain, int index) { struct proposal *proposal = &imsg->proposal; + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + if (ioctl(ioctlfd, SIOCGIFXFLAGS, (caddr_t)&ifr) < 0) + fatal("SIOGIFXFLAGS"); + if ((ifr.ifr_flags & IFXF_AUTOCONF4) == 0) + return; *resolv_conf = set_resolv_conf(name, proposal->rtsearch, |