dhcpd_tests.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. dhcp_name="dhcpd"
  10. . dhcp_lib.sh
  11. TST_SETUP="setup_dhcp"
  12. lease_dir="/var/lib/misc"
  13. lease_file="$lease_dir/dhcpd.leases_tst"
  14. setup_dhcp()
  15. {
  16. [ "$TST_IPV6" ] && lease="$lease_dir/dhcpd6.leases_tst"
  17. dhcp_lib_setup
  18. }
  19. setup_dhcpd_conf()
  20. {
  21. if [ -f /etc/dhcpd.conf ]; then
  22. DHCPD_CONF="/etc/dhcpd.conf"
  23. elif [ -f /etc/dhcp/dhcpd.conf ]; then
  24. DHCPD_CONF="/etc/dhcp/dhcpd.conf"
  25. else
  26. tst_brk TBROK "failed to find dhcpd.conf"
  27. fi
  28. mv $DHCPD_CONF dhcpd.conf
  29. [ $? -ne 0 ] && tst_brk TBROK "failed to backup dhcpd.conf"
  30. mv tst_dhcpd.conf $DHCPD_CONF
  31. [ $? -ne 0 ] && tst_brk TBROK "failed to create dhcpd.conf"
  32. }
  33. start_dhcpd()
  34. {
  35. touch $lease_file
  36. dhcpd -lf $lease_file -$TST_IPVER $iface0 > $log 2>&1
  37. }
  38. start_dhcp()
  39. {
  40. cat > tst_dhcpd.conf <<-EOF
  41. ddns-update-style none;
  42. update-static-leases off;
  43. subnet 10.1.1.0 netmask 255.255.255.0 {
  44. range 10.1.1.100 10.1.1.100;
  45. default-lease-time 60;
  46. max-lease-time 60;
  47. }
  48. EOF
  49. setup_dhcpd_conf
  50. start_dhcpd
  51. }
  52. start_dhcp6()
  53. {
  54. cat > tst_dhcpd.conf <<-EOF
  55. ddns-update-style none;
  56. update-static-leases off;
  57. subnet6 fd00:1:1:2::/64 {
  58. range6 fd00:1:1:2::100 fd00:1:1:2::100;
  59. default-lease-time 60;
  60. max-lease-time 60;
  61. }
  62. EOF
  63. setup_dhcpd_conf
  64. start_dhcpd
  65. }
  66. cleanup_dhcp()
  67. {
  68. [ -f dhcpd.conf ] && mv dhcpd.conf $DHCPD_CONF
  69. rm -f $lease_file
  70. }
  71. print_dhcp_version()
  72. {
  73. dhcpd --version 2>&1
  74. }
  75. tst_run