xref: /freebsd/sbin/route/tests/basic.sh (revision cd3a777bca91669fc4711d1eff66c40f3f62a223)
1#-
2# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3#
4# Copyright (c) 2020 Ahsan Barkati
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD$
28#
29
30. $(atf_get_srcdir)/utils.subr
31
32atf_test_case "basic_v4" "cleanup"
33basic_v4_head()
34{
35	atf_set descr 'add/change/delete route test for v4'
36	atf_set require.user root
37	atf_set require.progs jail jq
38}
39
40basic_v4_body()
41{
42	epair=$(vnet_mkepair)
43	ifconfig ${epair}a 192.0.2.2/24 up
44	vnet_mkjail alcatraz ${epair}b
45	jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
46
47	# add a new route in the jail
48	jexec alcatraz route add 192.0.2.3 192.0.2.2
49	gateway=$(check_route "alcatraz" "192.0.2.3")
50
51	if [ "${gateway}" != "192.0.2.2" ]; then
52		atf_fail "Failed to add new route."
53	fi
54
55	# change the added route
56	jexec alcatraz route change 192.0.2.3 192.0.2.4
57	gateway=$(check_route "alcatraz" "192.0.2.3")
58
59	if [ "${gateway}" != "192.0.2.4" ]; then
60		atf_fail "Failed to change route."
61	fi
62
63	# delete the route
64	jexec alcatraz route delete 192.0.2.3
65	gateway=$(check_route "alcatraz" "192.0.2.3")
66
67	if [ "${gateway}" != "" ]; then
68		atf_fail "Failed to delete route."
69	fi
70}
71
72basic_v4_cleanup()
73{
74	vnet_cleanup
75}
76
77atf_test_case "basic_v6" "cleanup"
78basic_v6_head()
79{
80	atf_set descr 'add/change/delete route test for v6'
81	atf_set require.user root
82	atf_set require.progs jail jq
83}
84
85basic_v6_body()
86{
87	epair=$(vnet_mkepair)
88	ifconfig ${epair}a inet6 2001:db8:cc4b::1/64 up no_dad
89	vnet_mkjail alcatraz ${epair}b
90	jexec alcatraz ifconfig ${epair}b inet6 2001:db8:cc4b::2/64 up no_dad
91
92	# add a new route in the jail
93	jexec alcatraz route add -6 2001:db8:cc4b::3 2001:db8:cc4b::1
94	gateway=$(check_route "alcatraz" "2001:db8:cc4b::3")
95
96	if [ "${gateway}" != "2001:db8:cc4b::1" ]; then
97		atf_fail "Failed to add new route."
98	fi
99
100	# change the added route
101	jexec alcatraz route change -6 2001:db8:cc4b::3 2001:db8:cc4b::4
102	gateway=$(check_route "alcatraz" "2001:db8:cc4b::3")
103	if [ "${gateway}" != "2001:db8:cc4b::4" ]; then
104		atf_fail "Failed to change route."
105	fi
106
107	# delete the route
108	jexec alcatraz route -6 delete 2001:db8:cc4b::3
109	gateway=$(check_route "alcatraz" "2001:db8:cc4b::3")
110
111	if [ "${gateway}" != "" ]; then
112		atf_fail "Failed to delete route."
113	fi
114}
115
116basic_v6_cleanup()
117{
118	vnet_cleanup
119}
120
121atf_init_test_cases()
122{
123	atf_add_test_case "basic_v4"
124	atf_add_test_case "basic_v6"
125}
126