3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright 2022 John-Mark Gurney
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # make WITH_TESTS=yes -j 4 all install && kyua test -k /usr/tests/Kyuafile sbin/dhclient/pcp
35 # kyua report --verbose -r $(ls -tr ~/.kyua/store/results.*.db | tail -n 1)
37 . $(atf_get_srcdir)/../../sys/common/vnet.subr
39 generic_dhcp_cleanup()
43 kill $(cat dhclient.test.pid) $(cat dhcpd.pid)
46 rm -f dhclient.dhcpd.conf lease.dhclient.test dhclient.test.pid
51 atf_test_case normal cleanup
54 atf_set descr 'test dhclient against a server'
55 atf_set require.user root
62 if ! [ -x "$dhcpd" ]; then
63 atf_skip "ISC dhcp server (isc-dhcp44-server) not installed"
70 vnet_mkjail dhclient_normal_test ${epair}b
72 # Set IP on server iface
73 ifconfig ${epair}a 192.0.2.2/24 up
75 # Create dhcp server config
76 cat > dhclient.dhcpd.conf << EOF
77 default-lease-time 36000;
80 subnet 192.0.2.0 netmask 255.255.255.0 {
81 range 192.0.2.10 192.0.2.10;
82 option routers 192.0.2.2;
83 option domain-name-servers 192.0.2.2;
88 touch dhcpd.leases.conf
89 atf_check -e ignore ${dhcpd} -cf ./dhclient.dhcpd.conf -lf ./dhcpd.leases.conf -pf ./dhcpd.pid ${epair}a
91 # Expect that we get an IP assigned
92 atf_check -e match:'DHCPACK from 192.0.2.2' jexec dhclient_normal_test dhclient -c /dev/null -l ./lease.dhclient.test -p ./dhclient.test.pid ${epair}b
94 # And it's the correct one
95 atf_check -o match:'inet 192.0.2.10' jexec dhclient_normal_test ifconfig ${epair}b
105 atf_test_case pcp cleanup
108 atf_set descr 'test dhclient on pcp interface'
109 atf_set require.user root
116 if ! [ -x "$dhcpd" ]; then
117 atf_skip "ISC dhcp server (isc-dhcp44-server) not installed"
122 epair=$(vnet_mkepair)
124 # Server side needs to be up to pass packets
125 ifconfig ${epair}a up
127 # Make sure necessary netgraph modules are loaded
128 kldstat -q -n ng_ether || kldload ng_ether
129 kldstat -q -n ng_iface || kldload ng_iface
130 kldstat -q -n ng_vlan || kldload ng_vlan
132 # create vlan, and attach epair to it (has incoming/outgoing vlan
134 ngctl mkpeer ${epair}a: vlan lower downstream
136 # create new interface on other side of vlan (untagged/pcp)
137 ngctl mkpeer ${epair}a:lower. eiface vlan0 ether
139 # get the interface created
140 ngiface=$(ngctl show ${epair}a:lower.vlan0 | head -n 1 | awk '{ print $2}')
142 # schedule it for clean up
143 echo ${ngiface} >> ngctl.shutdown
145 # set the filter on it
146 ngctl msg ${epair}a:lower. 'addfilter { vlan=0 hook="vlan0" }'
148 vnet_mkjail dhclient_pcp_test ${epair}b
150 # Set IP on server iface
151 ifconfig ${ngiface} up 192.0.2.2/24
154 jexec dhclient_pcp_test ifconfig ${epair}b pcp 0 up
156 # Create dhcp server config
157 cat > dhclient.dhcpd.conf << EOF
158 default-lease-time 36000;
159 max-lease-time 86400;
161 subnet 192.0.2.0 netmask 255.255.255.0 {
162 range 192.0.2.10 192.0.2.10;
163 option routers 192.0.2.2;
164 option domain-name-servers 192.0.2.2;
169 touch dhcpd.leases.conf
170 atf_check -e ignore ${dhcpd} -cf ./dhclient.dhcpd.conf -lf ./dhcpd.leases.conf -pf ./dhcpd.pid ${ngiface}
172 # Expect that we get an IP assigned
173 atf_check -e match:'DHCPACK from 192.0.2.2' jexec dhclient_pcp_test dhclient -c /dev/null -l ./lease.dhclient.test -p ./dhclient.test.pid ${epair}b
175 # And it's the correct one
176 atf_check -o match:'inet 192.0.2.10' jexec dhclient_pcp_test ifconfig ${epair}b
184 # Clean up netgraph nodes
185 for i in $(cat ngctl.shutdown); do
191 atf_init_test_cases()
193 atf_add_test_case normal
194 atf_add_test_case pcp