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 <pvorel@suse.cz> 5# Copyright (c) International Business Machines Corp., 2001 6# 7# Author: Manoj Iyer, manjo@mail.utexas.edu 8# Author: Alexey Kodanev alexey.kodanev@oracle.com 9 10dhcp_name="dhcpd" 11 12. dhcp_lib.sh 13TST_SETUP="setup_dhcp" 14lease_dir="/var/lib/misc" 15lease_file="$lease_dir/dhcpd.leases_tst" 16 17setup_dhcp() 18{ 19 [ "$TST_IPV6" ] && lease="$lease_dir/dhcpd6.leases_tst" 20 dhcp_lib_setup 21} 22 23setup_dhcpd_conf() 24{ 25 if [ -f /etc/dhcpd.conf ]; then 26 DHCPD_CONF="/etc/dhcpd.conf" 27 elif [ -f /etc/dhcp/dhcpd.conf ]; then 28 DHCPD_CONF="/etc/dhcp/dhcpd.conf" 29 else 30 tst_brk TBROK "failed to find dhcpd.conf" 31 fi 32 33 mv $DHCPD_CONF dhcpd.conf 34 [ $? -ne 0 ] && tst_brk TBROK "failed to backup dhcpd.conf" 35 36 mv tst_dhcpd.conf $DHCPD_CONF 37 [ $? -ne 0 ] && tst_brk TBROK "failed to create dhcpd.conf" 38} 39 40start_dhcpd() 41{ 42 touch $lease_file 43 dhcpd -lf $lease_file -$TST_IPVER $iface0 > $log 2>&1 44} 45 46start_dhcp() 47{ 48 cat > tst_dhcpd.conf <<-EOF 49 ddns-update-style none; 50 update-static-leases off; 51 subnet 10.1.1.0 netmask 255.255.255.0 { 52 range 10.1.1.100 10.1.1.100; 53 default-lease-time 60; 54 max-lease-time 60; 55 } 56 EOF 57 setup_dhcpd_conf 58 start_dhcpd 59} 60 61start_dhcp6() 62{ 63 cat > tst_dhcpd.conf <<-EOF 64 ddns-update-style none; 65 update-static-leases off; 66 subnet6 fd00:1:1:2::/64 { 67 range6 fd00:1:1:2::100 fd00:1:1:2::100; 68 default-lease-time 60; 69 max-lease-time 60; 70 } 71 EOF 72 setup_dhcpd_conf 73 start_dhcpd 74} 75 76cleanup_dhcp() 77{ 78 [ -f dhcpd.conf ] && mv dhcpd.conf $DHCPD_CONF 79 rm -f $lease_file 80} 81 82print_dhcp_version() 83{ 84 dhcpd --version 2>&1 85} 86 87tst_run 88