Browse Source

isc-dhcp: support dynamic dns for 10/8 and 172.16/12

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
lilik-openwrt-22.03
Philip Prindeville 4 years ago
parent
commit
cf8526dbb2
2 changed files with 59 additions and 16 deletions
  1. +1
    -1
      net/isc-dhcp/Makefile
  2. +58
    -15
      net/isc-dhcp/files/dhcpd.init

+ 1
- 1
net/isc-dhcp/Makefile View File

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=isc-dhcp PKG_NAME:=isc-dhcp
UPSTREAM_NAME:=dhcp UPSTREAM_NAME:=dhcp
PKG_VERSION:=4.4.1 PKG_VERSION:=4.4.1
PKG_RELEASE:=12
PKG_RELEASE:=13
PKG_LICENSE:=BSD-3-Clause PKG_LICENSE:=BSD-3-Clause
PKG_LICENSE_FILES:=LICENSE PKG_LICENSE_FILES:=LICENSE


+ 58
- 15
net/isc-dhcp/files/dhcpd.init View File

@ -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() { update() {
local lhs="$1" family="$2" type="$3" local lhs="$1" family="$2" type="$3"
shift 3 shift 3
@ -97,8 +91,18 @@ explode() {
echo "$arg" | sed -e 's/\./, /g' 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" local zone="$1"
if [ ! -f $dyndir/db."$zone" ]; then if [ ! -f $dyndir/db."$zone" ]; then
@ -182,7 +186,7 @@ static_domain_add() {
config_get ip "$cfg" "ip" config_get ip "$cfg" "ip"
[ -n "$ip" ] || return 0 [ -n "$ip" ] || return 0
revip="$(rev_quad "$ip")"
revip="$(rev_str "$ip" ".")"
update "$name.$domain." IN A "$ip" update "$name.$domain." IN A "$ip"
update "$revip.in-addr.arpa." IN PTR "$name.$domain." update "$revip.in-addr.arpa." IN PTR "$name.$domain."
@ -329,7 +333,7 @@ gen_dhcp_subnet() {
} }
dhcpd_add() { dhcpd_add() {
local cfg="$1"
local cfg="$1" synthesize="$2"
local dhcp6range="::" local dhcp6range="::"
local dynamicdhcp end gateway ifname ignore leasetime limit net netmask local dynamicdhcp end gateway ifname ignore leasetime limit net netmask
local proto networkid start subnet local proto networkid start subnet
@ -353,6 +357,17 @@ dhcpd_add() {
[ static = "$proto" ] || return 0 [ 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 config_get_bool dynamicdhcp "$cfg" "dynamicdhcp" 1
dhcp_ifs="$dhcp_ifs $ifname" dhcp_ifs="$dhcp_ifs $ifname"
@ -384,6 +399,7 @@ dhcpd_add() {
general_config() { general_config() {
local always_broadcast boot_unknown_clients log_facility local always_broadcast boot_unknown_clients log_facility
local default_lease_time max_lease_time local default_lease_time max_lease_time
config_get_bool always_broadcast "isc_dhcpd" "always_broadcast" 0 config_get_bool always_broadcast "isc_dhcpd" "always_broadcast" 0
config_get_bool authoritative "isc_dhcpd" "authoritative" 1 config_get_bool authoritative "isc_dhcpd" "authoritative" 1
config_get_bool boot_unknown_clients "isc_dhcpd" "boot_unknown_clients" 1 config_get_bool boot_unknown_clients "isc_dhcpd" "boot_unknown_clients" 1
@ -406,7 +422,12 @@ general_config() {
if [ $dynamicdns -eq 1 ]; then if [ $dynamicdns -eq 1 ]; then
create_empty_zone "$domain" 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 <<EOF > $conf_local_file cat <<EOF > $conf_local_file
zone "$domain" { zone "$domain" {
@ -416,14 +437,21 @@ zone "$domain" {
allow-transfer { key $session_key_name; }; allow-transfer { key $session_key_name; };
}; };
zone "168.192.in-addr.arpa" {
EOF
for mynet in $rfc1918_nets; do
mynet="$(rev_str "$mynet" ".")"
cat <<EOF >> $conf_local_file
zone "$mynet.in-addr.arpa" {
type master; type master;
file "$dyndir/db.168.192.in-addr.arpa";
file "$dyndir/db.$mynet.in-addr.arpa";
allow-update { key $session_key_name; }; allow-update { key $session_key_name; };
allow-transfer { key $session_key_name; }; allow-transfer { key $session_key_name; };
}; };
EOF EOF
done
/etc/init.d/named reload /etc/init.d/named reload
sleep 1 sleep 1
@ -445,12 +473,18 @@ zone $domain. {
key local-ddns; key local-ddns;
} }
zone 168.192.in-addr.arpa. {
EOF
for mynet in $rfc1918_nets; do
mynet="$(rev_str "$mynet" ".")"
cat <<EOF
zone $mynet.in-addr.arpa. {
primary 127.0.0.1; primary 127.0.0.1;
key local-ddns; key local-ddns;
} }
EOF EOF
done
fi fi
if [ -n "$log_facility" ] ; then if [ -n "$log_facility" ] ; then
@ -494,9 +528,18 @@ start_service() {
config_load dhcp config_load dhcp
local rfc1918_nets=""
# alas we have to make 2 passes...
config_foreach dhcpd_add dhcp 0
rfc1918_nets="$(echo "$rfc1918_nets" | tr ' ' $'\n' | sort | uniq | tr $'\n' ' ')"
general_config > $config_file general_config > $config_file
config_foreach dhcpd_add dhcp
rfc1918_nets=
config_foreach dhcpd_add dhcp 1
static_hosts >> $config_file static_hosts >> $config_file


Loading…
Cancel
Save