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
Joanne Hugé
re6stnet
Commits
8c4a1fb4
Commit
8c4a1fb4
authored
Apr 17, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
re6stnet: new --disable-proto option
parent
620b9e98
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
12 deletions
+28
-12
re6st/db.py
re6st/db.py
+14
-5
re6st/tunnel.py
re6st/tunnel.py
+10
-6
re6stnet
re6stnet
+4
-1
No files found.
re6st/db.py
View file @
8c4a1fb4
...
...
@@ -95,19 +95,28 @@ class PeerDB(object):
return
bootpeer
logging
.
warning
(
'Buggy registry sent us our own address'
)
def
addPeer
(
self
,
prefix
,
address
,
force
=
False
):
def
addPeer
(
self
,
prefix
,
address
,
set_preferred
=
False
):
logging
.
debug
(
'Adding peer %s: %s'
,
prefix
,
address
)
with
self
.
_db
:
q
=
self
.
_db
.
execute
try
:
(
a
,),
=
q
(
"SELECT address FROM peer WHERE prefix=?"
,
(
prefix
,))
a
=
a
!=
address
if
force
else
\
set
(
a
.
split
(
';'
))
!=
set
(
address
.
split
(
';'
))
if
set_preferred
:
preferred
=
address
.
split
(
';'
)
address
=
a
else
:
preferred
=
a
.
split
(
';'
)
def
key
(
a
):
try
:
return
preferred
.
index
(
a
)
except
ValueError
:
return
len
(
preferred
)
address
=
';'
.
join
(
sorted
(
address
.
split
(
';'
),
key
=
key
))
except
ValueError
:
q
(
"DELETE FROM peer WHERE prefix IN (SELECT peer"
" FROM volatile.stat ORDER BY try, RANDOM() LIMIT ?,-1)"
,
(
self
.
_db_size
,))
a
=
Tru
e
if
a
:
a
=
Non
e
if
a
!=
address
:
q
(
"INSERT OR REPLACE INTO peer VALUES (?,?)"
,
(
prefix
,
address
))
q
(
"INSERT OR REPLACE INTO volatile.stat VALUES (?,0)"
,
(
prefix
,))
re6st/tunnel.py
View file @
8c4a1fb4
...
...
@@ -41,8 +41,8 @@ class MultiGatewayManager(dict):
class
Connection
(
object
):
def
__init__
(
self
,
address
,
iface
,
prefix
):
self
.
address_list
=
list
(
utils
.
parse_address
(
address
))
def
__init__
(
self
,
address
_list
,
iface
,
prefix
):
self
.
address_list
=
address_list
self
.
iface
=
iface
self
.
routes
=
0
self
.
_prefix
=
prefix
...
...
@@ -78,8 +78,7 @@ class Connection(object):
except
TypeError
:
i
=
len
(
self
.
address_list
)
-
1
if
i
:
db
.
addPeer
(
self
.
_prefix
,
utils
.
dump_address
(
self
.
address_list
[
i
:]
+
self
.
address_list
[:
i
]),
True
)
db
.
addPeer
(
self
.
_prefix
,
','
.
join
(
self
.
address_list
[
i
]),
True
)
else
:
db
.
connecting
(
self
.
_prefix
,
0
)
...
...
@@ -106,7 +105,7 @@ class TunnelManager(object):
def
__init__
(
self
,
write_pipe
,
peer_db
,
openvpn_args
,
timeout
,
refresh
,
client_count
,
iface_list
,
network
,
prefix
,
address
,
ip_changed
,
encrypt
,
remote_gateway
):
address
,
ip_changed
,
encrypt
,
remote_gateway
,
disable_proto
):
self
.
_write_pipe
=
write_pipe
self
.
_peer_db
=
peer_db
self
.
_connecting
=
set
()
...
...
@@ -125,6 +124,7 @@ class TunnelManager(object):
self
.
_encrypt
=
encrypt
self
.
_gateway_manager
=
MultiGatewayManager
(
remote_gateway
)
\
if
remote_gateway
else
None
self
.
_disable_proto
=
disable_proto
self
.
_served
=
set
()
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
...
...
@@ -216,6 +216,11 @@ class TunnelManager(object):
if
prefix
in
self
.
_served
or
prefix
in
self
.
_connection_dict
:
return
False
assert
prefix
!=
self
.
_prefix
,
self
.
__dict__
address
=
[
x
for
x
in
utils
.
parse_address
(
address
)
if
x
[
2
]
not
in
self
.
_disable_proto
]
self
.
_peer_db
.
connecting
(
prefix
,
1
)
if
not
address
:
return
False
logging
.
info
(
'Establishing a connection with %u/%u'
,
int
(
prefix
,
2
),
len
(
prefix
))
iface
=
self
.
getFreeInterface
(
prefix
)
...
...
@@ -224,7 +229,6 @@ class TunnelManager(object):
for
ip
in
c
:
self
.
_gateway_manager
.
add
(
ip
,
True
)
c
.
open
(
self
.
_write_pipe
,
self
.
_timeout
,
self
.
_encrypt
,
self
.
_ovpn_args
)
self
.
_peer_db
.
connecting
(
prefix
,
1
)
return
True
def
_makeNewTunnels
(
self
,
route_counted
):
...
...
re6stnet
View file @
8c4a1fb4
...
...
@@ -101,6 +101,8 @@ def getConfig():
_
(
'--remote-gateway'
,
action
=
'append'
,
dest
=
'gw_list'
,
help
=
"Force each tunnel to be created through one the given gateways,"
" in a round-robin fashion."
)
_
(
'--disable-proto'
,
action
=
'append'
,
choices
=
(
'udp'
,
'tcp'
),
default
=
[],
help
=
"Do never try to create tunnels using given protocols."
)
_
(
'--client'
,
metavar
=
'HOST,PORT,PROTO[;...]'
,
help
=
"Do not run any OpenVPN server, but only 1 OpenVPN client,"
" with specified remotes. Any other option not required in this"
...
...
@@ -229,7 +231,8 @@ def main():
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
config
.
openvpn_args
,
timeout
,
config
.
tunnel_refresh
,
config
.
client_count
,
config
.
iface_list
,
network
,
prefix
,
address
,
ip_changed
,
config
.
encrypt
,
remote_gateway
)
address
,
ip_changed
,
config
.
encrypt
,
remote_gateway
,
config
.
disable_proto
)
tunnel_interfaces
+=
tunnel_manager
.
new_iface_list
else
:
tunnel_manager
=
write_pipe
=
None
...
...
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