+static int
+netifd_iface_handle_device(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct blob_attr *tb[__DEV_MAX];
+ struct interface *iface;
+ struct device *dev;
+ bool add = !strncmp(method, "add", 3);
+ int ret;
+
+ iface = container_of(obj, struct interface, ubus);
+
+ blobmsg_parse(dev_policy, __DEV_MAX, tb, blob_data(msg), blob_len(msg));
+
+ if (!tb[DEV_NAME])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ device_lock();
+
+ dev = device_get(blobmsg_data(tb[DEV_NAME]), add ? 2 : 0);
+ if (add && !dev)
+ return UBUS_STATUS_NOT_FOUND;
+
+ if (add)
+ return interface_add_link(iface, dev);
+ else
+ return interface_remove_link(iface, dev);
+
+ device_unlock();
+
+ return ret;
+}
+
+
+static int
+netifd_iface_notify_proto(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);
+
+ if (!iface->proto || !iface->proto->notify)
+ return UBUS_STATUS_NOT_SUPPORTED;
+
+ return iface->proto->notify(iface->proto, msg);
+}
+
+static void
+netifd_iface_do_remove(struct uloop_timeout *timeout)
+{
+ struct interface *iface;
+
+ iface = container_of(timeout, struct interface, remove_timer);
+ vlist_delete(&interfaces, &iface->node);
+}
+
+static int
+netifd_iface_remove(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);
+ if (iface->remove_timer.cb)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ iface->remove_timer.cb = netifd_iface_do_remove;
+ uloop_timeout_set(&iface->remove_timer, 100);
+ return 0;
+}
+
+static int
+netifd_handle_iface_prepare(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct interface *iface;
+ struct device *dev;
+ const struct device_hotplug_ops *ops;
+
+ iface = container_of(obj, struct interface, ubus);
+ dev = iface->main_dev.dev;
+ if (!dev)
+ return 0;
+
+ ops = dev->hotplug_ops;
+ if (!ops)
+ return 0;
+
+ return ops->prepare(dev);
+}
+
+static int
+netifd_handle_set_data(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ 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;
+}