From ded491574ed5d65e34368b979578a1e71f9d89fd Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Apr 2018 18:54:31 +0200 Subject: dns-forwarding.py: be more tolerant on missconfigured DHCP source If a user configures 'set service dns forwarding dhcp ' and is not a DHCP interface, this won't corrupt the recursor.conf. The missconfiguration is simply ignored. --- src/conf-mode/vyos-config-dns-forwarding.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/conf-mode/vyos-config-dns-forwarding.py b/src/conf-mode/vyos-config-dns-forwarding.py index 7a8aed75d..537e47d85 100755 --- a/src/conf-mode/vyos-config-dns-forwarding.py +++ b/src/conf-mode/vyos-config-dns-forwarding.py @@ -37,8 +37,8 @@ def get_resolvers(file): if 'nameserver' in line: resolvers.append(line.split()[1]) return resolvers - except IOError as error: - return error.strerror + except IOError: + return [] def get_config(): dns = {} @@ -57,11 +57,12 @@ def get_config(): interfaces = conf.return_values('dhcp') for interface in interfaces: resolvers = get_resolvers("/etc/resolv.conf.dhclient-new-{0}".format(interface)) - dhcp = { - "interface": interface, - "resolvers": resolvers - } - dns['dhcp'].append(dhcp) + if len(resolvers) > 0: + dhcp = { + "interface": interface, + "resolvers": resolvers + } + dns['dhcp'].append(dhcp) if conf.exists('domain'): dns.setdefault('domain', []) -- cgit v1.2.3