diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2017-01-19 15:59:54 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2017-01-25 09:35:27 +0100 |
commit | 650758b16e5185505a3fbc1307949340af70b611 (patch) | |
tree | b8fdadfb813f45d8f96186c8f71ba61edba14e64 /interface-ip.c | |
parent | a057f6e48f383c7e81cb22aa806216878d87947b (diff) |
interface-ip: route proto config support (FS#170)
Route proto support is usefull when using route distribution
via a routing daemon.
The route proto parameter can be specified via the route proto
uci config parameter, it can hold a numerical value or the string
values unspec, kernel, boot, static or a string present in
/etc/iproute2/rt_protos.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'interface-ip.c')
-rw-r--r-- | interface-ip.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/interface-ip.c b/interface-ip.c index 24ea054..f8dab84 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -40,6 +40,7 @@ enum { ROUTE_SOURCE, ROUTE_ONLINK, ROUTE_TYPE, + ROUTE_PROTO, __ROUTE_MAX }; @@ -54,7 +55,8 @@ static const struct blobmsg_policy route_attr[__ROUTE_MAX] = { [ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 }, [ROUTE_SOURCE] = { .name = "source", .type = BLOBMSG_TYPE_STRING }, [ROUTE_ONLINK] = { .name = "onlink", .type = BLOBMSG_TYPE_BOOL }, - [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING } + [ROUTE_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING }, + [ROUTE_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING }, }; const struct uci_blob_param_list route_attr_list = { @@ -405,6 +407,14 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) route->flags |= DEVROUTE_TYPE; } + if ((cur = tb[ROUTE_PROTO]) != NULL) { + if (!system_resolve_rt_proto(blobmsg_data(cur), &route->proto)) { + DPRINTF("Failed to resolve proto type: %s\n", (char *) blobmsg_data(cur)); + goto error; + } + route->flags |= DEVROUTE_PROTO; + } + interface_set_route_info(iface, route); vlist_add(&ip->route, &route->node, route); return; @@ -478,10 +488,13 @@ interface_handle_subnet_route(struct interface *iface, struct device_addr *addr, memcpy(&r->addr, &addr->addr, sizeof(r->addr)); clear_if_addr(&r->addr, r->mask); - r->flags |= DEVADDR_KERNEL; + if (!system_resolve_rt_proto("kernel", &r->proto)) + return; + + r->flags |= DEVROUTE_PROTO; system_del_route(dev, r); - r->flags &= ~DEVADDR_KERNEL; + r->flags &= ~DEVROUTE_PROTO; interface_set_route_info(iface, r); system_add_route(dev, r); @@ -634,7 +647,7 @@ interface_update_proto_route(struct vlist_tree *tree, if (node_old && node_new) keep = !memcmp(&route_old->nexthop, &route_new->nexthop, sizeof(route_old->nexthop)) && (route_old->mtu == route_new->mtu) && (route_old->type == route_new->type) && - !route_old->failed; + (route_old->proto == route_new->proto) && !route_old->failed; if (node_old) { if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep) |