Reorder alfabetically device type matching as they are growing in number
[project/netifd.git] / interface-ip.c
index 018b657..bd6f164 100644 (file)
@@ -38,6 +38,7 @@ enum {
        ROUTE_VALID,
        ROUTE_TABLE,
        ROUTE_SOURCE,
+       ROUTE_ONLINK,
        __ROUTE_MAX
 };
 
@@ -51,6 +52,7 @@ 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 },
 };
 
 const struct uci_blob_param_list route_attr_list = {
@@ -347,6 +349,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;
@@ -581,7 +586,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->table == route_new->table) && !route_old->failed;
+                       (route_old->mtu == route_new->mtu) && !route_old->failed;
 
        if (node_old) {
                if (!(route_old->flags & DEVADDR_EXTERNAL) && route_old->enabled && !keep)
@@ -622,8 +627,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;
+       }
 }
 
 
@@ -1140,7 +1147,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;