From nobody Sun Nov 22 21:18:49 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jXhlG03Gdz6wBsP for ; Sun, 22 Nov 2026 21:18:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jXhlF55gvz4s2y for ; Sun, 22 Nov 2026 21:18:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795382329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5X36SekhtuOMr+pGNiXGXCroPl2Uec5tVTd/T9ADj3s=; b=tPFmgXTkGECTanl0XOphz4tuztILz0L8GcxXsUKVC2z5YG72Som9ssiMbAkbL8UUWUx4bx gi+VR+QrIxxJwy2KPK6l0DLz75WD9rDeoVtnDA7we+5SlprxjnP1WrFVipzxhSZ3AhA+7M 0+v8PwLI4IHoVpoSQ9TwgJXEVC1MBwUyDcqxlIbhrFA3hvgkA/oe7XJXUaM3/JFjL/bb8Z UdJ6wxOhSRX2DEwE4s02WFC7x4xQfhHPFaomS57QjhJxL1I7OO9BDKygvYPY0qU9dBjr9m jUpGa5g22Imj8rzefYuNf36AL9xyC8uW2HLKYyoTSpSA8fvByPOEM+Jwiw4wGw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1795382329; b=sWtPpU8hUNNV9SZt1d720lb/uzc7FIcMD5dd+vF0JkvB3ZlPpKae6pMYX61nRr49NMVjne mQkEsPUKzLw4q17it/l0lATVSkh3Peo0tPl0nTuYa9XOClmoJ+9sfM8WbwqqOfHXLbdCRG /LOBBzaIYlBnZT3Xp5Wv/1QEoaA9uNv214qbIzX+dmTHCyk2NCpOT2S3qqB3WkSJ76QmY7 C7TvTpmc44su2AtaAfa3NAenYsng919fyL7GsEockoilGxx17kKQiU1lcwKpnDl5utsubP 3DsXfM06qVzt2sHWcBMgPlzGQLk68ObI4pOb1bZEvxFaEvsEqROvsFV9l4+WHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795382329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5X36SekhtuOMr+pGNiXGXCroPl2Uec5tVTd/T9ADj3s=; b=AVWhFFNlsEoZT6DMl6scJyHWX+LcZ5usr2tivX9UX7rMQz53Hy+FbWOMqQw5Q6IA0TQ5v4 /lCFLVEItiSNi0+9jrtOsKStFNa5w2+tDIoiQsm3itVXCLS91T17krY4qIlZE3WUvolSlF BNxC43Tw+PMwmqhI84jyA9HjcB8ljrNuOchKK57akaz7Srk9JmTkcekIHJVwdQFzXMxIH4 JbnPVVZdJdDV0Y5knBWFVvNBUUwU6Dx14h0NxQZtsdaWL5/RNJ+NE84XNxJpF8l3E0UTdL g2QgfP8/vR/pFM6lG8x35KIZ8ODKoAbYH1l0PBfw2pGAgrFi3ArWgOXs4N2+/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jXhlF4M9pzLC0 for ; Sun, 22 Nov 2026 21:18:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 9cba by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 22 Nov 2026 21:18:49 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: R. Christian McDonald Subject: git: c9f9c4fe47bf - main - ip6_forward: Do not reference the nexthop List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rcm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c9f9c4fe47bf17bb39d7ff3a200aadab6b69e60e Auto-Submitted: auto-generated Date: Sun, 22 Nov 2026 21:18:49 +0000 Message-Id: <6b035c39.9cba.75b8db0@gitrepo.freebsd.org> The branch main has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=c9f9c4fe47bf17bb39d7ff3a200aadab6b69e60e commit c9f9c4fe47bf17bb39d7ff3a200aadab6b69e60e Author: R. Christian McDonald AuthorDate: 2026-11-22 21:18:16 +0000 Commit: R. Christian McDonald CommitDate: 2026-11-22 21:18:16 +0000 ip6_forward: Do not reference the nexthop ip6_forward() looked the route up with NHR_REF and released the nexthop before returning. It runs in the network epoch and uses the nexthop only until it returns: nd6_output_ifp() gets the interface, and icmp6_redirect_output() runs before the return. The epoch keeps the nexthop valid that long, which ip6_tryforward() already relies on. Every packet that takes this path wrote twice to the nexthop reference count, which all CPUs forwarding to that nexthop share. Forwarded packets take it whenever IPsec has a security policy, and today also whenever net.inet6.ip6.redirect is set, which is the default. Look the nexthop up without a reference, and assert that the caller is in the network epoch. No functional change intended. Reviewed by: pouria MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D61393 --- sys/netinet6/ip6_forward.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index 4b263e65a637..81fa76e07e05 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -95,7 +95,7 @@ ip6_forward(struct mbuf *m, int srcrt) { struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); struct sockaddr_in6 dst; - struct nhop_object *nh = NULL; + struct nhop_object *nh; int error, type = 0, code = 0; struct mbuf *mcopy = NULL; struct ifnet *origifp; /* maybe unnecessary */ @@ -104,6 +104,8 @@ ip6_forward(struct mbuf *m, int srcrt) struct m_tag *fwd_tag; char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN]; + NET_EPOCH_ASSERT(); + /* * Do not forward packets to multicast destination (should be handled * by ip6_mforward(). @@ -186,8 +188,9 @@ ip6_forward(struct mbuf *m, int srcrt) dst.sin6_addr = ip6->ip6_dst; dst.sin6_scope_id = in6_get_unicast_scopeid(&ip6->ip6_dst, m->m_pkthdr.rcvif); again: + /* The network epoch keeps the nexthop valid until we return. */ nh = fib6_lookup(M_GETFIB(m), &dst.sin6_addr, dst.sin6_scope_id, - NHR_REF, m->m_pkthdr.flowid); + NHR_NONE, m->m_pkthdr.flowid); if (nh == NULL) { IP6STAT_INC(ip6s_noroute); in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_noroute); @@ -339,8 +342,6 @@ again: if (in6_localip(&ip6->ip6_dst)) m->m_flags |= M_FASTFWD_OURS; else { - NH_FREE(nh); - /* Update address and scopeid. Assume scope is embedded */ dst.sin6_scope_id = ntohs(in6_getscope(&ip6->ip6_dst)); dst.sin6_addr = ip6->ip6_dst; @@ -378,7 +379,6 @@ again: m->m_flags |= M_SKIP_FIREWALL; m->m_flags &= ~M_IP6_NEXTHOP; m_tag_delete(m, fwd_tag); - NH_FREE(nh); goto again; } @@ -440,12 +440,12 @@ pass: } if (mcopy == NULL) - goto out; + return; switch (error) { case 0: if (type == ND_REDIRECT) { icmp6_redirect_output(mcopy, nh); - goto out; + return; } goto freecopy; @@ -467,14 +467,11 @@ pass: break; } icmp6_error(mcopy, type, code, 0); - goto out; + return; freecopy: m_freem(mcopy); - goto out; + return; bad: m_freem(m); -out: - if (nh != NULL) - NH_FREE(nh); }