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