From 43abdd5301c1b1c40fa9d082267a2c2fd7a6f9fa Mon Sep 17 00:00:00 2001 From: kn Date: Mon, 28 Nov 2022 19:13:36 +0000 Subject: [PATCH] Document struct nd_ifinfo protection, remove obsolete .initialized member All access to struct ifnet's member *if_nd is read-only, with the one write exception being nd6_slowtimo() updating ND information. IPv6 Neighbour Discovery information is fully protected by the net lock. --- nd6_ifattach() allocates and unconditionally initialises struct ifnet's *if_nd member, so early in if_attachsetup() that there is no way to query unitialised Neighour Unreachable Detection bits. Only SIOCGIFINFO_IN6 through ndp(8) used the .initialized member: Added/set since 2002 sys/netinet6/nd6.c r1.42 attach nd_ifinfo structure to if_afdata. split IPv6 MTU (advertised by RA) from real link MTU. sync with kame Read since 2002 usr.sbin/ndp/ndp.c r1.16 use new SIOCGIFINFO_IN6. random other cleanups. sync w/kame. Obsolete since 2017 sys/netinet6/nd6.c r1.217 usr.sbin/ndp/ndp.c r1.85 Remove knob and always do neighbor unreachable detection. Feedback OK bluhm --- sys/netinet6/nd6.c | 4 +--- sys/netinet6/nd6.h | 17 +++++++++++------ usr.sbin/ndp/ndp.c | 5 +---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 18b590aa738..8cedafd1d35 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.255 2022/11/28 13:10:58 kn Exp $ */ +/* $OpenBSD: nd6.c,v 1.256 2022/11/28 19:13:36 kn Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -124,8 +124,6 @@ nd6_ifattach(struct ifnet *ifp) nd = malloc(sizeof(*nd), M_IP6NDP, M_WAITOK | M_ZERO); - nd->initialized = 1; - nd->basereachable = REACHABLE_TIME; nd->reachable = ND_COMPUTE_RTIME(nd->basereachable); nd->retrans = RETRANS_TIMER; diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index d4568b9b979..6f29de0fe72 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.h,v 1.89 2022/11/23 19:35:42 kn Exp $ */ +/* $OpenBSD: nd6.h,v 1.90 2022/11/28 19:13:36 kn Exp $ */ /* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ /* @@ -43,12 +43,17 @@ #define ND6_LLINFO_DELAY 3 #define ND6_LLINFO_PROBE 4 +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * N net lock + */ + struct nd_ifinfo { - u_int32_t basereachable; /* BaseReachableTime */ - u_int32_t reachable; /* Reachable Time */ - u_int32_t retrans; /* Retrans Timer */ - int recalctm; /* BaseReacable re-calculation timer */ - u_int8_t initialized; /* Flag to see the entry is initialized */ + u_int32_t basereachable; /* [I] BaseReachableTime */ + u_int32_t reachable; /* [N] Reachable Time */ + u_int32_t retrans; /* [I] Retrans Timer */ + int recalctm; /* [N] BaseReachable recalc timer */ }; struct in6_nbrinfo { diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c index 8b3cfeeb300..80cca743bc4 100644 --- a/usr.sbin/ndp/ndp.c +++ b/usr.sbin/ndp/ndp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ndp.c,v 1.104 2022/11/09 18:00:02 kn Exp $ */ +/* $OpenBSD: ndp.c,v 1.105 2022/11/28 19:13:36 kn Exp $ */ /* $KAME: ndp.c,v 1.101 2002/07/17 08:46:33 itojun Exp $ */ /* @@ -888,9 +888,6 @@ ifinfo(const char *ifname) if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) == -1) err(1, "ioctl(SIOCGIFINFO_IN6)"); - if (!nd.ndi.initialized) - errx(1, "%s: not initialized yet", ifname); - printf("basereachable=%ds%dms", nd.ndi.basereachable / 1000, nd.ndi.basereachable % 1000); printf(", reachable=%ds", nd.ndi.reachable); -- 2.20.1