From: kn Date: Wed, 23 Nov 2022 08:05:49 +0000 (+0000) Subject: ND_IFINFO() cannot be NULL, use inline read-only idiom for clarity X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2c55d1bcfafde237f1d522a85140e2f07ef0c111;p=openbsd ND_IFINFO() cannot be NULL, use inline read-only idiom for clarity ND_IFINFO() always points at a valid struct nd_ifinfo; ND6_LLINFO_DELAY checks for NULL, while other cases in nd6_llinfo_timer() dereference it unconditionally. Inline all three per-case read-only usages rather than having one hoisted *ndi pointer which could be used to write. nd6_nbr.c already uses this `ND_IFINFO(ifp)->retrans' idiom which makes it immediately clear that data is only read. OK bluhm --- diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 92034b6e8e7..97c3536be9d 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.250 2022/11/10 16:00:17 kn Exp $ */ +/* $OpenBSD: nd6.c,v 1.251 2022/11/23 08:05:49 kn Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -356,20 +356,17 @@ nd6_llinfo_timer(struct rtentry *rt) struct llinfo_nd6 *ln = (struct llinfo_nd6 *)rt->rt_llinfo; struct sockaddr_in6 *dst = satosin6(rt_key(rt)); struct ifnet *ifp; - struct nd_ifinfo *ndi = NULL; NET_ASSERT_LOCKED(); if ((ifp = if_get(rt->rt_ifidx)) == NULL) return 1; - ndi = ND_IFINFO(ifp); - switch (ln->ln_state) { case ND6_LLINFO_INCOMPLETE: if (ln->ln_asked < nd6_mmaxtries) { ln->ln_asked++; - nd6_llinfo_settimer(ln, ndi->retrans / 1000); + nd6_llinfo_settimer(ln, ND_IFINFO(ifp)->retrans / 1000); nd6_ns_output(ifp, NULL, &dst->sin6_addr, ln, 0); } else { struct mbuf *m = ln->ln_hold; @@ -413,19 +410,16 @@ nd6_llinfo_timer(struct rtentry *rt) break; case ND6_LLINFO_DELAY: - if (ndi) { - /* We need NUD */ - ln->ln_asked = 1; - ln->ln_state = ND6_LLINFO_PROBE; - nd6_llinfo_settimer(ln, ndi->retrans / 1000); - nd6_ns_output(ifp, &dst->sin6_addr, - &dst->sin6_addr, ln, 0); - } + /* We need NUD */ + ln->ln_asked = 1; + ln->ln_state = ND6_LLINFO_PROBE; + nd6_llinfo_settimer(ln, ND_IFINFO(ifp)->retrans / 1000); + nd6_ns_output(ifp, &dst->sin6_addr, &dst->sin6_addr, ln, 0); break; case ND6_LLINFO_PROBE: if (ln->ln_asked < nd6_umaxtries) { ln->ln_asked++; - nd6_llinfo_settimer(ln, ndi->retrans / 1000); + nd6_llinfo_settimer(ln, ND_IFINFO(ifp)->retrans / 1000); nd6_ns_output(ifp, &dst->sin6_addr, &dst->sin6_addr, ln, 0); } else {