Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Jul 2026 18:35:24 +0000
From:      Bruce M Simpson <bms@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: f884e820d87f - main - netinet6: Tear down IPv6 source address selection policies with rest of IPv6.
Message-ID:  <6a68f66c.3e90a.387b51d1@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by bms:

URL: https://cgit.FreeBSD.org/src/commit/?id=f884e820d87fe31962f3e0ce7fe6125cfda82eaa

commit f884e820d87fe31962f3e0ce7fe6125cfda82eaa
Author:     Bruce M Simpson <bms@FreeBSD.org>
AuthorDate: 2026-02-28 20:24:49 +0000
Commit:     Bruce M Simpson <bms@FreeBSD.org>
CommitDate: 2026-07-28 18:35:02 +0000

    netinet6: Tear down IPv6 source address selection policies with rest of IPv6.
    
    This may plug minor leaks which no-one has reported. The default IPv6 source
    address selection policy list in FreeBSD is usually limited to 9 entries,
    and can be readily inspected with ip6addrctl(8). The policy table is
    however instantiated for each VNET.
    
    The leak of a pol instance in delete_addrsel_policyent() was already
    plugged by @ae in commit-id ecc5c73, so that change has not been merged.
    
    Do not tear down the sxlocks as glebius has requested, and move the
    addrsel_policyent{} declarations further up to avoid redundant forward
    declarations as glebius requested for stylistic reasons.
    
    Reviewed by:    ae, pouria
    Sponsored by:   Cisco Systems, Inc.
    Differential Revision: https://reviews.freebsd.org/D55599
---
 sys/netinet6/in6.h       |  1 +
 sys/netinet6/in6_src.c   | 44 ++++++++++++++++++++++++++++----------------
 sys/netinet6/ip6_input.c |  1 +
 3 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index 168bb927fb57..a574e2cb137f 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -690,6 +690,7 @@ void	in6_sin_2_v4mapsin6(const struct sockaddr_in *sin,
 	    struct sockaddr_in6 *sin6);
 void	in6_sin6_2_sin_in_sock(struct sockaddr *nam);
 extern void addrsel_policy_init(void);
+void	addrsel_policy_destroy(void);
 
 #define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
 #define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index d5e8e0f952c6..07e5b191afc2 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -886,6 +886,22 @@ in6_selecthlim(struct inpcb *inp, struct ifnet *ifp)
 	return (V_ip6_defhlim);
 }
 
+/*
+ * The followings are implementation of the policy table using a
+ * simple tail queue.
+ * XXX such details should be hidden.
+ * XXX implementation using binary tree should be more efficient.
+ */
+struct addrsel_policyent {
+	TAILQ_ENTRY(addrsel_policyent) ape_entry;
+	struct in6_addrpolicy ape_policy;
+};
+
+TAILQ_HEAD(addrsel_policyhead, addrsel_policyent);
+
+VNET_DEFINE_STATIC(struct addrsel_policyhead, addrsel_policytab);
+#define	V_addrsel_policytab		VNET(addrsel_policytab)
+
 void
 addrsel_policy_init(void)
 {
@@ -903,6 +919,18 @@ addrsel_policy_init(void)
 	ADDRSEL_SXLOCK_INIT();
 }
 
+void
+addrsel_policy_destroy(void)
+{
+	struct addrsel_policyent *pol, *tpol;
+
+	TAILQ_FOREACH_SAFE(pol, &V_addrsel_policytab, ape_entry, tpol) {
+		TAILQ_REMOVE(&V_addrsel_policytab, pol, ape_entry);
+		free(pol, M_IFADDR);
+	}
+	/* TODO: Perform matching destruction of locks elsewhere. */
+}
+
 static struct in6_addrpolicy *
 lookup_addrsel_policy(struct sockaddr_in6 *key)
 {
@@ -976,22 +1004,6 @@ in6_src_ioctl(u_long cmd, caddr_t data)
 	return (0);		/* XXX: compromise compilers */
 }
 
-/*
- * The followings are implementation of the policy table using a
- * simple tail queue.
- * XXX such details should be hidden.
- * XXX implementation using binary tree should be more efficient.
- */
-struct addrsel_policyent {
-	TAILQ_ENTRY(addrsel_policyent) ape_entry;
-	struct in6_addrpolicy ape_policy;
-};
-
-TAILQ_HEAD(addrsel_policyhead, addrsel_policyent);
-
-VNET_DEFINE_STATIC(struct addrsel_policyhead, addrsel_policytab);
-#define	V_addrsel_policytab		VNET(addrsel_policytab)
-
 static void
 init_policy_queue(void)
 {
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index 426b81dc9c03..263acefe7211 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -398,6 +398,7 @@ ip6_destroy(void *unused __unused)
 
 	frag6_destroy();
 	nd6_destroy();
+	addrsel_policy_destroy();
 	in6_ifattach_destroy();
 
 	hashdestroy(V_in6_ifaddrhashtbl, M_IFADDR, V_in6_ifaddrhmask);


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a68f66c.3e90a.387b51d1>