git: 188e0696705f - main - if_ovpn tests: test explicit exit notifications

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 18 Oct 2022 08:23:13 UTC
The branch main has been updated by kp:

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

commit 188e0696705fecd6f063b41b61b7dc4b6a3b0343
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-10-17 15:42:35 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-10-18 08:12:22 +0000

    if_ovpn tests: test explicit exit notifications
    
    Test that when a client exits the server notices this, even without
    keepalive traffic.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 tests/sys/net/if_ovpn/if_ovpn.sh | 87 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/tests/sys/net/if_ovpn/if_ovpn.sh b/tests/sys/net/if_ovpn/if_ovpn.sh
index bc1d3a85c987..531a4fc2c856 100644
--- a/tests/sys/net/if_ovpn/if_ovpn.sh
+++ b/tests/sys/net/if_ovpn/if_ovpn.sh
@@ -475,6 +475,92 @@ timeout_client_cleanup()
 	ovpn_cleanup
 }
 
+atf_test_case "explicit_exit" "cleanup"
+explicit_exit_head()
+{
+	atf_set descr 'Text explicit exit notification'
+	atf_set require.user root
+	atf_set require.progs openvpn
+}
+
+explicit_exit_body()
+{
+	ovpn_init
+
+	l=$(vnet_mkepair)
+
+	vnet_mkjail a ${l}a
+	jexec a ifconfig ${l}a 192.0.2.1/24 up
+	jexec a ifconfig lo0 127.0.0.1/8 up
+	vnet_mkjail b ${l}b
+	jexec b ifconfig ${l}b 192.0.2.2/24 up
+
+	# Sanity check
+	atf_check -s exit:0 -o ignore jexec a ping -c 1 192.0.2.2
+
+	ovpn_start a "
+		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
+		script-security 2
+		auth-user-pass-verify /usr/bin/true via-env
+		topology subnet
+
+		management 192.0.2.1 1234
+	"
+	ovpn_start b "
+		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
+
+		explicit-exit-notify
+	"
+
+	# Give the tunnel time to come up
+	sleep 10
+
+	atf_check -s exit:0 -o ignore jexec b ping -c 3 198.51.100.1
+
+	if ! echo "status" | jexec a nc -N 192.0.2.1 1234 | grep 192.0.2.2; then
+		atf_fail "Client not found in status list!"
+	fi
+
+	# Kill the client
+	jexec b killall openvpn
+
+	while echo "status" | jexec a nc -N 192.0.2.1 1234 | grep 192.0.2.2; do
+		jexec a ps auxf
+		echo "Client disconnect not discovered"
+		sleep 1
+	done
+}
+
+explicit_exit_cleanup()
+{
+	ovpn_cleanup
+}
+
 atf_test_case "multi_client" "cleanup"
 multi_client_head()
 {
@@ -909,6 +995,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 "explicit_exit"
 	atf_add_test_case "multi_client"
 	atf_add_test_case "route_to"
 	atf_add_test_case "ra"