git: fe701c39e8aa - main - if_tun: Add basic connectivity test with nc tun support

From: Tom Jones <thj_at_FreeBSD.org>
Date: Tue, 17 Jan 2023 10:07:03 UTC
The branch main has been updated by thj:

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

commit fe701c39e8aa270a71b5010a1eb4b488a80dcae5
Author:     Tom Jones <thj@FreeBSD.org>
AuthorDate: 2023-01-17 10:05:00 +0000
Commit:     Tom Jones <thj@FreeBSD.org>
CommitDate: 2023-01-17 10:05:50 +0000

    if_tun: Add basic connectivity test with nc tun support
    
    Reviewed by:    kevans
    Sponsored by:   Zenarmor
    Sponsored by:   OPNsense
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D37435
---
 tests/sys/net/if_tun_test.sh | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/tests/sys/net/if_tun_test.sh b/tests/sys/net/if_tun_test.sh
index 64dc004e3a06..5f05ac7c5eff 100755
--- a/tests/sys/net/if_tun_test.sh
+++ b/tests/sys/net/if_tun_test.sh
@@ -2,7 +2,7 @@
 
 . $(atf_get_srcdir)/../common/vnet.subr
 
-atf_test_case "235704" "cleanup"
+atf_test_case "235704" "basic" "cleanup"
 235704_head()
 {
 	atf_set descr "Test PR #235704"
@@ -24,7 +24,44 @@ atf_test_case "235704" "cleanup"
 	vnet_cleanup
 }
 
+basic_head()
+{
+	atf_set descr "Test if_tun using nc"
+	atf_set require.user root
+}
+
+basic_body()
+{
+	vnet_init
+
+	epair=$(vnet_mkepair)
+
+	tun_duke=$(ifconfig tun create)
+	tun_bass=$(ifconfig tun create)
+
+	vnet_mkjail duke ${epair}a ${tun_duke}
+	vnet_mkjail bass ${epair}b ${tun_bass}
+
+	jexec duke ifconfig ${epair}a inet 10.0.0.1/24 up
+	jexec bass ifconfig ${epair}b inet 10.0.0.2/24 up
+
+	jexec duke nc -u -l --tun /dev/${tun_duke} 10.0.0.1 2600 &
+	jexec bass nc -u --tun /dev/${tun_bass} 10.0.0.1 2600 &
+
+	jexec duke ifconfig ${tun_duke} inet 10.100.0.1/24 10.100.0.2 up
+	jexec bass ifconfig ${tun_bass} inet 10.100.0.2/24 10.100.0.1 up
+
+	atf_check -s exit:0 -o ignore \
+		jexec bass ping -c 1 10.100.0.1
+}
+
+basic_clean()
+{
+	vnet_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "235704"
+	atf_add_test_case "basic"
 }