xref: /freebsd/sbin/ifconfig/tests/inet6.sh (revision df21a004be237a1dccd03c7b47254625eea62fa9)
1# SPDX-License-Identifier: ISC
2#
3# Copyright (c) 2025 Lexi Winter
4
5. $(atf_get_srcdir)/../../sys/common/vnet.subr
6
7# Bug 286910: adding 'netmask' or 'broadcast' to an IPv6 address crashed
8# ifconfig.
9
10atf_test_case "netmask" "cleanup"
11netmask_head()
12{
13	atf_set descr "Test invalid 'netmask' option"
14	atf_set require.user root
15}
16
17netmask_body()
18{
19	vnet_init
20
21	ep=$(vnet_mkepair)
22	vnet_mkjail ifcjail ${ep}a
23
24	# Add the address the wrong way
25	atf_check -s exit:1 \
26	    -e match:"ifconfig: netmask: invalid option for inet6" \
27	    jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1 netmask 64
28
29	# Add the address the correct way
30	atf_check -s exit:0 \
31	    jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1/64
32	atf_check -s exit:0 -o match:"2001:db8:1::1 prefixlen 64" \
33	    jexec ifcjail ifconfig ${ep}a
34
35	# Remove the address the wrong way
36	atf_check -s exit:1 \
37	    -e match:"ifconfig: netmask: invalid option for inet6" \
38	    jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1 netmask 64 -alias
39}
40
41netmask_cleanup()
42{
43	vnet_cleanup
44}
45
46atf_test_case "broadcast" "cleanup"
47broadcast_head()
48{
49	atf_set descr "Test invalid 'broadcast' option"
50	atf_set require.user root
51}
52
53broadcast_body()
54{
55	vnet_init
56
57	ep=$(vnet_mkepair)
58	vnet_mkjail ifcjail ${ep}a
59
60	atf_check -s exit:1 \
61	    -e match:"ifconfig: broadcast: invalid option for inet6" \
62	    jexec ifcjail ifconfig ${ep}a \
63	        inet6 2001:db8:1::1 broadcast 2001:db8:1::ffff
64
65	atf_check -s exit:0 \
66	    jexec ifcjail ifconfig ${ep}a inet6 2001:db8:1::1/64
67
68	atf_check -s exit:1 \
69	    -e match:"ifconfig: broadcast: invalid option for inet6" \
70	    jexec ifcjail ifconfig ${ep}a \
71	        inet6 2001:db8:1::1 broadcast 2001:db:1::ffff -alias
72}
73
74broadcast_cleanup()
75{
76	vnet_cleanup
77}
78
79atf_test_case "delete6" "cleanup"
80delete6_head()
81{
82	atf_set descr 'Test removing IPv6 addresses'
83	atf_set require.user root
84}
85
86delete6_body()
87{
88	vnet_init
89
90	ep=$(vnet_mkepair)
91
92	atf_check -s exit:0 \
93	    ifconfig ${ep}a inet6 fe80::42/64
94	atf_check -s exit:0 -o match:"fe80::42%${ep}" \
95	    ifconfig ${ep}a inet6
96
97	atf_check -s exit:0 \
98	    ifconfig ${ep}a inet6 -alias fe80::42
99	atf_check -s exit:0 -o not-match:"fe80::42%${ep}" \
100	    ifconfig ${ep}a inet6
101}
102
103delete6_cleanup()
104{
105	vnet_cleanup
106}
107
108atf_init_test_cases()
109{
110	atf_add_test_case netmask
111	atf_add_test_case broadcast
112	atf_add_test_case delete6
113}
114