mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
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:
parent
3849e7a085
commit
4e2e62d508
1 changed files with 15 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue