Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
3789f6d1
Commit
3789f6d1
authored
Jul 27, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server-side routing functions; plus some fixes
parent
25722083
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
src/netns/iproute.py
src/netns/iproute.py
+10
-7
src/netns/protocol.py
src/netns/protocol.py
+12
-5
No files found.
src/netns/iproute.py
View file @
3789f6d1
...
@@ -576,27 +576,30 @@ def get_all_route_data():
...
@@ -576,27 +576,30 @@ def get_all_route_data():
device = ifdata[match.group(4)]
device = ifdata[match.group(4)]
if prefix == 'default' or re.search(r'/0$', prefix):
if prefix == 'default' or re.search(r'/0$', prefix):
prefix = None
prefix = None
ret.append((tipe, prefix, nexthop, device))
prefix_len = 0
else:
prefix, foo, prefix_len = prefix.partition('/')
ret.append((tipe, prefix, int(prefix_len), nexthop, device))
return ret
return ret
def get_route_data():
def get_route_data():
# filter out non-unicast routes
# filter out non-unicast routes
return [x for x in get_all_route_data() if x[0] == 'unicast']
return [x for x in get_all_route_data() if x[0] == 'unicast']
def del_route(tipe, prefix, nexthop, device):
def del_route(tipe, prefix,
prefix_len,
nexthop, device):
_add_del_route('del', tipe, prefix, nexthop, device)
_add_del_route('del', tipe, prefix,
prefix_len,
nexthop, device)
def add_route(tipe, prefix, nexthop, device):
def add_route(tipe, prefix,
prefix_len,
nexthop, device):
_add_del_route('add', tipe, prefix, nexthop, device)
_add_del_route('add', tipe, prefix,
prefix_len,
nexthop, device)
def _add_del_route(action, tipe, prefix, nexthop, device):
def _add_del_route(action, tipe, prefix,
prefix_len,
nexthop, device):
cmd = ['ip', 'route', action]
cmd = ['ip', 'route', action]
if device:
if device:
device = _get_if_name(device)
device = _get_if_name(device)
if tipe and tipe != 'unicast':
if tipe and tipe != 'unicast':
cmd += [tipe]
cmd += [tipe]
if prefix:
if prefix:
cmd += [
prefix
]
cmd += [
"
%
s
/%
d
" % (prefix, prefix_len)
]
else:
else:
cmd += ['default']
cmd += ['default']
if nexthop:
if nexthop:
...
...
src/netns/protocol.py
View file @
3789f6d1
...
@@ -37,8 +37,8 @@ _proto_commands = {
...
@@ -37,8 +37,8 @@ _proto_commands = {
},
},
"ROUT"
:
{
"ROUT"
:
{
"LIST"
:
(
""
,
""
),
"LIST"
:
(
""
,
""
),
"ADD"
:
(
"sisi"
,
""
),
"ADD"
:
(
"s
s
isi"
,
""
),
"DEL"
:
(
"sisi"
,
""
)
"DEL"
:
(
"s
s
isi"
,
""
)
},
},
"PROC"
:
{
"PROC"
:
{
"CRTE"
:
(
"b"
,
"b*"
),
"CRTE"
:
(
"b"
,
"b*"
),
...
@@ -374,9 +374,16 @@ class Server(object):
...
@@ -374,9 +374,16 @@ class Server(object):
netns
.
iproute
.
del_addr
(
ifnr
,
a
)
netns
.
iproute
.
del_addr
(
ifnr
,
a
)
self
.
reply
(
200
,
"Done."
)
self
.
reply
(
200
,
"Done."
)
# def do_ROUT_LIST(self, cmdname):
def
do_ROUT_LIST
(
self
,
cmdname
):
# def do_ROUT_ADD(self, cmdname, prefix, prefixlen, nexthop, ifnr):
netns
.
iproute
.
get_route_data
()
# def do_ROUT_DEL(self, cmdname, prefix, prefixlen, nexthop, ifnr):
self
.
reply
(
200
,
[
"# Routing data follows."
]
+
yaml
.
dump
(
addrdata
).
split
(
"
\
n
"
))
def
do_ROUT_ADD
(
self
,
cmdname
,
tipe
,
prefix
,
prefixlen
,
nexthop
,
ifnr
):
netns
.
iproute
.
add_route
(
tipe
,
prefix
,
prefixlen
,
nexthop
,
ifnr
)
def
do_ROUT_DEL
(
self
,
cmdname
,
tipe
,
prefix
,
prefixlen
,
nexthop
,
ifnr
):
netns
.
iproute
.
del_route
(
tipe
,
prefix
,
prefixlen
,
nexthop
,
ifnr
)
# ============================================================================
# ============================================================================
#
#
...
...
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