Commit fffa5011 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

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

Conflicts:
	tunnelmanager.py
parents 6a665380 96b58da8
...@@ -8,11 +8,6 @@ To be done : ...@@ -8,11 +8,6 @@ To be done :
To be discuss: To be discuss:
Remove the --no-boot option since we know when no node is avalaible Remove the --no-boot option since we know when no node is avalaible
When I created PeersDB, I thought only be used to access the DB and not do some logic.
We should decide what it is suppose to do :
Just access the DB
Or manage the peers
The organisation of the code The organisation of the code
vifibnet.py Just contain the main loop and the init vifibnet.py Just contain the main loop and the init
openpvn.py To launch openvpn processes openpvn.py To launch openvpn processes
...@@ -26,4 +21,5 @@ To be discuss: ...@@ -26,4 +21,5 @@ To be discuss:
Every time a packet is lost, it is resend 2 times, one for each TCP tunnel Every time a packet is lost, it is resend 2 times, one for each TCP tunnel
And many GW allow UDP port forwarding (for bittorent, Xbox, ...) but not TCP port forwarding And many GW allow UDP port forwarding (for bittorent, Xbox, ...) but not TCP port forwarding
Use peers_db.populate(100) every once in a while ? Use peers_db.populate(100) every once in a while ? -> yes but be warry of the refresh time ( populate
the db once every 20s is bad.. )
#!/bin/sh -e
ip link set $dev up
#!/bin/sh -e
ip link set $dev up
ip addr add $1 dev $dev
#!/usr/bin/python -S #!/usr/bin/python -S
import os, time, sys import os, sys
if os.environ['script_type'] == '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\n' % os.environ) os.write(int(sys.argv[1]), '%(script_type)s %(OPENVPN_external_ip)s\n' % os.environ)
#!/usr/bin/python -S #!/usr/bin/python -S
import os, time, sys
# example of os.environ # example of os.environ
{'X509_0_C': 'FR', {'X509_0_C': 'FR',
...@@ -37,10 +36,18 @@ import os, time, sys ...@@ -37,10 +36,18 @@ import os, time, sys
'untrusted_port': '59345', 'untrusted_port': '59345',
'verb': '3'} 'verb': '3'}
# Send to client his external ip address script_type = os.environ['script_type']
if os.environ['script_type'] == 'client-connect': if script_type == 'up':
from subprocess import call
dev = os.environ['dev']
sys.exit(call(('ip', 'link', 'set', dev, 'up'))
or call(('ip', 'addr', 'add', sys.argv[1], 'dev', dev)))
if script_type == 'client-connect':
# Send client its external ip address
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' % os.environ['trusted_ip']) f.write('push "setenv-safe external_ip %s"\n'
% os.environ['trusted_ip'])
# 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)
#!/usr/bin/env python
import subprocess import subprocess
import utils import utils
import os import os
...@@ -26,26 +27,29 @@ def openvpn(*args, **kw): ...@@ -26,26 +27,29 @@ def openvpn(*args, **kw):
# ! check working directory before launching up script ? # ! check working directory before launching up script ?
def server(ip, pipe_fd, *args, **kw): def server(ip, pipe_fd, *args, **kw):
utils.log('Starting server', 3)
return openvpn( return openvpn(
'--tls-server', '--tls-server',
'--mode', 'server', '--mode', 'server',
'--up', 'openvpn-up-server %s/%u' % (ip, len(utils.config.vifibnet)), '--up', 'ovpn-server %s/%u' % (ip, len(utils.config.vifibnet)),
'--client-connect', 'openvpn-server-events ' + str(pipe_fd), '--client-connect', 'ovpn-server ' + str(pipe_fd),
'--client-disconnect', 'openvpn-server-events ' + str(pipe_fd), '--client-disconnect', 'ovpn-server ' + str(pipe_fd),
'--dh', utils.config.dh, '--dh', utils.config.dh,
'--max-clients', str(utils.config.max_clients), '--max-clients', str(utils.config.max_clients),
*args, **kw) *args, **kw)
def client(serverIp, pipe_fd, *args, **kw): def client(serverIp, pipe_fd, *args, **kw):
utils.log('Starting client', 5)
return openvpn( return openvpn(
'--nobind', '--nobind',
'--client', '--client',
'--remote', serverIp, '--remote', serverIp,
'--up', 'openvpn-up-client', '--up', 'ovpn-client',
'--route-up', 'openvpn-route-up ' + str(pipe_fd), '--route-up', 'ovpn-client ' + str(pipe_fd),
*args, **kw) *args, **kw)
def startBabel(**kw): def babel(**kw):
utils.log('Starting babel', 3)
args = ['babeld', args = ['babeld',
'-C', 'redistribute local ip %s' % (utils.config.internal_ip), '-C', 'redistribute local ip %s' % (utils.config.internal_ip),
'-C', 'redistribute local deny', '-C', 'redistribute local deny',
...@@ -63,7 +67,6 @@ def startBabel(**kw): ...@@ -63,7 +67,6 @@ def startBabel(**kw):
if utils.config.babel_state: if utils.config.babel_state:
args += '-S', utils.config.babel_state args += '-S', utils.config.babel_state
args = args + ['vifibnet'] + list(tunnelmanager.free_interface_set) args = args + ['vifibnet'] + list(tunnelmanager.free_interface_set)
if utils.config.verbose >= 5: utils.log(str(args), 5)
print args
return subprocess.Popen(args, **kw) return subprocess.Popen(args, **kw)
import os, random, traceback import os, random, traceback
import openvpn import plib, utils, db
import utils
import db
free_interface_set = set(('client1', 'client2', 'client3', 'client4', 'client5', free_interface_set = set(('client1', 'client2', 'client3', 'client4', 'client5',
'client6', 'client7', 'client8', 'client9', 'client10')) 'client6', 'client7', 'client8', 'client9', 'client10'))
......
#!/usr/bin/env python #!/usr/bin/env python
import argparse, errno, math, os, select, subprocess, sys, time, traceback import argparse, errno, math, os, select, subprocess, sys, time, traceback
from OpenSSL import crypto from OpenSSL import crypto
import db, openvpn, upnpigd, utils, tunnelmanager import db, plib, upnpigd, utils, tunnelmanager
def handle_message(msg): def handle_message(msg):
script_type, arg = msg.split() script_type, arg = msg.split()
...@@ -21,22 +21,20 @@ def main(): ...@@ -21,22 +21,20 @@ def main():
utils.getConfig() utils.getConfig()
# Launch babel on all interfaces. WARNING : you have to be root to start babeld # Launch babel on all interfaces. WARNING : you have to be root to start babeld
utils.log('Starting babel', 3) babel = plib.babel(stdout=os.open(os.path.join(utils.config.log, 'vifibnet.babeld.log'),
babel = startBabel(stdout=os.open(os.path.join(utils.config.log, 'vifibnet.babeld.log'),
os.O_WRONLY | os.O_CREAT | os.O_TRUNC), stderr=subprocess.STDOUT) os.O_WRONLY | os.O_CREAT | os.O_TRUNC), stderr=subprocess.STDOUT)
# Create and open read_only pipe to get connect/disconnect events from openvpn # Create and open read_only pipe to get connect/disconnect events from openvpn
utils.log('Creating pipe for openvpn events', 3) utils.log('Creating pipe for server events', 3)
r_pipe, write_pipe = os.pipe() r_pipe, write_pipe = os.pipe()
read_pipe = os.fdopen(r_pipe) read_pipe = os.fdopen(r_pipe)
# setup the tunnel manager # Setup the tunnel manager
peers_db = db.PeersDB(utils.config.db) peers_db = db.PeersDB(utils.config.db)
tunnelManager = tunnelmanager.TunnelManager(write_pipe, peers_db) tunnelManager = tunnelmanager.TunnelManager(write_pipe, peers_db)
# Establish connections # Establish connections
utils.log('Starting openvpn server', 3) serverProcess = plib.server(utils.config.internal_ip, write_pipe, '--dev', 'vifibnet',
serverProcess = openvpn.server(utils.config.internal_ip, write_pipe, '--dev', 'vifibnet',
stdout=os.open(os.path.join(utils.config.log, 'vifibnet.server.log'), os.O_WRONLY | os.O_CREAT | os.O_TRUNC)) stdout=os.open(os.path.join(utils.config.log, 'vifibnet.server.log'), os.O_WRONLY | os.O_CREAT | os.O_TRUNC))
tunnelManager.refresh() tunnelManager.refresh()
......
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