Implement support for route / route6 table attribute
[project/netifd.git] / interface-ip.c
index ed95b2e..190c158 100644 (file)
@@ -34,6 +34,7 @@ enum {
        ROUTE_METRIC,
        ROUTE_MTU,
        ROUTE_VALID,
        ROUTE_METRIC,
        ROUTE_MTU,
        ROUTE_VALID,
+       ROUTE_TABLE,
        __ROUTE_MAX
 };
 
        __ROUTE_MAX
 };
 
@@ -44,6 +45,7 @@ static const struct blobmsg_policy route_attr[__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_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 },
 };
 
        [ROUTE_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 },
 };
 
@@ -124,6 +126,9 @@ __find_ip_route_target(struct interface_ip_settings *ip, union if_addr *a,
                if (!match_if_addr(&route->addr, a, route->mask))
                        continue;
 
                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 (!*res || route->mask < (*res)->mask)
                        *res = route;
        }
@@ -251,6 +256,16 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6)
                route->flags |= DEVROUTE_MTU;
        }
 
                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);
 
        if ((cur = tb[ROUTE_VALID]) != NULL)
                route->valid_until = system_get_rtime() + blobmsg_get_u32(cur);