summaryrefslogtreecommitdiff
path: root/sys/netinet6
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2016-10-03 12:33:22 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2016-10-03 12:33:22 +0000
commit2ccbc991cb3c0ab5161657b9618933487f2e78a4 (patch)
tree0a565920444959cdd6ca3b107811406e2dc5f039 /sys/netinet6
parentae60c1c6b0fa997314e9c82471a6e0ac2a7f1ea1 (diff)
Convert some of the remaining usages of time_second to time_uptime.
time_second is unix time so it can be affected by clock changes. time_uptime is monotonic so it isnt affected by clock changes. that in turn means route expiries wont jump with clock changes if set against time_uptime. the expiry is translated into unix time for export to userland though. Should fix mismatch between route timers that were already converted and ND default routers that were still using time_second. Tested by matthieu@ and sthen@ ok sthen@, dlg@
Diffstat (limited to 'sys/netinet6')
-rw-r--r--sys/netinet6/in6.c17
-rw-r--r--sys/netinet6/in6.h6
-rw-r--r--sys/netinet6/ip6_forward.c10
-rw-r--r--sys/netinet6/ip6_id.c6
-rw-r--r--sys/netinet6/ip6_mroute.c4
-rw-r--r--sys/netinet6/nd6.c18
-rw-r--r--sys/netinet6/nd6_rtr.c20
7 files changed, 46 insertions, 35 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index 74e2327dc50..941e3640dee 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6.c,v 1.192 2016/09/04 10:32:01 mpi Exp $ */
+/* $OpenBSD: in6.c,v 1.193 2016/10/03 12:33:21 mpi Exp $ */
/* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */
/*
@@ -353,7 +353,7 @@ in6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged)
case SIOCGIFALIFETIME_IN6:
ifr->ifr_ifru.ifru_lifetime = ia6->ia6_lifetime;
if (ia6->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME) {
- time_t maxexpire;
+ time_t expire, maxexpire;
struct in6_addrlifetime *retlt =
&ifr->ifr_ifru.ifru_lifetime;
@@ -365,8 +365,13 @@ in6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, int privileged)
(time_t)~(1ULL << ((sizeof(maxexpire) * 8) - 1));
if (ia6->ia6_lifetime.ia6t_vltime <
maxexpire - ia6->ia6_updatetime) {
- retlt->ia6t_expire = ia6->ia6_updatetime +
+ expire = ia6->ia6_updatetime +
ia6->ia6_lifetime.ia6t_vltime;
+ if (expire != 0) {
+ expire -= time_uptime;
+ expire += time_second;
+ }
+ retlt->ia6t_expire = expire;
} else
retlt->ia6t_expire = maxexpire;
}
@@ -604,7 +609,7 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra,
ia6->ia_ifa.ifa_addr = sin6tosa(&ia6->ia_addr);
ia6->ia_addr.sin6_family = AF_INET6;
ia6->ia_addr.sin6_len = sizeof(ia6->ia_addr);
- ia6->ia6_createtime = ia6->ia6_updatetime = time_second;
+ ia6->ia6_createtime = ia6->ia6_updatetime = time_uptime;
if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) != 0) {
/*
* XXX: some functions expect that ifa_dstaddr is not
@@ -667,12 +672,12 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra,
ia6->ia6_lifetime = ifra->ifra_lifetime;
if (ia6->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME) {
ia6->ia6_lifetime.ia6t_expire =
- time_second + ia6->ia6_lifetime.ia6t_vltime;
+ time_uptime + ia6->ia6_lifetime.ia6t_vltime;
} else
ia6->ia6_lifetime.ia6t_expire = 0;
if (ia6->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME) {
ia6->ia6_lifetime.ia6t_preferred =
- time_second + ia6->ia6_lifetime.ia6t_pltime;
+ time_uptime + ia6->ia6_lifetime.ia6t_pltime;
} else
ia6->ia6_lifetime.ia6t_preferred = 0;
diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index 8ba57fecae5..524e836c43e 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6.h,v 1.90 2016/06/27 16:33:48 jca Exp $ */
+/* $OpenBSD: in6.h,v 1.91 2016/10/03 12:33:21 mpi Exp $ */
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
/*
@@ -280,11 +280,11 @@ struct route_in6 {
#define IFA6_IS_DEPRECATED(a) \
((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
- (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
+ (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
(a)->ia6_lifetime.ia6t_pltime)
#define IFA6_IS_INVALID(a) \
((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
- (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
+ (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
(a)->ia6_lifetime.ia6t_vltime)
#endif /* _KERNEL */
diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c
index 09e7ac29dbe..9d9bfdccc97 100644
--- a/sys/netinet6/ip6_forward.c
+++ b/sys/netinet6/ip6_forward.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_forward.c,v 1.92 2016/08/24 09:41:12 mpi Exp $ */
+/* $OpenBSD: ip6_forward.c,v 1.93 2016/10/03 12:33:21 mpi Exp $ */
/* $KAME: ip6_forward.c,v 1.75 2001/06/29 12:42:13 jinmei Exp $ */
/*
@@ -104,8 +104,8 @@ ip6_forward(struct mbuf *m, struct rtentry *rt, int srcrt)
IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
ip6stat.ip6s_cantforward++;
- if (ip6_log_time + ip6_log_interval < time_second) {
- ip6_log_time = time_second;
+ if (ip6_log_time + ip6_log_interval < time_uptime) {
+ ip6_log_time = time_uptime;
inet_ntop(AF_INET6, &ip6->ip6_src, src6, sizeof(src6));
inet_ntop(AF_INET6, &ip6->ip6_dst, dst6, sizeof(dst6));
log(LOG_DEBUG,
@@ -193,8 +193,8 @@ reroute:
ip6stat.ip6s_cantforward++;
ip6stat.ip6s_badscope++;
- if (ip6_log_time + ip6_log_interval < time_second) {
- ip6_log_time = time_second;
+ if (ip6_log_time + ip6_log_interval < time_uptime) {
+ ip6_log_time = time_uptime;
inet_ntop(AF_INET6, &ip6->ip6_src, src6, sizeof(src6));
inet_ntop(AF_INET6, &ip6->ip6_dst, dst6, sizeof(dst6));
log(LOG_DEBUG,
diff --git a/sys/netinet6/ip6_id.c b/sys/netinet6/ip6_id.c
index 2eb125fa204..1b85241625c 100644
--- a/sys/netinet6/ip6_id.c
+++ b/sys/netinet6/ip6_id.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_id.c,v 1.11 2015/12/04 12:10:26 tedu Exp $ */
+/* $OpenBSD: ip6_id.c,v 1.12 2016/10/03 12:33:21 mpi Exp $ */
/* $NetBSD: ip6_id.c,v 1.7 2003/09/13 21:32:59 itojun Exp $ */
/* $KAME: ip6_id.c,v 1.8 2003/09/06 13:41:06 itojun Exp $ */
@@ -197,7 +197,7 @@ ip6id_initid(struct randomtab *p)
p->ru_g = ip6id_pmod(p->ru_gen, j, p->ru_n);
p->ru_counter = 0;
- p->ru_reseed = time_second + p->ru_out;
+ p->ru_reseed = time_uptime + p->ru_out;
p->ru_msb = p->ru_msb ? 0 : (1U << (p->ru_bits - 1));
}
@@ -206,7 +206,7 @@ ip6id_randomid(struct randomtab *p)
{
int i, n;
- if (p->ru_counter >= p->ru_max || time_second > p->ru_reseed)
+ if (p->ru_counter >= p->ru_max || time_uptime > p->ru_reseed)
ip6id_initid(p);
/* Skip a random number of ids */
diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c
index 9911d7c9f02..e988aed79f5 100644
--- a/sys/netinet6/ip6_mroute.c
+++ b/sys/netinet6/ip6_mroute.c
@@ -980,10 +980,10 @@ ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
*/
if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
ip6stat.ip6s_cantforward++;
- if (ip6_log_time + ip6_log_interval < time_second) {
+ if (ip6_log_time + ip6_log_interval < time_uptime) {
char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
- ip6_log_time = time_second;
+ ip6_log_time = time_uptime;
inet_ntop(AF_INET6, &ip6->ip6_src, src, sizeof(src));
inet_ntop(AF_INET6, &ip6->ip6_dst, dst, sizeof(dst));
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 5d95d9018b1..34c8d9c17ba 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.c,v 1.192 2016/09/15 02:00:18 dlg Exp $ */
+/* $OpenBSD: nd6.c,v 1.193 2016/10/03 12:33:21 mpi Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@@ -447,7 +447,7 @@ nd6_timer_work(void *null)
/* expire default router list */
TAILQ_FOREACH_SAFE(dr, &nd_defrouter, dr_entry, ndr)
- if (dr->expire && dr->expire < time_second)
+ if (dr->expire && dr->expire < time_uptime)
defrtrlist_del(dr);
/*
@@ -479,7 +479,7 @@ nd6_timer_work(void *null)
* prefix is not necessary.
*/
if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME &&
- time_second - pr->ndpr_lastupdate > pr->ndpr_vltime) {
+ time_uptime - pr->ndpr_lastupdate > pr->ndpr_vltime) {
/*
* address expiration and prefix expiration are
* separate. NEVER perform in6_purgeaddr here.
@@ -764,9 +764,9 @@ nd6_free(struct rtentry *rt, int gc)
* XXX: the check for ln_state would be redundant,
* but we intentionally keep it just in case.
*/
- if (dr->expire > time_second) {
+ if (dr->expire > time_uptime) {
nd6_llinfo_settimer(ln,
- dr->expire - time_second);
+ dr->expire - time_uptime);
} else
nd6_llinfo_settimer(ln, nd6_gctimer);
splx(s);
@@ -1686,6 +1686,7 @@ fill_drlist(void *oldp, size_t *oldlenp, size_t ol)
int error = 0, s;
struct in6_defrouter *d = NULL, *de = NULL;
struct nd_defrouter *dr;
+ time_t expire;
size_t l;
s = splsoftnet();
@@ -1704,7 +1705,12 @@ fill_drlist(void *oldp, size_t *oldlenp, size_t ol)
in6_recoverscope(&d->rtaddr, &dr->rtaddr);
d->flags = dr->flags;
d->rtlifetime = dr->rtlifetime;
- d->expire = dr->expire;
+ expire = dr->expire;
+ if (expire != 0) {
+ expire -= time_uptime;
+ expire += time_second;
+ }
+ d->expire = expire;
d->if_index = dr->ifp->if_index;
}
diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index e9695f601a1..c46625b7eb3 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6_rtr.c,v 1.147 2016/09/30 06:27:21 florian Exp $ */
+/* $OpenBSD: nd6_rtr.c,v 1.148 2016/10/03 12:33:21 mpi Exp $ */
/* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */
/*
@@ -428,7 +428,7 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
dr0.rtaddr = saddr6;
dr0.flags = nd_ra->nd_ra_flags_reserved;
dr0.rtlifetime = ntohs(nd_ra->nd_ra_router_lifetime);
- dr0.expire = time_second + dr0.rtlifetime;
+ dr0.expire = time_uptime + dr0.rtlifetime;
dr0.ifp = ifp;
/* unspecified or not? (RFC 2461 6.3.4) */
if (advreachable) {
@@ -518,7 +518,7 @@ nd6_ra_input(struct mbuf *m, int off, int icmp6len)
pr.ndpr_plen = pi->nd_opt_pi_prefix_len;
pr.ndpr_vltime = ntohl(pi->nd_opt_pi_valid_time);
pr.ndpr_pltime = ntohl(pi->nd_opt_pi_preferred_time);
- pr.ndpr_lastupdate = time_second;
+ pr.ndpr_lastupdate = time_uptime;
if (in6_init_prefix_ltimes(&pr))
continue; /* prefix lifetime init failed */
@@ -1350,7 +1350,7 @@ prelist_update(struct nd_prefix *new, struct nd_defrouter *dr, struct mbuf *m)
if (lt6_tmp.ia6t_vltime == ND6_INFINITE_LIFETIME)
storedlifetime = ND6_INFINITE_LIFETIME;
- else if (time_second - ia6->ia6_updatetime >
+ else if (time_uptime - ia6->ia6_updatetime >
lt6_tmp.ia6t_vltime) {
/*
* The case of "invalid" address. We should usually
@@ -1359,7 +1359,7 @@ prelist_update(struct nd_prefix *new, struct nd_defrouter *dr, struct mbuf *m)
storedlifetime = 0;
} else
storedlifetime = lt6_tmp.ia6t_vltime -
- (time_second - ia6->ia6_updatetime);
+ (time_uptime - ia6->ia6_updatetime);
if (TWOHOUR < new->ndpr_vltime ||
storedlifetime < new->ndpr_vltime) {
lt6_tmp.ia6t_vltime = new->ndpr_vltime;
@@ -1390,7 +1390,7 @@ prelist_update(struct nd_prefix *new, struct nd_defrouter *dr, struct mbuf *m)
in6_init_address_ltimes(pr, &lt6_tmp);
ia6->ia6_lifetime = lt6_tmp;
- ia6->ia6_updatetime = time_second;
+ ia6->ia6_updatetime = time_uptime;
}
if ((!autoconf || ((ifp->if_xflags & IFXF_INET6_NOPRIVACY) == 0 &&
@@ -1978,11 +1978,11 @@ in6_init_prefix_ltimes(struct nd_prefix *ndpr)
if (ndpr->ndpr_pltime == ND6_INFINITE_LIFETIME)
ndpr->ndpr_preferred = 0;
else
- ndpr->ndpr_preferred = time_second + ndpr->ndpr_pltime;
+ ndpr->ndpr_preferred = time_uptime + ndpr->ndpr_pltime;
if (ndpr->ndpr_vltime == ND6_INFINITE_LIFETIME)
ndpr->ndpr_expire = 0;
else
- ndpr->ndpr_expire = time_second + ndpr->ndpr_vltime;
+ ndpr->ndpr_expire = time_uptime + ndpr->ndpr_vltime;
return 0;
}
@@ -1996,7 +1996,7 @@ in6_init_address_ltimes(struct nd_prefix *new, struct in6_addrlifetime *lt6)
if (lt6->ia6t_vltime == ND6_INFINITE_LIFETIME)
lt6->ia6t_expire = 0;
else {
- lt6->ia6t_expire = time_second;
+ lt6->ia6t_expire = time_uptime;
lt6->ia6t_expire += lt6->ia6t_vltime;
}
@@ -2004,7 +2004,7 @@ in6_init_address_ltimes(struct nd_prefix *new, struct in6_addrlifetime *lt6)
if (lt6->ia6t_pltime == ND6_INFINITE_LIFETIME)
lt6->ia6t_preferred = 0;
else {
- lt6->ia6t_preferred = time_second;
+ lt6->ia6t_preferred = time_uptime;
lt6->ia6t_preferred += lt6->ia6t_pltime;
}
}