git: 9a2b4665958e - stable/14 - route: introduce add interface route test cases

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Thu, 14 Mar 2024 09:54:50 UTC
The branch stable/14 has been updated by zlei:

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

commit 9a2b4665958e25eccf06a3b8445eacc24c5be379
Author:     R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2023-11-28 18:18:15 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-03-14 09:52:50 +0000

    route: introduce add interface route test cases
    
    As a followup to D41330 and D41436, this patch introduces two new tests
    for sbin/route: interface_route_v[46].
    
    These tests fail without D41330.
    
    Reviewed by:    kp
    Approved by:    kp (mentor)
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit ca7edd0d2c339b8e6e5e52257ea6d4f22db02550)
---
 sbin/route/tests/basic.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/sbin/route/tests/basic.sh b/sbin/route/tests/basic.sh
index bb432daa0793..2e2ab9dba97f 100644
--- a/sbin/route/tests/basic.sh
+++ b/sbin/route/tests/basic.sh
@@ -117,8 +117,66 @@ basic_v6_cleanup()
 	vnet_cleanup
 }
 
+atf_test_case "interface_route_v4" "cleanup"
+interface_route_v4_head()
+{
+	atf_set descr 'add interface route for v4'
+	atf_set require.user root
+	atf_set require.progs jail jq
+}
+
+interface_route_v4_body()
+{
+	epair=$(vnet_mkepair)
+	ifconfig ${epair}a up
+	vnet_mkjail alcatraz ${epair}b
+
+	# add interface route
+	jexec alcatraz route add "192.0.2.1" -iface ${epair}b
+	gateway=$(check_route "alcatraz" "192.0.2.1")
+
+	if [ -z "${gateway}" ]; then
+		atf_fail "Failed to add interface route."
+	fi
+}
+
+interface_route_v4_cleanup()
+{
+	vnet_cleanup
+}
+
+atf_test_case "interface_route_v6" "cleanup"
+interface_route_v6_head()
+{
+	atf_set descr 'add interface route for v6'
+	atf_set require.user root
+	atf_set require.progs jail jq
+}
+
+interface_route_v6_body()
+{
+	epair=$(vnet_mkepair)
+	ifconfig ${epair}a up
+	vnet_mkjail alcatraz ${epair}b
+
+	# add interface route
+	jexec alcatraz route add -6 "2001:db8:cc4b::1" -iface ${epair}b
+	gateway=$(check_route "alcatraz" "2001:db8:cc4b::1")
+
+	if [ -z "${gateway}" ]; then
+		atf_fail "Failed to add interface route."
+	fi
+}
+
+interface_route_v6_cleanup()
+{
+	vnet_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "basic_v4"
 	atf_add_test_case "basic_v6"
+	atf_add_test_case "interface_route_v4"
+	atf_add_test_case "interface_route_v6"
 }