From: Roy Marples Date: Sun, 25 Aug 2013 10:22:48 +0000 (+0000) Subject: Fix the persistent option. X-Git-Tag: v6.1.0~36 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=15fc1181d54a92fd48427c77fb3615a39774511a;p=thirdparty%2Fdhcpcd.git Fix the persistent option. --- diff --git a/dhcp6.c b/dhcp6.c index 9f4a14ae..54978446 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -2421,7 +2421,9 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) * this. */ if (ifp->options && - ifp->options->options & (DHCPCD_STOPPING | DHCPCD_RELEASE)) + ifp->options->options & (DHCPCD_STOPPING | DHCPCD_RELEASE) && + (ifp->options->options & (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) dhcp6_delete_delegates(ifp); state = D6_STATE(ifp); @@ -2432,7 +2434,11 @@ dhcp6_freedrop(struct interface *ifp, int drop, const char *reason) unlink(state->leasefile); } dhcp6_freedrop_addrs(ifp, drop, NULL); - if (drop && state->new) { + if (drop && state->new && + (ifp->options->options & + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) + { if (reason == NULL) reason = "STOP6"; script_runreason(ifp, reason); diff --git a/dhcpcd.c b/dhcpcd.c index 3a8102ac..d410c4a0 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -747,6 +747,7 @@ handle_signal(int sig, siginfo_t *siginfo, __unused void *context) break; if (do_release) ifp->options->options |= DHCPCD_RELEASE; + ifp->options->options |= DHCPCD_EXITING; stop_interface(ifp); } exit(EXIT_FAILURE); @@ -884,6 +885,7 @@ handle_args(struct fd_list *fd, int argc, char **argv) continue; if (do_release) ifp->options->options |= DHCPCD_RELEASE; + ifp->options->options |= DHCPCD_EXITING; stop_interface(ifp); } return 0; diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 24e833cf..bdbd65bf 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 25, 2013 +.Dd August 25, 2013 .Dt DHCPCD.CONF 5 SMM .Os .Sh NAME @@ -134,6 +134,12 @@ is generated, otherwise DUID-LL is generated (link local address). The DUID-LLT generated will be held in .Pa @SYSCONFDIR@/dhcpcd.duid and should not be copied to other hosts. +.It Ic persistent +.Nm dhcpcd +normally de-configures the interface and configuration when it exits. +Sometimes, this isn't desirable if, for example, you have root mounted over +NFS. +You can use this option to stop this from happening. .It Ic fallback Ar profile Fallback to using this profile if DHCP fails. This allows you to configure a static profile instead of using ZeroConf. diff --git a/if-options.h b/if-options.h index a00dd769..9eb768ca 100644 --- a/if-options.h +++ b/if-options.h @@ -95,6 +95,7 @@ #define DHCPCD_STOPPING (1ULL << 41) #define DHCPCD_DEPARTED (1ULL << 42) #define DHCPCD_HOSTNAME_SHORT (1ULL << 43) +#define DHCPCD_EXITING (1ULL << 44) extern const struct option cf_options[]; diff --git a/ipv4.c b/ipv4.c index 845f3860..4d497fb2 100644 --- a/ipv4.c +++ b/ipv4.c @@ -608,7 +608,9 @@ ipv4_applyaddr(void *arg) lease = &state->lease; if (dhcp == NULL) { - if (!(ifo->options & DHCPCD_PERSISTENT)) { + if ((ifo->options & (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) + { ipv4_buildroutes(); if (state->addr.s_addr != 0) delete_address(ifp); diff --git a/ipv6.c b/ipv6.c index 84e3e156..19da0ab3 100644 --- a/ipv6.c +++ b/ipv6.c @@ -457,7 +457,10 @@ ipv6_freedrop_addrs(struct ipv6_addrhead *addrs, int drop, * This is safe because the RA is removed from the list * before we are called. */ if (drop && ap->flags & IPV6_AF_ADDED && - !ipv6nd_addrexists(ap) && !dhcp6_addrexists(ap)) + !ipv6nd_addrexists(ap) && !dhcp6_addrexists(ap) && + (ap->iface->options->options & + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) { syslog(LOG_INFO, "%s: deleting address %s", ap->iface->name, ap->saddr); @@ -1026,7 +1029,9 @@ ipv6_buildroutes(void) /* no need to add it back to our routing table * as we delete an exiting route when we add * a new one */ - else + else if ((rt->iface->options->options & + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) d_route(rt); } free(rt); diff --git a/ipv6nd.c b/ipv6nd.c index 38486b12..8f372b0d 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -1268,7 +1268,10 @@ ipv6nd_drop(struct interface *ifp) ipv6nd_drop_ra(rap); } ipv6_buildroutes(); - script_runreason(ifp, "ROUTERADVERT"); + if ((ifp->options->options & + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != + (DHCPCD_EXITING | DHCPCD_PERSISTENT)) + script_runreason(ifp, "ROUTERADVERT"); } } static void