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));
const char *name = blobmsg_get_string(tb[DI_NAME]);
- iface = interface_alloc(name, msg);
+ iface = interface_alloc(name, msg, true);
if (!iface)
return UBUS_STATUS_UNKNOWN_ERROR;
if (!config)
goto error;
- interface_add(iface, config);
-
- // need to look up the interface name again, in case of config update
- // the pointer will have changed
- iface = vlist_find(&interfaces, name, iface, node);
- if (!iface)
- return UBUS_STATUS_UNKNOWN_ERROR;
-
- // Set interface as dynamic
- interface_set_dynamic(iface);
-
- dev = iface->main_dev.dev;
- if (!dev || !dev->default_config)
- return UBUS_STATUS_UNKNOWN_ERROR;
+ if (!interface_add(iface, config))
+ goto error_free_config;
return UBUS_STATUS_OK;
+error_free_config:
+ free(config);
error:
free(iface);
return UBUS_STATUS_UNKNOWN_ERROR;
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 (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
goto error;
- if (!blobmsg_check_attr(cur, NULL))
+ if (!blobmsg_check_attr(cur, false))
goto error;
alias_notify_device(blobmsg_data(cur), dev);
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)
}
}
+static void
+interface_ip_dump_neighbor_list(struct interface_ip_settings *ip, bool enabled)
+{
+ struct device_neighbor *neighbor;
+ int buflen = 128;
+ char *buf;
+ void *r;
+ int af;
+
+ vlist_for_each_element(&ip->neighbor, neighbor, node) {
+ if (neighbor->enabled != enabled)
+ continue;
+
+ if ((neighbor->flags & DEVADDR_FAMILY) == DEVADDR_INET4)
+ af = AF_INET;
+ else
+ af = AF_INET6;
+
+ r = blobmsg_open_table(&b, NULL);
+
+ if (neighbor->flags & DEVNEIGH_MAC)
+ blobmsg_add_string(&b, "mac", format_macaddr(neighbor->macaddr));
+
+ buf = blobmsg_alloc_string_buffer(&b , "address", buflen);
+ inet_ntop(af, &neighbor->addr, buf, buflen);
+ blobmsg_add_string_buffer(&b);
+
+ if (neighbor->proxy)
+ blobmsg_add_u32(&b, "proxy", neighbor->proxy);
+
+ if (neighbor->router)
+ blobmsg_add_u32(&b, "router", neighbor->router);
+
+ blobmsg_close_table(&b, r);
+ }
+}
+
static void
interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled)
{
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);
interface_ip_dump_dns_search_list(&iface->config_ip, true);
interface_ip_dump_dns_search_list(&iface->proto_ip, true);
blobmsg_close_array(&b, a);
+ a = blobmsg_open_array(&b, "neighbors");
+ interface_ip_dump_neighbor_list(&iface->config_ip, true);
+ interface_ip_dump_neighbor_list(&iface->proto_ip, true);
+ blobmsg_close_array(&b, a);
inactive = blobmsg_open_table(&b, "inactive");
a = blobmsg_open_array(&b, "ipv4-address");
interface_ip_dump_dns_search_list(&iface->config_ip, false);
interface_ip_dump_dns_search_list(&iface->proto_ip, false);
blobmsg_close_array(&b, a);
+ a = blobmsg_open_array(&b, "neighbors");
+ interface_ip_dump_neighbor_list(&iface->config_ip, false);
+ interface_ip_dump_neighbor_list(&iface->proto_ip, false);
+ blobmsg_close_array(&b, a);
blobmsg_close_table(&b, inactive);
}
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;
return wdev;
}
+static int
+netifd_handle_wdev_reconf(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct wireless_device *wdev;
+ int ret;
+
+ wdev = get_wdev(msg, &ret);
+ if (ret == UBUS_STATUS_NOT_FOUND)
+ return ret;
+
+ if (wdev) {
+ wireless_device_reconf(wdev);
+ } else {
+ vlist_for_each_element(&wireless_devices, wdev, node)
+ wireless_device_reconf(wdev);
+ }
+
+ return 0;
+}
+
static int
netifd_handle_wdev_up(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
static struct ubus_method wireless_object_methods[] = {
{ .name = "up", .handler = netifd_handle_wdev_up },
{ .name = "down", .handler = netifd_handle_wdev_down },
+ { .name = "reconf", .handler = netifd_handle_wdev_reconf },
{ .name = "status", .handler = netifd_handle_wdev_status },
{ .name = "notify", .handler = netifd_handle_wdev_notify },
{ .name = "get_validate", .handler = netifd_handle_wdev_get_validate },