From nobody Mon Feb 13 06:10:30 2023 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 4PFYqC1mrfz3rBNY; Mon, 13 Feb 2023 06:10:31 +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 4PFYqC1DpTz4DlD; Mon, 13 Feb 2023 06:10:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676268631; 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=7OS9i8x5OH1kOMAEWBot5fO7WRdxkUmpm3ekL/0VOnc=; b=UpAR827+d39J1Icp/6HNdgvR31CEe8jykmGox73N6Zj9YqPaPjpv+0MFX6feqgvBT8QyDR xvO3ONATOgy6GD6MTc+F+0AvPiDBEwJUpKKTFTCTQ3wAnYlWROOGUbvkpPEZRiHrWgs1i2 UsvYbFJCxSHg0nmwe2xp0IjPRzRejH6Ygj1LSqARnU2WWrAMt92n+cgN4FdnFf3FeTYXcu RK3sCHqmJECDsf2UY2bXahCL2quhh+ccz2r+U5/wo5LyZRu0ILyvrPPpA848mTFdcGzV/2 VF/9zfq+Kdij7Y8cgSh36fRzNPzW3Hz/SQY+K4+o3337BBVN7Aapv/r7m7iZkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676268631; 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=7OS9i8x5OH1kOMAEWBot5fO7WRdxkUmpm3ekL/0VOnc=; b=yDT3JDfaGOor9KnNvwKuCPE/WYMzae9JIP5cYOE1WNKra3/RVidZ/lLQIHxBEMtB+EV1Tu EgLqyd11BhDeW47MJoZptB8SY3aEYVwI7xDm+8JOj2DEDkUH+7CMPevnfFCjmG4H/kc4n0 pn3K4gXGeNNlItC5wQFhagN05V9ILIiXRIvTDZPNsiWneAs+UWtFzGfW8sH/KGOa5mX/Gq f+2fttuetLr1x637+TruPypHAphOw6SRF3n806EfyKT4WfyDO8DsMivX9g5CtmEZSrT4Un +hN5jzdHGfc2kSazedm9uWN9cUkuHq9BtLgEDBIH+JM5lqSoOBh+avACfS4psg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676268631; a=rsa-sha256; cv=none; b=TP07ngM0YtU1ZWHmtr4bn6q05UWVxFXxkfF8kl3ajWAhKS8GUj73R1WWhL5mOdM3YmyINH x6OUOya3nvigXjvHq7doDLGFn0zvFQb6XxomtWhJkvb/h+ywghQfubmUyGJKNULqQpxah9 uqKZQPZ0xlyZkfwydN5gTkP2pWcyDgLJsSh1p/JCY+wBgStsfp2jaKE+gVKARgVFprndtJ p9a2D5g27oMEpq4bV3HG7QUmx0nO5/DkojYh8ih6ceKcp0iMIJrVDVP0DpwBgHXRJupFoG QgzmE6KDY9x58li4CzhnnZhMmcc8HKPtHGFE5dIONyp1mg42oYN0ZjXQQz4ulg== 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 4PFYqC0HJhz16Pl; Mon, 13 Feb 2023 06:10:31 +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 31D6AU2A076642; Mon, 13 Feb 2023 06:10:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31D6AUHe076641; Mon, 13 Feb 2023 06:10:30 GMT (envelope-from git) Date: Mon, 13 Feb 2023 06:10:30 GMT Message-Id: <202302130610.31D6AUHe076641@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 96f4ab26633a - main - wg: add a test for the home jail socket 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 96f4ab26633a457c52fdb9c45f48dcb052b408a4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=96f4ab26633a457c52fdb9c45f48dcb052b408a4 commit 96f4ab26633a457c52fdb9c45f48dcb052b408a4 Author: Kyle Evans AuthorDate: 2023-02-13 05:59:20 +0000 Commit: Kyle Evans CommitDate: 2023-02-13 05:59:35 +0000 wg: add a test for the home jail socket feature This adds a test for a semantic that we added to mirror a feature of the Linux implementation w/ netns: if a wg interface is moved into a jail, we still create the socket in the context of the home vnet. With this added, one can actually create vnet jails that only have a wg tunnel to the outside world providing network connectivity without any epairs in the setup. Reviewed by: jhb, markj (both earlier version) Differential Revision: https://reviews.freebsd.org/D37755 --- tests/sys/net/if_wg.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/sys/net/if_wg.sh b/tests/sys/net/if_wg.sh index 1612e05ef168..80461127fde7 100644 --- a/tests/sys/net/if_wg.sh +++ b/tests/sys/net/if_wg.sh @@ -189,9 +189,81 @@ wg_key_peerdev_makeshared_cleanup() vnet_cleanup } +# The kernel is expected to create the wg socket in the jail context that the +# wg interface was created in, even if the interface is moved to a different +# vnet. +atf_test_case "wg_vnet_parent_routing" "cleanup" +wg_vnet_parent_routing_head() +{ + atf_set descr 'Create a wg(4) tunnel without epairs and pass traffic between jails' + atf_set require.user root +} + +wg_vnet_parent_routing_body() +{ + local pri1 pri2 pub1 pub2 wg1 wg2 + local tunnel1 tunnel2 + + kldload -n if_wg + + pri1=$(wg genkey) + pri2=$(wg genkey) + + tunnel1=169.254.0.1 + tunnel2=169.254.0.2 + + vnet_init + + wg1=$(ifconfig wg create) + wg2=$(ifconfig wg create) + + vnet_mkjail wgtest1 ${wg1} + vnet_mkjail wgtest2 ${wg2} + + echo "$pri1" | jexec wgtest1 wg set $wg1 listen-port 12345 \ + private-key /dev/stdin + pub1=$(jexec wgtest1 wg show $wg1 public-key) + echo "$pri2" | jexec wgtest2 wg set $wg2 listen-port 12346 \ + private-key /dev/stdin + pub2=$(jexec wgtest2 wg show $wg2 public-key) + + atf_check -s exit:0 -o ignore \ + jexec wgtest1 wg set $wg1 peer "$pub2" \ + endpoint 127.0.0.1:12346 allowed-ips ${tunnel2}/32 + atf_check -s exit:0 \ + jexec wgtest1 ifconfig $wg1 inet ${tunnel1}/24 up + + atf_check -s exit:0 -o ignore \ + jexec wgtest2 wg set $wg2 peer "$pub1" \ + endpoint 127.0.0.1:12345 allowed-ips ${tunnel1}/32 + atf_check -s exit:0 \ + jexec wgtest2 ifconfig $wg2 inet ${tunnel2}/24 up + + # Sanity check ICMP counters; should clearly be nothing on these new + # jails. We'll check them as we go to ensure that the ICMP packets + # generated really are being handled by the jails' vnets. + atf_check -o not-match:"histogram" jexec wgtest1 netstat -s -p icmp + atf_check -o not-match:"histogram" jexec wgtest2 netstat -s -p icmp + + # Generous timeout since the handshake takes some time. + atf_check -s exit:0 -o ignore jexec wgtest1 ping -c 1 -t 5 $tunnel2 + atf_check -o match:"echo reply: 1" jexec wgtest1 netstat -s -p icmp + atf_check -o match:"echo: 1" jexec wgtest2 netstat -s -p icmp + + atf_check -s exit:0 -o ignore jexec wgtest2 ping -c 1 $tunnel1 + atf_check -o match:"echo reply: 1" jexec wgtest2 netstat -s -p icmp + atf_check -o match:"echo: 1" jexec wgtest1 netstat -s -p icmp +} + +wg_vnet_parent_routing_cleanup() +{ + vnet_cleanup +} + atf_init_test_cases() { atf_add_test_case "wg_basic" atf_add_test_case "wg_key_peerdev_shared" atf_add_test_case "wg_key_peerdev_makeshared" + atf_add_test_case "wg_vnet_parent_routing" }