xref: /freebsd/sbin/ifconfig/tests/inet6.sh (revision 9f0f30bc1f5f08d25243952bad3fdc6e13a75c2a)
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_init_test_cases()
80{
81	atf_add_test_case netmask
82	atf_add_test_case broadcast
83}
84