From nobody Wed Mar 02 16:00:51 2022 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 C51E719E0C9D; Wed, 2 Mar 2022 16:00:52 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K7zP00Ggcz3NVs; Wed, 2 Mar 2022 16:00:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646236852; 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=GNGSDYEUAQe7ktMk3kIWMO7Fx/u0Q5LmYvyFXticDTk=; b=DbkpZFl6m6yqwCS6nkDv9VnlKlf0zV22bAVE71zf5lt5n/U7f0ga8BXInyUd4BAnxI9w0R OmrtnpbY9/HD1R5jxkrA5Hc/m3M7IG7Wcg+2OXXrB6/gQN3YgemcsPNAgLN8ROq+Tcvhs5 zCFDDw0bWbHYE3H/BH9dOD++EsBMKTWVlwIOMAY6t6O95/h+GnQPzZKDSeq+enx/wMsT9V uCLjOOR+nSTeDhD4CJoLlG2+ZG2XJjIpy5rD/4d1eAVT2u01n4dMSf/p7+ggGYU6Rqre8a zraY+y134GkH7yMfVZr/v7DChFkxbfcUTuqp9X60wigrZ/10Yx19pvhIYxVfQg== 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 7FEAD262D3; Wed, 2 Mar 2022 16:00:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 222G0pYA091181; Wed, 2 Mar 2022 16:00:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 222G0pes091180; Wed, 2 Mar 2022 16:00:51 GMT (envelope-from git) Date: Wed, 2 Mar 2022 16:00:51 GMT Message-Id: <202203021600.222G0pes091180@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: feefb5625b65 - main - pf tests: Test ether direction List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: feefb5625b65b4b00c828f9dbe1b8dc4f481a542 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646236852; 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=GNGSDYEUAQe7ktMk3kIWMO7Fx/u0Q5LmYvyFXticDTk=; b=W4iISxa8bEVVCEJlARF4affVk03YVAdlU0BsXD2nI1nYkX5/1FRE5iN7Nwj5/w+ZoQITre nC50lyqUX6jB3cLjrr4nslifhlT3BS4mZjU4dv4261adNDgCqTUCIaXzEjKOZ8DJxI8nsW sH3GXcHPVcV4W118/CRhLMlTE/t4NfrCf3QLSbFEy2fd3GdDc1+NB1IVk4h6FBslitkHvQ lfwszLVNUqlZDQCZr8OfvgSGid32Z8JzwOwIaguL+XIAD4scoCeCXWffWjAhzeKyNCZO3g zY+ewcmXvLOeGbJrhaVQtOuv/7f/ysrZ1XR843BUs4TjYKCny3SV6MI1eJvAug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646236852; a=rsa-sha256; cv=none; b=W63dCI7TKF5cYg22LOKC9QPOg5OXvZFtcY/ZIiBUTV5kTnm9pNBdYpt6ZlBFUFb0xbanPD bPOeba9qFwGPZLZLNX0egB2CxxXmt9Xbq3xABfR9e7biSSVpftyYkflLwm4nmZf20Ku6Nb jOi0yd+a84vG0TfWF1YVQ4j1wPCM4+gESJkbf2RWXu2Zu04vGvMTmUs8gBoH1zYQn9jTYj 8QvU8b2k3mlQQfEPqy5fvDJ60bD83usxSR0Rp4zPzxmBw6Xn+r2ozMW6i3Ud4k2aO96vdI 1gY84UKg8g/vSafdQlN1fI6keFvpynbgwoU+c1rySh2XmEcMtCWiH8oRDzVlTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=feefb5625b65b4b00c828f9dbe1b8dc4f481a542 commit feefb5625b65b4b00c828f9dbe1b8dc4f481a542 Author: Kristof Provost AuthorDate: 2021-02-15 18:03:59 +0000 Commit: Kristof Provost CommitDate: 2022-03-02 16:00:05 +0000 pf tests: Test ether direction Test that we correctly match inbound ('in') or outbound ('out') Ethernet packets. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D31747 --- tests/sys/netpfil/pf/ether.sh | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/sys/netpfil/pf/ether.sh b/tests/sys/netpfil/pf/ether.sh index 9178a0845773..340eb079ca23 100644 --- a/tests/sys/netpfil/pf/ether.sh +++ b/tests/sys/netpfil/pf/ether.sh @@ -133,6 +133,79 @@ proto_cleanup() pft_cleanup } +atf_test_case "direction" "cleanup" +direction_head() +{ + atf_set descr 'Test directionality of ether rules' + atf_set require.user root + atf_set require.progs jq +} + +direction_body() +{ + pft_init + + epair=$(vnet_mkepair) + epair_a_mac=$(ifconfig ${epair}a ether | awk '/ether/ { print $2; }') + epair_b_mac=$(ifconfig ${epair}b ether | awk '/ether/ { print $2; }') + + ifconfig ${epair}a 192.0.2.1/24 up + + vnet_mkjail alcatraz ${epair}b + jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up + + pft_set_rules alcatraz \ + "ether block in proto 0x0806" + jexec alcatraz pfctl -e + + arp -d 192.0.2.2 + jexec alcatraz arp -d 192.0.2.1 + + # We don't allow the jail to receive ARP requests, so if we try to ping + # from host to jail the host can't resolve the MAC address + ping -c 1 -t 1 192.0.2.2 + + mac=$(arp -an --libxo json \ + | jq '."arp"."arp-cache"[] | + select(."ip-address"=="192.0.2.2")."mac-address"') + atf_check_not_equal "$mac" "$epair_b_mac" + + # Clear ARP table again + arp -d 192.0.2.2 + jexec alcatraz arp -d 192.0.2.1 + + # However, we allow outbound ARP, so the host will learn our MAC if the + # jail tries to ping + jexec alcatraz ping -c 1 -t 1 192.0.2.1 + + mac=$(arp -an --libxo json \ + | jq '."arp"."arp-cache"[] | + select(."ip-address"=="192.0.2.2")."mac-address"') + atf_check_equal "$mac" "$epair_b_mac" + + # Now do the same, but with outbound ARP blocking + pft_set_rules alcatraz \ + "ether block out proto 0x0806" + + # Clear ARP table again + arp -d 192.0.2.2 + jexec alcatraz arp -d 192.0.2.1 + + # The jail can't send ARP requests to us, so we'll never learn our MAC + # address + jexec alcatraz ping -c 1 -t 1 192.0.2.1 + + mac=$(jexec alcatraz arp -an --libxo json \ + | jq '."arp"."arp-cache"[] | + select(."ip-address"=="192.0.2.1")."mac-address"') + atf_check_not_equal "$mac" "$epair_a_mac" +} + +direction_cleanup() +{ + pft_cleanup +} + atf_test_case "captive" "cleanup" captive_head() { @@ -211,5 +284,6 @@ atf_init_test_cases() { atf_add_test_case "mac" atf_add_test_case "proto" + atf_add_test_case "direction" atf_add_test_case "captive" }