xref: /aosp_15_r20/external/ltp/testcases/network/dhcp/dhcpd_tests.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2014-2018 Oracle and/or its affiliates. All Rights Reserved.
4# Copyright (c) 2018 Petr Vorel <[email protected]>
5# Copyright (c) International Business Machines  Corp., 2001
6#
7# Author:       Manoj Iyer, [email protected]
8# Author:       Alexey Kodanev [email protected]
9
10TST_SETUP="setup_dhcp"
11
12dhcp_name="dhcpd"
13lease_dir="/var/lib/misc"
14lease_file="$lease_dir/dhcpd.leases_tst"
15
16setup_dhcp()
17{
18	[ "$TST_IPV6" ] && lease="$lease_dir/dhcpd6.leases_tst"
19	dhcp_lib_setup
20}
21
22setup_dhcpd_conf()
23{
24	if [ -f /etc/dhcpd.conf ]; then
25		DHCPD_CONF="/etc/dhcpd.conf"
26	elif [ -f /etc/dhcp/dhcpd.conf ]; then
27		DHCPD_CONF="/etc/dhcp/dhcpd.conf"
28	else
29		tst_brk TBROK "failed to find dhcpd.conf"
30	fi
31
32	mv $DHCPD_CONF dhcpd.conf
33	[ $? -ne 0 ] && tst_brk TBROK "failed to backup dhcpd.conf"
34
35	mv tst_dhcpd.conf $DHCPD_CONF
36	[ $? -ne 0 ] && tst_brk TBROK "failed to create dhcpd.conf"
37}
38
39start_dhcpd()
40{
41	touch $lease_file
42	dhcpd -lf $lease_file -$TST_IPVER $iface0 > $log 2>&1
43}
44
45start_dhcp()
46{
47	cat > tst_dhcpd.conf <<-EOF
48	ddns-update-style none;
49	update-static-leases off;
50	subnet 10.1.1.0 netmask 255.255.255.0 {
51		range 10.1.1.100 10.1.1.100;
52		default-lease-time 60;
53		max-lease-time 60;
54	}
55	EOF
56	setup_dhcpd_conf
57	start_dhcpd
58}
59
60start_dhcp6()
61{
62	cat > tst_dhcpd.conf <<-EOF
63	ddns-update-style none;
64	update-static-leases off;
65	subnet6 fd00:1:1:2::/64 {
66		range6 fd00:1:1:2::100 fd00:1:1:2::100;
67		default-lease-time 60;
68		max-lease-time 60;
69	}
70	EOF
71	setup_dhcpd_conf
72	start_dhcpd
73}
74
75cleanup_dhcp()
76{
77	[ -f dhcpd.conf ] && mv dhcpd.conf $DHCPD_CONF
78	rm -f $lease_file
79}
80
81print_dhcp_version()
82{
83	dhcpd --version 2>&1
84}
85
86. dhcp_lib.sh
87tst_run
88