summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/hostsd_client.py7
-rwxr-xr-xsrc/conf_mode/dns_forwarding.py23
-rwxr-xr-xsrc/services/vyos-hostsd18
3 files changed, 32 insertions, 16 deletions
diff --git a/python/vyos/hostsd_client.py b/python/vyos/hostsd_client.py
index e2f05071b..f009aba98 100644
--- a/python/vyos/hostsd_client.py
+++ b/python/vyos/hostsd_client.py
@@ -30,6 +30,8 @@ class Client(object):
reply = json.loads(reply_msg)
if 'error' in reply:
raise VyOSHostsdError(reply['error'])
+ else:
+ return reply["data"]
except zmq.error.Again:
raise VyOSHostsdError("Could not connect to vyos-hostsd")
@@ -60,3 +62,8 @@ class Client(object):
def delete_name_servers(self, tag):
msg = {'type': 'name_servers', 'op': 'delete', 'tag': tag}
self._communicate(msg)
+
+ def get_name_servers(self, tag):
+ msg = {'type': 'name_servers', 'op': 'get', 'tag': tag}
+ return self._communicate(msg)
+
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
diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd
index 1bcb2e1f5..8f70eb4e9 100755
--- a/src/services/vyos-hostsd
+++ b/src/services/vyos-hostsd
@@ -171,6 +171,14 @@ def set_host_name(state, data):
if data['search_domains']:
state['search_domains'] = data['search_domains']
+def get_name_servers(state, tag):
+ ns = []
+ data = state['name_servers']
+ for n in data:
+ if data[n]['tag'] == tag:
+ ns.append(n)
+ return ns
+
def get_option(msg, key):
if key in msg:
return msg[key]
@@ -209,6 +217,13 @@ def handle_message(msg_json):
set_host_name(STATE, data)
else:
raise ValueError("Unknown message type {0}".format(_type))
+ elif op == 'get':
+ tag = get_option(msg, 'tag')
+ if _type == 'name_servers':
+ result = get_name_servers(STATE, tag)
+ else:
+ raise ValueError("Unimplemented")
+ return result
else:
raise ValueError("Unknown operation {0}".format(op))
@@ -254,7 +269,8 @@ if __name__ == '__main__':
resp = {}
try:
- handle_message(message)
+ result = handle_message(message)
+ resp['data'] = result
except ValueError as e:
resp['error'] = str(e)
except: