git: a7a273546e38 - main - if_ovpn tests: test multiple simultaneous clients

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 28 Jun 2022 11:59:41 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=a7a273546e389af8fab3b7d9cc6c449a2ab4f84e

commit a7a273546e389af8fab3b7d9cc6c449a2ab4f84e
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-06-15 08:56:49 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-06-28 11:51:41 +0000

    if_ovpn tests: test multiple simultaneous clients
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 tests/sys/net/if_ovpn/if_ovpn.sh | 112 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)

diff --git a/tests/sys/net/if_ovpn/if_ovpn.sh b/tests/sys/net/if_ovpn/if_ovpn.sh
index 49266c6597e6..280897031a6d 100644
--- a/tests/sys/net/if_ovpn/if_ovpn.sh
+++ b/tests/sys/net/if_ovpn/if_ovpn.sh
@@ -401,6 +401,117 @@ timeout_client_cleanup()
 	ovpn_cleanup
 }
 
+atf_test_case "multi_client" "cleanup"
+multi_client_head()
+{
+	atf_set descr 'Multiple simultaneous clients'
+	atf_set require.user root
+	atf_set require.progs openvpn
+}
+
+multi_client_body()
+{
+	ovpn_init
+
+	bridge=$(vnet_mkbridge)
+	srv=$(vnet_mkepair)
+	one=$(vnet_mkepair)
+	two=$(vnet_mkepair)
+
+	ifconfig ${bridge} up
+
+	ifconfig ${srv}a up
+	ifconfig ${bridge} addm ${srv}a
+	ifconfig ${one}a up
+	ifconfig ${bridge} addm ${one}a
+	ifconfig ${two}a up
+	ifconfig ${bridge} addm ${two}a
+
+	vnet_mkjail srv ${srv}b
+	jexec srv ifconfig ${srv}b 192.0.2.1/24 up
+	vnet_mkjail one ${one}b
+	jexec one ifconfig ${one}b 192.0.2.2/24 up
+	vnet_mkjail two ${two}b
+	jexec two ifconfig ${two}b 192.0.2.3/24 up
+
+	# Sanity checks
+	atf_check -s exit:0 -o ignore jexec one ping -c 1 192.0.2.1
+	atf_check -s exit:0 -o ignore jexec two ping -c 1 192.0.2.1
+
+	jexec srv sysctl net.inet.ip.forwarding=1
+
+	ovpn_start srv "
+		dev ovpn0
+		dev-type tun
+		proto udp4
+
+		cipher AES-256-GCM
+		auth SHA256
+
+		local 192.0.2.1
+		server 198.51.100.0 255.255.255.0
+		ca $(atf_get_srcdir)/ca.crt
+		cert $(atf_get_srcdir)/server.crt
+		key $(atf_get_srcdir)/server.key
+		dh $(atf_get_srcdir)/dh.pem
+
+		mode server
+		duplicate-cn
+		script-security 2
+		auth-user-pass-verify /usr/bin/true via-env
+		topology subnet
+
+		keepalive 100 600
+	"
+	ovpn_start one "
+		dev tun0
+		dev-type tun
+
+		client
+
+		remote 192.0.2.1
+		auth-user-pass $(atf_get_srcdir)/user.pass
+
+		ca $(atf_get_srcdir)/ca.crt
+		cert $(atf_get_srcdir)/client.crt
+		key $(atf_get_srcdir)/client.key
+		dh $(atf_get_srcdir)/dh.pem
+
+		keepalive 100 600
+	"
+	ovpn_start two "
+		dev tun0
+		dev-type tun
+
+		client
+
+		remote 192.0.2.1
+		auth-user-pass $(atf_get_srcdir)/user.pass
+
+		ca $(atf_get_srcdir)/ca.crt
+		cert $(atf_get_srcdir)/client.crt
+		key $(atf_get_srcdir)/client.key
+		dh $(atf_get_srcdir)/dh.pem
+
+		keepalive 100 600
+	"
+
+	# Give the tunnel time to come up
+	sleep 10
+
+	atf_check -s exit:0 -o ignore jexec one ping -c 3 198.51.100.1
+	atf_check -s exit:0 -o ignore jexec two ping -c 3 198.51.100.1
+
+	# Client-to-client communication
+	atf_check -s exit:0 -o ignore jexec one ping -c 3 198.51.100.3
+	atf_check -s exit:0 -o ignore jexec two ping -c 3 198.51.100.2
+}
+
+multi_client_cleanup()
+{
+	ovpn_cleanup
+}
+
 atf_test_case "route_to" "cleanup"
 route_to_head()
 {
@@ -576,6 +687,7 @@ atf_init_test_cases()
 	atf_add_test_case "6in6"
 	atf_add_test_case "4in6"
 	atf_add_test_case "timeout_client"
+	atf_add_test_case "multi_client"
 	atf_add_test_case "route_to"
 	atf_add_test_case "chacha"
 }