ROUTE_TARGET,
ROUTE_MASK,
ROUTE_GATEWAY,
- ROUTE_DEVICE,
ROUTE_METRIC,
ROUTE_MTU,
__ROUTE_MAX
[ROUTE_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
[ROUTE_MASK] = { .name = "netmask", .type = BLOBMSG_TYPE_STRING },
[ROUTE_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING },
- [ROUTE_DEVICE] = { .name = "device", .type = BLOBMSG_TYPE_STRING },
[ROUTE_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 },
[ROUTE_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
};
struct blob_attr *tb[__ROUTE_MAX], *cur;
struct device_route *route;
int af = v6 ? AF_INET6 : AF_INET;
- bool config = false;
blobmsg_parse(route_attr, __ROUTE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));
- if (!tb[ROUTE_GATEWAY] && !tb[ROUTE_DEVICE])
- return;
-
if (!iface) {
if ((cur = tb[ROUTE_INTERFACE]) == NULL)
return;
return;
ip = &iface->config_ip;
- config = true;
} else {
ip = &iface->proto_ip;
}
DPRINTF("Failed to parse route gateway: %s\n", (char *) blobmsg_data(cur));
goto error;
}
+ } else {
+ route->flags |= DEVADDR_DEVICE;
}
if ((cur = tb[ROUTE_METRIC]) != NULL)
route->metric = blobmsg_get_u32(cur);
+ else
+ route->metric = -1;
if ((cur = tb[ROUTE_MTU]) != NULL)
route->mtu = blobmsg_get_u32(cur);
- if (!config && (cur = tb[ROUTE_DEVICE]) != NULL)
- route->device = device_get(blobmsg_data(cur), true);
-
vlist_add(&ip->route, &route->node);
return;
}
}
+static bool
+enable_route(struct interface_ip_settings *ip, struct device_route *route)
+{
+ if (ip->no_defaultroute && !route->mask)
+ return false;
+
+ return true;
+}
+
static void
interface_update_proto_route(struct vlist_tree *tree,
struct vlist_node *node_new,
}
if (node_new) {
- if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep)
+ bool _enabled = enable_route(ip, route_new);
+
+ if (!(route_new->flags & DEVADDR_EXTERNAL) && !keep && _enabled)
system_add_route(dev, route_new);
- route_new->enabled = true;
+
+ route_new->enabled = _enabled;
}
}
}
vlist_for_each_element(&ip->route, route, node) {
- if (route->enabled == enabled)
+ bool _enabled = enabled;
+
+ if (!enable_route(ip, route))
+ _enabled = false;
+
+ if (route->enabled == _enabled)
continue;
- if (enabled)
+ if (_enabled)
system_add_route(dev, route);
else
system_del_route(dev, route);
- route->enabled = enabled;
+ route->enabled = _enabled;
}
}