Commit 8c4a1fb4 authored by Julien Muchembled's avatar Julien Muchembled

re6stnet: new --disable-proto option

parent 620b9e98
......@@ -95,19 +95,28 @@ class PeerDB(object):
return bootpeer
logging.warning('Buggy registry sent us our own address')
def addPeer(self, prefix, address, force=False):
def addPeer(self, prefix, address, set_preferred=False):
logging.debug('Adding peer %s: %s', prefix, address)
with self._db:
q = self._db.execute
(a,), = q("SELECT address FROM peer WHERE prefix=?", (prefix,))
a = a != address if force else \
set(a.split(';')) != set(address.split(';'))
if set_preferred:
preferred = address.split(';')
address = a
preferred = a.split(';')
def key(a):
return preferred.index(a)
except ValueError:
return len(preferred)
address = ';'.join(sorted(address.split(';'), key=key))
except ValueError:
q("DELETE FROM peer WHERE prefix IN (SELECT peer"
" FROM volatile.stat ORDER BY try, RANDOM() LIMIT ?,-1)",
a = True
if a:
a = None
if a != address:
q("INSERT OR REPLACE INTO peer VALUES (?,?)", (prefix, address))
q("INSERT OR REPLACE INTO volatile.stat VALUES (?,0)", (prefix,))
......@@ -41,8 +41,8 @@ class MultiGatewayManager(dict):
class Connection(object):
def __init__(self, address, iface, prefix):
self.address_list = list(utils.parse_address(address))
def __init__(self, address_list, iface, prefix):
self.address_list = address_list
self.iface = iface
self.routes = 0
self._prefix = prefix
......@@ -78,8 +78,7 @@ class Connection(object):
except TypeError:
i = len(self.address_list) - 1
if i:
db.addPeer(self._prefix, utils.dump_address(
self.address_list[i:] + self.address_list[:i]), True)
db.addPeer(self._prefix, ','.join(self.address_list[i]), True)
db.connecting(self._prefix, 0)
......@@ -106,7 +105,7 @@ class TunnelManager(object):
def __init__(self, write_pipe, peer_db, openvpn_args, timeout,
refresh, client_count, iface_list, network, prefix,
address, ip_changed, encrypt, remote_gateway):
address, ip_changed, encrypt, remote_gateway, disable_proto):
self._write_pipe = write_pipe
self._peer_db = peer_db
self._connecting = set()
......@@ -125,6 +124,7 @@ class TunnelManager(object):
self._encrypt = encrypt
self._gateway_manager = MultiGatewayManager(remote_gateway) \
if remote_gateway else None
self._disable_proto = disable_proto
self._served = set()
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
......@@ -216,6 +216,11 @@ class TunnelManager(object):
if prefix in self._served or prefix in self._connection_dict:
return False
assert prefix != self._prefix, self.__dict__
address = [x for x in utils.parse_address(address)
if x[2] not in self._disable_proto]
self._peer_db.connecting(prefix, 1)
if not address:
return False'Establishing a connection with %u/%u',
int(prefix, 2), len(prefix))
iface = self.getFreeInterface(prefix)
......@@ -224,7 +229,6 @@ class TunnelManager(object):
for ip in c:
self._gateway_manager.add(ip, True), self._timeout, self._encrypt, self._ovpn_args)
self._peer_db.connecting(prefix, 1)
return True
def _makeNewTunnels(self, route_counted):
......@@ -101,6 +101,8 @@ def getConfig():
_('--remote-gateway', action='append', dest='gw_list',
help="Force each tunnel to be created through one the given gateways,"
" in a round-robin fashion.")
_('--disable-proto', action='append', choices=('udp', 'tcp'), default=[],
help="Do never try to create tunnels using given protocols.")
_('--client', metavar='HOST,PORT,PROTO[;...]',
help="Do not run any OpenVPN server, but only 1 OpenVPN client,"
" with specified remotes. Any other option not required in this"
......@@ -229,7 +231,8 @@ def main():
tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db,
config.openvpn_args, timeout, config.tunnel_refresh,
config.client_count, config.iface_list, network, prefix,
address, ip_changed, config.encrypt, remote_gateway)
address, ip_changed, config.encrypt, remote_gateway,
tunnel_interfaces += tunnel_manager.new_iface_list
tunnel_manager = write_pipe = 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