Backout "Call getuptime() just once per function"
authorkn <kn@openbsd.org>
Tue, 9 Aug 2022 21:10:02 +0000 (21:10 +0000)
committerkn <kn@openbsd.org>
Tue, 9 Aug 2022 21:10:02 +0000 (21:10 +0000)
This caused stuck ndp cache entries as found by naddy, sorry.

sys/netinet6/ip6_forward.c
sys/netinet6/ip6_mroute.c
sys/netinet6/nd6.c

index cc9a8c7..7dd2934 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ip6_forward.c,v 1.107 2022/08/08 15:56:35 kn Exp $    */
+/*     $OpenBSD: ip6_forward.c,v 1.108 2022/08/09 21:10:02 kn Exp $    */
 /*     $KAME: ip6_forward.c,v 1.75 2001/06/29 12:42:13 jinmei Exp $    */
 
 /*
@@ -102,13 +102,9 @@ 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);
-               uptime = getuptime();
-
-               if (ip6_log_time + ip6_log_interval < uptime) {
-                       ip6_log_time = uptime;
+               if (ip6_log_time + ip6_log_interval < getuptime()) {
+                       ip6_log_time = getuptime();
                        inet_ntop(AF_INET6, &ip6->ip6_src, src6, sizeof(src6));
                        inet_ntop(AF_INET6, &ip6->ip6_dst, dst6, sizeof(dst6));
                        log(LOG_DEBUG,
@@ -193,14 +189,11 @@ 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 < uptime) {
-                       ip6_log_time = uptime;
+               if (ip6_log_time + ip6_log_interval < getuptime()) {
+                       ip6_log_time = getuptime();
                        inet_ntop(AF_INET6, &ip6->ip6_src, src6, sizeof(src6));
                        inet_ntop(AF_INET6, &ip6->ip6_dst, dst6, sizeof(dst6));
                        log(LOG_DEBUG,
index 06a2312..161eba6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ip6_mroute.c,v 1.133 2022/08/08 15:56:35 kn Exp $     */
+/*     $OpenBSD: ip6_mroute.c,v 1.134 2022/08/09 21:10:03 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,15 +897,11 @@ 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);
-               uptime = getuptime();
-
-               if (ip6_log_time + ip6_log_interval < uptime) {
+               if (ip6_log_time + ip6_log_interval < getuptime()) {
                        char src[INET6_ADDRSTRLEN], dst[INET6_ADDRSTRLEN];
 
-                       ip6_log_time = uptime;
+                       ip6_log_time = getuptime();
 
                        inet_ntop(AF_INET6, &ip6->ip6_src, src, sizeof(src));
                        inet_ntop(AF_INET6, &ip6->ip6_dst, dst, sizeof(dst));
index c06ee29..f91ea1b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: nd6.c,v 1.245 2022/08/08 17:47:59 kn Exp $    */
+/*     $OpenBSD: nd6.c,v 1.246 2022/08/09 21:10:03 kn Exp $    */
 /*     $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $   */
 
 /*
@@ -319,16 +319,14 @@ void
 nd6_timer(void *unused)
 {
        struct llinfo_nd6 *ln, *nln;
-       time_t uptime, expire;
-
-       uptime = getuptime();
-       expire = uptime + nd6_gctimer;
+       time_t expire = getuptime() + nd6_gctimer;
+       int secs;
 
        NET_LOCK();
        TAILQ_FOREACH_SAFE(ln, &nd6_list, ln_list, nln) {
                struct rtentry *rt = ln->ln_rt;
 
-               if (rt->rt_expire && rt->rt_expire <= uptime)
+               if (rt->rt_expire && rt->rt_expire <= getuptime())
                        if (nd6_llinfo_timer(rt))
                                continue;
 
@@ -336,9 +334,12 @@ nd6_timer(void *unused)
                        expire = rt->rt_expire;
        }
 
+       secs = expire - getuptime();
+       if (secs < 0)
+               secs = 0;
        if (!TAILQ_EMPTY(&nd6_list)) {
-               nd6_timer_next = expire;
-               timeout_add_sec(&nd6_timer_to, nd6_gctimer);
+               nd6_timer_next = getuptime() + secs;
+               timeout_add_sec(&nd6_timer_to, secs);
        }
 
        NET_UNLOCK();
@@ -443,6 +444,7 @@ void
 nd6_expire_timer_update(struct in6_ifaddr *ia6)
 {
        time_t expire_time = INT64_MAX;
+       int secs;
 
        KERNEL_ASSERT_LOCKED();
 
@@ -467,8 +469,6 @@ 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;