From nobody Mon Sep 30 09:06:21 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 4XHFYT4NF5z5Y1XZ; Mon, 30 Sep 2024 09:06:21 +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 4XHFYT30Zrz55xc; Mon, 30 Sep 2024 09:06:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727687181; 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=lYxHhMKzan0H+towtMBFJgoEBUwaBi+E0S6QW7Jl6E8=; b=Lcn3DW18FyvUidcb5T4RhyhVre1AHEk2Fs4X6yrpel3axdYFU1lT4SF9zV5d/5ci/dhFsH JAhfJQqr3pcNsRC0ZfQgtKFT1OC3O7zzGGBMpTdjWog9Gl2offJIKL5HKACc2x1Y5AsMs8 cV0LLtLUUw1LajHdppd7cOgpzLk+w2BECtdPA8YLmmIea7KB30amE9iGmzjv/tnZoyDwx4 6BCztjIy7WdvAU4Jg19gNrNuc634kPdKxPPf379UHDEBmJ+uCjcMny+3lM8BP70fCpQW0u A2+A2ZY9AJFDL5jSbz2/BMX1GuYrNHzHzlbB3cOyd30cJQP3vi7kcTXI/VCwVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727687181; 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=lYxHhMKzan0H+towtMBFJgoEBUwaBi+E0S6QW7Jl6E8=; b=EaYZbtbRWGiISS0Jo+UZ1QkgcZUOCxLUCy1IEKNjjpk6VUYlxvAgIGL3jcazoBwmYSR9NL NIDFSjYnzt78chhJWXCY4UslC61TS6sO8Zp0ICfvpf3JYdLHpPuTF3TpoxBMqZOpl847Av jaL5WlIilOXXhIghm+4qcrKRJJbHrc7086zLOHL10lpyYrbHjOyjsTNna1Jla2S2VBCGu7 0XiNfscMI6+0CfHQVhgPhDDH+iM9YLgcS+8bCmZxAwVkuqvtLfm+tyK+/lwc1foDkRbuTf zXEjXE/EtAdFGPmF4tJKSiOj+hGE3WXsKOd42We2YadSYz4YrN7kYkWhWfsAfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727687181; a=rsa-sha256; cv=none; b=vKKWzk0YTo5K9OoPrI4xpAn7a8sekQywLD9VSqEE7LRs3IcW4TxG7OoetpGrWEOPaTxTMg f4ygdSoKT1z2QrEtY9+1LiJ9FIBDGzW+ywfW1LkjHGoJ5PVOTWen2EF0vkJf65zQD4WtD7 gje1u1lF8zfRMj/Y7hHi/gpT0XqxTl1kIg6IqTkherN4jtHsjGcG6I7TUIBsGzptAVbMN+ ZUS7u8I+4WLOHlZuIeXz9yD/hyYLkaBjPa3ip7qJW/Kq6oYUmrw6acMzq86jfcbyVH0z3q NC10i44ba82505q9o9Y0XNrblTJS8+qaILnA/ZRutYLXP2HbfJecFctBr0cHOw== 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 4XHFYT284XznDW; Mon, 30 Sep 2024 09:06:21 +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 48U96LB0031584; Mon, 30 Sep 2024 09:06:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48U96L0u031581; Mon, 30 Sep 2024 09:06:21 GMT (envelope-from git) Date: Mon, 30 Sep 2024 09:06:21 GMT Message-Id: <202409300906.48U96L0u031581@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: 3ec4fbdd98f2 - main - pf tests: Add test for max-src-states 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: 3ec4fbdd98f21463c8d12f1468a07f45100680cf Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=3ec4fbdd98f21463c8d12f1468a07f45100680cf commit 3ec4fbdd98f21463c8d12f1468a07f45100680cf Author: Kajetan Staszkiewicz AuthorDate: 2024-09-28 21:24:47 +0000 Commit: Kristof Provost CommitDate: 2024-09-30 07:48:40 +0000 pf tests: Add test for max-src-states Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D46840 --- tests/sys/netpfil/pf/src_track.sh | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/sys/netpfil/pf/src_track.sh b/tests/sys/netpfil/pf/src_track.sh index eb053dd84a90..2038393a240e 100755 --- a/tests/sys/netpfil/pf/src_track.sh +++ b/tests/sys/netpfil/pf/src_track.sh @@ -120,8 +120,74 @@ max_src_conn_rule_cleanup() pft_cleanup } +max_src_states_rule_head() +{ + atf_set descr 'Max states per source per rule' + atf_set require.user root +} + +max_src_states_rule_body() +{ + setup_router_server_ipv6 + + # Clients will connect from another network behind the router. + # This allows for using multiple source addresses and for tester jail + # to not respond with RST packets for SYN+ACKs. + jexec router route add -6 2001:db8:44::0/64 2001:db8:42::2 + jexec server route add -6 2001:db8:44::0/64 2001:db8:43::1 + + pft_set_rules router \ + "block" \ + "pass inet6 proto icmp6 icmp6-type { neighbrsol, neighbradv }" \ + "pass in on ${epair_tester}b inet6 proto tcp from port 4210:4219 keep state (max-src-states 3 source-track rule) label rule_A" \ + "pass in on ${epair_tester}b inet6 proto tcp from port 4220:4229 keep state (max-src-states 3 source-track rule) label rule_B" \ + "pass out on ${epair_server}a keep state" + + # The option max-src-states prevents even the initial SYN packet going + # through. It's enough that we check ping_server_check_reply, no need to + # bother checking created states. + + # 2 connections from host ::1 matching rule_A will be allowed, 1 will fail to create a state. + ping_server_check_reply exit:0 --ping-type=tcp3way --send-sport=4211 --fromaddr 2001:db8:44::1 + ping_server_check_reply exit:0 --ping-type=tcp3way --send-sport=4212 --fromaddr 2001:db8:44::1 + ping_server_check_reply exit:1 --ping-type=tcp3way --send-sport=4213 --fromaddr 2001:db8:44::1 + + # 2 connections from host ::1 matching rule_B will be allowed, 1 will fail to create a state. + # Limits from rule_A don't interfere with rule_B. + ping_server_check_reply exit:0 --ping-type=tcp3way --send-sport=4221 --fromaddr 2001:db8:44::1 + ping_server_check_reply exit:0 --ping-type=tcp3way --send-sport=4222 --fromaddr 2001:db8:44::1 + ping_server_check_reply exit:1 --ping-type=tcp3way --send-sport=4223 --fromaddr 2001:db8:44::1 + + # 2 connections from host ::2 matching rule_B will be allowed, 1 will fail to create a state. + # Limits for host ::1 will not interfere with host ::2. + ping_server_check_reply exit:0 --ping-type=tcp3way --send-sport=4224 --fromaddr 2001:db8:44::2 + ping_server_check_reply exit:0 --ping-type=tcp3way --send-sport=4225 --fromaddr 2001:db8:44::2 + ping_server_check_reply exit:1 --ping-type=tcp3way --send-sport=4226 --fromaddr 2001:db8:44::2 + + # We will check the resulting source nodes, though. + # Order of source nodes in output is not guaranteed, find each one separately. + nodes=$(mktemp) || exit 1 + jexec router pfctl -qvsS > $nodes + for node_regexp in \ + '2001:db8:44::1 -> :: \( states 2, connections 2, rate [0-9/\.]+s \)\s+age [0-9:]+, 6 pkts, [0-9]+ bytes, filter rule 3' \ + '2001:db8:44::1 -> :: \( states 2, connections 2, rate [0-9/\.]+s \)\s+age [0-9:]+, 6 pkts, [0-9]+ bytes, filter rule 4' \ + '2001:db8:44::2 -> :: \( states 2, connections 2, rate [0-9/\.]+s \)\s+age [0-9:]+, 6 pkts, [0-9]+ bytes, filter rule 4' \ + ; do + cat $nodes | tr '\n' ' ' | grep -qE "$node_regexp" || atf_fail "Source nodes not matching expected output" + done + + # Check if limit counters have been properly set. + jexec router pfctl -qvvsi | grep -qE 'max-src-states\s+3\s+' || atf_fail "max-src-states not set to 3" +} + +max_src_states_rule_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "source_track" atf_add_test_case "max_src_conn_rule" + atf_add_test_case "max_src_states_rule" }