diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-08-26 19:58:39 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-08-26 19:58:39 +0200 |
commit | fdae741be5ffaa3719ce889d0342c3091ad3c92c (patch) | |
tree | c6df74dc6ec681cb97bbd6cf6f82afc2d04fd915 /src/conf_mode/dns_forwarding.py | |
parent | b812bae9e317f7bcc91371316af28d07345682ba (diff) | |
download | vyos-1x-fdae741be5ffaa3719ce889d0342c3091ad3c92c.tar.gz vyos-1x-fdae741be5ffaa3719ce889d0342c3091ad3c92c.zip |
T1598: make dns_forwarding.py retrieve name servers from vyos-hostsd.
Diffstat (limited to 'src/conf_mode/dns_forwarding.py')
-rwxr-xr-x | src/conf_mode/dns_forwarding.py | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/conf_mode/dns_forwarding.py b/src/conf_mode/dns_forwarding.py index 9e81c7294..38f3cb4de 100755 --- a/src/conf_mode/dns_forwarding.py +++ b/src/conf_mode/dns_forwarding.py @@ -24,6 +24,7 @@ import jinja2 import netifaces import vyos.util +import vyos.hostsd_client from vyos.config import Config from vyos import ConfigError @@ -94,19 +95,6 @@ default_config_data = { } -# borrowed from: https://github.com/donjajo/py-world/blob/master/resolvconfReader.py, THX! -def get_resolvers(file): - try: - with open(file, 'r') as resolvconf: - lines = [line.split('#', 1)[0].rstrip() - for line in resolvconf.readlines()] - resolvers = [line.split()[1] - for line in lines if 'nameserver' in line] - return resolvers - except IOError: - return [] - - def get_config(arguments): dns = default_config_data conf = Config() @@ -171,11 +159,16 @@ def get_config(arguments): if conf.exists('dhcp'): interfaces = [] interfaces = conf.return_values('dhcp') + hc = vyos.hostsd_client.Client() + for interface in interfaces: - dhcp_resolvers = get_resolvers( - "/etc/resolv.conf.dhclient-new-{0}".format(interface)) + dhcp_resolvers = hc.get_name_servers("dhcp-{0}".format(interface)) + dhcpv6_resolvers = hc.get_name_servers("dhcpv6-{0}".format(interface)) + if dhcp_resolvers: dns['name_servers'] = dns['name_servers'] + dhcp_resolvers + if dhcpv6_resolvers: + dns['name_servers'] = dns['name_servers'] + dhcpv6_resolvers return dns |