From: Nicolas BESNARD Date: Wed, 22 Jan 2025 10:21:48 +0000 (+0000) Subject: ubus: implement ubus methods to force a Renew and Release X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=7b1f67c23de620f1f480e7d51eec87c6162c5510;p=project%2Fodhcp6c.git ubus: implement ubus methods to force a Renew and Release 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 Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcp6c/pull/106 Signed-off-by: Álvaro Fernández Rojas --- diff --git a/src/ubus.c b/src/ubus.c index fde51bf..2573220 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -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)