On Thu, Aug 04, 2022 at 02:19:58PM +0000, Klemens Nanni wrote:
> 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@
>
> Feedback? OK?
OK bluhm@
> diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c
> index 099f77aee24..a8eefd6c121 100644
> --- a/sys/netinet6/ip6_forward.c
> +++ b/sys/netinet6/ip6_forward.c
> @@ -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 006f6ad964a..f281376064a 100644
> --- a/sys/netinet6/ip6_mroute.c
> +++ b/sys/netinet6/ip6_mroute.c
> @@ -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 2dbfa1ab866..c0b92f059c9 100644
> --- a/sys/netinet6/nd6.c
> +++ b/sys/netinet6/nd6.c
> @@ -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;