/*
* netifd - network interface daemon
* Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2012 Steven Barth <steven@midlink.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
ROUTE_METRIC,
ROUTE_MTU,
ROUTE_VALID,
+ ROUTE_TABLE,
__ROUTE_MAX
};
[ROUTE_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING },
[ROUTE_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
[ROUTE_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
+ [ROUTE_TABLE] = { .name = "table", .type = BLOBMSG_TYPE_STRING },
[ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 },
};
if (!match_if_addr(&route->addr, a, route->mask))
continue;
+ if (route->flags & DEVROUTE_TABLE)
+ continue;
+
if (!*res || route->mask < (*res)->mask)
*res = route;
}
if (defaultroute_target)
free(route);
else
- vlist_add(&iface->host_routes, &route->node, &route->flags);
+ vlist_add(&iface->host_routes, &route->node, route);
return iface;
}
route->flags |= DEVROUTE_MTU;
}
+ if ((cur = tb[ROUTE_TABLE]) != NULL) {
+ if (!system_resolve_rt_table(blobmsg_data(cur), &route->table)) {
+ DPRINTF("Failed to resolve routing table: %s\n", (char *) blobmsg_data(cur));
+ goto error;
+ }
+
+ if (route->table)
+ route->flags |= DEVROUTE_TABLE;
+ }
+
if ((cur = tb[ROUTE_VALID]) != NULL)
route->valid_until = system_get_rtime() + blobmsg_get_u32(cur);
- vlist_add(&ip->route, &route->node, &route->flags);
+ vlist_add(&ip->route, &route->node, route);
return;
error:
static int
route_cmp(const void *k1, const void *k2, void *ptr)
{
- return memcmp(k1, k2, sizeof(struct device_route) -
- offsetof(struct device_route, flags));
+ const struct device_route *r1 = k1, *r2 = k2;
+
+ if (r1->mask != r2->mask);
+ return r2->mask - r1->mask;
+
+ if (r1->metric != r2->metric);
+ return r1->metric - r2->metric;
+
+ if (r1->flags != r2->flags)
+ return r2->flags - r1->flags;
+
+ return memcmp(&r1->addr, &r2->addr, sizeof(r1->addr));
}
static int