ROUTE_SOURCE,
ROUTE_ONLINK,
ROUTE_TYPE,
+ ROUTE_PROTO,
__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 = {
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;
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);
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)
/* route overrides the default interface mtu */
DEVROUTE_MTU = (1 << 4),
- /* route automatically added by kernel */
- DEVADDR_KERNEL = (1 << 5),
+ /* route overrides the default proto type */
+ DEVROUTE_PROTO = (1 << 5),
/* address is off-link (no subnet-route) */
DEVADDR_OFFLINK = (1 << 6),
union if_addr nexthop;
int mtu;
unsigned int type;
+ unsigned int proto;
time_t valid_until;
/* must be last */
return true;
}
+bool system_resolve_rt_proto(const char *type, unsigned int *id)
+{
+ *id = 0;
+ return true;
+}
+
bool system_resolve_rt_table(const char *name, unsigned int *id)
{
*id = 0;
#define IFA_FLAGS (IFA_MULTICAST + 1)
#endif
-
#include <string.h>
#include <fcntl.h>
#include <glob.h>
.rtm_dst_len = route->mask,
.rtm_src_len = route->sourcemask,
.rtm_table = (table < 256) ? table : RT_TABLE_UNSPEC,
- .rtm_protocol = (route->flags & DEVADDR_KERNEL) ? RTPROT_KERNEL : RTPROT_STATIC,
+ .rtm_protocol = (route->flags & DEVROUTE_PROTO) ? route->proto : RTPROT_STATIC,
.rtm_scope = RT_SCOPE_NOWHERE,
.rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST,
.rtm_flags = (route->flags & DEVROUTE_ONLINK) ? RTNH_F_ONLINK : 0,
return system_rtn_aton(type, id);
}
+bool system_resolve_rt_proto(const char *type, unsigned int *id)
+{
+ FILE *f;
+ char *e, buf[128];
+ unsigned int n, proto = 256;
+
+ if ((n = strtoul(type, &e, 0)) >= 0 && !*e && e != type)
+ proto = n;
+ else if (!strcmp(type, "unspec"))
+ proto = RTPROT_UNSPEC;
+ else if (!strcmp(type, "kernel"))
+ proto = RTPROT_KERNEL;
+ else if (!strcmp(type, "boot"))
+ proto = RTPROT_BOOT;
+ else if (!strcmp(type, "static"))
+ proto = RTPROT_STATIC;
+ else if ((f = fopen("/etc/iproute2/rt_protos", "r")) != NULL) {
+ while (fgets(buf, sizeof(buf) - 1, f) != NULL) {
+ if ((e = strtok(buf, " \t\n")) == NULL || *e == '#')
+ continue;
+
+ n = strtoul(e, NULL, 10);
+ e = strtok(NULL, " \t\n");
+
+ if (e && !strcmp(e, type)) {
+ proto = n;
+ break;
+ }
+ }
+ fclose(f);
+ }
+
+ if (proto > 255)
+ return false;
+
+ *id = proto;
+ return true;
+}
+
bool system_resolve_rt_table(const char *name, unsigned int *id)
{
FILE *f;
int system_flush_routes(void);
bool system_resolve_rt_type(const char *type, unsigned int *id);
+bool system_resolve_rt_proto(const char *type, unsigned int *id);
bool system_resolve_rt_table(const char *name, unsigned int *id);
bool system_is_default_rt_table(unsigned int id);
bool system_resolve_rpfilter(const char *filter, unsigned int *id);
if (route->flags & DEVROUTE_TYPE)
blobmsg_add_u32(&b, "type", route->type);
+ if (route->flags & DEVROUTE_PROTO)
+ blobmsg_add_u32(&b, "proto", route->proto);
+
if (route->flags & DEVROUTE_MTU)
blobmsg_add_u32(&b, "mtu", route->mtu);