Commit 0820ffd1 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Merge branch 'master' of https://git.erp5.org/repos/vifibnet

Conflicts:
	TODO
parents 6b0076d2 23f47592
Bugs: Bugs:
The address of the client is declared while it should only be the address The address of the client is declared while it should only be the address
of the server of the server
To be done : To be done :
use the server as a bootstrap node -> switch peer discovery to be done use the server as a bootstrap node -> switch peer discovery to be done
......
...@@ -6,7 +6,7 @@ class PeerManager: ...@@ -6,7 +6,7 @@ class PeerManager:
# internal ip = temp arg/attribute # internal ip = temp arg/attribute
def __init__(self, db_dir_path, server, server_port, refresh_time, address, def __init__(self, db_dir_path, server, server_port, refresh_time, address,
internal_ip, prefix, manual, proto, db_size): internal_ip, prefix, manual, pp , db_size):
self._refresh_time = refresh_time self._refresh_time = refresh_time
self._address = address self._address = address
self._internal_ip = internal_ip self._internal_ip = internal_ip
...@@ -14,7 +14,7 @@ class PeerManager: ...@@ -14,7 +14,7 @@ class PeerManager:
self._server = server self._server = server
self._server_port = server_port self._server_port = server_port
self._db_size = db_size self._db_size = db_size
self._proto = proto self._pp = pp
self._manual = manual self._manual = manual
self._proxy = xmlrpclib.ServerProxy('http://%s:%u' self._proxy = xmlrpclib.ServerProxy('http://%s:%u'
...@@ -92,13 +92,13 @@ class PeerManager: ...@@ -92,13 +92,13 @@ class PeerManager:
utils.log('%s has disconnected' % (arg,), 3) utils.log('%s has disconnected' % (arg,), 3)
elif script_type == 'route-up': elif script_type == 'route-up':
if not self._manual: if not self._manual:
external_ip, external_port = arg.split(',') external_ip = arg
new_address = list([external_ip, external_port, proto] new_address = list([external_ip, port, proto]
for proto in self._proto) for port, proto in self._pp)
if self._address != new_address: if self._address != new_address:
self._address = new_address self._address = new_address
utils.log('Received new external configuration : %s:%s' utils.log('Received new external ip : %s'
% (external_ip, external_port), 3) % (external_ip,), 3)
self._declare() self._declare()
else: else:
utils.log('Unknow message recieved from the openvpn pipe : ' utils.log('Unknow message recieved from the openvpn pipe : '
......
...@@ -5,4 +5,4 @@ if os.environ['script_type'] == 'up': ...@@ -5,4 +5,4 @@ if os.environ['script_type'] == 'up':
os.execlp('ip', 'ip', 'link', 'set', os.environ['dev'], 'up') os.execlp('ip', 'ip', 'link', 'set', os.environ['dev'], 'up')
# Write into pipe external ip address received # Write into pipe external ip address received
os.write(int(sys.argv[1]), '%(script_type)s %(OPENVPN_external_ip)s,%(OPENVPN_external_port)s\n' % os.environ) os.write(int(sys.argv[1]), '%(script_type)s %(OPENVPN_external_ip)s\n' % os.environ)
...@@ -49,8 +49,6 @@ if script_type == 'client-connect': ...@@ -49,8 +49,6 @@ if script_type == 'client-connect':
with open(sys.argv[2], 'w') as f: with open(sys.argv[2], 'w') as f:
f.write('push "setenv-safe external_ip %s"\n' f.write('push "setenv-safe external_ip %s"\n'
% os.environ['trusted_ip']) % os.environ['trusted_ip'])
f.write('push "setenv-safe external_port %s"\n'
% os.environ['trusted_port'])
# Write into pipe connect/disconnect events # Write into pipe connect/disconnect events
os.write(int(sys.argv[1]), '%(script_type)s %(common_name)s\n' % os.environ) os.write(int(sys.argv[1]), '%(script_type)s %(common_name)s\n' % os.environ)
...@@ -33,8 +33,6 @@ def getConfig(): ...@@ -33,8 +33,6 @@ def getConfig():
# General Configuration options # General Configuration options
_('--ip', default=None, dest='address', action='append', nargs=3, _('--ip', default=None, dest='address', action='append', nargs=3,
help='Ip address, port and protocol advertised to other vpn nodes') help='Ip address, port and protocol advertised to other vpn nodes')
_('--internal-port', default=1194,
help='Port on the machine to listen on for incomming connections')
_('--peers-db-refresh', default=3600, type=int, _('--peers-db-refresh', default=3600, type=int,
help='the time (seconds) to wait before refreshing the peers db') help='the time (seconds) to wait before refreshing the peers db')
_('-l', '--log', default='/var/log', _('-l', '--log', default='/var/log',
...@@ -60,8 +58,8 @@ def getConfig(): ...@@ -60,8 +58,8 @@ def getConfig():
for the routing protocol''') for the routing protocol''')
# Tunnel options # Tunnel options
_('--proto', choices=['udp', 'tcp-server'], nargs='+', default=['udp'], _('--pp', nargs=2, action='append',
help='Protocol(s) to be used by other peers to connect') help='Port and protocol to be used by other peers to connect')
_('--tunnel-refresh', default=300, type=int, _('--tunnel-refresh', default=300, type=int,
help='the time (seconds) to wait before changing the connections') help='the time (seconds) to wait before changing the connections')
_('--dh', required=True, _('--dh', required=True,
...@@ -85,6 +83,8 @@ def getConfig(): ...@@ -85,6 +83,8 @@ def getConfig():
def main(): def main():
# Get arguments # Get arguments
config = getConfig() config = getConfig()
if not config.pp:
config.pp = [['1194', 'udp']]
manual = bool(config.address) manual = bool(config.address)
network = utils.networkFromCa(config.ca) network = utils.networkFromCa(config.ca)
internal_ip, prefix = utils.ipFromCert(network, config.cert) internal_ip, prefix = utils.ipFromCert(network, config.cert)
...@@ -102,19 +102,21 @@ def main(): ...@@ -102,19 +102,21 @@ def main():
# Init db and tunnels # Init db and tunnels
if manual: if manual:
utils.log('Manual external configuration', 3) utils.log('Manual external configuration', 3)
forward = None
else: else:
utils.log('Attempting automatic configuration via UPnP', 4) utils.log('Attempting automatic configuration via UPnP', 4)
try: try:
forward = upnpigd.UpnpForward(config.internal_port, config.proto) forward = list([upnpigd.UpnpForward(int(port), proto), proto]
config.address = list([forward.external_ip, for port, proto in config.pp)
str(forward.external_port), proto] for proto in config.proto) config.address = list([ext.external_ip, str(ext.external_port),
proto] for ext, proto in forward)
except Exception: except Exception:
forward = None forward = None
utils.log('An atempt to forward a port via UPnP failed', 4) utils.log('An atempt to forward a port via UPnP failed', 4)
peer_db = db.PeerManager(config.state, config.server, config.server_port, peer_db = db.PeerManager(config.state, config.server, config.server_port,
config.peers_db_refresh, config.address, internal_ip, prefix, config.peers_db_refresh, config.address, internal_ip, prefix,
manual, config.proto, 200) manual, config.pp, 200)
tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, openvpn_args, tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, openvpn_args,
config.hello, config.tunnel_refresh, config.connection_count, config.hello, config.tunnel_refresh, config.connection_count,
config.refresh_rate) config.refresh_rate)
...@@ -128,11 +130,12 @@ def main(): ...@@ -128,11 +130,12 @@ def main():
# Establish connections # Establish connections
server_process = list(plib.server(internal_ip, len(network) + len(prefix), server_process = list(plib.server(internal_ip, len(network) + len(prefix),
config.connection_count, config.dh, write_pipe, config.internal_port, config.connection_count, config.dh, write_pipe, port,
proto, config.hello, '--dev', 'vifibnet', *openvpn_args, proto, config.hello, '--dev', 'vifibnet', *openvpn_args,
stdout=os.open(os.path.join(config.log, stdout=os.open(os.path.join(config.log,
'vifibnet.server.%s.log' % (proto,)), 'vifibnet.server.%s.log' % (proto,)),
os.O_WRONLY | os.O_CREAT | os.O_TRUNC)) for proto in config.proto) os.O_WRONLY | os.O_CREAT | os.O_TRUNC))
for port, proto in config.pp)
tunnel_manager.refresh() tunnel_manager.refresh()
# main loop # main loop
......
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