From 5d905914d86d52e4d16d391c5e791ac990b0476a Mon Sep 17 00:00:00 2001 From: kn Date: Mon, 8 Aug 2022 15:56:35 +0000 Subject: [PATCH] Call getuptime() just once per function IPv6 pendant to bluhm's sys/netinet/if_ether.c r1.249: Instead of calling getuptime() all the time in ARP code, do it only once per function. This gives a more consistent time value. OK claudio@ miod@ mvs@ OK bluhm --- sys/netinet6/ip6_forward.c | 17 ++++++++++++----- sys/netinet6/ip6_mroute.c | 10 +++++++--- sys/netinet6/nd6.c | 20 ++++++++++---------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index 099f77aee24..cc9a8c7ea92 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_forward.c,v 1.106 2022/02/22 01:15:02 guenther Exp $ */ +/* $OpenBSD: ip6_forward.c,v 1.107 2022/08/08 15:56:35 kn Exp $ */ /* $KAME: ip6_forward.c,v 1.75 2001/06/29 12:42:13 jinmei Exp $ */ /* @@ -102,9 +102,13 @@ ip6_forward(struct mbuf *m, struct rtentry *rt, int srcrt) if ((m->m_flags & (M_BCAST|M_MCAST)) != 0 || IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) || IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) { + time_t uptime; + ip6stat_inc(ip6s_cantforward); - if (ip6_log_time + ip6_log_interval < getuptime()) { - ip6_log_time = getuptime(); + uptime = getuptime(); + + if (ip6_log_time + ip6_log_interval < uptime) { + ip6_log_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, @@ -189,11 +193,14 @@ reroute: */ if (in6_addr2scopeid(m->m_pkthdr.ph_ifidx, &ip6->ip6_src) != in6_addr2scopeid(rt->rt_ifidx, &ip6->ip6_src)) { + time_t uptime; + ip6stat_inc(ip6s_cantforward); ip6stat_inc(ip6s_badscope); + uptime = getuptime(); - if (ip6_log_time + ip6_log_interval < getuptime()) { - ip6_log_time = getuptime(); + if (ip6_log_time + ip6_log_interval < uptime) { + ip6_log_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_mroute.c b/sys/netinet6/ip6_mroute.c index d113ecfd338..06a23125f0e 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_mroute.c,v 1.132 2022/08/06 15:57:59 bluhm Exp $ */ +/* $OpenBSD: ip6_mroute.c,v 1.133 2022/08/08 15:56:35 kn Exp $ */ /* $NetBSD: ip6_mroute.c,v 1.59 2003/12/10 09:28:38 itojun Exp $ */ /* $KAME: ip6_mroute.c,v 1.45 2001/03/25 08:38:51 itojun Exp $ */ @@ -897,11 +897,15 @@ ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m) * (although such packets must normally set 1 to the hop limit field). */ if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) { + time_t uptime; + ip6stat_inc(ip6s_cantforward); - if (ip6_log_time + ip6_log_interval < getuptime()) { + uptime = getuptime(); + + if (ip6_log_time + ip6_log_interval < uptime) { char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN]; - ip6_log_time = getuptime(); + ip6_log_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 dca4508a678..35162ce597f 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.243 2022/08/06 15:57:59 bluhm Exp $ */ +/* $OpenBSD: nd6.c,v 1.244 2022/08/08 15:56:35 kn Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -319,14 +319,16 @@ void nd6_timer(void *unused) { struct llinfo_nd6 *ln, *nln; - time_t expire = getuptime() + nd6_gctimer; - int secs; + time_t uptime, expire; + + uptime = getuptime(); + expire = uptime + nd6_gctimer; NET_LOCK(); TAILQ_FOREACH_SAFE(ln, &nd6_list, ln_list, nln) { struct rtentry *rt = ln->ln_rt; - if (rt->rt_expire && rt->rt_expire <= getuptime()) + if (rt->rt_expire && rt->rt_expire <= uptime) if (nd6_llinfo_timer(rt)) continue; @@ -334,12 +336,9 @@ nd6_timer(void *unused) expire = rt->rt_expire; } - secs = expire - getuptime(); - if (secs < 0) - secs = 0; if (!TAILQ_EMPTY(&nd6_list)) { - nd6_timer_next = getuptime() + secs; - timeout_add_sec(&nd6_timer_to, secs); + nd6_timer_next = expire; + timeout_add_sec(&nd6_timer_to, nd6_gctimer); } NET_UNLOCK(); @@ -444,7 +443,6 @@ void nd6_expire_timer_update(struct in6_ifaddr *ia6) { time_t expire_time = INT64_MAX; - int secs; KERNEL_ASSERT_LOCKED(); @@ -469,6 +467,8 @@ nd6_expire_timer_update(struct in6_ifaddr *ia6) if (!timeout_pending(&nd6_expire_timeout) || nd6_expire_next > expire_time) { + int secs; + secs = expire_time - getuptime(); if (secs < 0) secs = 0; -- 2.20.1