Date: Fri, 3 Oct 2025 10:11:08 GMT From: Guido Falsi <madpilot@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 0c94dc9da7c2 - main - sys/netinet6: Use atomic(9) for dad_failures counter Message-ID: <202510031011.593AB8Ep005320@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by madpilot: URL: https://cgit.FreeBSD.org/src/commit/?id=0c94dc9da7c238603e43c55ca6da64c417fc2204 commit 0c94dc9da7c238603e43c55ca6da64c417fc2204 Author: Guido Falsi <madpilot@FreeBSD.org> AuthorDate: 2025-10-03 10:09:42 +0000 Commit: Guido Falsi <madpilot@FreeBSD.org> CommitDate: 2025-10-03 10:09:42 +0000 sys/netinet6: Use atomic(9) for dad_failures counter Replace counter(9) usage with more lightweight atomic(9) in the code handling RFC 7217 SLAAC address generation. Also, use `u_int` types with this. Leaving `dad_failures` local to `in6_get_stableifid()` as a `uint64_t` to avoid changing the generated addresses from previous code; this also gives some headroom for future changes. While here, moved some `#include` lines to adhere to style(9). Reviewed by: glebius, jhibbits, jtl, zlei Approved by: glebius, jtl, zlei Differential Revision: https://reviews.freebsd.org/D52731 --- sys/netinet6/in6.c | 3 --- sys/netinet6/in6_ifattach.c | 6 ++++-- sys/netinet6/in6_proto.c | 4 ++-- sys/netinet6/in6_var.h | 2 +- sys/netinet6/ip6_var.h | 2 +- sys/netinet6/nd6_nbr.c | 8 +++++--- sys/netinet6/nd6_rtr.c | 4 +++- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 8ef755e2dc0a..4f756a75fac7 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -2604,8 +2604,6 @@ in6_domifattach(struct ifnet *ifp) COUNTER_ARRAY_ALLOC(ext->icmp6_ifstat, sizeof(struct icmp6_ifstat) / sizeof(uint64_t), M_WAITOK); - ext->dad_failures = counter_u64_alloc(M_WAITOK); - ext->nd_ifinfo = nd6_ifattach(ifp); ext->scope6_id = scope6_ifattach(ifp); ext->lltable = in6_lltattach(ifp); @@ -2641,7 +2639,6 @@ in6_domifdetach(struct ifnet *ifp, void *aux) COUNTER_ARRAY_FREE(ext->icmp6_ifstat, sizeof(struct icmp6_ifstat) / sizeof(uint64_t)); free(ext->icmp6_ifstat, M_IFADDR); - counter_u64_free(ext->dad_failures); free(ext, M_IFADDR); } diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index 4fde346fb691..090ba610460b 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -44,7 +44,6 @@ #include <sys/rmlock.h> #include <sys/syslog.h> #include <sys/md5.h> -#include <crypto/sha2/sha256.h> #include <net/if.h> #include <net/if_var.h> @@ -72,6 +71,9 @@ #include <netinet6/mld6_var.h> #include <netinet6/scope6_var.h> +#include <crypto/sha2/sha256.h> +#include <machine/atomic.h> + #ifdef IP6_AUTO_LINKLOCAL VNET_DEFINE(int, ip6_auto_linklocal) = IP6_AUTO_LINKLOCAL; #else @@ -377,7 +379,7 @@ in6_get_stableifid(struct ifnet *ifp, struct in6_addr *in6, int prefixlen) } hostuuid_len = strlen(hostuuid); - dad_failures = counter_u64_fetch(DAD_FAILURES(ifp)); + dad_failures = atomic_load_int(&DAD_FAILURES(ifp)); /* * RFC 7217 section 7 diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 6669a2ba56ce..f567b42b42ca 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -167,7 +167,7 @@ VNET_DEFINE(int, ip6_rr_prune) = 5; /* router renumbering prefix * walk list every 5 sec. */ VNET_DEFINE(int, ip6_mcast_pmtu) = 0; /* enable pMTU discovery for multicast? */ VNET_DEFINE(int, ip6_v6only) = 1; -VNET_DEFINE(int, ip6_stableaddr_maxretries) = IP6_IDGEN_RETRIES; +VNET_DEFINE(u_int, ip6_stableaddr_maxretries) = IP6_IDGEN_RETRIES; #ifdef IPSTEALTH VNET_DEFINE(int, ip6stealth) = 0; @@ -317,7 +317,7 @@ SYSCTL_INT(_net_inet6_ip6, IPV6CTL_USETEMPADDR, use_tempaddr, SYSCTL_BOOL(_net_inet6_ip6, IPV6CTL_USESTABLEADDR, use_stableaddr, CTLFLAG_VNET | CTLFLAG_RWTUN, &VNET_NAME(ip6_use_stableaddr), 0, "Create RFC7217 semantically opaque address for autoconfigured addresses (default for new interfaces)"); -SYSCTL_INT(_net_inet6_ip6, IPV6CTL_STABLEADDR_MAXRETRIES, stableaddr_maxretries, +SYSCTL_UINT(_net_inet6_ip6, IPV6CTL_STABLEADDR_MAXRETRIES, stableaddr_maxretries, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(ip6_stableaddr_maxretries), IP6_IDGEN_RETRIES, "RFC7217 semantically opaque address DAD max retries"); SYSCTL_INT(_net_inet6_ip6, IPV6CTL_STABLEADDR_NETIFSRC, stableaddr_netifsource, diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h index e511ead24f08..1414cc71388d 100644 --- a/sys/netinet6/in6_var.h +++ b/sys/netinet6/in6_var.h @@ -106,7 +106,7 @@ struct in6_ifextra { struct scope6_id *scope6_id; struct lltable *lltable; struct mld_ifsoftc *mld_ifinfo; - counter_u64_t dad_failures; /* DAD failures when using RFC 7217 stable addresses */ + u_int dad_failures; /* DAD failures when using RFC 7217 stable addresses */ }; #define LLTABLE6(ifp) (((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->lltable) diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index c28bfa5a9d08..db1631736c4a 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -344,7 +344,7 @@ VNET_DECLARE(bool, ip6_use_stableaddr); /* Whether to use stable address generat #define V_ip6_use_stableaddr VNET(ip6_use_stableaddr) #define IP6_IDGEN_RETRIES 3 /* RFC 7217 section 7 default max retries */ -VNET_DECLARE(int, ip6_stableaddr_maxretries); +VNET_DECLARE(u_int, ip6_stableaddr_maxretries); #define V_ip6_stableaddr_maxretries VNET(ip6_stableaddr_maxretries) #define IP6_STABLEADDR_NETIFSRC_NAME 0 diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index e2db192bca15..29151b29a071 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -77,6 +77,8 @@ #include <netinet/ip_carp.h> #include <netinet6/send.h> +#include <machine/atomic.h> + #define SDL(s) ((struct sockaddr_dl *)s) struct dadq; @@ -1460,7 +1462,7 @@ nd6_dad_timer(void *arg) if ((ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED) == 0) { ia->ia6_flags &= ~IN6_IFF_TENTATIVE; if ((ND_IFINFO(ifp)->flags & ND6_IFF_STABLEADDR) && !(ia->ia6_flags & IN6_IFF_TEMPORARY)) - counter_u64_zero(DAD_FAILURES(ifp)); + atomic_store_int(&DAD_FAILURES(ifp), 0); } nd6log((LOG_DEBUG, @@ -1509,10 +1511,10 @@ nd6_dad_duplicated(struct ifaddr *ifa, struct dadq *dp) * More addresses will be generated as long as retries are not exhausted. */ if ((ND_IFINFO(ifp)->flags & ND6_IFF_STABLEADDR) && !(ia->ia6_flags & IN6_IFF_TEMPORARY)) { - uint64_t dad_failures = counter_u64_fetch(DAD_FAILURES(ifp)); + u_int dad_failures = atomic_load_int(&DAD_FAILURES(ifp)); if (dad_failures <= V_ip6_stableaddr_maxretries) { - counter_u64_add(DAD_FAILURES(ifp), 1); + atomic_add_int(&DAD_FAILURES(ifp), 1); /* if retries exhausted, output an informative error message */ if (dad_failures == V_ip6_stableaddr_maxretries) log(LOG_ERR, "%s: manual intervention required, consider disabling \"stableaddr\" on the interface" diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index f9684b085767..10f0342f2bc4 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -74,6 +74,8 @@ #include <netinet/icmp6.h> #include <netinet6/scope6_var.h> +#include <machine/atomic.h> + static struct nd_defrouter *defrtrlist_update(struct nd_defrouter *); static int prelist_update(struct nd_prefixctl *, struct nd_defrouter *, struct mbuf *, int); @@ -1756,7 +1758,7 @@ prelist_update(struct nd_prefixctl *new, struct nd_defrouter *dr, * to fail and no further retries should happen. */ if (ND_IFINFO(ifp)->flags & ND6_IFF_STABLEADDR && - counter_u64_fetch(DAD_FAILURES(ifp)) <= V_ip6_stableaddr_maxretries && + atomic_load_int(&DAD_FAILURES(ifp)) <= V_ip6_stableaddr_maxretries && ifa6->ia6_flags & (IN6_IFF_DUPLICATED | IN6_IFF_TEMPORARY)) continue;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202510031011.593AB8Ep005320>