Page MenuHomeVyOS Platform

110-powerdns_advanced_opts.patch

Authored By
wsapplegate
Feb 22 2021, 8:36 PM
Size
12 KB
Referenced Files
None
Subscribers
None

110-powerdns_advanced_opts.patch

diff --git a/data/templates/dns-forwarding/recursor.conf.tmpl b/data/templates/dns-forwarding/recursor.conf.tmpl
index 8799718b..62ba6620 100644
--- a/data/templates/dns-forwarding/recursor.conf.tmpl
+++ b/data/templates/dns-forwarding/recursor.conf.tmpl
@@ -29,5 +29,14 @@ local-address={{ listen_address | join(',') }}
# dnssec
dnssec={{ dnssec }}
+# max-ttl
+max-cache-ttl={{ advanced.max_ttl }}
+
+# port
+local-port={{ advanced.port }}
+
+# zones
+auth-zones={% for z in zones %}{{ z.name }}={{ z.file }}{{- "," if not loop.last -}}{% endfor %}
+
forward-zones-file=recursor.forward-zones.conf
diff --git a/data/templates/dns-forwarding/recursor.zone.conf.tmpl b/data/templates/dns-forwarding/recursor.zone.conf.tmpl
new file mode 100644
index 00000000..c46787ed
--- /dev/null
+++ b/data/templates/dns-forwarding/recursor.zone.conf.tmpl
@@ -0,0 +1,8 @@
+;
+; Autogenerated by dns_forwarding.py
+;
+ ;
+{% for r in records %}
+{{ r.name }} {{ r.type }} {{ r.preference }} {{ r.target }}
+{% endfor %}
+
diff --git a/interface-definitions/dns-forwarding.xml.in b/interface-definitions/dns-forwarding.xml.in
index 66b4db40..cda1204b 100644
--- a/interface-definitions/dns-forwarding.xml.in
+++ b/interface-definitions/dns-forwarding.xml.in
@@ -182,6 +182,178 @@
</properties>
<defaultValue>0.0.0.0 ::</defaultValue>
</leafNode>
+ <node name="advanced">
+ <properties>
+ <help>Set advanced settings and DNS manipulations</help>
+ </properties>
+ <children>
+ <leafNode name="max-ttl">
+ <properties>
+ <help>Maximum amount of time requesting clients are allowed to cache replies</help>
+ <valueHelp>
+ <format>u32:0-604800</format>
+ <description>Seconds to cache records</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 0-60400"/>
+ </constraint>
+ </properties>
+ <defaultValue>86400</defaultValue>
+ </leafNode>
+ <leafNode name="port">
+ <properties>
+ <help>Set different listening port</help>
+ <valueHelp>
+ <format>u32:1-65535</format>
+ <description>Port to listen on</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-65535"/>
+ </constraint>
+ </properties>
+ <defaultValue>53</defaultValue>
+ </leafNode>
+ <tagNode name="zone">
+ <properties>
+ <help>Set domain name to create/manipulate DNS zone for</help>
+ </properties>
+ <children>
+ <tagNode name="a">
+ <properties>
+ <help>Set A record name</help>
+ </properties>
+ <children>
+ <leafNode name="address">
+ <properties>
+ <help>Set IP address to be returned for specified domain</help>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>Record IPv4 address</description>
+ </valueHelp>
+ <multi/>
+ <constraint>
+ <validator name="ipv4-address"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ #include <include/generic-disable-node.xml.i>
+ </children>
+ </tagNode>
+ <tagNode name="aaaa">
+ <properties>
+ <help>Set AAAA record name</help>
+ </properties>
+ <children>
+ <leafNode name="address">
+ <properties>
+ <help>Set IP address to be returned for specified domain</help>
+ <valueHelp>
+ <format>ipv6</format>
+ <description>Record IPv6 address</description>
+ </valueHelp>
+ <multi/>
+ <constraint>
+ <validator name="ipv6-address"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ #include <include/generic-disable-node.xml.i>
+ </children>
+ </tagNode>
+ <tagNode name="cname">
+ <properties>
+ <help>Set CNAME record name</help>
+ </properties>
+ <children>
+ #include <include/generic-disable-node.xml.i>
+ <leafNode name="hostname">
+ <properties>
+ <help>Set CNAME record target name</help>
+ <valueHelp>
+ <format>text</format>
+ <description>Record target name</description>
+ </valueHelp>
+ <constraint>
+ <regex>^[-a-zA-Z0-9.]{0,63}$</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ <tagNode name="mx">
+ <properties>
+ <help>Set MX record name</help>
+ </properties>
+ <children>
+ #include <include/generic-disable-node.xml.i>
+ <leafNode name="hostname">
+ <properties>
+ <help>Set MX destination hostname</help>
+ <valueHelp>
+ <format>text</format>
+ <description>Record destination hostname</description>
+ </valueHelp>
+ <constraint>
+ <regex>^[-a-zA-Z0-9.]{0,63}$</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="preference">
+ <properties>
+ <help>Set preference for MX record</help>
+ <valueHelp>
+ <format>1-999</format>
+ <description>Preference for MX record</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-999"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ <tagNode name="ptr">
+ <properties>
+ <help>Set PTR record name</help>
+ </properties>
+ <children>
+ #include <include/generic-disable-node.xml.i>
+ <leafNode name="hostname">
+ <properties>
+ <help>Set PTR record target</help>
+ <valueHelp>
+ <format>text</format>
+ <description>Record target name</description>
+ </valueHelp>
+ <constraint>
+ <regex>^[-a-zA-Z0-9.]{0,63}$</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ <tagNode name="txt">
+ <properties>
+ <help>Set TXT record name</help>
+ </properties>
+ <children>
+ #include <include/generic-disable-node.xml.i>
+ <leafNode name="text">
+ <properties>
+ <help>Set TXT record text content</help>
+ <valueHelp>
+ <format>text</format>
+ <description>Record text content</description>
+ </valueHelp>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ #include <include/generic-disable-node.xml.i>
+ </children>
+ </tagNode>
+ </children>
+ </node>
<leafNode name="system">
<properties>
<help>Use system name servers</help>
diff --git a/src/conf_mode/dns_forwarding.py b/src/conf_mode/dns_forwarding.py
index c44e6c97..28e39f4d 100755
--- a/src/conf_mode/dns_forwarding.py
+++ b/src/conf_mode/dns_forwarding.py
@@ -81,6 +81,49 @@ def get_config(config=None):
dns.update({'source_address_v4': source_address_v4})
dns.update({'source_address_v6': source_address_v6})
+ advanced = dns.get('advanced', {})
+ if 'pdns_option' not in advanced:
+ dns['advanced']['pdns_option'] = []
+ dns['zones'] = []
+ if 'zone' in advanced:
+ for node in advanced['zone']:
+ zonedata = advanced['zone'][node]
+ if 'disable' in zonedata:
+ continue
+ zone = {
+ 'name': node,
+ 'file': "{}/zone.{}.conf".format(pdns_rec_run_dir, node),
+ 'records': [],
+ }
+ for rtype in [ 'a', 'aaaa', 'cname', 'mx', 'ptr', 'txt' ]:
+ if rtype not in zonedata:
+ continue
+ for subnode in zonedata[rtype]:
+ if 'disable' in zonedata[rtype][subnode]:
+ continue
+ preference = '10'
+ if 'preference' in zonedata[rtype][subnode]:
+ preference = zonedata[rtype][subnode]['preference']
+ target = 'hostname'
+ if rtype in [ 'a', 'aaaa' ]:
+ target = 'address'
+ if rtype == 'txt':
+ target = 'text'
+ if target not in zonedata[rtype][subnode]:
+ continue
+ targetdata = zonedata[rtype][subnode][target] if rtype in [ 'a', 'aaaa' ] else [ zonedata[rtype][subnode][target] ]
+ for item in targetdata:
+ if rtype == 'txt':
+ item = "\"{}\"".format(item.replace("\"", "\\\""))
+ record = {
+ 'name': subnode,
+ 'type': rtype.upper(),
+ 'preference': preference if rtype == 'mx' else '',
+ 'target': item,
+ }
+ zone['records'].append(record)
+ dns['zones'].append(zone)
+
return dns
def verify(dns):
@@ -119,6 +162,10 @@ def generate(dns):
render(pdns_rec_lua_conf_file, 'dns-forwarding/recursor.conf.lua.tmpl',
dns, user=pdns_rec_user, group=pdns_rec_group)
+ for zone in dns['zones']:
+ render(zone['file'], 'dns-forwarding/recursor.zone.conf.tmpl',
+ zone, user=pdns_rec_user, group=pdns_rec_group)
+
# if vyos-hostsd didn't create its files yet, create them (empty)
for file in [pdns_rec_hostsd_lua_conf_file, pdns_rec_hostsd_zones_file]:
with open(file, 'a'):

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
01/79/25df79d36a421bcc4146e5b1d6cb
Default Alt Text
110-powerdns_advanced_opts.patch (12 KB)

Event Timeline