From: Roy Marples Date: Wed, 26 Apr 2017 08:57:16 +0000 (+0100) Subject: IPv6: show actual address lifetimes being applied X-Git-Tag: v7.0.0-rc1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=644335978a4064eb586084b557c2436b608eadc4;p=thirdparty%2Fdhcpcd.git IPv6: show actual address lifetimes being applied Summary: For IPv6, the acquisition time of the address is stored. When adding the address during a refresh, the valid and preferred times are decreased by the difference between the acquisition time and the current time. This is not shown in the logs, but it should be otherwise you could be confused by a prefix adding an address, but it really came from a stale lease. While here, if vltime overflows then log an error and zero it. This effectively removes the address when it's added. Related to T114. Test Plan: Configure your DHCPv6 server to lease a Prefix from Pool A. Configure dhcpcd to request a Prefix Delegation and assign to a downstream interface. Start dhcpcd. Configure your DHCPv6 server to lease a Prefix from Pool B. Observe dhcpcd debug logs - it should note that addresses previously assigned from group A have decreasing valid times. Reviewers: Harri Reviewed By: Harri Differential Revision: https://dev.marples.name/D110 --- diff --git a/src/ipv6.c b/src/ipv6.c index 1ac191ef..b4214883 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -642,29 +642,6 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now) ipv6_iffindaddr(ap->iface, &ap->addr, IN6_IFF_NOTUSEABLE)) ap->flags |= IPV6_AF_DADCOMPLETED; - logfunc = ap->flags & IPV6_AF_NEW ? loginfox : logdebugx; - logfunc("%s: adding %saddress %s", ap->iface->name, -#ifdef IPV6_AF_TEMPORARY - ap->flags & IPV6_AF_TEMPORARY ? "temporary " : "", -#else - "", -#endif - ap->saddr); - if (ap->prefix_pltime == ND6_INFINITE_LIFETIME && - ap->prefix_vltime == ND6_INFINITE_LIFETIME) - logdebugx("%s: pltime infinity, vltime infinity", - ap->iface->name); - else if (ap->prefix_pltime == ND6_INFINITE_LIFETIME) - logdebugx("%s: pltime infinity, vltime %"PRIu32" seconds", - ap->iface->name, ap->prefix_vltime); - else if (ap->prefix_vltime == ND6_INFINITE_LIFETIME) - logdebugx("%s: pltime %"PRIu32"seconds, vltime infinity", - ap->iface->name, ap->prefix_pltime); - else - logdebugx("%s: pltime %"PRIu32" seconds, vltime %"PRIu32 - " seconds", - ap->iface->name, ap->prefix_pltime, ap->prefix_vltime); - /* Adjust plftime and vltime based on acquired time */ pltime = ap->prefix_pltime; vltime = ap->prefix_vltime; @@ -686,20 +663,40 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now) if (ap->prefix_pltime > pltime) ap->prefix_pltime = 0; } - if (ap->prefix_vltime != ND6_INFINITE_LIFETIME) + if (ap->prefix_vltime != ND6_INFINITE_LIFETIME) { ap->prefix_vltime -= (uint32_t)n.tv_sec; + /* This should never happen. */ + if (ap->prefix_vltime > vltime) { + logerrx("%s: %s: lifetime overflow", + ifp->name, ap->saddr); + ap->prefix_vltime = ap->prefix_pltime = 0; + } + } + } -#if 0 - logdebugx("%s: acquired %lld.%.9ld, now %lld.%.9ld, diff %lld.%.9ld", - ap->iface->name, - (long long)ap->acquired.tv_sec, ap->acquired.tv_nsec, - (long long)now->tv_sec, now->tv_nsec, - (long long)n.tv_sec, n.tv_nsec); - logdebugx("%s: adj pltime %"PRIu32" seconds, " - "vltime %"PRIu32" seconds", - ap->iface->name, ap->prefix_pltime, ap->prefix_vltime); + logfunc = ap->flags & IPV6_AF_NEW ? loginfox : logdebugx; + logfunc("%s: adding %saddress %s", ap->iface->name, +#ifdef IPV6_AF_TEMPORARY + ap->flags & IPV6_AF_TEMPORARY ? "temporary " : "", +#else + "", #endif - } + ap->saddr); + if (ap->prefix_pltime == ND6_INFINITE_LIFETIME && + ap->prefix_vltime == ND6_INFINITE_LIFETIME) + logdebugx("%s: pltime infinity, vltime infinity", + ap->iface->name); + else if (ap->prefix_pltime == ND6_INFINITE_LIFETIME) + logdebugx("%s: pltime infinity, vltime %"PRIu32" seconds", + ap->iface->name, ap->prefix_vltime); + else if (ap->prefix_vltime == ND6_INFINITE_LIFETIME) + logdebugx("%s: pltime %"PRIu32"seconds, vltime infinity", + ap->iface->name, ap->prefix_pltime); + else + logdebugx("%s: pltime %"PRIu32" seconds, vltime %"PRIu32 + " seconds", + ap->iface->name, ap->prefix_pltime, ap->prefix_vltime); + if (if_address6(RTM_NEWADDR, ap) == -1) { logerr(__func__);