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
6a4315f8
Commit
6a4315f8
authored
Jul 20, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.erp5.org/repos/vifibnet
parents
d0f47075
767e6793
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
tunnel.py
tunnel.py
+22
-2
No files found.
tunnel.py
View file @
6a4315f8
import
os
,
random
,
traceback
,
time
import
os
,
random
,
traceback
,
time
,
struct
import
plib
,
utils
,
db
log
=
None
...
...
@@ -10,7 +10,7 @@ class Connection:
self
.
process
=
plib
.
client
(
address
,
write_pipe
,
hello
,
'--dev'
,
iface
,
*
ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
prefix
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
))
self
.
iface
=
iface
self
.
_prefix
=
prefix
...
...
@@ -63,6 +63,7 @@ class TunnelManager:
self
.
_write_pipe
=
write_pipe
self
.
_peer_db
=
peer_db
self
.
_connection_dict
=
{}
self
.
_route_count
=
{}
self
.
_ovpn_args
=
openvpn_args
self
.
_hello
=
hello_interval
self
.
_refresh_time
=
refresh
...
...
@@ -78,6 +79,7 @@ class TunnelManager:
def
refresh
(
self
):
utils
.
log
(
'Refreshing the tunnels'
,
2
)
self
.
_cleanDeads
()
self
.
_countRoutes
()
self
.
_removeSomeTunnels
()
self
.
_makeNewTunnels
()
self
.
next_refresh
=
time
.
time
()
+
self
.
_refresh_time
...
...
@@ -103,6 +105,7 @@ class TunnelManager:
pass
self
.
free_interface_set
.
add
(
connection
.
iface
)
self
.
_peer_db
.
unusePeer
(
prefix
)
del
self
.
_route_count
[
connection
.
iface
]
def
_makeNewTunnels
(
self
):
utils
.
log
(
'Trying to make %i new tunnels'
%
...
...
@@ -115,9 +118,26 @@ class TunnelManager:
self
.
_connection_dict
[
prefix
]
=
Connection
(
address
,
self
.
_write_pipe
,
self
.
_hello
,
iface
,
prefix
,
self
.
_ovpn_args
)
self
.
_route_count
[
iface
]
=
0
self
.
_peer_db
.
usePeer
(
prefix
)
except
KeyError
:
utils
.
log
(
"""Can't establish connection with %s
: no available interface"""
%
prefix
,
2
)
except
Exception
:
traceback
.
print_exc
()
def
_countRoutes
(
self
):
utils
.
log
(
'Starting to count the routes on each interface'
,
3
)
for
iface
in
self
.
_route_count
.
keys
():
self
.
_route_count
[
iface
]
=
0
f
=
open
(
'/proc/net/ipv6_route'
,
'r'
)
for
line
in
f
:
ip
,
subnet_size
,
iface
=
struct
.
unpack
(
"""32s x 2s x 32x x 2x x
32x x 8x x 8x x 8x x 8x x %ss x"""
%
(
len
(
line
)
-
142
),
line
)
iface
=
iface
.
replace
(
' '
,
''
)
if
iface
in
self
.
_route_count
.
keys
():
self
.
_route_count
[
iface
]
+=
1
for
iface
in
self
.
_route_count
.
keys
():
utils
.
log
(
'Routes on iface %s : %s'
%
(
iface
,
self
.
_route_count
[
iface
]
),
5
)
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