]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
IPv6: show actual address lifetimes being applied
authorRoy Marples <roy@marples.name>
Wed, 26 Apr 2017 08:57:16 +0000 (09:57 +0100)
committerRoy Marples <roy@marples.name>
Fri, 5 May 2017 13:26:12 +0000 (14:26 +0100)
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

src/ipv6.c

index 1ac191ef92fbd7f33083ffb52bab9372185c1768..b4214883e5d00f26996110cca78870bb4de3b244 100644 (file)
@@ -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__);