On Tue, Aug 09, 2022 at 03:10:03PM -0600, Klemens Nanni wrote: > CVSROOT: /cvs > Module name: src > Changes by: k...@cvs.openbsd.org 2022/08/09 15:10:03 > > Modified files: > sys/netinet6 : ip6_forward.c ip6_mroute.c nd6.c > > Log message: > Backout "Call getuptime() just once per function" > > This caused stuck ndp cache entries as found by naddy, sorry.
Maybe the timeout layer can do more to help developers catch these issues in the future. This patch is strict. It would require a sizeable audit. There are many callers. Would guardrails like this have helped you? Index: kern_timeout.c =================================================================== RCS file: /cvs/src/sys/kern/kern_timeout.c,v retrieving revision 1.85 diff -u -p -r1.85 kern_timeout.c --- kern_timeout.c 19 Jun 2021 02:05:33 -0000 1.85 +++ kern_timeout.c 11 Aug 2022 18:09:24 -0000 @@ -335,6 +335,8 @@ timeout_add_tv(struct timeout *to, const { uint64_t to_ticks; + KASSERT(tv->tv_sec >= 0 && timerisvalid(tv)); + to_ticks = (uint64_t)hz * tv->tv_sec + tv->tv_usec / tick; if (to_ticks > INT_MAX) to_ticks = INT_MAX; @@ -349,6 +351,8 @@ timeout_add_sec(struct timeout *to, int { uint64_t to_ticks; + KASSERT(secs >= 0); + to_ticks = (uint64_t)hz * secs; if (to_ticks > INT_MAX) to_ticks = INT_MAX; @@ -363,6 +367,8 @@ timeout_add_msec(struct timeout *to, int { uint64_t to_ticks; + KASSERT(msecs >= 0); + to_ticks = (uint64_t)msecs * 1000 / tick; if (to_ticks > INT_MAX) to_ticks = INT_MAX; @@ -375,8 +381,11 @@ timeout_add_msec(struct timeout *to, int int timeout_add_usec(struct timeout *to, int usecs) { - int to_ticks = usecs / tick; + int to_ticks; + KASSERT(usecs >= 0); + + to_ticks = usecs / tick; if (to_ticks == 0 && usecs > 0) to_ticks = 1; @@ -386,8 +395,11 @@ timeout_add_usec(struct timeout *to, int int timeout_add_nsec(struct timeout *to, int nsecs) { - int to_ticks = nsecs / (tick * 1000); + int to_ticks; + + KASSERT(nsecs >= 0); + to_ticks = nsecs / (tick * 1000); if (to_ticks == 0 && nsecs > 0) to_ticks = 1;