ubus: implement ubus methods to force a Renew and Release
authorNicolas BESNARD <[email protected]>
Wed, 22 Jan 2025 10:21:48 +0000 (10:21 +0000)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 3 Nov 2025 15:21:24 +0000 (16:21 +0100)
Problem: Renew/Information-Request or Release messages are sent when
odhcp6c receives signal SIGUSR1 or SIGUSR2.
It should also be possible to trigger these messages via a ubus methods.

Solution: Implement two new ubus methods : release() and renew().

Signed-off-by: Nicolas BESNARD <[email protected]>
Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/106
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/ubus.c

index fde51bf7f273be6e6435f9c715d7536b9ebe91a9..257322076f3df6299e6e42709c19abcd940dd763 100644 (file)
@@ -137,6 +137,10 @@ static int ubus_handle_reset_stats(struct ubus_context *ctx, struct ubus_object
                struct ubus_request_data *req, const char *method, struct blob_attr *msg);
 static int ubus_handle_reconfigure_dhcp(struct ubus_context *ctx, struct ubus_object *obj,
                struct ubus_request_data *req, const char *method, struct blob_attr *msg);
+static int ubus_handle_renew(struct ubus_context *ctx, struct ubus_object *obj,
+               struct ubus_request_data *req, const char *method, struct blob_attr *msg);
+static int ubus_handle_release(struct ubus_context *ctx, struct ubus_object *obj,
+               struct ubus_request_data *req, const char *method, struct blob_attr *msg);
 
 static const struct blobmsg_policy reconfigure_dhcp_policy[RECONFIGURE_DHCP_ATTR_MAX] = {
        [RECONFIGURE_DHCP_ATTR_DSCP] = { .name = "dscp", .type = BLOBMSG_TYPE_INT32},
@@ -169,6 +173,8 @@ static struct ubus_method odhcp6c_object_methods[] = {
        UBUS_METHOD_NOARG("get_statistics", ubus_handle_get_stats),
        UBUS_METHOD_NOARG("reset_statistics", ubus_handle_reset_stats),
        UBUS_METHOD("reconfigure_dhcp", ubus_handle_reconfigure_dhcp, reconfigure_dhcp_policy),
+       UBUS_METHOD_NOARG("renew", ubus_handle_renew),
+       UBUS_METHOD_NOARG("release", ubus_handle_release),
 };
 
 static struct ubus_object_type odhcp6c_object_type = 
@@ -905,6 +911,22 @@ static int ubus_handle_reconfigure_dhcp(_unused struct ubus_context *ctx, _unuse
        return valid_args ? UBUS_STATUS_OK : UBUS_STATUS_INVALID_ARGUMENT;
 }
 
+static int ubus_handle_renew(_unused struct ubus_context *ctx, _unused struct ubus_object *obj,
+               _unused struct ubus_request_data *req, _unused const char *method,
+               _unused struct blob_attr *msg)
+{
+       raise(SIGUSR1);
+       return UBUS_STATUS_OK;
+}
+
+static int ubus_handle_release(_unused struct ubus_context *ctx, _unused struct ubus_object *obj,
+               _unused struct ubus_request_data *req, _unused const char *method,
+               _unused struct blob_attr *msg)
+{
+       raise(SIGUSR2);
+       return UBUS_STATUS_OK;
+}
+
 int ubus_dhcp_event(const char *status)
 {
        if (!ubus || !odhcp6c_object.has_subscribers)