struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
- netifd_reload();
- return 0;
+ if (netifd_reload())
+ return UBUS_STATUS_NOT_FOUND;
+
+ return UBUS_STATUS_OK;
}
enum {
struct blob_attr *tb[__DI_MAX];
struct interface *iface;
struct blob_attr *config;
- struct device *dev;
blobmsg_parse(dynamic_policy, __DI_MAX, tb, blob_data(msg), blob_len(msg));
// Set interface as dynamic
interface_set_dynamic(iface);
- dev = iface->main_dev.dev;
- if (!dev || !dev->default_config)
- return UBUS_STATUS_UNKNOWN_ERROR;
-
return UBUS_STATUS_OK;
error:
return UBUS_STATUS_UNKNOWN_ERROR;
}
-static int
-netifd_del_dynamic(struct ubus_context *ctx, struct ubus_object *obj,
- struct ubus_request_data *req, const char *method,
- struct blob_attr *msg)
-{
- struct blob_attr *tb[__DI_MAX];
- struct interface *iface;
-
- blobmsg_parse(dynamic_policy, __DI_MAX, tb, blob_data(msg), blob_len(msg));
-
- if (!tb[DI_NAME])
- return UBUS_STATUS_INVALID_ARGUMENT;
-
- const char *name = blobmsg_get_string(tb[DI_NAME]);
- iface = vlist_find(&interfaces, name, iface, node);
-
- if (!iface)
- return UBUS_STATUS_NOT_FOUND;
- else if (!iface->dynamic)
- return UBUS_STATUS_INVALID_COMMAND;
-
- vlist_delete(&interfaces, &iface->node);
- return UBUS_STATUS_OK;
-}
-
static struct ubus_method main_object_methods[] = {
{ .name = "restart", .handler = netifd_handle_restart },
{ .name = "reload", .handler = netifd_handle_reload },
UBUS_METHOD("add_host_route", netifd_add_host_route, route_policy),
{ .name = "get_proto_handlers", .handler = netifd_get_proto_handlers },
UBUS_METHOD("add_dynamic", netifd_add_dynamic, dynamic_policy),
- UBUS_METHOD("del_dynamic", netifd_del_dynamic, dynamic_policy),
};
static struct ubus_object_type main_object_type =
blobmsg_parse(dev_policy, __DEV_MAX, tb, blob_data(msg), blob_len(msg));
if (tb[DEV_NAME]) {
- dev = device_get(blobmsg_data(tb[DEV_NAME]), false);
+ dev = device_find(blobmsg_data(tb[DEV_NAME]));
if (!dev)
return UBUS_STATUS_INVALID_ARGUMENT;
}
if (!cur)
return UBUS_STATUS_INVALID_ARGUMENT;
- dev = device_get(blobmsg_data(cur), false);
+ dev = device_find(blobmsg_data(cur));
if (!dev)
return UBUS_STATUS_NOT_FOUND;
return 0;
}
+static int
+netifd_handle_renew(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct interface *iface;
+
+ iface = container_of(obj, struct interface, ubus);
+ interface_renew(iface);
+
+ return 0;
+}
+
static void
netifd_add_interface_errors(struct blob_buf *b, struct interface *iface)
{
}
static void
-interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6,
- bool enabled)
+interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6, bool enabled)
{
struct device_addr *addr;
char *buf;
blobmsg_add_u32(&b, "mask", addr->mask);
+ if (addr->point_to_point) {
+ buf = blobmsg_alloc_string_buffer(&b, "ptpaddress", buflen);
+ inet_ntop(af, &addr->point_to_point, buf, buflen);
+ blobmsg_add_string_buffer(&b);
+ }
+
if (addr->preferred_until) {
int preferred = addr->preferred_until - now;
if (preferred < 0)
if (route->flags & DEVROUTE_TYPE)
blobmsg_add_u32(&b, "type", route->type);
+ if (route->flags & DEVROUTE_PROTO)
+ blobmsg_add_u32(&b, "proto", route->proto);
+
if (route->flags & DEVROUTE_MTU)
blobmsg_add_u32(&b, "mtu", route->mtu);
if (prefix->valid_until)
blobmsg_add_u32(&b, "valid", prefix->valid_until - now);
+ void *c = blobmsg_open_table(&b, "local-address");
+ if (assign->enabled) {
+ buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
+ inet_ntop(AF_INET6, &assign->addr, buf, buflen);
+ blobmsg_add_string_buffer(&b);
+
+ blobmsg_add_u32(&b, "mask", assign->length);
+ }
+ blobmsg_close_table(&b, c);
+
blobmsg_close_table(&b, a);
}
}
}
-
static void
-interface_ip_dump_dns_server_list(struct interface_ip_settings *ip,
- bool enabled)
+interface_ip_dump_dns_server_list(struct interface_ip_settings *ip, bool enabled)
{
struct dns_server *dns;
int buflen = 128;
}
static void
-interface_ip_dump_dns_search_list(struct interface_ip_settings *ip,
- bool enabled)
+interface_ip_dump_dns_search_list(struct interface_ip_settings *ip, bool enabled)
{
struct dns_search_domain *dns;
blobmsg_add_u8(&b, "pending", iface->state == IFS_SETUP);
blobmsg_add_u8(&b, "available", iface->available);
blobmsg_add_u8(&b, "autostart", iface->autostart);
+ blobmsg_add_u8(&b, "dynamic", iface->dynamic);
if (iface->state == IFS_UP) {
time_t cur = system_get_rtime();
if (iface->ip4table)
blobmsg_add_u32(&b, "ip4table", iface->ip4table);
if (iface->ip6table)
- blobmsg_add_u32(&b, "ip6table", iface->ip6table);
+ blobmsg_add_u32(&b, "ip6table", iface->ip6table);
blobmsg_add_u32(&b, "metric", iface->metric);
+ blobmsg_add_u32(&b, "dns_metric", iface->dns_metric);
blobmsg_add_u8(&b, "delegation", !iface->proto_ip.no_delegation);
+ if (iface->assignment_weight)
+ blobmsg_add_u32(&b, "ip6weight", iface->assignment_weight);
a = blobmsg_open_array(&b, "ipv4-address");
interface_ip_dump_address_list(&iface->config_ip, false, true);
interface_ip_dump_address_list(&iface->proto_ip, false, true);
cur = tb[DEV_LINK_EXT];
if (cur)
- link_ext = !!blobmsg_get_u8(cur);
+ link_ext = blobmsg_get_bool(cur);
return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]), add, link_ext);
}
struct blob_attr *msg)
{
struct interface *iface;
- struct blob_attr *cur;
- int rem, ret;
iface = container_of(obj, struct interface, ubus);
- blob_for_each_attr(cur, msg, rem) {
- ret = interface_add_data(iface, cur);
- if (ret)
- return ret;
- }
-
- return 0;
+ return interface_parse_data(iface, msg);
}
static struct ubus_method iface_object_methods[] = {
{ .name = "up", .handler = netifd_handle_up },
{ .name = "down", .handler = netifd_handle_down },
+ { .name = "renew", .handler = netifd_handle_renew },
{ .name = "status", .handler = netifd_handle_status },
{ .name = "prepare", .handler = netifd_handle_iface_prepare },
{ .name = "dump", .handler = netifd_handle_dump },
int i;
methods = calloc(1, sizeof(iface_object_methods));
+ if (!methods)
+ return;
+
memcpy(methods, iface_object_methods, sizeof(iface_object_methods));
iface_object.methods = methods;