You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.2 KiB

  1. #!/bin/sh
  2. ##############################################################################
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License version 2 as
  6. # published by the Free Software Foundation.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # Copyright (C) 2016 Eric Luehrsen
  14. #
  15. ##############################################################################
  16. #
  17. # This script facilitates alternate installation of Unbound+odhcpd and no
  18. # need for dnsmasq. There are some limitations, but it works and is small.
  19. # The lease file is parsed to make "zone-data:" and "local-data:" entries.
  20. #
  21. # config odhcpd 'odhcpd'
  22. # option leasetrigger '/usr/lib/unbound/odhcpd.sh'
  23. #
  24. ##############################################################################
  25. # Common file location definitions
  26. . /usr/lib/unbound/unbound.sh
  27. ##############################################################################
  28. odhcpd_settings() {
  29. # This trigger is out of normal init context, so we need to read some UCI.
  30. local cfg="$1"
  31. config_get UNBOUND_D_DHCP_LINK "$cfg" dhcp_link none
  32. config_get_bool UNBOUND_B_SLAAC6_MAC "$cfg" dhcp4_slaac6 0
  33. }
  34. ##############################################################################
  35. odhcpd_zonedata() {
  36. local dns_ls_add=$UNBOUND_VARDIR/dhcp_dns.add
  37. local dns_ls_del=$UNBOUND_VARDIR/dhcp_dns.del
  38. local dhcp_ls_new=$UNBOUND_VARDIR/dhcp_lease.new
  39. local dhcp_ls_old=$UNBOUND_VARDIR/dhcp_lease.old
  40. local dhcp_ls_add=$UNBOUND_VARDIR/dhcp_lease.add
  41. local dhcp_ls_del=$UNBOUND_VARDIR/dhcp_lease.del
  42. local dhcp_origin=$( uci get dhcp.@odhcpd[0].leasefile )
  43. config_load unbound
  44. config_foreach odhcpd_settings unbound
  45. if [ "$UNBOUND_D_DHCP_LINK" = "odhcpd" -a -f "$dhcp_origin" ] ; then
  46. # Capture the lease file which could be changing often,
  47. # and unbound-control only for changes in hosts (or else...)
  48. cat $dhcp_origin | sort > $dhcp_ls_new
  49. touch $dhcp_ls_old
  50. sort $dhcp_ls_new $dhcp_ls_old $dhcp_ls_old | uniq -u > $dhcp_ls_add
  51. sort $dhcp_ls_old $dhcp_ls_new $dhcp_ls_new | uniq -u > $dhcp_ls_del
  52. # Go through the messy business of coding up A, AAAA, and PTR records.
  53. awk -v hostfile=$dns_ls_del -v domain=$UNBOUND_TXT_DOMAIN \
  54. -v bslaac=$UNBOUND_B_SLAAC6_MAC -v bisolt=0 \
  55. -f /usr/lib/unbound/odhcpd.awk $dhcp_ls_del
  56. awk -v hostfile=$dns_ls_add -v domain=$UNBOUND_TXT_DOMAIN \
  57. -v bslaac=$UNBOUND_B_SLAAC6_MAC -v bisolt=0 \
  58. -f /usr/lib/unbound/odhcpd.awk $dhcp_ls_add
  59. if [ -f "$dns_ls_del" ] ; then
  60. cat $dns_ls_del | $UNBOUND_CONTROL_CFG local_datas_remove
  61. fi
  62. if [ -f "$dns_ls_add" ] ; then
  63. cat $dns_ls_add | $UNBOUND_CONTROL_CFG local_datas
  64. fi
  65. # prepare next round
  66. mv $dhcp_ls_new $dhcp_ls_old
  67. rm -f $dns_ls_del $dns_ls_add
  68. fi
  69. }
  70. ##############################################################################
  71. odhcpd_zonedata
  72. ##############################################################################