From d34e1cfa7bb9d4c2f2675801841c5be75b827441 Mon Sep 17 00:00:00 2001 From: Rahul Thakur Date: Wed, 20 Mar 2024 11:29:13 +0530 Subject: [PATCH] device: add ubus event for link state change Add a ubus event network.device for link state change to generate an event when the link goes up and down. The event looks as follows: { "network.device": {"ifname":"eth3","link":"down"} } Signed-off-by: Rahul Thakur --- device.c | 1 + ubus.c | 9 +++++++++ ubus.h | 1 + 3 files changed, 11 insertions(+) diff --git a/device.c b/device.c index 322e009..c896a32 100644 --- a/device.c +++ b/device.c @@ -969,6 +969,7 @@ void device_set_link(struct device *dev, bool state) if (!state) dev->auth_status = false; device_broadcast_event(dev, state ? DEV_EVENT_LINK_UP : DEV_EVENT_LINK_DOWN); + netifd_ubus_device_event(dev, state); } void device_set_ifindex(struct device *dev, int ifindex) diff --git a/ubus.c b/ubus.c index f8662c2..69e9751 100644 --- a/ubus.c +++ b/ubus.c @@ -1405,6 +1405,15 @@ netifd_ubus_interface_event(struct interface *iface, bool up) ubus_send_event(ubus_ctx, "network.interface", b.head); } +void +netifd_ubus_device_event(struct device *dev, bool state) +{ + blob_buf_init(&b, 0); + blobmsg_add_string(&b, "ifname", dev->ifname); + blobmsg_add_string(&b, "link", state? "up" : "down"); + ubus_send_event(ubus_ctx, "network.device", b.head); +} + void netifd_ubus_interface_notify(struct interface *iface, bool up) { diff --git a/ubus.h b/ubus.h index b9b4b69..1a48643 100644 --- a/ubus.h +++ b/ubus.h @@ -29,5 +29,6 @@ void netifd_ubus_interface_event(struct interface *iface, bool up); void netifd_ubus_interface_notify(struct interface *iface, bool up); void netifd_ubus_device_notify(const char *event, struct blob_attr *data, int timeout); void netifd_ubus_get_procd_data(const char *type, procd_data_cb cb); +void netifd_ubus_device_event(struct device *dev, bool state); #endif