Skip to content

Commit

Permalink
device: add ubus event for link state change
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rthakur33 committed Mar 20, 2024
1 parent 841b05f commit 94625c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,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)
Expand Down
9 changes: 9 additions & 0 deletions ubus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions ubus.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ void netifd_ubus_remove_interface(struct interface *iface);
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 comments on commit 94625c0

Please sign in to comment.