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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
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
Hide 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
verbose
=
None
def
openvpn
(
*
args
,
**
kw
):
def
openvpn
(
hello_interval
,
*
args
,
**
kw
):
args
=
[
'openvpn'
,
'--dev-type'
,
'tap'
,
'--persist-tun'
,
'--persist-key'
,
'--script-security'
,
'2'
,
'--user'
,
'nobody'
,
'--ping'
,
'1'
,
'--ping-exit'
,
'3'
,
'--ping-exit'
,
str
(
4
*
hello_interval
),
'--group'
,
'nogroup'
,
'--verb'
,
str
(
verbose
),
]
+
list
(
args
)
...
...
@@ -21,9 +20,9 @@ def openvpn(*args, **kw):
# TODO : set iface up when creating a server/client
# ! 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
)
return
openvpn
(
return
openvpn
(
hello_interval
,
'--tls-server'
,
'--mode'
,
'server'
,
'--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
'--proto'
,
proto
,
*
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
)
return
openvpn
(
return
openvpn
(
hello_interval
,
'--nobind'
,
'--client'
,
'--remote'
,
server_ip
,
...
...
@@ -45,7 +44,8 @@ def client(server_ip, pipe_fd, *args, **kw):
'--route-up'
,
'ovpn-client '
+
str
(
pipe_fd
),
*
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
)
args
=
[
'babeld'
,
'-C'
,
'redistribute local ip %s'
%
(
internal_ip
),
...
...
@@ -59,10 +59,14 @@ def router(network, internal_ip, interface_list, **kw):
# Don't route other addresses
'-C'
,
'in deny'
,
'-d'
,
str
(
verbose
),
'-h'
,
str
(
hello_interval
),
'-H'
,
str
(
hello_interval
),
'-s'
,
]
#if utils.config.babel_state:
# args += '-S', utils.config.babel_state
if
wireless
:
args
.
append
(
'-w'
)
args
=
args
+
interface_list
utils
.
log
(
str
(
args
),
5
)
return
subprocess
.
Popen
(
args
,
**
kw
)
...
...
tunnel.py
View file @
a565fe10
...
...
@@ -5,11 +5,12 @@ log = None
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
.
_peer_db
=
peer_db
self
.
_connection_dict
=
{}
self
.
_ovpn_args
=
openvpn_args
self
.
_hello
=
hello_interval
self
.
_refresh_time
=
refresh
self
.
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
...
...
@@ -53,10 +54,12 @@ class TunnelManager:
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
)
iface
=
self
.
free_interface_set
.
pop
()
self
.
_connection_dict
[
peer_id
]
=
(
plib
.
client
(
ip
,
self
.
_write_pipe
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
*
self
.
_ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
self
.
_connection_dict
[
peer_id
]
=
(
plib
.
client
(
ip
,
self
.
_write_pipe
,
self
.
_hello
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
*
self
.
_ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
self
.
_peer_db
.
usePeer
(
peer_id
)
except
KeyError
:
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
...
...
vifibnet.py
View file @
a565fe10
...
...
@@ -24,6 +24,10 @@ def getConfig():
help
=
'Path to dh file'
)
_
(
'--babel-state'
,
default
=
'/var/lib/vifibnet/babel_state'
,
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
,
help
=
'Defines the verbose level'
)
_
(
'--ca'
,
required
=
True
,
...
...
@@ -73,17 +77,18 @@ def main():
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
)
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
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'
),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
),
stderr
=
subprocess
.
STDOUT
)
# Establish connections
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
))
# 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