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
251ae411
Commit
251ae411
authored
Aug 10, 2021
by
Yohann D'Anello
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework on routing configuration
Signed-off-by:
Yohann D'ANELLO
<
ynerant@crans.org
>
parent
266ec5b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
30 deletions
+42
-30
re6st/cli/node.py
re6st/cli/node.py
+4
-0
re6st/tunnel.py
re6st/tunnel.py
+38
-30
No files found.
re6st/cli/node.py
View file @
251ae411
...
@@ -366,6 +366,10 @@ def main():
...
@@ -366,6 +366,10 @@ def main():
ip
(
'addr'
,
my_ip
+
'/%s'
%
len
(
subnet
),
ip
(
'addr'
,
my_ip
+
'/%s'
%
len
(
subnet
),
'dev'
,
config
.
main_interface
)
'dev'
,
config
.
main_interface
)
ip
(
'rule'
,
'from'
,
'all'
,
'lookup'
,
'34072'
)
ip
(
'route'
,
'table'
,
'34072'
,
'local'
,
my_ip
,
'dev'
,
config
.
main_interface
)
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'del'
,
'table'
,
'local'
,
my_ip
))
ip
(
'rule'
,
'from'
,
my_subnet
,
'to'
,
my_subnet
,
'iif'
,
config
.
main_interface
,
'lookup'
,
'34071'
)
if_rt
=
[
'ip'
,
'-6'
,
'route'
,
'del'
,
if_rt
=
[
'ip'
,
'-6'
,
'route'
,
'del'
,
'fe80::/64'
,
'dev'
,
config
.
main_interface
]
'fe80::/64'
,
'dev'
,
config
.
main_interface
]
if
config
.
main_interface
==
'lo'
:
if
config
.
main_interface
==
'lo'
:
...
...
re6st/tunnel.py
View file @
251ae411
...
@@ -70,7 +70,6 @@ class Connection(object):
...
@@ -70,7 +70,6 @@ class Connection(object):
self
.
address_list
=
address_list
self
.
address_list
=
address_list
self
.
iface
=
iface
self
.
iface
=
iface
self
.
_prefix
=
prefix
self
.
_prefix
=
prefix
self
.
_monitoring_address
=
None
def
__iter__
(
self
):
def
__iter__
(
self
):
if
not
hasattr
(
self
,
'_remote_ip_set'
):
if
not
hasattr
(
self
,
'_remote_ip_set'
):
...
@@ -100,22 +99,6 @@ class Connection(object):
...
@@ -100,22 +99,6 @@ class Connection(object):
self
.
_retry
+=
1
self
.
_retry
+=
1
def
connected
(
self
,
serial
):
def
connected
(
self
,
serial
):
# Generate random IP address in the prefix
# FIXME Run DAD
# TODO Check if there are enough IP addresses. If not, we have to find a rule.
prefix
=
self
.
tunnel_manager
.
ctl
.
network
+
self
.
tunnel_manager
.
_prefix
suffix
=
bin
(
random
.
randint
(
2
,
2
**
(
128
-
len
(
prefix
))))[
2
:]
self
.
_monitoring_address
=
utils
.
ipFromBin
(
prefix
,
suffix
)
# Add IP address on Re6stnet interface
subprocess
.
check_call
((
'ip'
,
'-6'
,
'address'
,
'add'
,
self
.
_monitoring_address
,
'dev'
,
self
.
iface
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'del'
,
self
.
_monitoring_address
))
# Add IP rule to indicate to search main route first instead of local route
# FIXME Get main interface instead of hardcoding 'lo'
subprocess
.
check_call
((
'ip'
,
'-6'
,
'rule'
,
'add'
,
'from'
,
utils
.
ipFromBin
(
prefix
,
'1'
),
'to'
,
self
.
_monitoring_address
,
'iif'
,
'lo'
,
'priority'
,
'0'
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'rule'
,
'del'
,
'from'
,
'all'
,
'lookup'
,
'local'
,
'priority'
,
'0'
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'rule'
,
'add'
,
'from'
,
'all'
,
'lookup'
,
'local'
,
'priority'
,
'1'
))
cache
=
self
.
tunnel_manager
.
cache
cache
=
self
.
tunnel_manager
.
cache
if
serial
in
cache
.
crl
:
if
serial
in
cache
.
crl
:
self
.
tunnel_manager
.
_kill
(
self
.
_prefix
)
self
.
tunnel_manager
.
_kill
(
self
.
_prefix
)
...
@@ -129,11 +112,6 @@ class Connection(object):
...
@@ -129,11 +112,6 @@ class Connection(object):
cache
.
connecting
(
self
.
_prefix
,
0
)
cache
.
connecting
(
self
.
_prefix
,
0
)
def
close
(
self
):
def
close
(
self
):
if
self
.
_monitoring_address
:
# Remove address and reset IP rule
subprocess
.
check_call
((
'ip'
,
'-6'
,
'address'
,
'del'
,
self
.
_monitoring_address
,
'dev'
,
self
.
iface
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'rule'
,
'del'
,
'to'
,
self
.
_monitoring_address
,
'priority'
,
'0'
))
try
:
try
:
self
.
process
.
stop
()
self
.
process
.
stop
()
except
AttributeError
:
except
AttributeError
:
...
@@ -228,6 +206,7 @@ class BaseTunnelManager(object):
...
@@ -228,6 +206,7 @@ class BaseTunnelManager(object):
self
.
cache
=
cache
self
.
cache
=
cache
self
.
_connecting
=
set
()
self
.
_connecting
=
set
()
self
.
_connection_dict
=
{}
self
.
_connection_dict
=
{}
self
.
_neighbour_monitoring_addresses
=
{}
self
.
_served
=
defaultdict
(
dict
)
self
.
_served
=
defaultdict
(
dict
)
self
.
_version
=
cache
.
version
self
.
_version
=
cache
.
version
self
.
_conf_country
=
conf_country
self
.
_conf_country
=
conf_country
...
@@ -692,25 +671,54 @@ class BaseTunnelManager(object):
...
@@ -692,25 +671,54 @@ class BaseTunnelManager(object):
"""
"""
Refresh routes that are used for link monitoring.
Refresh routes that are used for link monitoring.
"""
"""
my_address
=
utils
.
ipFromBin
(
self
.
_network
+
self
.
_prefix
,
'1'
)
# Cleanup old routes
# Cleanup old routes
for
connection
in
self
.
_connection_dict
.
values
():
for
prefix
in
list
(
self
.
_neighbour_monitoring_addresses
.
keys
()):
if
connection
.
_monitoring_address
:
if
prefix
not
in
self
.
ctl
.
neighbours
:
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'del'
,
connection
.
_monitoring_address
,
address
=
self
.
_neighbour_monitoring_addresses
[
prefix
]
'dev'
,
connection
.
iface
))
# FIXME Replace lo by main inteface name
subprocess
.
check_call
((
'ip'
,
'-6'
,
'address'
,
'del'
,
address
,
'dev'
,
'lo'
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'del'
,
my_address
,
'from'
,
address
,
'dev'
,
'lo'
,
'table'
,
'34071'
))
# Babel is not initialized yet.
if
not
hasattr
(
self
.
ctl
,
'neighbours'
):
return
# Get nexthop for each prefix, and draw a route for monitoring addresses
# Get nexthop for each prefix, and draw a route for monitoring addresses
for
prefix
in
self
.
ctl
.
neighbours
.
keys
():
for
prefix
in
self
.
ctl
.
neighbours
.
keys
():
if
prefix
is
None
or
prefix
not
in
self
.
_connection_dict
:
if
prefix
is
None
:
continue
continue
neighbour
=
self
.
ctl
.
neighbours
[
prefix
][
0
]
neighbour
=
self
.
ctl
.
neighbours
[
prefix
][
0
]
nexthop
=
neighbour
.
address
nexthop
=
neighbour
.
address
nexthop
=
utils
.
ipFromBin
(
""
.
join
(
bin
(
ord
(
c
))[
2
:].
zfill
(
8
)
for
c
in
nexthop
))
nexthop
=
utils
.
ipFromBin
(
""
.
join
(
bin
(
ord
(
c
))[
2
:].
zfill
(
8
)
for
c
in
nexthop
))
connection
=
self
.
_connection_dict
[
prefix
]
# Find interface name from interface id
address
=
connection
.
_monitoring_address
ifindex
=
neighbour
.
ifindex
output
=
subprocess
.
check_output
((
'ip'
,
'link'
))
for
line
in
output
.
split
(
'
\
n
'
):
if
line
.
startswith
(
str
(
ifindex
)
+
':'
):
iface
=
line
.
split
(
' '
)[
1
][:
-
1
]
break
else
:
logging
.
error
(
"Unknown interface index: "
+
str
(
ifindex
))
continue
# Assign new IP address to this link is not existing
if
prefix
not
in
self
.
_neighbour_monitoring_addresses
:
p
=
self
.
ctl
.
network
+
self
.
_prefix
s
=
bin
(
random
.
randint
(
2
,
2
**
(
128
-
len
(
p
))))[
2
:]
self
.
_neighbour_monitoring_addresses
[
prefix
]
=
utils
.
ipFromBin
(
p
,
s
)
address
=
self
.
_neighbour_monitoring_addresses
[
prefix
]
# Add route in kernel
# Add route in kernel
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'add'
,
address
,
'via'
,
nexthop
,
'dev'
,
connection
.
iface
))
# FIXME Replace lo by main inteface name
subprocess
.
check_call
((
'ip'
,
'-6'
,
'address'
,
'add'
,
address
,
'dev'
,
'lo'
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'del'
,
address
,
'dev'
,
'lo'
,
'table'
,
'main'
))
subprocess
.
check_call
((
'ip'
,
'-6'
,
'route'
,
'add'
,
my_address
,
'from'
,
address
,
'via'
,
nexthop
,
'dev'
,
iface
,
'src'
,
address
,
'table'
,
'34071'
))
def
_updateCountry
(
self
,
address
):
def
_updateCountry
(
self
,
address
):
def
update
():
def
update
():
...
...
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