Commit 0106e2f9 authored by Julien Muchembled's avatar Julien Muchembled

New --ipv6 option and fix learning of external IPv6 from other peers

When re6st attempts to use UPnP and IPv6 is enabled at the same time,
the external IPv4 was published for IPv6 protocols.
For example, machine6 in the demo had:
  10.0.1.3,1194,tcp;10.0.1.3,1194,udp;10.0.1.3,1195,udp6

This caused re6stnet to crash (socket.gaierror) if GEOIP2_MMDB is set.

With this commit, IPv4 & IPv6 are now processed independently.
parent ebee829d
log m6/ log m6/
run m6/run run m6/run
state m6/ state m6/
ipv6 fc42:6::1
pp 1194 tcp pp 1194 tcp
pp 1194 udp pp 1194 udp
pp 1195 udp6 pp 1195 udp6
......
...@@ -23,6 +23,9 @@ def getConfig(): ...@@ -23,6 +23,9 @@ def getConfig():
"- any: ask peers our IP\n" "- any: ask peers our IP\n"
" (default: like 'upnp' if miniupnpc is installed,\n" " (default: like 'upnp' if miniupnpc is installed,\n"
" otherwise like 'any')") " otherwise like 'any')")
_('--ipv6', action='append', default=[],
help="IPv6 address advertised to other nodes."
" If not given, ask peers our IP.")
_('--registry', metavar='URL', required=True, _('--registry', metavar='URL', required=True,
help="Public HTTP URL of the registry, for bootstrapping.") help="Public HTTP URL of the registry, for bootstrapping.")
_('-l', '--log', default='/var/log/re6stnet', _('-l', '--log', default='/var/log/re6stnet',
...@@ -166,7 +169,7 @@ def main(): ...@@ -166,7 +169,7 @@ def main():
# Make sure we won't tunnel over re6st. # Make sure we won't tunnel over re6st.
config.disable_proto = tuple(set(('tcp6', 'udp6')).union( config.disable_proto = tuple(set(('tcp6', 'udp6')).union(
config.disable_proto)) config.disable_proto))
address = () address = []
server_tunnels = {} server_tunnels = {}
forwarder = None forwarder = None
if config.client: if config.client:
...@@ -181,18 +184,23 @@ def main(): ...@@ -181,18 +184,23 @@ def main():
else: else:
pp = [x for x in ((1194, 'udp'), (1194, 'tcp')) pp = [x for x in ((1194, 'udp'), (1194, 'tcp'))
if x[1] not in config.disable_proto] if x[1] not in config.disable_proto]
ipv4_any = []
ipv6_any = []
for x in pp:
server_tunnels.setdefault('re6stnet-' + x[1], x)
(ipv4_any if x[1] in ('tcp', 'udp') else ipv6_any).append(x)
def ip_changed(ip): def ip_changed(ip):
for family, proto_list in ((socket.AF_INET, ('tcp', 'udp')),
(socket.AF_INET6, ('tcp6', 'udp6'))):
try: try:
socket.inet_pton(family, ip) socket.inet_aton(ip)
break
except socket.error: except socket.error:
pass family = socket.AF_INET6
pp = ipv6_any
else: else:
family = None if forwarder:
return family, [(ip, str(port), proto) for port, proto in pp return forwarder.checkExternalIp(ip)
if not family or proto in proto_list] family = socket.AF_INET
pp = ipv4_any
return family, [(ip, str(port), proto) for port, proto in pp]
if config.gw_list: if config.gw_list:
gw_list = deque(config.gw_list) gw_list = deque(config.gw_list)
def remote_gateway(dest): def remote_gateway(dest):
...@@ -220,15 +228,15 @@ def main(): ...@@ -220,15 +228,15 @@ def main():
logging.info("%s: assume we are not NATed", e) logging.info("%s: assume we are not NATed", e)
else: else:
atexit.register(forwarder.clear) atexit.register(forwarder.clear)
for port, proto in pp: for port, proto in ipv4_any:
forwarder.addRule(port, proto) forwarder.addRule(port, proto)
ip_changed = forwarder.checkExternalIp address.append(forwarder.checkExternalIp())
address = ip_changed(),
elif 'any' not in config.ip: elif 'any' not in config.ip:
address = map(ip_changed, config.ip) address += map(ip_changed, config.ip)
ip_changed = None ipv4_any = ()
for x in pp: if config.ipv6:
server_tunnels.setdefault('re6stnet-' + x[1], x) address += map(ip_changed, config.ipv6)
ipv6_any = ()
else: else:
ip_changed = remote_gateway = None ip_changed = remote_gateway = None
......
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