X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=interface-ip.c;h=587826a996cd708d094b00fc658fcaf3a4919dbc;hp=b000725e3ec1f51e4f8b711c39dc8d445829f3eb;hb=3f88c1dc2f738bc50dfa47038fde2565daf84385;hpb=ae3c6891596950ac7c2d5c45a078ab51efc53d99 diff --git a/interface-ip.c b/interface-ip.c index b000725..587826a 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -38,6 +38,8 @@ enum { ROUTE_VALID, ROUTE_TABLE, ROUTE_SOURCE, + ROUTE_ONLINK, + ROUTE_TYPE, __ROUTE_MAX }; @@ -51,6 +53,8 @@ static const struct blobmsg_policy route_attr[__ROUTE_MAX] = { [ROUTE_TABLE] = { .name = "table", .type = BLOBMSG_TYPE_STRING }, [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 } }; const struct uci_blob_param_list route_attr_list = { @@ -347,6 +351,9 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) route->sourcemask = (mask) ? atoi(mask) : ((af == AF_INET6) ? 128 : 32); } + if ((cur = tb[ROUTE_ONLINK]) != NULL && blobmsg_get_bool(cur)) + route->flags |= DEVROUTE_ONLINK; + if (is_proto_route) { route->table = (v6) ? iface->ip6table : iface->ip4table; route->flags |= DEVROUTE_SRCTABLE; @@ -358,6 +365,10 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) goto error; } + /* only set the table flag if not using the main (default) table */ + if (system_is_default_rt_table(route->table)) + route->table = 0; + if (route->table) route->flags |= DEVROUTE_TABLE; } @@ -369,6 +380,14 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) route->valid_until = valid_until; } + if ((cur = tb[ROUTE_TYPE]) != NULL) { + if (!system_resolve_rt_type(blobmsg_data(cur), &route->type)) { + DPRINTF("Failed to resolve routing type: %s\n", (char *) blobmsg_data(cur)); + goto error; + } + route->flags |= DEVROUTE_TYPE; + } + vlist_add(&ip->route, &route->node, route); return; @@ -400,6 +419,9 @@ route_cmp(const void *k1, const void *k2, void *ptr) if (r1->sourcemask != r2->sourcemask) return r1->sourcemask - r2->sourcemask; + if (r1->table != r2->table) + return r1->table - r2->table; + int maskcmp = memcmp(&r1->source, &r2->source, sizeof(r1->source)); if (maskcmp) return maskcmp; @@ -578,7 +600,8 @@ 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->table == route_new->table) && !route_old->failed; + (route_old->mtu == route_new->mtu) && (route_old->type == route_new->type) && + !route_old->failed; if (node_old) { if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep) @@ -619,8 +642,10 @@ interface_update_host_route(struct vlist_tree *tree, free(route_old); } - if (node_new) - system_add_route(dev, route_new); + if (node_new) { + if (system_add_route(dev, route_new)) + route_new->failed = true; + } } @@ -1040,7 +1065,7 @@ write_resolv_conf_entries(FILE *f, struct interface_ip_settings *ip, const char if (!str) continue; - if (s->af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&s->addr)) + if (s->af == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&s->addr.in6)) fprintf(f, "nameserver %s%%%s\n", str, dev); else fprintf(f, "nameserver %s\n", str); @@ -1137,7 +1162,8 @@ void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled) if (!(route->flags & DEVROUTE_METRIC)) route->metric = ip->iface->metric; - system_add_route(dev, route); + if (system_add_route(dev, route)) + route->failed = true; } else system_del_route(dev, route); route->enabled = _enabled; @@ -1212,7 +1238,6 @@ interface_ip_init(struct interface *iface) __interface_ip_init(&iface->proto_ip, iface); __interface_ip_init(&iface->config_ip, iface); vlist_init(&iface->host_routes, route_cmp, interface_update_host_route); - } static void