Commit e7abbba0 authored by Julien Muchembled's avatar Julien Muchembled

Fix OpenVPN server not closing dead tunnels

This fixes a regression in commit b10674f3
("re6stnet: new client-only and routing-only mode").
parent d6ab9f80
...@@ -9,12 +9,12 @@ RTF_CACHE = 0x01000000 # cache entry ...@@ -9,12 +9,12 @@ RTF_CACHE = 0x01000000 # cache entry
class Connection: class Connection:
def __init__(self, address, write_pipe, hello, iface, prefix, encrypt, def __init__(self, address, write_pipe, timeout, iface, prefix, encrypt,
ovpn_args): ovpn_args):
self.process = plib.client(iface, address, encrypt, self.process = plib.client(iface, address, encrypt,
'--tls-remote', '%u/%u' % (int(prefix, 2), len(prefix)), '--tls-remote', '%u/%u' % (int(prefix, 2), len(prefix)),
'--connect-retry-max', '3', '--tls-exit', '--connect-retry-max', '3', '--tls-exit',
'--ping-exit', str(4 * hello), '--ping-exit', str(timeout),
'--up', plib.ovpn_client, '--up', plib.ovpn_client,
'--route-up', '%s %u' % (plib.ovpn_client, write_pipe), '--route-up', '%s %u' % (plib.ovpn_client, write_pipe),
*ovpn_args) *ovpn_args)
...@@ -33,7 +33,7 @@ class Connection: ...@@ -33,7 +33,7 @@ class Connection:
class TunnelManager(object): class TunnelManager(object):
def __init__(self, write_pipe, peer_db, openvpn_args, hello_interval, def __init__(self, write_pipe, peer_db, openvpn_args, timeout,
refresh, client_count, iface_list, network, prefix, refresh, client_count, iface_list, network, prefix,
address, ip_changed, encrypt): address, ip_changed, encrypt):
self._write_pipe = write_pipe self._write_pipe = write_pipe
...@@ -44,7 +44,7 @@ class TunnelManager(object): ...@@ -44,7 +44,7 @@ class TunnelManager(object):
self._distant_peers = [] self._distant_peers = []
self._iface_to_prefix = {} self._iface_to_prefix = {}
self._ovpn_args = openvpn_args self._ovpn_args = openvpn_args
self._hello = hello_interval self._timeout = timeout
self._refresh_time = refresh self._refresh_time = refresh
self._network = network self._network = network
self._iface_list = iface_list self._iface_list = iface_list
...@@ -115,7 +115,7 @@ class TunnelManager(object): ...@@ -115,7 +115,7 @@ class TunnelManager(object):
int(prefix, 2), len(prefix)) int(prefix, 2), len(prefix))
iface = self.free_interface_set.pop() iface = self.free_interface_set.pop()
self._connection_dict[prefix] = Connection(address, self._write_pipe, self._connection_dict[prefix] = Connection(address, self._write_pipe,
self._hello, iface, prefix, self._encrypt, self._ovpn_args) self._timeout, iface, prefix, self._encrypt, self._ovpn_args)
self._iface_to_prefix[iface] = prefix self._iface_to_prefix[iface] = prefix
self._peer_db.connecting(prefix, 1) self._peer_db.connecting(prefix, 1)
return True return True
......
...@@ -160,6 +160,7 @@ def main(): ...@@ -160,6 +160,7 @@ def main():
my_ip = '%s/%s' % (utils.ipFromBin(subnet, '1'), len(subnet)) my_ip = '%s/%s' % (utils.ipFromBin(subnet, '1'), len(subnet))
# Init db and tunnels # Init db and tunnels
timeout = 4 * config.hello
if config.client_count and not config.client: if config.client_count and not config.client:
required('registry') required('registry')
# Create and open read_only pipe to get server events # Create and open read_only pipe to get server events
...@@ -167,7 +168,7 @@ def main(): ...@@ -167,7 +168,7 @@ def main():
read_pipe = os.fdopen(r_pipe) read_pipe = os.fdopen(r_pipe)
peer_db = db.PeerDB(db_path, config.registry, config.key, prefix) peer_db = db.PeerDB(db_path, config.registry, config.key, prefix)
tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db,
config.openvpn_args, config.hello, config.tunnel_refresh, config.openvpn_args, timeout, config.tunnel_refresh,
config.client_count, config.iface_list, network, prefix, config.client_count, config.iface_list, network, prefix,
address, ip_changed, config.encrypt) address, ip_changed, config.encrypt)
config.babel_args += tunnel_manager.free_interface_set config.babel_args += tunnel_manager.free_interface_set
...@@ -188,7 +189,7 @@ def main(): ...@@ -188,7 +189,7 @@ def main():
config.encrypt, config.encrypt,
'--up', '%s %s' % (plib.ovpn_server, None '--up', '%s %s' % (plib.ovpn_server, None
if config.main_interface else my_ip), if config.main_interface else my_ip),
'--ping-restart', str(4 * config.hello), '--ping-restart', str(timeout),
*config.openvpn_args).kill) *config.openvpn_args).kill)
elif server_tunnels: elif server_tunnels:
required('dh') required('dh')
...@@ -196,7 +197,8 @@ def main(): ...@@ -196,7 +197,8 @@ def main():
cleanup.append(plib.server(iface, None cleanup.append(plib.server(iface, None
if config.main_interface or proto != pp[0][1] if config.main_interface or proto != pp[0][1]
else my_ip, config.max_clients, config.dh, write_pipe, else my_ip, config.max_clients, config.dh, write_pipe,
port, proto, config.encrypt, *config.openvpn_args).kill) port, proto, config.encrypt,
'--ping-exit', str(timeout), *config.openvpn_args).kill)
elif config.iface_list and not config.main_interface: elif config.iface_list and not config.main_interface:
config.main_interface = config.iface_list[0] config.main_interface = config.iface_list[0]
else: else:
......
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