Autodetect IPv6 connectivity from minion to master

This commit is contained in:
Ivan Babrou 2017-02-09 11:33:21 -08:00
parent 52440416ca
commit 55965ce505
No known key found for this signature in database
GPG key ID: DBF6C142408CB4F0
4 changed files with 19 additions and 5 deletions

View file

@ -81,9 +81,10 @@ The option can can also be set to a list of masters, enabling
``ipv6``
--------
Default: ``False``
Default: ``None``
Whether the master should be connected over IPv6.
Whether the master should be connected over IPv6. By default salt minion
will try to automatically detect IPv6 connectivity to master.
.. code-block:: yaml

View file

@ -990,7 +990,7 @@ DEFAULT_MINION_OPTS = {
'mine_interval': 60,
'ipc_mode': _DFLT_IPC_MODE,
'ipc_write_buffer': _DFLT_IPC_WBUFFER,
'ipv6': False,
'ipv6': None,
'file_buffer_size': 262144,
'tcp_pub_port': 4510,
'tcp_pull_port': 4511,

View file

@ -346,7 +346,7 @@ class AsyncZeroMQPubChannel(salt.transport.mixins.auth.AESPubClientMixin, salt.t
zmq.RECONNECT_IVL_MAX, self.opts['recon_max']
)
if self.opts['ipv6'] is True and hasattr(zmq, 'IPV4ONLY'):
if (self.opts['ipv6'] is True or ':' in self.opts['master_ip']) and hasattr(zmq, 'IPV4ONLY'):
# IPv6 sockets work for both IPv6 and IPv4 addresses
self._socket.setsockopt(zmq.IPV4ONLY, 0)

View file

@ -716,12 +716,25 @@ def ip_bracket(addr):
return addr
def dns_check(addr, safe=False, ipv6=False):
def dns_check(addr, safe=False, ipv6=None):
'''
Return the ip resolved by dns, but do not exit on failure, only raise an
exception. Obeys system preference for IPv4/6 address resolution.
'''
error = False
# Detect IPv6 support if it is not forced by trying to connect
# to the give address over IPv6.
if ipv6 is None:
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
try:
s.connect((addr, 0))
s.close()
ipv6 = True
except:
ipv6 = False
try:
# issue #21397: force glibc to re-read resolv.conf
if HAS_RESINIT: