Commit 3789f6d1 authored by Martín Ferrari's avatar Martín Ferrari

server-side routing functions; plus some fixes

parent 25722083
...@@ -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:
......
...@@ -37,8 +37,8 @@ _proto_commands = { ...@@ -37,8 +37,8 @@ _proto_commands = {
}, },
"ROUT": { "ROUT": {
"LIST": ("", ""), "LIST": ("", ""),
"ADD": ("sisi", ""), "ADD": ("ssisi", ""),
"DEL": ("sisi", "") "DEL": ("ssisi", "")
}, },
"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)
# ============================================================================ # ============================================================================
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment