return 0;
}
+int
+interface_handle_link(struct interface *iface, const char *name, bool add)
+{
+ struct device *dev;
+ int ret;
+
+ device_lock();
+
+ dev = device_get(name, add ? 2 : 0);
+ if (!dev) {
+ ret = UBUS_STATUS_NOT_FOUND;
+ goto out;
+ }
+
+ if (add) {
+ device_set_present(dev, true);
+ if (iface->device_config)
+ device_set_config(dev, &simple_device_type, iface->config);
+
+ system_if_apply_settings(dev, &dev->settings);
+ ret = interface_add_link(iface, dev);
+ } else {
+ ret = interface_remove_link(iface, dev);
+ }
+
+out:
+ device_unlock();
+
+ return ret;
+}
+
int
interface_set_up(struct interface *iface)
{
int interface_add_link(struct interface *iface, struct device *dev);
int interface_remove_link(struct interface *iface, struct device *dev);
+int interface_handle_link(struct interface *iface, const char *name, bool add);
void interface_add_error(struct interface *iface, const char *subsystem,
const char *code, const char **data, int n_data);
{
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);
if (!tb[DEV_NAME])
return UBUS_STATUS_INVALID_ARGUMENT;
- device_lock();
-
- dev = device_get(blobmsg_data(tb[DEV_NAME]), add ? 2 : 0);
- if (!dev) {
- ret = UBUS_STATUS_NOT_FOUND;
- goto out;
- }
-
- if (add) {
- device_set_present(dev, true);
- if (iface->device_config)
- device_set_config(dev, &simple_device_type, iface->config);
-
- system_if_apply_settings(dev, &dev->settings);
- ret = interface_add_link(iface, dev);
- } else {
- ret = interface_remove_link(iface, dev);
- }
-
-out:
- device_unlock();
-
- return ret;
+ return interface_handle_link(iface, blobmsg_data(tb[DEV_NAME]), add);
}