Commit 56e4c4a0 authored by Manuel Franceschini's avatar Manuel Franceschini
Browse files

Enable utils.OwnIpAddress to work with IPv6 addresses



Currently a TcpPing using the target address as source is used to
determine wheter or not an IP address belongs to a node. This does not
work for IPv6 anymore (I'm not sure why) as binding to IPv6 localhost as
source for the TCP connection in TcpPing still results in a successful
connection, even in case the target address is non-local.
Signed-off-by: default avatarManuel Franceschini <livewire@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 4b5e40a5
......@@ -1794,8 +1794,8 @@ def TcpPing(target, port, timeout=10, live_port_needed=False, source=None):
def OwnIpAddress(address):
"""Check if the current host has the the given IP address.
Currently this is done by TCP-pinging the address from the loopback
address.
This is done by trying to bind the given address. We return True if we
succeed or false if a socket.error is raised.
@type address: string
@param address: the address to check
......@@ -1803,8 +1803,17 @@ def OwnIpAddress(address):
@return: True if we own the address
"""
return TcpPing(address, constants.DEFAULT_NODED_PORT,
source=constants.IP4_ADDRESS_LOCALHOST)
family = GetAddressFamily(address)
s = socket.socket(family, socket.SOCK_DGRAM)
success = False
try:
s.bind((address, 0))
success = True
except socket.error:
success = False
finally:
s.close()
return success
def ListVisibleFiles(path):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment