Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Apr 2014 19:05:42 +0300
From:      Guy Yur <guyyur@gmail.com>
To:        freebsd-net@freebsd.org
Subject:   [patch] ifconfig -L shows inet6 addresses pltime and vltime as zero since 10.0-RELEASE
Message-ID:  <CAC67Hz_AxvO2wJc=xmmqPgcF=F9R3uewN3iCi-eeuheO=aoTzg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi,

"ifconfig -L" shows inet6 addresses pltime and vltime as zero since
10.0-RELEASE.

Seems that ifconfig was missed in r253970 which
changed usage from time_second to time_uptime.

I filed bin/188520 with a patch to use clock_gettime(CLOCK_MONOTONIC_FAST)
in ifconfig per r253970 comment.

http://www.freebsd.org/cgi/query-pr.cgi?pr=188520


ifconfig -L
...
        inet6 XXXX:XXXX:XXXX:XXXX:YYYY:YYYY:YYYY:YYYY
          prefixlen 64 autoconf temporary pltime 0 vltime 0


The prefix is learned via router advertisment.
tcpdump shows non zero values in the icmp6 packet.

A test program that calls SIOCGIFALIFETIME_IN6
shows the value is < wall clock which is
the test done by ifconfig.
time = 1397314436
ia6t_preferred = 608907
ia6t_expire = 2596107


Thanks,
Guy

[-- Attachment #2 --]
Index: sbin/ifconfig/af_inet6.c
===================================================================
--- sbin/ifconfig/af_inet6.c	(revision 264366)
+++ sbin/ifconfig/af_inet6.c	(working copy)
@@ -42,6 +42,7 @@ static const char rcsid[] =
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <time.h>
 #include <ifaddrs.h>
 
 #include <arpa/inet.h>
@@ -98,10 +99,11 @@ static void
 setip6lifetime(const char *cmd, const char *val, int s, 
     const struct afswtch *afp)
 {
-	time_t newval, t;
+	struct timespec now;
+	time_t newval;
 	char *ep;
 
-	t = time(NULL);
+	clock_gettime(CLOCK_MONOTONIC_FAST, &now);
 	newval = (time_t)strtoul(val, &ep, 0);
 	if (val == ep)
 		errx(1, "invalid %s", cmd);
@@ -108,10 +110,10 @@ setip6lifetime(const char *cmd, const char *val, i
 	if (afp->af_af != AF_INET6)
 		errx(1, "%s not allowed for the AF", cmd);
 	if (strcmp(cmd, "vltime") == 0) {
-		in6_addreq.ifra_lifetime.ia6t_expire = t + newval;
+		in6_addreq.ifra_lifetime.ia6t_expire = now.tv_sec + newval;
 		in6_addreq.ifra_lifetime.ia6t_vltime = newval;
 	} else if (strcmp(cmd, "pltime") == 0) {
-		in6_addreq.ifra_lifetime.ia6t_preferred = t + newval;
+		in6_addreq.ifra_lifetime.ia6t_preferred = now.tv_sec + newval;
 		in6_addreq.ifra_lifetime.ia6t_pltime = newval;
 	}
 }
@@ -172,9 +174,11 @@ in6_status(int s __unused, const struct ifaddrs *i
 	int s6;
 	u_int32_t flags6;
 	struct in6_addrlifetime lifetime;
-	time_t t = time(NULL);
+	struct timespec now;
 	int error;
 
+	clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+
 	memset(&null_sin, 0, sizeof(null_sin));
 
 	sin = (struct sockaddr_in6 *)ifa->ifa_addr;
@@ -258,15 +262,15 @@ in6_status(int s __unused, const struct ifaddrs *i
 	if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
 		printf("pltime ");
 		if (lifetime.ia6t_preferred) {
-			printf("%s ", lifetime.ia6t_preferred < t
-				? "0" : sec2str(lifetime.ia6t_preferred - t));
+			printf("%s ", lifetime.ia6t_preferred < now.tv_sec
+				? "0" : sec2str(lifetime.ia6t_preferred - now.tv_sec));
 		} else
 			printf("infty ");
 
 		printf("vltime ");
 		if (lifetime.ia6t_expire) {
-			printf("%s ", lifetime.ia6t_expire < t
-				? "0" : sec2str(lifetime.ia6t_expire - t));
+			printf("%s ", lifetime.ia6t_expire < now.tv_sec
+				? "0" : sec2str(lifetime.ia6t_expire - now.tv_sec));
 		} else
 			printf("infty ");
 	}

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAC67Hz_AxvO2wJc=xmmqPgcF=F9R3uewN3iCi-eeuheO=aoTzg>