git: aa3bbc06e5f0 - main - netinet6: embed struct scope6_id into struct in6_ifextra
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 23 Jan 2026 22:36:42 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=aa3bbc06e5f0856dcb9b9d15ddde1a0a030088e2
commit aa3bbc06e5f0856dcb9b9d15ddde1a0a030088e2
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2026-01-23 22:18:07 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2026-01-23 22:18:07 +0000
netinet6: embed struct scope6_id into struct in6_ifextra
Reviewed by: tuexen
Differential Revision: https://reviews.freebsd.org/D54726
---
sys/netinet6/in6.c | 2 +-
sys/netinet6/in6_ifattach.c | 1 -
sys/netinet6/in6_var.h | 10 +++++++++-
sys/netinet6/scope6.c | 19 ++++++-------------
sys/netinet6/scope6_var.h | 13 +------------
5 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index d283aba62dcc..45a7256cfc9e 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -2613,8 +2613,8 @@ in6_ifarrival(void *arg __unused, struct ifnet *ifp)
COUNTER_ARRAY_ALLOC(ext->icmp6_ifstat,
sizeof(struct icmp6_ifstat) / sizeof(uint64_t), M_WAITOK);
nd6_ifattach(ifp);
+ scope6_ifattach(ifp);
- ext->scope6_id = scope6_ifattach(ifp);
ext->lltable = in6_lltattach(ifp);
ext->mld_ifinfo = mld_domifattach(ifp);
diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c
index f21f96cd86c8..b9ce64e5b86b 100644
--- a/sys/netinet6/in6_ifattach.c
+++ b/sys/netinet6/in6_ifattach.c
@@ -917,7 +917,6 @@ in6_ifdeparture(void *arg __unused, struct ifnet *ifp)
#endif
_in6_ifdetach(ifp, 1);
mld_domifdetach(ifp);
- scope6_ifdetach(ext->scope6_id);
nd6_ifdetach(ifp);
lltable_free(ext->lltable);
COUNTER_ARRAY_FREE(ext->in6_ifstat,
diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h
index 514030ed594d..a8ae343ffaed 100644
--- a/sys/netinet6/in6_var.h
+++ b/sys/netinet6/in6_var.h
@@ -506,7 +506,15 @@ struct in6_ifextra {
u_int nd_dad_failures;
uint8_t nd_curhoplimit;
- struct scope6_id *scope6_id;
+ struct scope6_id {
+ /*
+ * 16 is correspondent to 4bit multicast scope field. i.e. from
+ * node-local to global with some reserved/unassigned types.
+ */
+#define IPV6_ADDR_SCOPES_COUNT 16
+ uint32_t s6id_list[IPV6_ADDR_SCOPES_COUNT];
+ } scope6_id;
+
struct lltable *lltable;
struct mld_ifsoftc *mld_ifinfo;
};
diff --git a/sys/netinet6/scope6.c b/sys/netinet6/scope6.c
index 6862c75fb5e7..44a9d976d5fe 100644
--- a/sys/netinet6/scope6.c
+++ b/sys/netinet6/scope6.c
@@ -73,10 +73,11 @@ static struct mtx scope6_lock;
VNET_DEFINE_STATIC(struct scope6_id, sid_default);
#define V_sid_default VNET(sid_default)
-#define SID(ifp) ((ifp)->if_inet6->scope6_id)
+#define SID(ifp) (&(ifp)->if_inet6->scope6_id)
static int scope6_get(struct ifnet *, struct scope6_id *);
static int scope6_set(struct ifnet *, struct scope6_id *);
+static int scope6_get_default(struct scope6_id *);
void
scope6_init(void)
@@ -90,26 +91,18 @@ scope6_init(void)
SCOPE6_LOCK_INIT();
}
-struct scope6_id *
+void
scope6_ifattach(struct ifnet *ifp)
{
- struct scope6_id *sid;
+ struct scope6_id *sid = &ifp->if_inet6->scope6_id;
- sid = malloc(sizeof(*sid), M_IFADDR, M_WAITOK | M_ZERO);
/*
* XXX: IPV6_ADDR_SCOPE_xxx macros are not standard.
* Should we rather hardcode here?
*/
+ bzero(sid, sizeof(*sid));
sid->s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = ifp->if_index;
sid->s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = ifp->if_index;
- return (sid);
-}
-
-void
-scope6_ifdetach(struct scope6_id *sid)
-{
-
- free(sid, M_IFADDR);
}
int
@@ -280,7 +273,7 @@ scope6_setdefault(struct ifnet *ifp)
SCOPE6_UNLOCK();
}
-int
+static int
scope6_get_default(struct scope6_id *idlist)
{
diff --git a/sys/netinet6/scope6_var.h b/sys/netinet6/scope6_var.h
index f914d5981bb0..7832444e0658 100644
--- a/sys/netinet6/scope6_var.h
+++ b/sys/netinet6/scope6_var.h
@@ -37,21 +37,10 @@
#ifdef _KERNEL
#include <net/vnet.h>
-#define IPV6_ADDR_SCOPES_COUNT 16
-struct scope6_id {
- /*
- * 16 is correspondent to 4bit multicast scope field.
- * i.e. from node-local to global with some reserved/unassigned types.
- */
- uint32_t s6id_list[IPV6_ADDR_SCOPES_COUNT];
-};
-
void scope6_init(void);
-struct scope6_id *scope6_ifattach(struct ifnet *);
-void scope6_ifdetach(struct scope6_id *);
+void scope6_ifattach(struct ifnet *);
int scope6_ioctl(u_long cmd, caddr_t data, struct ifnet *);
void scope6_setdefault(struct ifnet *);
-int scope6_get_default(struct scope6_id *);
u_int32_t scope6_addr2default(struct in6_addr *);
int sa6_embedscope(struct sockaddr_in6 *, int);
int sa6_recoverscope(struct sockaddr_in6 *);