salt.utils.dns parse scope param for ipv6 servers

Recent versions of resolv.conf append the device name to IPv6 nameserver
IP address entries as a scoping parameter for that nameserver.  See for
example, https://bugzilla.redhat.com/show_bug.cgi?id=1093294#c4.
This commit is contained in:
Justin Findlay 2018-02-19 04:06:52 -08:00
parent 3849e7a085
commit 4e2e62d508
No known key found for this signature in database
GPG key ID: 423725EEF5A74B6F

View file

@ -797,6 +797,8 @@ def parse_resolv(src='/etc/resolv.conf'):
'''
nameservers = []
ip4_nameservers = []
ip6_nameservers = []
search = []
sortlist = []
domain = ''
@ -815,10 +817,20 @@ def parse_resolv(src='/etc/resolv.conf'):
lambda x: x[0] not in ('#', ';'), arg))
if directive == 'nameserver':
# Split the scope (interface) if it is present
addr, scope = arg[0].split('%', 1) if '%' in arg[0] else (arg[0], '')
try:
ip_addr = ipaddress.ip_address(arg[0])
ip_addr = ipaddress.ip_address(addr)
version = ip_addr.version
# Rejoin scope after address validation
if scope:
ip_addr = '%'.join((str(ip_addr), scope))
if ip_addr not in nameservers:
nameservers.append(ip_addr)
if version == 4 and ip_addr not in ip4_nameservers:
ip4_nameservers.append(ip_addr)
elif version == 6 and ip_addr not in ip6_nameservers:
ip6_nameservers.append(ip_addr)
except ValueError as exc:
log.error('{0}: {1}'.format(src, exc))
elif directive == 'domain':
@ -870,8 +882,8 @@ def parse_resolv(src='/etc/resolv.conf'):
return {
'nameservers': nameservers,
'ip4_nameservers': [ip for ip in nameservers if ip.version == 4],
'ip6_nameservers': [ip for ip in nameservers if ip.version == 6],
'ip4_nameservers': ip4_nameservers,
'ip6_nameservers': ip6_nameservers,
'sortlist': [ip.with_netmask for ip in sortlist],
'domain': domain,
'search': search,