2020-12-13 13:59:44 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
|
|
|
'unbound': {},
|
|
|
|
'unbound-anchor': {},
|
|
|
|
},
|
|
|
|
},
|
2020-12-13 14:22:19 +00:00
|
|
|
'cron': {
|
2021-01-29 16:58:24 +00:00
|
|
|
'unbound_refresh_root-hints': '{} {} * * {} root wget -q -O/etc/unbound/root-hints.txt https://www.internic.net/domain/named.root'.format(
|
2020-12-13 14:22:19 +00:00
|
|
|
node.magic_number%60,
|
|
|
|
node.magic_number%24,
|
|
|
|
node.magic_number%7,
|
|
|
|
),
|
|
|
|
},
|
2020-12-13 13:59:44 +00:00
|
|
|
'nameservers': {
|
|
|
|
'127.0.0.1',
|
|
|
|
},
|
|
|
|
'unbound': {
|
|
|
|
'max_ttl': 3600,
|
2020-12-22 08:22:37 +00:00
|
|
|
'cache_size': '512M',
|
2020-12-13 13:59:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'unbound/threads',
|
|
|
|
'unbound/cache_slabs',
|
|
|
|
)
|
2020-12-22 08:22:37 +00:00
|
|
|
def cpu_cores_to_config_values(metadata):
|
|
|
|
num_cpus = metadata.get('vm/cpu', 1)
|
|
|
|
|
2020-12-13 13:59:44 +00:00
|
|
|
return {
|
|
|
|
'unbound': {
|
2020-12-22 08:22:37 +00:00
|
|
|
'threads': num_cpus*2,
|
|
|
|
'cache_slabs': 2**(num_cpus-1).bit_length(),
|
2020-12-13 13:59:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'iptables/bundle_rules/unbound',
|
|
|
|
)
|
2020-12-13 13:59:44 +00:00
|
|
|
def iptables(metadata):
|
|
|
|
interfaces = metadata.get('unbound/restrict-to-interfaces', set())
|
|
|
|
iptables = []
|
|
|
|
|
|
|
|
for iface in sorted(interfaces):
|
2021-01-02 15:19:55 +00:00
|
|
|
iptables.append(f'iptables_both -A INPUT -i {iface} -p tcp --dport 53 -j ACCEPT')
|
|
|
|
iptables.append(f'iptables_both -A INPUT -i {iface} -p udp --dport 53 -j ACCEPT')
|
2020-12-13 13:59:44 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'iptables': {
|
|
|
|
'bundle_rules': {
|
|
|
|
'unbound': iptables,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|