Skip to content
Snippets Groups Projects
Commit 2f9508c6 authored by Rahul Thakur's avatar Rahul Thakur
Browse files

netifd: add ubus event for link state

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 follow:

{ "network.device": {"ifname":"eth3","link":"down"} }
parent 0b4f154d
No related branches found
No related tags found
1 merge request!558netifd: add ubus event for link state
diff --git a/device.c b/device.c
index 1370335..279f2f7 100644
--- a/device.c
+++ b/device.c
@@ -956,6 +956,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 e2aa3f8..d88a5ca 100644
--- a/ubus.c
+++ b/ubus.c
@@ -1402,6 +1402,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 dde7124..eccefed 100644
--- a/ubus.h
+++ b/ubus.h
@@ -27,4 +27,5 @@ 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_device_event(struct device *dev, bool state);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment