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():
device = ifdata[match.group(4)]
if prefix == 'default' or re.search(r'/0$', prefix):
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
def get_route_data():
# filter out non-unicast routes
return [x for x in get_all_route_data() if x[0] == 'unicast']
def del_route(tipe, prefix, nexthop, device):
_add_del_route('del', tipe, prefix, nexthop, device)
def del_route(tipe, prefix, prefix_len, nexthop, device):
_add_del_route('del', tipe, prefix, prefix_len, nexthop, device)
def add_route(tipe, prefix, nexthop, device):
_add_del_route('add', tipe, prefix, nexthop, device)
def add_route(tipe, prefix, prefix_len, 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]
if device:
device = _get_if_name(device)
if tipe and tipe != 'unicast':
cmd += [tipe]
if prefix:
cmd += [prefix]
cmd += ["%s/%d" % (prefix, prefix_len)]
else:
cmd += ['default']
if nexthop:
......
......@@ -37,8 +37,8 @@ _proto_commands = {
},
"ROUT": {
"LIST": ("", ""),
"ADD": ("sisi", ""),
"DEL": ("sisi", "")
"ADD": ("ssisi", ""),
"DEL": ("ssisi", "")
},
"PROC": {
"CRTE": ("b", "b*"),
......@@ -374,9 +374,16 @@ class Server(object):
netns.iproute.del_addr(ifnr, a)
self.reply(200, "Done.")
# def do_ROUT_LIST(self, cmdname):
# def do_ROUT_ADD(self, cmdname, prefix, prefixlen, nexthop, ifnr):
# def do_ROUT_DEL(self, cmdname, prefix, prefixlen, nexthop, ifnr):
def do_ROUT_LIST(self, cmdname):
netns.iproute.get_route_data()
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