From nobody Tue Oct 20 13:58:06 2026 X-Original-To: dev-commits-src-all@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 4j8DX35VS6z6x39d for ; Tue, 20 Oct 2026 13:58:11 +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 4j8DX33WzKz3KBY for ; Tue, 20 Oct 2026 13:58:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792504691; 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=VRauqBPl16XAz1A+tdNiykdsFFy9Q3S9ObMLKoAdW1kfwyhYje7aDzLqTM1Y5uWX3B4IMR GG1RsXALHLVMwXaJ/8wkAOavc0bSQz2rCXwtdUMagxDaCu/ZQMPEZZeosWUFHSRM3dBtog y2w65md502aQZaApb5lrSyGUg7u7n6Fv34MOScVmNArdLvsFFOrEvLB2jMOR1AQL4MlMbX /28vLeA4jm6HgUdAuU4JhDIxWyc9veUVKL8t+Y4dUXbwzDamNTaMeMxtHValJH3EAhYFMR mhxXOpAlKRMmeUuBLO5jkeokUtmCwEgI81AhSXJteFhQ/blmos1ZDcYTQGjBbg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792504691; b=TX6NbKCTMIz2nc4EkBXQV1+aOSL5L2WY3t7usAyB8Yj//8mW2vKv0Ul5qLE7Sa+g+bLsPd Ni9s2ZUzuF3ROM2atdoT1WZV6go9TWA7mb6bdKsVVbT1eLzgs5uXqToNjZJH2k5XcE6yuW QaQuVKtLNw0XHkEcVj73DzVaIB6/CjZR5wgB/xR9D/GDcXqJPtiZSisle/4LuaEVgN0js2 wlgaMBrE2oxURZ66T9+wgfq+VuC8JwrYNCVZldHj5qbYP9Fv0a8KHZ1Eru7TRKgApzYl0E krcZvLY7j9mGRPauMZYNMP86HwYHh3BREBRkainfDmibBmNpqQ0ECIZj0f7rjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792504691; 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=WJSHBX7aHM+sdY+3TmXCLOa2MlOWX8nXOGVUspJ9hXYFhH5GDSJ+mL7gRjzP/0Ou0GJAdf 35SJFc/WiNBkDr1mebMRn5RYwCSkzCaN3Wnc35C+go5gGpyrC0vs56ZKHGpe90QlLFH04k VzoyYYFsC5/dcglbgbUSJlLQlXyzG3iSfmqGcO+hgWXihsS8IgMqgLOJsE7QIzS09XdOSf P5RTKFtq2XcKQZ8t1OkFwfx+IKyIBFTZ1ubh/4e+pLw+3YV5zj+0oQ2nNiBR9Hbxyl2PbG Uxz4zjX7XCnr11uO6Js81X3hQEj1VdWF04lNSd7hKKwjrwv88XJxeYJIgMnQLg== 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 4j8DX337Jsz1957 for ; Tue, 20 Oct 2026 13:58:11 +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-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches 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: 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" }