From nobody Mon Sep 16 13:05:23 2024 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 4X6lWm0dYsz5Vxv9; Mon, 16 Sep 2024 13:05:24 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X6lWl5C2Lz54RJ; Mon, 16 Sep 2024 13:05:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726491923; 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=7LEpULdVULkmllDQBzUrRhk1CkNUkjKsiF/Rg0g+MNY=; b=dA+gGOQhn8CaIHrKGvNBpxIswQF+HoE/S4AR8OlDxSu+8sG1TEBfi1Bjv+/5CuKg4b5Bxe vD/4FS3lS3dPWHViAVadaFEoAu/kPZT+wT/kBaanuJ1Kb5v93XF5Kwe2L9FQiSK/uNLEko 9+TYH+UwNPsBTzaJCzfp6dUeTBxgKiUiLQKHuC4k1wcr/1KCq61QOQigJ54vS+lhxcqnB2 aHT6sf4Y6O1h/Af2hweihq86MKjRQKsVKw7XZ+1Jta3DQRnJtaFHS8cKKIiV/eqzcF48W2 8m7dEFHlvQW+OT9MIKeor5CwkiqaTcgoRvWMbcdWWgFJqZ2xGH79xcw1hZ9kOg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726491923; a=rsa-sha256; cv=none; b=aqmmUKYybN2WJAoVYIQkfR0MMxUkPYIiilnKT4Q3X7onWJbqNevN11zz9FCc3GXaXuQKNm heULMCD8bjLH1w5QOpERaRWsBWdxBlBXrRmQ9Axf94gP4kShNmLgdSK2Y5JJiyjizIZvIQ ewIC3Zmo/ZJW69BhMFYUoZgPGKlxlHtOxXm37YBoxhKBQbVCFAxZLgc2D79tFXqV7e1VTR llsih8xu03q3xhzJAjboMmdG1Ye5iSXJ8l9V1YArW++sQ/zb1/oSGo6iqRnCoy2babX32e OAS61f/I7D2NchVEsMPAEiPaGTnOeBZiu4T73pvCjfXMXjOgwTwazLpRMr8b6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726491923; 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=7LEpULdVULkmllDQBzUrRhk1CkNUkjKsiF/Rg0g+MNY=; b=DHmuHaxLTnDnw/12UpRq10tjYLtnM0bsuIA21F6esIdFHVOEmmOYVIyns3zuUJCZNA9QMO S6Ropoc166PUzBoEVcM+cJMboYAikHrSmcYQTwLOFEmX+eKBIykFDvT4MQk+T099Mv8Vk3 NVYJ1ZDn2pvfAd3MMPVoiXqIyGsGpvY8vrToQgNj12vPjlyKcDcq8DxoPcex2XyE8a8N4B YJXBeXE/ghXyAwVWUigFJB+5spAkPAb74LXZjhBtvamZ0byWhf7H2I5lQIGs8ew2Iz4WfJ K0QACV44p1ubVj8YUbZuDP6YlmTT4ZPIiYKpJ+BoJ6Hp9D/9lAqHPK7wFGAhSA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X6lWl4J6qzw5w; Mon, 16 Sep 2024 13:05:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48GD5NBs020741; Mon, 16 Sep 2024 13:05:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48GD5NcR020738; Mon, 16 Sep 2024 13:05:23 GMT (envelope-from git) Date: Mon, 16 Sep 2024 13:05:23 GMT Message-Id: <202409161305.48GD5NcR020738@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 661d0031bbc6 - main - pf tests: test the new received-on feature List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org 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/main X-Git-Reftype: branch X-Git-Commit: 661d0031bbc6b5623eb11234a9c4f20c6a1a5972 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=661d0031bbc6b5623eb11234a9c4f20c6a1a5972 commit 661d0031bbc6b5623eb11234a9c4f20c6a1a5972 Author: Kristof Provost AuthorDate: 2024-09-06 13:06:35 +0000 Commit: Kristof Provost CommitDate: 2024-09-16 11:48:20 +0000 pf tests: test the new received-on feature Reviewed by: zlei Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D46578 --- sbin/pfctl/tests/files/pf1022.in | 1 + sbin/pfctl/tests/files/pf1022.ok | 1 + sbin/pfctl/tests/pfctl_test_list.inc | 1 + tests/sys/netpfil/pf/pass_block.sh | 82 ++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) diff --git a/sbin/pfctl/tests/files/pf1022.in b/sbin/pfctl/tests/files/pf1022.in new file mode 100644 index 000000000000..640eb1334100 --- /dev/null +++ b/sbin/pfctl/tests/files/pf1022.in @@ -0,0 +1 @@ +pass out on em0 from 192.0.2.1 to 198.51.100.1 received-on fxp0 diff --git a/sbin/pfctl/tests/files/pf1022.ok b/sbin/pfctl/tests/files/pf1022.ok new file mode 100644 index 000000000000..2f7b4a5bd616 --- /dev/null +++ b/sbin/pfctl/tests/files/pf1022.ok @@ -0,0 +1 @@ +pass out on em0 inet from 192.0.2.1 to 198.51.100.1 received-on fxp0 flags S/SA keep state diff --git a/sbin/pfctl/tests/pfctl_test_list.inc b/sbin/pfctl/tests/pfctl_test_list.inc index 1fd31de6ccc4..0ab336ec100d 100644 --- a/sbin/pfctl/tests/pfctl_test_list.inc +++ b/sbin/pfctl/tests/pfctl_test_list.inc @@ -130,3 +130,4 @@ PFCTL_TEST(1018, "Test dynamic address mask") PFCTL_TEST(1019, "Test pflow option") PFCTL_TEST(1020, "Test hashmark and semicolon comment") PFCTL_TEST(1021, "Endpoint-independent") +PFCTL_TEST(1022, "Test received-on") diff --git a/tests/sys/netpfil/pf/pass_block.sh b/tests/sys/netpfil/pf/pass_block.sh index faf5c2de4de2..36218d8e673f 100644 --- a/tests/sys/netpfil/pf/pass_block.sh +++ b/tests/sys/netpfil/pf/pass_block.sh @@ -292,6 +292,87 @@ urpf_cleanup() pft_cleanup } +atf_test_case "received_on" "cleanup" +received_on_head() +{ + atf_set descr 'Test received-on filtering' + atf_set require.user root +} + +received_on_body() +{ + pft_init + + epair_one=$(vnet_mkepair) + epair_two=$(vnet_mkepair) + epair_route=$(vnet_mkepair) + + vnet_mkjail alcatraz ${epair_one}b ${epair_two}b ${epair_route}a + vnet_mkjail srv ${epair_route}b + + ifconfig ${epair_one}a 192.0.2.2/24 up + ifconfig ${epair_two}a 198.51.100.2/24 up + route add 203.0.113.2 192.0.2.1 + route add 203.0.113.3 198.51.100.1 + + jexec alcatraz ifconfig ${epair_one}b 192.0.2.1/24 up + jexec alcatraz ifconfig ${epair_two}b 198.51.100.1/24 up + jexec alcatraz ifconfig ${epair_route}a 203.0.113.1/24 up + jexec alcatraz sysctl net.inet.ip.forwarding=1 + + jexec srv ifconfig ${epair_route}b 203.0.113.2/24 up + jexec srv ifconfig ${epair_route}b inet alias 203.0.113.3/24 up + jexec srv route add default 203.0.113.1 + + # Sanity checks + atf_check -s exit:0 -o ignore \ + ping -c 1 192.0.2.1 + atf_check -s exit:0 -o ignore \ + ping -c 1 198.51.100.1 + atf_check -s exit:0 -o ignore \ + ping -c 1 203.0.113.2 + atf_check -s exit:0 -o ignore \ + ping -c 1 203.0.113.3 + + jexec alcatraz pfctl -e + pft_set_rules alcatraz \ + "block in" \ + "pass received-on ${epair_one}b" + + atf_check -s exit:0 -o ignore \ + ping -c 1 192.0.2.1 + atf_check -s exit:2 -o ignore \ + ping -c 1 198.51.100.1 + + # And ensure we can check the received-on interface after routing + atf_check -s exit:0 -o ignore \ + ping -c 1 203.0.113.2 + atf_check -s exit:2 -o ignore \ + ping -c 1 203.0.113.3 + + # Now try this with a group instead + jexec alcatraz ifconfig ${epair_one}b group test + pft_set_rules alcatraz \ + "block in" \ + "pass received-on test" + + atf_check -s exit:0 -o ignore \ + ping -c 1 192.0.2.1 + atf_check -s exit:2 -o ignore \ + ping -c 1 198.51.100.1 + + # And ensure we can check the received-on interface after routing + atf_check -s exit:0 -o ignore \ + ping -c 1 203.0.113.2 + atf_check -s exit:2 -o ignore \ + ping -c 1 203.0.113.3 +} + +received_on_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "enable_disable" @@ -300,4 +381,5 @@ atf_init_test_cases() atf_add_test_case "noalias" atf_add_test_case "nested_inline" atf_add_test_case "urpf" + atf_add_test_case "received_on" }