#include "netifd.h"
#include "interface.h"
+#include "interface-ip.h"
#include "proto.h"
#include "config.h"
device_set_config(dev, dev->type, b.head);
}
+static void
+config_parse_route(struct uci_section *s, bool v6)
+{
+ void *route;
+
+ blob_buf_init(&b, 0);
+ route = blobmsg_open_array(&b, "route");
+ uci_to_blob(&b, s, &route_attr_list);
+ blobmsg_close_array(&b, route);
+ interface_ip_add_route(NULL, blob_data(b.head), v6);
+}
+
static void
config_init_devices(void)
{
}
}
+static void
+config_init_routes(void)
+{
+ struct interface *iface;
+ struct uci_element *e;
+
+ vlist_for_each_element(&interfaces, iface, node)
+ interface_ip_update_start(&iface->config_ip);
+
+ uci_foreach_element(&uci_network->sections, e) {
+ struct uci_section *s = uci_to_section(e);
+
+ if (!strcmp(s->type, "route"))
+ config_parse_route(s, false);
+ else if (!strcmp(s->type, "route6"))
+ config_parse_route(s, true);
+ }
+
+ vlist_for_each_element(&interfaces, iface, node)
+ interface_ip_update_complete(&iface->config_ip);
+}
+
void
config_init_all(void)
{
device_reset_config();
config_init_devices();
config_init_interfaces();
+ config_init_routes();
config_init = false;
device_unlock();
option proto static
option ipaddr 192.168.5.1
option netmask 255.255.255.0
+
+config route
+ option target 192.168.0.1
+ option netmask 24
+ option gateway 192.168.5.2
+ option interface wan
ROUTE_DEVICE,
ROUTE_METRIC,
ROUTE_MTU,
- __ROUTE_LAST
+ __ROUTE_MAX
};
-static const struct blobmsg_policy route_attr[__ROUTE_LAST] = {
+static const struct blobmsg_policy route_attr[__ROUTE_MAX] = {
[ROUTE_INTERFACE] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
[ROUTE_TARGET] = { .name = "target", .type = BLOBMSG_TYPE_STRING },
[ROUTE_MASK] = { .name = "netmask", .type = BLOBMSG_TYPE_STRING },
[ROUTE_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
};
+const struct config_param_list route_attr_list = {
+ .n_params = __ROUTE_MAX,
+ .params = route_attr,
+};
+
void
interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6)
{
struct interface_ip_settings *ip;
- struct blob_attr *tb[__ROUTE_LAST], *cur;
+ 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_LAST, tb, blobmsg_data(attr), blobmsg_data_len(attr));
+ blobmsg_parse(route_attr, __ROUTE_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr));
if (!tb[ROUTE_GATEWAY] && !tb[ROUTE_DEVICE])
return;
char name[];
};
+extern const struct config_param_list route_attr_list;
+
void interface_ip_init(struct interface_ip_settings *ip, struct interface *iface);
void interface_add_dns_server(struct interface_ip_settings *ip, const char *str);
void interface_add_dns_server_list(struct interface_ip_settings *ip, struct blob_attr *list);
interface_ip_update_complete(&iface->proto_ip);
vlist_for_each_element(&iface->config_ip.route, route, node) {
- if (iface->l3_dev->dev)
+ if (iface->l3_dev->dev) {
system_add_route(iface->l3_dev->dev, route);
+ route->enabled = true;
+ }
}
}