summaryrefslogtreecommitdiff
path: root/ubus.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2021-06-19 08:19:02 +0200
committerFelix Fietkau <nbd@nbd.name>2021-06-19 08:19:04 +0200
commit16bff892f4155005d9cd9ec3981f099e4c1076d2 (patch)
tree81c46d1e44ecf17a5d6773e795e39a5865955fce /ubus.c
parentff3764ce28e0672d8290e925d13a34ddbf38c984 (diff)
downloadnetifd-16bff892f4155005d9cd9ec3981f099e4c1076d2.tar.gz
ubus: add a dummy mode ubus call to simulate hotplug events
Can be used to test the device hotplug handling Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'ubus.c')
-rw-r--r--ubus.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/ubus.c b/ubus.c
index be15062..8a0c53a 100644
--- a/ubus.c
+++ b/ubus.c
@@ -338,10 +338,46 @@ netifd_handle_set_state(struct ubus_context *ctx, struct ubus_object *obj,
return 0;
}
+#ifdef DUMMY_MODE
+enum {
+ DEV_HOTPLUG_ATTR_NAME,
+ DEV_HOTPLUG_ATTR_ADD,
+ __DEV_HOTPLUG_ATTR_MAX,
+};
+
+static const struct blobmsg_policy dev_hotplug_policy[__DEV_HOTPLUG_ATTR_MAX] = {
+ [DEV_HOTPLUG_ATTR_NAME] = { "name", BLOBMSG_TYPE_STRING },
+ [DEV_HOTPLUG_ATTR_ADD] = { "add", BLOBMSG_TYPE_BOOL },
+};
+
+static int
+netifd_handle_dev_hotplug(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_HOTPLUG_ATTR_MAX];
+ const char *name;
+
+ blobmsg_parse(dev_hotplug_policy, __DEV_HOTPLUG_ATTR_MAX, tb,
+ blob_data(msg), blob_len(msg));
+
+ if (!tb[DEV_HOTPLUG_ATTR_NAME] || !tb[DEV_HOTPLUG_ATTR_ADD])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ name = blobmsg_get_string(tb[DEV_HOTPLUG_ATTR_NAME]);
+ device_hotplug_event(name, blobmsg_get_bool(tb[DEV_HOTPLUG_ATTR_ADD]));
+
+ return 0;
+}
+#endif
+
static struct ubus_method dev_object_methods[] = {
UBUS_METHOD("status", netifd_dev_status, dev_policy),
UBUS_METHOD("set_alias", netifd_handle_alias, alias_attrs),
UBUS_METHOD("set_state", netifd_handle_set_state, dev_state_policy),
+#ifdef DUMMY_MODE
+ UBUS_METHOD("hotplug_event", netifd_handle_dev_hotplug, dev_hotplug_policy),
+#endif
};
static struct ubus_object_type dev_object_type =