From: krw Date: Wed, 28 Jun 2017 14:35:43 +0000 (+0000) Subject: Stop trying to clean up addresses, routes and "-L" file X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=93759f31f9942cbd7042cc731a568dfd68277338;p=openbsd Stop trying to clean up addresses, routes and "-L" file whenever dhclient dies. Eliminates differences in handling and thus need to intercept signals INT, TERM, USR1, USR2. Eliminates need for 'zapzombies' field and thus entire struct imsg_flushroutes. Eliminates need for 'imsg' parameter to and associated logic in priv_flush_routes(). Address, routes and '-L' file are still cleaned out when binding a lease. --- diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index f440a05515e..6c6e0f151c9 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.8,v 1.29 2017/02/15 19:36:24 krw Exp $ +.\" $OpenBSD: dhclient.8,v 1.30 2017/06/28 14:35:43 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: February 15 2017 $ +.Dd $Mdocdate: June 28 2017 $ .Dt DHCLIENT 8 .Os .Sh NAME @@ -117,9 +117,6 @@ to the specified file. will be the lease offered by the DHCP server; .Dq effective will be the modified lease bound to the interface. -.Ar file -will be truncated when a lease is no longer bound to the interface or the -link goes down. .It Fl l Ar file Specify an alternate location to .Pa /var/db/dhclient.leases. Ns Aq Ar IFNAME @@ -248,10 +245,7 @@ arrange with the network administrator for an entry on the BOOTP database, so that the host can boot quickly on that network rather than cycling through the list of old leases. .Sh SIGNALS -While running, -.Nm -reacts to a few different signals: -.Bl -tag -width "USR1, USR2XXX" +.Bl -tag -width "HUP" .It Dv HUP On receiving .Dv HUP @@ -259,33 +253,6 @@ On receiving will restart itself, reading .Xr dhclient.conf 5 and obtaining a new lease. -.It Dv INT -On receiving -.Dv INT -.Nm -will exit after attempting to remove any routes, interface addresses -or temporary files it created. -.It Dv QUIT -On receiving -.Dv QUIT -.Nm -will dump core and exit without attempting to remove any routes, interface -addresses or temporary files it created. -.It Dv TERM -On receiving -.Dv TERM -.Nm -will exit without attempting to remove any routes, interface addresses -or temporary files it created. -.It Dv USR1, USR2 -On receiving either -.Dv USR1 -or -.Dv USR2 , -.Nm -will exit after attempting to remove any routes, interface addresses -or temporary files it created. -.El .Sh FILES .Bl -tag -width "/var/db/dhclient.leases.XXX" -compact .It Pa /etc/dhclient.conf diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 6acc6c5f266..b4c1fb3d155 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.450 2017/06/28 12:53:46 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.451 2017/06/28 14:35:43 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -392,11 +392,6 @@ routehandler(struct interface_info *ifi) state_reboot(ifi); } } else { - /* Let monitoring programs see link loss. */ - if (optionDB) { - rewind(optionDB); - ftruncate(fileno(optionDB), 0); - } /* No need to wait for anything but link. */ cancel_timeout(ifi); } @@ -638,7 +633,7 @@ main(int argc, char *argv[]) close(fd); if (strlen(path_option_db) != 0) { - if ((optionDB = fopen(path_option_db, "w")) == NULL) + if ((optionDB = fopen(path_option_db, "a")) == NULL) fatal("can't open %s", path_option_db); } @@ -1919,13 +1914,7 @@ go_daemon(void) if (rdaemon(nullfd) == -1) fatal("Cannot daemonize"); - /* Catch stuff that might be trying to terminate the program. */ signal(SIGHUP, sighdlr); - signal(SIGINT, sighdlr); - signal(SIGTERM, sighdlr); - signal(SIGUSR1, sighdlr); - signal(SIGUSR2, sighdlr); - signal(SIGPIPE, SIG_IGN); } @@ -2027,7 +2016,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) struct pollfd pfd[1]; struct imsgbuf *priv_ibuf; ssize_t n; - int nfds, rslt, got_imsg_hup = 0; + int nfds, got_imsg_hup = 0; switch (fork()) { case -1: @@ -2087,21 +2076,6 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) imsg_clear(priv_ibuf); close(fd); - if (strlen(path_option_db)) { - /* Truncate the file so monitoring process see exit. */ - rslt = truncate(path_option_db, 0); - if (rslt == -1) - log_warn("Unable to truncate '%s'", path_option_db); - } - - /* - * SIGTERM is used by system at shut down. Be nice and don't cleanup - * routes, possibly preventing NFS from properly shutting down. - */ - if (quit != SIGTERM) { - priv_cleanup(ifi); - } - if (quit == SIGHUP) { if (!got_imsg_hup) log_warnx("%s; restarting.", strsignal(quit)); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 9094e345db3..2151304ab3e 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.196 2017/06/27 13:24:49 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.197 2017/06/28 14:35:43 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -165,7 +165,6 @@ extern struct imsgbuf *unpriv_ibuf; extern volatile sig_atomic_t quit; extern struct in_addr deleting; extern struct in_addr adding; -extern struct in_addr active_addr; /* options.c */ int cons_options(struct interface_info *, struct option_data *); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index e8953447eef..94474c4e4f4 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.95 2017/06/28 11:53:08 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.96 2017/06/28 14:35:43 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -70,7 +70,6 @@ flush_unpriv_ibuf(const char *who) } } -struct in_addr active_addr; struct in_addr deleting; struct in_addr adding; @@ -130,13 +129,9 @@ check_route_label(struct sockaddr_rtlabel *label) void flush_routes(void) { - struct imsg_flush_routes imsg; int rslt; - imsg.zapzombies = 1; - - rslt = imsg_compose(unpriv_ibuf, IMSG_FLUSH_ROUTES, 0, 0, -1, - &imsg, sizeof(imsg)); + rslt = imsg_compose(unpriv_ibuf, IMSG_FLUSH_ROUTES, 0, 0, -1, NULL, 0); if (rslt == -1) log_warn("flush_routes: imsg_compose"); @@ -144,7 +139,7 @@ flush_routes(void) } void -priv_flush_routes(struct interface_info *ifi, struct imsg_flush_routes *imsg) +priv_flush_routes(struct interface_info *ifi) { char ifname[IF_NAMESIZE]; struct sockaddr *rti_info[RTAX_MAX]; @@ -214,8 +209,7 @@ priv_flush_routes(struct interface_info *ifi, struct imsg_flush_routes *imsg) delete_route(ifi, s, rtm); break; case ROUTE_LABEL_DHCLIENT_DEAD: - if (imsg->zapzombies) - delete_route(ifi, s, rtm); + delete_route(ifi, s, rtm); break; case ROUTE_LABEL_DHCLIENT_LIVE: case ROUTE_LABEL_DHCLIENT_UNKNOWN: @@ -731,27 +725,6 @@ priv_add_address(struct interface_info *ifi, struct imsg_add_address *imsg) log_warn("SIOCAIFADDR failed (%s)", inet_ntoa(imsg->addr)); close(s); - - active_addr = imsg->addr; -} - -/* - * priv_cleanup removes dhclient installed routes and address. - */ -void -priv_cleanup(struct interface_info *ifi) -{ - struct imsg_flush_routes fimsg; - struct imsg_delete_address dimsg; - - fimsg.zapzombies = 0; /* Only zapzombies when binding a lease. */ - priv_flush_routes(ifi, &fimsg); - - if (active_addr.s_addr == INADDR_ANY) - return; - - dimsg.addr = active_addr; - priv_delete_address(ifi, &dimsg); } /* diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c index 446570c3f3d..3833ce5e7f7 100644 --- a/sbin/dhclient/privsep.c +++ b/sbin/dhclient/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.50 2017/06/24 23:32:57 krw Exp $ */ +/* $OpenBSD: privsep.c,v 1.51 2017/06/28 14:35:43 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -66,11 +66,10 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) break; case IMSG_FLUSH_ROUTES: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct imsg_flush_routes)) + if (imsg.hdr.len != IMSG_HEADER_SIZE) log_warnx("bad IMSG_FLUSH_ROUTES"); else - priv_flush_routes(ifi, imsg.data); + priv_flush_routes(ifi); break; case IMSG_ADD_ROUTE: diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h index 777b96d7ae4..c2319a0f84d 100644 --- a/sbin/dhclient/privsep.h +++ b/sbin/dhclient/privsep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.h,v 1.38 2017/06/24 23:32:57 krw Exp $ */ +/* $OpenBSD: privsep.h,v 1.39 2017/06/28 14:35:43 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -36,10 +36,6 @@ struct imsg_add_address { struct in_addr mask; }; -struct imsg_flush_routes { - int zapzombies; -}; - struct imsg_add_route { struct in_addr dest; struct in_addr netmask; @@ -60,7 +56,7 @@ void add_default_route(struct in_addr, struct in_addr); void add_static_routes(struct option_data *, struct in_addr); void add_classless_static_routes(struct option_data *, struct in_addr); void priv_add_route(struct interface_info *, struct imsg_add_route *); -void priv_flush_routes(struct interface_info *, struct imsg_flush_routes *); +void priv_flush_routes(struct interface_info *); char *resolv_conf_contents(struct interface_info *ifi, struct option_data *, struct option_data *, struct option_data *); @@ -73,5 +69,3 @@ void priv_add_address(struct interface_info *, struct imsg_add_address *); void priv_set_interface_mtu(struct interface_info *, struct imsg_set_interface_mtu *); - -void priv_cleanup(struct interface_info *);