static struct ubus_context *ctx = NULL;
static struct blob_buf b;
-static struct netifd_fd ubus_fd;
static const char *ubus_path;
/* global object */
netifd_ubus_add_fd(void)
{
ubus_add_uloop(ctx);
- ubus_fd.fd = ctx->sock.fd;
- netifd_fd_add(&ubus_fd);
+ system_fd_set_cloexec(ctx->sock.fd);
}
static void
static void
netifd_ubus_connection_lost(struct ubus_context *ctx)
{
- netifd_fd_delete(&ubus_fd);
netifd_ubus_reconnect_timer(NULL);
}
}
}
+
+static void
+interface_ip_dump_prefix_list(struct interface_ip_settings *ip)
+{
+ struct device_prefix *prefix;
+ char *buf;
+ void *a, *c;
+ const int buflen = INET6_ADDRSTRLEN;
+
+ vlist_for_each_element(&ip->prefix, prefix, node) {
+ a = blobmsg_open_table(&b, NULL);
+
+ buf = blobmsg_alloc_string_buffer(&b, "address", buflen);
+ inet_ntop(AF_INET6, &prefix->addr, buf, buflen);
+ blobmsg_add_string_buffer(&b);
+
+ blobmsg_add_u32(&b, "mask", prefix->length);
+
+ time_t now = system_get_rtime();
+ if (prefix->preferred_until) {
+ int preferred = prefix->preferred_until - now;
+ if (preferred < 0)
+ preferred = 0;
+ blobmsg_add_u32(&b, "preferred", preferred);
+ }
+
+ if (prefix->valid_until) {
+ int valid = prefix->valid_until - now;
+ if (valid < 0)
+ valid = 0;
+ blobmsg_add_u32(&b, "valid", valid);
+ }
+
+ c = blobmsg_open_table(&b, "assigned");
+ struct device_prefix_assignment *assign;
+ vlist_for_each_element(prefix->assignments, assign, node) {
+ void *d = blobmsg_open_table(&b, assign->name);
+
+ 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, d);
+ }
+ 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_address_list(&iface->config_ip, true, true);
interface_ip_dump_address_list(&iface->proto_ip, true, true);
blobmsg_close_array(&b, a);
+ a = blobmsg_open_array(&b, "ipv6-prefix");
+ interface_ip_dump_prefix_list(&iface->config_ip);
+ interface_ip_dump_prefix_list(&iface->proto_ip);
+ blobmsg_close_array(&b, a);
a = blobmsg_open_array(&b, "route");
interface_ip_dump_route_list(&iface->config_ip, true);
interface_ip_dump_route_list(&iface->proto_ip, true);
device_lock();
dev = device_get(blobmsg_data(tb[DEV_NAME]), add ? 2 : 0);
- if (add && !dev) {
+ if (!dev) {
ret = UBUS_STATUS_NOT_FOUND;
goto out;
}
struct ubus_object *obj = &iface->ubus;
char *name = NULL;
- asprintf(&name, "%s.interface.%s", main_object.name, iface->name);
- if (!name)
+ if (asprintf(&name, "%s.interface.%s", main_object.name, iface->name) == -1)
return;
obj->name = name;