Commit 343e910a authored by Julien Muchembled's avatar Julien Muchembled

Remove --ipv6, reuse --ip instead

The previous commit, which adds --ipv6, has the issue
that it does not check whether given IPs are valid.
Since IPv4 & IPv6 use completely different address
representation, --ip can be used for both.
parent 0106e2f9
log m6/ log m6/
run m6/run run m6/run
state m6/ state m6/
ipv6 fc42:6::1 ip fc42:6::1
pp 1194 tcp pp 1194 tcp
pp 1194 udp pp 1194 udp
pp 1195 udp6 pp 1195 udp6
......
...@@ -18,14 +18,13 @@ def getConfig(): ...@@ -18,14 +18,13 @@ def getConfig():
_('-V', '--version', action='version', version=version.version) _('-V', '--version', action='version', version=version.version)
_('--ip', action='append', default=[], _('--ip', action='append', default=[],
help="IP address advertised to other nodes. Special values:\n" help="IP address advertised to other nodes.\n"
"Special values for IPv4:\n"
"- upnp: redirect ports when UPnP device is found\n" "- upnp: redirect ports when UPnP device is found\n"
"- 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')\n"
_('--ipv6', action='append', default=[], "For IPv6, ask peers our IP if none given.")
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',
...@@ -189,6 +188,17 @@ def main(): ...@@ -189,6 +188,17 @@ def main():
for x in pp: for x in pp:
server_tunnels.setdefault('re6stnet-' + x[1], x) server_tunnels.setdefault('re6stnet-' + x[1], x)
(ipv4_any if x[1] in ('tcp', 'udp') else ipv6_any).append(x) (ipv4_any if x[1] in ('tcp', 'udp') else ipv6_any).append(x)
ipv4 = []
ipv6 = []
for ip in config.ip:
if ip not in ('any', 'upnp'):
try:
socket.inet_pton(socket.AF_INET, ip)
except socket.error:
socket.inet_pton(socket.AF_INET6, ip)
ipv6.append(ip)
continue
ipv4.append(ip)
def ip_changed(ip): def ip_changed(ip):
try: try:
socket.inet_aton(ip) socket.inet_aton(ip)
...@@ -208,8 +218,8 @@ def main(): ...@@ -208,8 +218,8 @@ def main():
return gw_list[0] return gw_list[0]
else: else:
remote_gateway = None remote_gateway = None
if len(config.ip) > 1: if len(ipv4) > 1:
if 'upnp' in config.ip or 'any' in config.ip: if 'upnp' in ipv4 or 'any' in ipv4:
sys.exit("error: argument --ip can be given only once with" sys.exit("error: argument --ip can be given only once with"
" 'any' or 'upnp' value") " 'any' or 'upnp' value")
logging.info("Multiple --ip passed: note that re6st does nothing to" logging.info("Multiple --ip passed: note that re6st does nothing to"
...@@ -217,13 +227,13 @@ def main(): ...@@ -217,13 +227,13 @@ def main():
" gateway. So without manual network configuration, this can" " gateway. So without manual network configuration, this can"
" not be used to accept server connections from multiple" " not be used to accept server connections from multiple"
" gateways.") " gateways.")
if 'upnp' in config.ip or not config.ip: if 'upnp' in ipv4 or not ipv4:
logging.info('Attempting automatic configuration via UPnP...') logging.info('Attempting automatic configuration via UPnP...')
try: try:
from re6st.upnpigd import Forwarder from re6st.upnpigd import Forwarder
forwarder = Forwarder('re6stnet openvpn server') forwarder = Forwarder('re6stnet openvpn server')
except Exception, e: except Exception, e:
if config.ip: if ipv4:
raise raise
logging.info("%s: assume we are not NATed", e) logging.info("%s: assume we are not NATed", e)
else: else:
...@@ -231,11 +241,11 @@ def main(): ...@@ -231,11 +241,11 @@ def main():
for port, proto in ipv4_any: for port, proto in ipv4_any:
forwarder.addRule(port, proto) forwarder.addRule(port, proto)
address.append(forwarder.checkExternalIp()) address.append(forwarder.checkExternalIp())
elif 'any' not in config.ip: elif 'any' not in ipv4:
address += map(ip_changed, config.ip) address += map(ip_changed, ipv4)
ipv4_any = () ipv4_any = ()
if config.ipv6: if ipv6:
address += map(ip_changed, config.ipv6) address += map(ip_changed, ipv6)
ipv6_any = () 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