Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Yohann D'Anello
re6stnet
Commits
a565fe10
Commit
a565fe10
authored
Jul 18, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added hello_interval option and set ping-exit accordingly
parent
088f2f9d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
16 deletions
+28
-16
plib.py
plib.py
+12
-8
tunnel.py
tunnel.py
+8
-5
vifibnet.py
vifibnet.py
+8
-3
No files found.
plib.py
View file @
a565fe10
...
@@ -3,15 +3,14 @@ import utils
...
@@ -3,15 +3,14 @@ import utils
verbose
=
None
verbose
=
None
def
openvpn
(
*
args
,
**
kw
):
def
openvpn
(
hello_interval
,
*
args
,
**
kw
):
args
=
[
'openvpn'
,
args
=
[
'openvpn'
,
'--dev-type'
,
'tap'
,
'--dev-type'
,
'tap'
,
'--persist-tun'
,
'--persist-tun'
,
'--persist-key'
,
'--persist-key'
,
'--script-security'
,
'2'
,
'--script-security'
,
'2'
,
'--user'
,
'nobody'
,
'--user'
,
'nobody'
,
'--ping'
,
'1'
,
'--ping-exit'
,
str
(
4
*
hello_interval
),
'--ping-exit'
,
'3'
,
'--group'
,
'nogroup'
,
'--group'
,
'nogroup'
,
'--verb'
,
str
(
verbose
),
'--verb'
,
str
(
verbose
),
]
+
list
(
args
)
]
+
list
(
args
)
...
@@ -21,9 +20,9 @@ def openvpn(*args, **kw):
...
@@ -21,9 +20,9 @@ def openvpn(*args, **kw):
# TODO : set iface up when creating a server/client
# TODO : set iface up when creating a server/client
# ! check working directory before launching up script ?
# ! check working directory before launching up script ?
def
server
(
server_ip
,
network
,
max_clients
,
dh_path
,
pipe_fd
,
port
,
proto
,
*
args
,
**
kw
):
def
server
(
server_ip
,
network
,
max_clients
,
dh_path
,
pipe_fd
,
port
,
proto
,
hello_interval
,
*
args
,
**
kw
):
utils
.
log
(
'Starting server'
,
3
)
utils
.
log
(
'Starting server'
,
3
)
return
openvpn
(
return
openvpn
(
hello_interval
,
'--tls-server'
,
'--tls-server'
,
'--mode'
,
'server'
,
'--mode'
,
'server'
,
'--up'
,
'ovpn-server %s/%u'
%
(
server_ip
,
len
(
network
)),
'--up'
,
'ovpn-server %s/%u'
%
(
server_ip
,
len
(
network
)),
...
@@ -35,9 +34,9 @@ def server(server_ip, network, max_clients, dh_path, pipe_fd, port, proto, *args
...
@@ -35,9 +34,9 @@ def server(server_ip, network, max_clients, dh_path, pipe_fd, port, proto, *args
'--proto'
,
proto
,
'--proto'
,
proto
,
*
args
,
**
kw
)
*
args
,
**
kw
)
def
client
(
server_ip
,
pipe_fd
,
*
args
,
**
kw
):
def
client
(
server_ip
,
pipe_fd
,
hello_interval
,
*
args
,
**
kw
):
utils
.
log
(
'Starting client'
,
5
)
utils
.
log
(
'Starting client'
,
5
)
return
openvpn
(
return
openvpn
(
hello_interval
,
'--nobind'
,
'--nobind'
,
'--client'
,
'--client'
,
'--remote'
,
server_ip
,
'--remote'
,
server_ip
,
...
@@ -45,7 +44,8 @@ def client(server_ip, pipe_fd, *args, **kw):
...
@@ -45,7 +44,8 @@ def client(server_ip, pipe_fd, *args, **kw):
'--route-up'
,
'ovpn-client '
+
str
(
pipe_fd
),
'--route-up'
,
'ovpn-client '
+
str
(
pipe_fd
),
*
args
,
**
kw
)
*
args
,
**
kw
)
def
router
(
network
,
internal_ip
,
interface_list
,
**
kw
):
def
router
(
network
,
internal_ip
,
interface_list
,
wireless
,
hello_interval
,
**
kw
):
utils
.
log
(
'Starting babel'
,
3
)
utils
.
log
(
'Starting babel'
,
3
)
args
=
[
'babeld'
,
args
=
[
'babeld'
,
'-C'
,
'redistribute local ip %s'
%
(
internal_ip
),
'-C'
,
'redistribute local ip %s'
%
(
internal_ip
),
...
@@ -59,10 +59,14 @@ def router(network, internal_ip, interface_list, **kw):
...
@@ -59,10 +59,14 @@ def router(network, internal_ip, interface_list, **kw):
# Don't route other addresses
# Don't route other addresses
'-C'
,
'in deny'
,
'-C'
,
'in deny'
,
'-d'
,
str
(
verbose
),
'-d'
,
str
(
verbose
),
'-h'
,
str
(
hello_interval
),
'-H'
,
str
(
hello_interval
),
'-s'
,
'-s'
,
]
]
#if utils.config.babel_state:
#if utils.config.babel_state:
# args += '-S', utils.config.babel_state
# args += '-S', utils.config.babel_state
if
wireless
:
args
.
append
(
'-w'
)
args
=
args
+
interface_list
args
=
args
+
interface_list
utils
.
log
(
str
(
args
),
5
)
utils
.
log
(
str
(
args
),
5
)
return
subprocess
.
Popen
(
args
,
**
kw
)
return
subprocess
.
Popen
(
args
,
**
kw
)
...
...
tunnel.py
View file @
a565fe10
...
@@ -5,11 +5,12 @@ log = None
...
@@ -5,11 +5,12 @@ log = None
class
TunnelManager
:
class
TunnelManager
:
def
__init__
(
self
,
write_pipe
,
peer_db
,
openvpn_args
,
refresh
,
connection_count
,
refresh_rate
):
def
__init__
(
self
,
write_pipe
,
peer_db
,
openvpn_args
,
hello_interval
,
refresh
,
connection_count
,
refresh_rate
):
self
.
_write_pipe
=
write_pipe
self
.
_write_pipe
=
write_pipe
self
.
_peer_db
=
peer_db
self
.
_peer_db
=
peer_db
self
.
_connection_dict
=
{}
self
.
_connection_dict
=
{}
self
.
_ovpn_args
=
openvpn_args
self
.
_ovpn_args
=
openvpn_args
self
.
_hello
=
hello_interval
self
.
_refresh_time
=
refresh
self
.
_refresh_time
=
refresh
self
.
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
self
.
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
...
@@ -53,10 +54,12 @@ class TunnelManager:
...
@@ -53,10 +54,12 @@ class TunnelManager:
for
peer_id
,
ip
,
port
,
proto
in
self
.
_peer_db
.
getUnusedPeers
(
self
.
_client_count
-
len
(
self
.
_connection_dict
)):
for
peer_id
,
ip
,
port
,
proto
in
self
.
_peer_db
.
getUnusedPeers
(
self
.
_client_count
-
len
(
self
.
_connection_dict
)):
utils
.
log
(
'Establishing a connection with id %s (%s:%s)'
%
(
peer_id
,
ip
,
port
),
2
)
utils
.
log
(
'Establishing a connection with id %s (%s:%s)'
%
(
peer_id
,
ip
,
port
),
2
)
iface
=
self
.
free_interface_set
.
pop
()
iface
=
self
.
free_interface_set
.
pop
()
self
.
_connection_dict
[
peer_id
]
=
(
plib
.
client
(
ip
,
self
.
_write_pipe
,
self
.
_connection_dict
[
peer_id
]
=
(
plib
.
client
(
ip
,
self
.
_write_pipe
,
self
.
_hello
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
*
self
.
_ovpn_args
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
*
self
.
_ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
self
.
_peer_db
.
usePeer
(
peer_id
)
self
.
_peer_db
.
usePeer
(
peer_id
)
except
KeyError
:
except
KeyError
:
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
...
...
vifibnet.py
View file @
a565fe10
...
@@ -24,6 +24,10 @@ def getConfig():
...
@@ -24,6 +24,10 @@ def getConfig():
help
=
'Path to dh file'
)
help
=
'Path to dh file'
)
_
(
'--babel-state'
,
default
=
'/var/lib/vifibnet/babel_state'
,
_
(
'--babel-state'
,
default
=
'/var/lib/vifibnet/babel_state'
,
help
=
'Path to babeld state-file'
)
help
=
'Path to babeld state-file'
)
_
(
'--hello'
,
type
=
int
,
default
=
30
,
help
=
'Hello interval for babel, in seconds'
)
_
(
'-w'
,
'--wireless'
,
action
=
'store_true'
,
help
=
'Set all interfaces to be treated as wireless interfaces ( in babel )'
)
_
(
'--verbose'
,
'-v'
,
default
=
0
,
type
=
int
,
_
(
'--verbose'
,
'-v'
,
default
=
0
,
type
=
int
,
help
=
'Defines the verbose level'
)
help
=
'Defines the verbose level'
)
_
(
'--ca'
,
required
=
True
,
_
(
'--ca'
,
required
=
True
,
...
@@ -73,17 +77,18 @@ def main():
...
@@ -73,17 +77,18 @@ def main():
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
config
.
peers_db_refresh
,
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
config
.
peers_db_refresh
,
config
.
external_ip
,
internal_ip
,
config
.
external_port
,
config
.
proto
,
200
)
config
.
external_ip
,
internal_ip
,
config
.
external_port
,
config
.
proto
,
200
)
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
openvpn_args
,
config
.
tunnel_refresh
,
config
.
connection_count
,
config
.
refresh_rate
)
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
openvpn_args
,
config
.
hello
,
config
.
tunnel_refresh
,
config
.
connection_count
,
config
.
refresh_rate
)
# 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
interface_list
=
[
'vifibnet'
]
+
list
(
tunnel_manager
.
free_interface_set
)
interface_list
=
[
'vifibnet'
]
+
list
(
tunnel_manager
.
free_interface_set
)
router
=
plib
.
router
(
network
,
internal_ip
,
interface_list
,
router
=
plib
.
router
(
network
,
internal_ip
,
interface_list
,
config
.
wireless
,
config
.
hello
,
stdout
=
os
.
open
(
os
.
path
.
join
(
config
.
log
,
'vifibnet.babeld.log'
),
stdout
=
os
.
open
(
os
.
path
.
join
(
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
)
# Establish connections
# Establish connections
server_process
=
plib
.
server
(
internal_ip
,
network
,
config
.
connection_count
,
config
.
dh
,
write_pipe
,
server_process
=
plib
.
server
(
internal_ip
,
network
,
config
.
connection_count
,
config
.
dh
,
write_pipe
,
config
.
internal_port
,
config
.
proto
,
'--dev'
,
'vifibnet'
,
*
openvpn_args
,
config
.
internal_port
,
config
.
proto
,
config
.
hello
,
'--dev'
,
'vifibnet'
,
*
openvpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
config
.
log
,
'vifibnet.server.log'
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
))
stdout
=
os
.
open
(
os
.
path
.
join
(
config
.
log
,
'vifibnet.server.log'
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
))
# main loop
# main loop
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment