On Wed, Nov 23, 2022 at 11:40:15AM +0100, Claudio Jeker wrote:
> While I agree, I think bad code should not be copied. It makes the code
> not more complex makes the diff shorter and is quite obvious.
> Lets do this right.
New *if_nd diff without spl dance below.
> I don't mind them to be two commits but please share both of them at the
> same time. Because they should hit the tree at the same time. Changing
> header files like net/if_var.h comes at a cost so don't let people suffer
> twice for little reason.
Will follow in next mail.
---
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.
Next up as separate commits:
- remove *if_afdata[] struct domain's dom_if{at,de}tach()
- nd6_if{at,de}tach() return/argument type cleanup
- inline ND_IFINFO()
Feedback? Objection? OK?
diff --git a/sys/net/if.c b/sys/net/if.c
index f3fba33de3f..a540f564887 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -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..3bf07ed3071 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -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 d45944116f6..913ff3e72e0 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1606,15 +1606,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..e302f39cddf 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -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 f108927f9e1..9adb0c700f6 100644
--- a/sys/netinet6/nd6.h
+++ b/sys/netinet6/nd6.h
@@ -77,7 +77,7 @@ struct in6_ndireq {
#include <sys/queue.h>
#define ND_IFINFO(ifp) \
- ((struct nd_ifinfo *)(ifp)->if_afdata[AF_INET6])
+ ((ifp)->if_nd)
struct llinfo_nd6 {
TAILQ_ENTRY(llinfo_nd6) ln_list;