diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-07-17 15:05:04 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-07-17 15:05:04 +0000 |
commit | 71af147886c29c33b523ab431750c228fb9d5860 (patch) | |
tree | 5ad6c7656bf5f6c83d27c34281e578d838a165fa /sbin/dhclient | |
parent | 9579cf0af297e462ab4c348acbb2fa31475bc1ad (diff) |
Remove some magic formerly used to detect the presence of another
dhclient taking control of the interface.
In particular do not exit when addresses are manually added to or
deleted from the interface dhclient(8) is concerned about. Note that
such changes will still be removed whenever dhclient(8) is re-started
or gets a different lease during renewal.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/dhclient.8 | 9 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 114 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 7 |
3 files changed, 17 insertions, 113 deletions
diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index 1770351bcd2..c1438bd2bb0 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.8,v 1.31 2017/06/28 17:54:31 jmc Exp $ +.\" $OpenBSD: dhclient.8,v 1.32 2017/07/17 15:05:03 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: June 28 2017 $ +.Dd $Mdocdate: July 17 2017 $ .Dt DHCLIENT 8 .Os .Sh NAME @@ -168,11 +168,8 @@ attempts to remove any existing addresses, gateway routes that use the interface, and non-permanent .Xr arp 8 entries. -Conversely, if the interface is later manipulated to add or delete -addresses then .Nm -will automatically exit. -It thus automatically exits whenever a new +automatically exits whenever a new .Nm is run on the same interface. .Pp diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index ea12c64f69f..f118060618d 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.469 2017/07/14 16:21:03 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.470 2017/07/17 15:05:03 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -238,11 +238,7 @@ get_ifa(char *cp, int n) void routehandler(struct interface_info *ifi, int routefd) { - char ntoabuf[INET_ADDRSTRLEN]; - struct in_addr a; struct ether_addr hw; - struct sockaddr *sa; - struct ifa_msghdr *ifam; struct rt_msghdr *rtm; struct if_msghdr *ifm; struct if_announcemsghdr *ifan; @@ -282,89 +278,6 @@ routehandler(struct interface_info *ifi, int routefd) goto done; } break; - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (ifam->ifam_index != ifi->index) - break; - if (findproto((char *)ifam + ifam->ifam_hdrlen, - ifam->ifam_addrs) != AF_INET) - break; - sa = get_ifa((char *)ifam + ifam->ifam_hdrlen, - ifam->ifam_addrs); - if (sa == NULL) - goto done; - - memcpy(&a, &((struct sockaddr_in *)sa)->sin_addr, sizeof(a)); - if (a.s_addr == INADDR_ANY) - break; - - /* - * If we are in the process of adding a new address, ignore - * messages generated by that process. - */ - if (a.s_addr == adding.s_addr) { - adding.s_addr = INADDR_ANY; - log_info("bound to %s -- renewal in %lld seconds.", - inet_ntoa(ifi->active->address), - (long long)(ifi->active->renewal - - time(NULL))); - ifi->flags |= IFI_IS_RESPONSIBLE; - go_daemon(); - break; - } - if ((ifi->flags & IFI_IS_RESPONSIBLE) == 0) - /* We're not responsible yet! */ - break; - if (adding.s_addr != INADDR_ANY) { - strlcpy(ntoabuf, inet_ntoa(a), sizeof(ntoabuf)); - rslt = asprintf(&errmsg, "%s, not %s, added to %s", - ntoabuf, inet_ntoa(adding), ifi->name); - } else - rslt = asprintf(&errmsg, "%s added to %s", - inet_ntoa(a), ifi->name); - goto die; - case RTM_DELADDR: - ifam = (struct ifa_msghdr *)rtm; - if (ifam->ifam_index != ifi->index) - break; - if (findproto((char *)ifam + ifam->ifam_hdrlen, - ifam->ifam_addrs) != AF_INET) - break; - sa = get_ifa((char *)ifam + ifam->ifam_hdrlen, - ifam->ifam_addrs); - if (sa == NULL) - goto done; - - memcpy(&a, &((struct sockaddr_in *)sa)->sin_addr, sizeof(a)); - if (a.s_addr == INADDR_ANY) - break; - - /* - * If we are in the process of deleting an address, ignore - * messages generated by that process. - */ - if (a.s_addr == deleting.s_addr) { - deleting.s_addr = INADDR_ANY; - break; - } - if ((ifi->flags & IFI_IS_RESPONSIBLE) == 0) - /* We're not responsible yet! */ - break; - if (adding.s_addr == INADDR_ANY && ifi->active && - a.s_addr == ifi->active->address.s_addr) { - log_warnx("Active address (%s) deleted; exiting", - inet_ntoa(ifi->active->address)); - quit = INTERNALSIG; - goto done; - } - if (deleting.s_addr != INADDR_ANY) { - strlcpy(ntoabuf, inet_ntoa(a), sizeof(ntoabuf)); - rslt = asprintf(&errmsg, "%s, not %s, deleted from %s", - ntoabuf, inet_ntoa(deleting), ifi->name); - } else - rslt = asprintf(&errmsg, "%s deleted from %s", - inet_ntoa(a), ifi->name); - goto die; case RTM_DESYNC: log_warnx("route socket buffer overflow"); break; @@ -423,7 +336,7 @@ routehandler(struct interface_info *ifi, int routefd) /* Something has happened. Try to write out the resolv.conf. */ if (ifi->active != NULL && ifi->active->resolv_conf != NULL && - (ifi->flags & IFI_IS_RESPONSIBLE) != 0) + (ifi->flags & IFI_IN_CHARGE) != 0) write_resolv_conf(ifi->active->resolv_conf, strlen(ifi->active->resolv_conf)); @@ -621,8 +534,7 @@ main(int argc, char *argv[]) if ((routefd = socket(PF_ROUTE, SOCK_RAW, AF_INET)) == -1) fatal("socket(PF_ROUTE, SOCK_RAW)"); - rtfilter = ROUTE_FILTER(RTM_PROPOSAL) | ROUTE_FILTER(RTM_NEWADDR) | - ROUTE_FILTER(RTM_DELADDR) | ROUTE_FILTER(RTM_IFINFO) | + rtfilter = ROUTE_FILTER(RTM_PROPOSAL) | ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_IFANNOUNCE); if (setsockopt(routefd, PF_ROUTE, ROUTE_MSGFILTER, @@ -764,9 +676,6 @@ state_reboot(struct interface_info *ifi) { cancel_timeout(ifi); - deleting.s_addr = INADDR_ANY; - adding.s_addr = INADDR_ANY; - /* * If there is no recorded lease or the lease is BOOTP then * go straight to INIT and try to DISCOVER a new lease. @@ -1020,19 +929,16 @@ bind_lease(struct interface_info *ifi) * A duplicate proposal once we are responsible & S_RENEWING means we * don't need to change the interface, routing table or resolv.conf. */ - if ((ifi->flags & IFI_IS_RESPONSIBLE) && ifi->state == S_RENEWING) { + if ((ifi->flags & IFI_IN_CHARGE) && ifi->state == S_RENEWING) { active_proposal = lease_as_proposal(ifi->active); offered_proposal = lease_as_proposal(ifi->offer); if (memcmp(active_proposal, offered_proposal, sizeof(*active_proposal)) == 0) { ifi->offer->resolv_conf = ifi->active->resolv_conf; - ifi->active->resolv_conf = NULL; - ifi->active = ifi->offer; - ifi->offer = NULL; - log_info("bound to %s -- renewal in %lld seconds.", - inet_ntoa(ifi->active->address), - (long long)(ifi->active->renewal - time(NULL))); - goto newlease; + ifi->active->resolv_conf = NULL; + ifi->active = ifi->offer; + ifi->offer = NULL; + goto newlease; } } @@ -1103,6 +1009,10 @@ bind_lease(struct interface_info *ifi) } newlease: + log_info("bound to %s -- renewal in %lld seconds.", + inet_ntoa(ifi->active->address), + (long long)(ifi->active->renewal - time(NULL))); + go_daemon(); rewrite_option_db(ifi->name, ifi->active, lease); free_client_lease(lease); free(active_proposal); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index ed2da0df18f..19651864326 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.211 2017/07/10 17:13:24 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.212 2017/07/17 15:05:03 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -133,8 +133,7 @@ struct interface_info { int rdomain; int flags; #define IFI_VALID_LLADDR 0x01 -#define IFI_IS_RESPONSIBLE 0x08 -#define IFI_IN_CHARGE 0x10 +#define IFI_IN_CHARGE 0x02 struct dhcp_packet recv_packet; struct dhcp_packet sent_packet; int sent_packet_length; @@ -161,8 +160,6 @@ struct interface_info { extern struct client_config *config; extern struct imsgbuf *unpriv_ibuf; extern volatile sig_atomic_t quit; -extern struct in_addr deleting; -extern struct in_addr adding; /* options.c */ int pack_options(unsigned char *, int, struct option_data *); |