From nobody Mon Aug 25 11:14:32 2025 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 4c9SqY18bWz65d0W; Mon, 25 Aug 2025 11:14:33 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c9SqY0S80z49Qd; Mon, 25 Aug 2025 11:14:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756120473; 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=M5pwqZL/NWkdwKhd7Nbq9BWE5neJC9haeJ1YEZS3p/o=; b=r0wU8Pv/efGJIfBWZinHPylMHGRKaIqtRw3GCLdWyiOCXdCqyCeKiaAyK/EDqe3FcEmr04 GjKS36UsMAkI87N4yKSpQyTdFUMAJQDqhPYA0okxrnQWEpYCIUsA/57IOiqoQ6EqXwexpX r7q/VlhBUQi6AFYMdx9GHyX1trweU2zubq7ibd5k44jjbjeLwDVAu6ETOUFDXX7eN9Vm6P Tx8Tpp3d3mOmD5sCWUzRaVgggMR0gUdz6QR3ONcaRGI/j+WUH+sFe1lK9O4IOV8dyLwVbe fu92rwpZvXDDn9MtRKIgbWIoXy7xaNBRP4M3BGP+XD24o9gKsNPNQ748FiRjBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756120473; 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=M5pwqZL/NWkdwKhd7Nbq9BWE5neJC9haeJ1YEZS3p/o=; b=LrnnepPSQiEccLEMWvlXLjAhdbtyQTX4v5jDUxMijkeESdhcCMawlelqNnlwHMirxjBjjk HdQH2Hido36VtBUFdArwrIOb7HyP4uEPoFlRt4dJIpGydvWuSm5/u5DRMa9/RgwRoInAEu 9DYbvLRXuFlv2WKF74tBceZsBWpEJv4bG+6zUx300f+Loow8k/TPM7vW8mcZQnVyYwq4Lp m9NWyO/YouNsPykzWoC+ln58fKhvgFB9Dco2KQ8MtWxZ4gC5ks02C0ineMt1a7WqB41Nx8 fl2cTHPRyO4jqUNZEeA6JlDLdMw0zl2RBQ8eKxGdDocQhhkWWy4s74rgPtItNw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756120473; a=rsa-sha256; cv=none; b=P36ctoRnabLa6UHY3PPVpgAoJGMHcM3GqS5ukGULjRVTUK1tiKKZMx19AV5fJBbHI8IKLK ekvyk2eJ8zO8ZxMyytk1J6aZuQKA4Jc7wQZALRS1fs3+AUytKIdrYU2TZ8YKvLoRFGoGce mBtL3tD10qctWq2/RK+r6NTR2dIF8rBL0XsIh9b1h5e5lYbyRBSv5yc61faKgKQV3x100U dx7DaQ8ReXeM6M5sPxNOGNyskLj0QIJYMBaLRaPdnlxyzKHuobbTGGZOAuQTqL9qWjMwph y6orU3xSGGkR741Kwm1yYqGWXH7eua8DVf01U+Uu8XynrcIhGfhbf1JfSghHkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4c9SqX73zkznkT; Mon, 25 Aug 2025 11:14:32 +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 57PBEWWh081681; Mon, 25 Aug 2025 11:14:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57PBEWEw081678; Mon, 25 Aug 2025 11:14:32 GMT (envelope-from git) Date: Mon, 25 Aug 2025 11:14:32 GMT Message-Id: <202508251114.57PBEWEw081678@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: d879f1c8961d - main - ipfw: Add tests for the NPTv6 rule parser 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d879f1c8961d99bdbe6727004bfc6c23924526f8 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d879f1c8961d99bdbe6727004bfc6c23924526f8 commit d879f1c8961d99bdbe6727004bfc6c23924526f8 Author: Dag-Erling Smørgrav AuthorDate: 2025-08-21 17:47:41 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-08-25 11:13:27 +0000 ipfw: Add tests for the NPTv6 rule parser --- sbin/ipfw/Makefile | 3 ++ sbin/ipfw/tests/Makefile | 1 + sbin/ipfw/tests/ipfw_test.sh | 107 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) diff --git a/sbin/ipfw/Makefile b/sbin/ipfw/Makefile index bfbe70130de7..418c0f613741 100644 --- a/sbin/ipfw/Makefile +++ b/sbin/ipfw/Makefile @@ -17,6 +17,9 @@ CFLAGS+=-DPF LIBADD= jail util MAN= ipfw.8 +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests + .include CWARNFLAGS+= -Wno-cast-align diff --git a/sbin/ipfw/tests/Makefile b/sbin/ipfw/tests/Makefile index 987410f5d710..e2d4dab2729a 100644 --- a/sbin/ipfw/tests/Makefile +++ b/sbin/ipfw/tests/Makefile @@ -1,5 +1,6 @@ PACKAGE= tests ATF_TESTS_PYTEST+= test_add_rule.py +ATF_TESTS_SH+= ipfw_test .include diff --git a/sbin/ipfw/tests/ipfw_test.sh b/sbin/ipfw/tests/ipfw_test.sh new file mode 100644 index 000000000000..c7993c430a3d --- /dev/null +++ b/sbin/ipfw/tests/ipfw_test.sh @@ -0,0 +1,107 @@ +# +# Copyright (c) 2025 Dag-Erling Smørgrav +# +# SPDX-License-Identifier: BSD-2-Clause +# + +. $(atf_get_srcdir)/../../sys/common/vnet.subr + +atf_test_case nptv6 cleanup +nptv6_head() +{ + atf_set "descr" "Test creation of NPTv6 rules" + atf_set "require.user" "root" + atf_set "require.kmods" "ipfw_nptv6" +} +nptv6_body() +{ + vnet_init + local jail=ipfw_$(atf_get ident) + local epair=$(vnet_mkepair) + vnet_mkjail ${jail} ${epair}a + + local rule="xyzzy" + local int="2001:db8:1::" + local ext="2001:db8:2::" + + atf_check jexec ${jail} \ + ifconfig "${epair}"a inet6 ${ext}1/64 up + + # This is how it's supposed to be used + atf_check jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int} ext_prefix ${ext} prefixlen 64 + atf_check -o inline:\ +"nptv6 $rule int_prefix $int ext_prefix $ext prefixlen 64\n" \ + jexec ${jail} ipfw nptv6 all list + atf_check jexec ${jail} ipfw nptv6 all destroy + + # Specify external interface rather than network + atf_check jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int} ext_if ${epair}a prefixlen 64 + atf_check -o inline:\ +"nptv6 $rule int_prefix $int ext_if ${epair}a prefixlen 64\n" \ + jexec ${jail} ipfw nptv6 all list + atf_check jexec ${jail} ipfw nptv6 all destroy + + # This should also work + atf_check jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int}/64 ext_prefix ${ext}/64 prefixlen 64 + atf_check -o inline:\ +"nptv6 $rule int_prefix $int ext_prefix $ext prefixlen 64\n" \ + jexec ${jail} ipfw nptv6 all list + atf_check jexec ${jail} ipfw nptv6 all destroy + + # This should also work, although it's not encouraged + atf_check -e match:"use prefixlen instead" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int}/64 ext_prefix ${ext}/64 + atf_check -o inline:\ +"nptv6 $rule int_prefix $int ext_prefix $ext prefixlen 64\n" \ + jexec ${jail} ipfw nptv6 all list + atf_check jexec ${jail} ipfw nptv6 all destroy + + # These should all fail + atf_check -s not-exit:0 -e match:"one ext_prefix or ext_if" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int} ext_prefix ${ext} ext_if ${epair}a + atf_check -o empty jexec ${jail} ipfw nptv6 all list + + atf_check -s not-exit:0 -e match:"one ext_prefix or ext_if" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int} ext_if ${epair}a ext_prefix ${ext} + atf_check -o empty jexec ${jail} ipfw nptv6 all list + + atf_check -s not-exit:0 -e match:"prefix length mismatch" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int}/48 ext_prefix ${ext}/64 + atf_check -o empty jexec ${jail} ipfw nptv6 all list + + atf_check -s not-exit:0 -e match:"prefix length mismatch" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int}/64 ext_prefix ${ext}/64 prefixlen 48 + atf_check -o empty jexec ${jail} ipfw nptv6 all list + + atf_check -s not-exit:0 -e match:"prefix length mismatch" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int}/64 ext_prefix ${ext} prefixlen 48 + atf_check -o empty jexec ${jail} ipfw nptv6 all list + + atf_check -s not-exit:0 -e match:"prefix length mismatch" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int} ext_prefix ${ext}/64 prefixlen 48 + atf_check -o empty jexec ${jail} ipfw nptv6 all list + + atf_check -s not-exit:0 -e match:"prefix length mismatch" \ + jexec ${jail} ipfw nptv6 ${rule} create \ + int_prefix ${int}/64 ext_if ${epair}a prefixlen 48 + atf_check -o empty jexec ${jail} ipfw nptv6 all list +} +nptv6_cleanup() +{ + vnet_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case nptv6 +}