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