summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-08-26 19:58:39 +0200
committerDaniil Baturin <daniil@baturin.org>2019-08-26 19:58:39 +0200
commitfdae741be5ffaa3719ce889d0342c3091ad3c92c (patch)
treec6df74dc6ec681cb97bbd6cf6f82afc2d04fd915 /src
parentb812bae9e317f7bcc91371316af28d07345682ba (diff)
downloadvyos-1x-fdae741be5ffaa3719ce889d0342c3091ad3c92c.tar.gz
vyos-1x-fdae741be5ffaa3719ce889d0342c3091ad3c92c.zip
T1598: make dns_forwarding.py retrieve name servers from vyos-hostsd.
Diffstat (limited to 'src')
-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 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