From cf8526dbb2c719b0fdc7c0f5e233e7b107a4d916 Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Fri, 15 Jan 2021 21:00:20 -0700 Subject: [PATCH] isc-dhcp: support dynamic dns for 10/8 and 172.16/12 Signed-off-by: Philip Prindeville --- net/isc-dhcp/Makefile | 2 +- net/isc-dhcp/files/dhcpd.init | 73 ++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/net/isc-dhcp/Makefile b/net/isc-dhcp/Makefile index 68c60e58a..e01b10eb9 100644 --- a/net/isc-dhcp/Makefile +++ b/net/isc-dhcp/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=isc-dhcp UPSTREAM_NAME:=dhcp PKG_VERSION:=4.4.1 -PKG_RELEASE:=12 +PKG_RELEASE:=13 PKG_LICENSE:=BSD-3-Clause PKG_LICENSE_FILES:=LICENSE diff --git a/net/isc-dhcp/files/dhcpd.init b/net/isc-dhcp/files/dhcpd.init index 2c8d21b25..1436e7e2a 100755 --- a/net/isc-dhcp/files/dhcpd.init +++ b/net/isc-dhcp/files/dhcpd.init @@ -78,12 +78,6 @@ typeof() { ' } -rev_quad() { - local ip="$1" - - echo "$ip" | awk -F '.' '{ printf "%s.%s.%s.%s\n", $4, $3, $2, $1; }' -} - update() { local lhs="$1" family="$2" type="$3" shift 3 @@ -97,8 +91,18 @@ explode() { echo "$arg" | sed -e 's/\./, /g' } -create_empty_zone() -{ +rev_str() { + local str="$1" delim="$2" + local frag result="" IFS="$delim" + + for frag in $str; do + result="$frag${result:+$delim}$result" + done + + echo "$result" +} + +create_empty_zone() { local zone="$1" if [ ! -f $dyndir/db."$zone" ]; then @@ -182,7 +186,7 @@ static_domain_add() { config_get ip "$cfg" "ip" [ -n "$ip" ] || return 0 - revip="$(rev_quad "$ip")" + revip="$(rev_str "$ip" ".")" update "$name.$domain." IN A "$ip" update "$revip.in-addr.arpa." IN PTR "$name.$domain." @@ -329,7 +333,7 @@ gen_dhcp_subnet() { } dhcpd_add() { - local cfg="$1" + local cfg="$1" synthesize="$2" local dhcp6range="::" local dynamicdhcp end gateway ifname ignore leasetime limit net netmask local proto networkid start subnet @@ -353,6 +357,17 @@ dhcpd_add() { [ static = "$proto" ] || return 0 + local pair="$(echo "${subnet%%/*}" | cut -d. -f1-2)" + case "$pair" in + 10.*) + rfc1918_nets="$rfc1918_nets${rfc1918_nets:+ }10" + ;; + 172.1[6789]|172.2[0-9]|172.3[01]|192.168) + rfc1918_nets="$rfc1918_nets${rfc1918_nets:+ }$pair" + ;; + esac + [ $synthesize -eq 0 ] && return + config_get_bool dynamicdhcp "$cfg" "dynamicdhcp" 1 dhcp_ifs="$dhcp_ifs $ifname" @@ -384,6 +399,7 @@ dhcpd_add() { general_config() { local always_broadcast boot_unknown_clients log_facility local default_lease_time max_lease_time + config_get_bool always_broadcast "isc_dhcpd" "always_broadcast" 0 config_get_bool authoritative "isc_dhcpd" "authoritative" 1 config_get_bool boot_unknown_clients "isc_dhcpd" "boot_unknown_clients" 1 @@ -406,7 +422,12 @@ general_config() { if [ $dynamicdns -eq 1 ]; then create_empty_zone "$domain" - create_empty_zone "168.192.in-addr.arpa" + local mynet + + for mynet in $rfc1918_nets; do + mynet="$(rev_str "$mynet" ".")" + create_empty_zone "$mynet.in-addr.arpa" + done cat < $conf_local_file zone "$domain" { @@ -416,14 +437,21 @@ zone "$domain" { allow-transfer { key $session_key_name; }; }; -zone "168.192.in-addr.arpa" { +EOF + + for mynet in $rfc1918_nets; do + mynet="$(rev_str "$mynet" ".")" + cat <> $conf_local_file +zone "$mynet.in-addr.arpa" { type master; - file "$dyndir/db.168.192.in-addr.arpa"; + file "$dyndir/db.$mynet.in-addr.arpa"; allow-update { key $session_key_name; }; allow-transfer { key $session_key_name; }; }; EOF + done + /etc/init.d/named reload sleep 1 @@ -445,12 +473,18 @@ zone $domain. { key local-ddns; } -zone 168.192.in-addr.arpa. { +EOF + + for mynet in $rfc1918_nets; do + mynet="$(rev_str "$mynet" ".")" + cat < $config_file - config_foreach dhcpd_add dhcp + rfc1918_nets= + + config_foreach dhcpd_add dhcp 1 static_hosts >> $config_file