From ac40cb1679d5bdab31c9a4eb014fe9a6985092db Mon Sep 17 00:00:00 2001 From: kn Date: Wed, 23 Nov 2022 14:48:27 +0000 Subject: [PATCH] Add *if_nd to struct ifnet, call nd6_if{at,de}tach() directly *if_afdata[] and struct domain's dom_if{at,de}tach() are only used with IPv6 Neighbour Discovery in6_dom{at,de}tach(), which allocate/init and free single struct nd_ifinfo. Set up a new ND-specific *if_nd member directly to avoid yet another layer of indirection and thus make the generic domain API obsolete. The per-interface data is only accessed in nd6.c and nd6_nbr.c through the ND_IFINFO() macro; it is allocated and freed exactly once during interface at/detach, so document it as [I]mmutable. OK bluhm mvs claudio --- sys/net/if.c | 9 ++++++++- sys/net/if_var.h | 3 ++- sys/netinet6/in6.c | 14 +------------- sys/netinet6/in6_proto.c | 4 +--- sys/netinet6/nd6.h | 4 ++-- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index f3fba33de3f..36ac89ceb46 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.680 2022/11/14 22:45:02 kn Exp $ */ +/* $OpenBSD: if.c,v 1.681 2022/11/23 14:48:27 kn Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -461,6 +461,10 @@ if_attachsetup(struct ifnet *ifp) if_addgroup(ifp, IFG_ALL); if_attachdomain(ifp); +#ifdef INET6 + ifp->if_nd = nd6_ifattach(ifp); +#endif + #if NPF > 0 pfi_attach_ifnet(ifp); #endif @@ -1127,6 +1131,9 @@ if_detach(struct ifnet *ifp) (*dp->dom_ifdetach)(ifp, ifp->if_afdata[dp->dom_family]); } +#ifdef INET6 + nd6_ifdetach(ifp->if_nd); +#endif /* Announce that the interface is gone. */ rtm_ifannounce(ifp, IFAN_DEPARTURE); diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 3a418bf0547..eeb2aa8ba4a 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.120 2022/11/14 22:06:26 kn Exp $ */ +/* $OpenBSD: if_var.h,v 1.121 2022/11/23 14:48:27 kn Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -187,6 +187,7 @@ struct ifnet { /* and the entries */ struct sockaddr_dl *if_sadl; /* [N] pointer to our sockaddr_dl */ void *if_afdata[AF_MAX]; + struct nd_ifinfo *if_nd; /* [I] IPv6 Neighour Discovery info */ }; #define if_mtu if_data.ifi_mtu #define if_type if_data.ifi_type diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 0c45b3048bc..44dfa3488ef 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.255 2022/11/23 07:57:39 kn Exp $ */ +/* $OpenBSD: in6.c,v 1.256 2022/11/23 14:48:28 kn Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -1597,15 +1597,3 @@ in6if_do_dad(struct ifnet *ifp) return (1); } } - -void * -in6_domifattach(struct ifnet *ifp) -{ - return nd6_ifattach(ifp); -} - -void -in6_domifdetach(struct ifnet *ifp, void *aux) -{ - nd6_ifdetach(aux); -} diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 808422f6eab..4e48a1e45b5 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_proto.c,v 1.111 2022/09/02 13:12:32 mvs Exp $ */ +/* $OpenBSD: in6_proto.c,v 1.112 2022/11/23 14:48:28 kn Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -338,8 +338,6 @@ const struct domain inet6domain = { .dom_sasize = sizeof(struct sockaddr_in6), .dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr), .dom_maxplen = 128, - .dom_ifattach = in6_domifattach, - .dom_ifdetach = in6_domifdetach }; /* diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index e43e9b721f1..39c2fb384c0 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.h,v 1.83 2022/11/23 07:57:39 kn Exp $ */ +/* $OpenBSD: nd6.h,v 1.84 2022/11/23 14:48:28 kn Exp $ */ /* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ /* @@ -94,7 +94,7 @@ struct in6_ndifreq { #include #define ND_IFINFO(ifp) \ - ((struct nd_ifinfo *)(ifp)->if_afdata[AF_INET6]) + ((ifp)->if_nd) struct llinfo_nd6 { TAILQ_ENTRY(llinfo_nd6) ln_list; -- 2.20.1