From nobody Tue Oct 20 13:58:06 2026 X-Original-To: dev-commits-src-branches@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 4j8DWy1wVNz6x30x for ; Tue, 20 Oct 2026 13:58:06 +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 4j8DWy1G7Qz3K13 for ; Tue, 20 Oct 2026 13:58:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792504686; 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=VghQRfLASpSzfnzyzNEhA9WMMJPOY4K8ymNb8gA2D3M=; b=Q4jVSqy/vcsEpMQwDGZkfyLre8UhY1kfavoucYQ5hIjdQrQWTBjF+5KP+XkZFVUoAS8JwK /v0/3PxjNGslc6o1Vhzw2yT8XIqVQNtDH2+mvL9NjkV4tAauouI2tFeM19Hm0DF2RwXsNS UlYUdgHFLAAnohTAMc00ts4w8PrXCV/xN6US74DTSYtOsfResWSDS7k9Lh0wZxJXQqKLpO OJlKhgOS5YXVCwLkHVRODsrebIHSP3k6zxPf2UuiRJ8yNwj+g10eS3h/3EllFjbPOQl7J0 MMOn7jlt99tP4kOQ41F+AK446N/SyyWX2gJdIXufdsbzc6dH5djoYBFwiMNnHg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792504686; b=tTMedhmiMfsh7LjJhBd3J3ua28IltmxzsHMlmoJjAM5wFsA7TE/KSxML6OBVCTlRqRCWIH 3rWJWjK4kDQxmKosb/oIhbB6mhD6Y8WUZ4l4zuFczgtZZS7xL5atwhHcOUPaSNxghFxtr0 EUlJR6uCXhCA5pyFnUsQkXwYBFjmjGQFiSL/zvVEwPxtAt4tlZd5+DvOsO38CckkOTr971 Eia2D0q5tlWajjnDiGSRZuKFWQJAHQf0woQPhyRuNJE5rEQP5xugr94d8m3B9SKpoRe/WI HN7QUsGiFzAth31LzA9IddVp4KauWrNaR5dwydnX9+FENYtW5FL4YcE6P0QaIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792504686; 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=VghQRfLASpSzfnzyzNEhA9WMMJPOY4K8ymNb8gA2D3M=; b=XptLc8wBjkN8+ySrr192gD7LtcgXqB8lDHGifcRSJMHY+Jxk9Jpzf3uSqbXg/Cqf+rAJcL ZoCTg/9DTV1v7fP9B2L9jIywXOuwgZcg0eCs2JDgc6Moqz7FT+SVO43aYTMxi1eefyRXwh g0P2PBdHKQwKKasgsNLbBSde9iOcNHvw6FZ6e7pEJxZh5VSql9znXtBxWe/UpVxRtdQgN8 KLmyEaFhuK6+pvCW+1Eztvps+pSgP3KZDnnaucX2hr8pcZZRi9CWVf7dqvDJpwZ0GLJVaN 60b02g7xrFBKbvfJ5Z6p2kFt+X2/tpFeu4SY3WegQc9HEv2VhWZ7QRhrlord4g== 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 4j8DWy0wVDz192c for ; Tue, 20 Oct 2026 13:58:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3e4c3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 20 Oct 2026 13:58:06 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 820804014074 - stable/15 - pf: first-match-wins for nat rules, even in anchors List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: Commits to the stable branches of the FreeBSD 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 820804014074cdc4f56dca7a3966019b8aa172ae Auto-Submitted: auto-generated Date: Tue, 20 Oct 2026 13:58:06 +0000 Message-Id: <6ad7736e.3e4c3.431e8dfd@gitrepo.freebsd.org> The branch stable/15 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=820804014074cdc4f56dca7a3966019b8aa172ae commit 820804014074cdc4f56dca7a3966019b8aa172ae Author: Kristof Provost AuthorDate: 2026-10-13 12:40:58 +0000 Commit: Kristof Provost CommitDate: 2026-10-20 13:53:41 +0000 pf: first-match-wins for nat rules, even in anchors Ensure we stop evaluating nat rules if we find a match in a nat-anchor. PR: 299320 MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit b5219c068fbc133dde91d5cf48423e34ce27bd4f) --- sys/netpfil/pf/pf_lb.c | 4 ++ tests/sys/netpfil/pf/nat.sh | 91 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index cb99038a07fa..eecb14149dfd 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -224,6 +224,10 @@ pf_match_translation_rule(int rs_num, struct pf_test_ctx *ctx, struct pf_krulese r) != PF_TEST_OK) { break; } + /* If we found a match in the anchor we're done. */ + if (ctx->tr != NULL) { + break; + } } r = TAILQ_NEXT(r, entries); } diff --git a/tests/sys/netpfil/pf/nat.sh b/tests/sys/netpfil/pf/nat.sh index 1355da83d2f3..47292b1c7642 100644 --- a/tests/sys/netpfil/pf/nat.sh +++ b/tests/sys/netpfil/pf/nat.sh @@ -916,6 +916,95 @@ empty_pool_cleanup() pft_cleanup } +atf_test_case "first_match" "cleanup" +first_match_head() +{ + atf_set descr 'Test that NAT rules are first match' + atf_set require.user root +} + +first_match_body() +{ + pft_init + + epair_nat=$(vnet_mkepair) + epair_echo=$(vnet_mkepair) + + vnet_mkjail nat ${epair_nat}b ${epair_echo}a + vnet_mkjail echo ${epair_echo}b + + ifconfig ${epair_nat}a 192.0.2.2/24 up + route add -net 198.51.100.0/24 192.0.2.1 + + jexec nat ifconfig ${epair_nat}b 192.0.2.1/24 up + jexec nat ifconfig ${epair_echo}a 198.51.100.1/24 up + jexec nat sysctl net.inet.ip.forwarding=1 + + jexec echo ifconfig ${epair_echo}b 198.51.100.2/24 up + + # Enable pf! + jexec nat pfctl -e + pft_set_rules nat \ + "table { 192.0.2.0/24 }" \ + "nat on ${epair_echo}a inet from to any -> 198.51.100.1" \ + "nat on ${epair_echo}a inet from 192.0.2.0/24 to any -> 198.51.100.3" + + atf_check -s exit:0 -o ignore ping -c 3 198.51.100.2 + atf_check -s exit:0 -e ignore \ + -o match:"all icmp 198.51.100.1:.*(192.0.2.2:.*) -> 198.51.100.2:8.*" \ + jexec nat pfctl -ss +} + +first_match_cleanup() +{ + pft_cleanup +} + +atf_test_case "first_match_anchor" "cleanup" +first_match_anchor_head() +{ + atf_set descr 'Test that NAT matches within an anchor are final (PR 299320)' + atf_set require.user root +} + +first_match_anchor_body() +{ + pft_init + + epair_nat=$(vnet_mkepair) + epair_echo=$(vnet_mkepair) + + vnet_mkjail nat ${epair_nat}b ${epair_echo}a + vnet_mkjail echo ${epair_echo}b + + ifconfig ${epair_nat}a 192.0.2.2/24 up + route add -net 198.51.100.0/24 192.0.2.1 + + jexec nat ifconfig ${epair_nat}b 192.0.2.1/24 up + jexec nat ifconfig ${epair_echo}a 198.51.100.1/24 up + jexec nat sysctl net.inet.ip.forwarding=1 + + jexec echo ifconfig ${epair_echo}b 198.51.100.2/24 up + + # Enable pf! + jexec nat pfctl -e + pft_set_rules nat \ + "nat-anchor \"foo\"" \ + "nat on ${epair_echo}a inet from 192.0.2.0/24 to any -> 198.51.100.3" + + echo "nat on ${epair_echo}a inet from 192.0.2.0/24 to any -> 198.51.100.1" | jexec nat pfctl -g -f - -a "foo" + + atf_check -s exit:0 -o ignore ping -c 3 198.51.100.2 + atf_check -s exit:0 -e ignore \ + -o match:"all icmp 198.51.100.1:.*(192.0.2.2:.*) -> 198.51.100.2:8.*" \ + jexec nat pfctl -ss +} + +first_match_anchor_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "exhaust" @@ -937,4 +1026,6 @@ atf_init_test_cases() atf_add_test_case "binat_compat" atf_add_test_case "binat_match" atf_add_test_case "empty_pool" + atf_add_test_case "first_match" + atf_add_test_case "first_match_anchor" }