nsd: support network with prefix smaller than 24

This commit is contained in:
egarette@silique.fr 2023-03-03 14:08:12 +01:00
parent a2838d1068
commit cc56ea6286
4 changed files with 11 additions and 5 deletions

View file

@ -93,6 +93,7 @@
<param>/etc/nsd/</param>
<param type="variable">nsd_reverse_name</param>
<param>reverse</param>
<param name="remove_duplicate_value" type="boolean">True</param>
<param name="join"></param>
<param name="multi" type="boolean">True</param>
<target>nsd_reverse_filenames</target>

View file

@ -44,8 +44,8 @@ def get_reverse_name(network: str) -> str:
if not network:
return
network_obj = ip_network(network)
if network_obj.prefixlen != 24:
raise ValueError('only netmask "255.255.255.0" is supported for DNS reverse name')
if network_obj.prefixlen < 24:
raise ValueError('only netmask greater than 24 is supported for DNS reverse name')
o1, o2, o3, o4 = network.split('.')
return f'{o3}.{o2}.{o1}.in-addr.arpa.'

View file

@ -1,5 +1,5 @@
%set %%name = None
%set %%network = %%ip_network(%%nsd_reverse_network[%%rougail_index])
%set %%network = %%str(%%nsd_reverse_network[%%rougail_index]).rsplit('.', 1)[0]
%for %%zone in %%nsd_zones
%set %%suffix = %%normalize_family(%%zone)
%set %%hostnames = %%nsd["nsd_zone_" + %%suffix]["hostname_" + %%suffix]["hostname_" + %%suffix]
@ -23,7 +23,7 @@ $TTL 1800
IN NS %%domain_name_eth0.
%end if
%set %%ip = %%hostname['ip_' + %%suffix]
%if %%ip_address(%%ip) in %%network
%if %%ip.startswith(%%network)
%set %%id = %%ip.rsplit('.', 1)[1]
%%id PTR %%hostname.%%{zone}.
%end if

View file

@ -17,9 +17,14 @@ zone:
name: "%%zone"
zonefile: "%%{zone}.zone.signed"
%end for
%set %%reversed = []
%for %%reverse in %%nsd_reverse_network
%if %%reverse.nsd_reverse_name in %%reversed
%continue
%end if
%%reversed.append(%%reverse.nsd_reverse_name)%slurp
zone:
name: "%%reverse.nsd_reverse_name"
zonefile: "%%{reverse.nsd_reverse_name}reverse.signed"
zonefile: "%%{reverse.nsd_reverse_name.replace('/', '-')}reverse.signed"
%end for