summaryrefslogtreecommitdiff
path: root/src/conf_mode/dns_forwarding.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-08-26 19:58:39 +0200
committerDaniil Baturin <daniil@baturin.org>2019-08-27 08:16:44 +0200
commitbb0c520a7a09516ce6f34c69c337ac463ee5d74c (patch)
tree642f9783c316554ea78519399f99249b77519a45 /src/conf_mode/dns_forwarding.py
parent3a6ce1c83b5615bd8eee153a74c5eab9f919ad55 (diff)
downloadvyos-1x-bb0c520a7a09516ce6f34c69c337ac463ee5d74c.tar.gz
vyos-1x-bb0c520a7a09516ce6f34c69c337ac463ee5d74c.zip
T1598: make dns_forwarding.py retrieve name servers from vyos-hostsd.
Diffstat (limited to 'src/conf_mode/dns_forwarding.py')
-rwxr-xr-xsrc/conf_mode/dns_forwarding.py23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/conf_mode/dns_forwarding.py b/src/conf_mode/dns_forwarding.py
index 86683e72c..1fa26d3cc 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
@@ -95,19 +96,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()
@@ -212,11 +200,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