add ubus events for interface up/down
authorFelix Fietkau <nbd@openwrt.org>
Sun, 9 Oct 2011 16:49:46 +0000 (18:49 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 9 Oct 2011 16:49:46 +0000 (18:49 +0200)
interface-event.c
ubus.c
ubus.h

index ba7405a8410534b3ae4b90e7995f3e8c131e4a83..46611432c7738387a6b3c6d5783dc77ff52e1a47 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "netifd.h"
 #include "interface.h"
+#include "ubus.h"
 
 char *hotplug_cmd_path = DEFAULT_HOTPLUG_PATH;
 static struct interface *current;
@@ -79,6 +80,7 @@ interface_queue_event(struct interface *iface, enum interface_event ev)
        enum interface_event last_ev;
 
        D(SYSTEM, "Queue hotplug handler for interface '%s'\n", iface->name);
+       netifd_ubus_interface_event(iface, ev == IFEV_UP);
        if (current == iface)
                last_ev = current_ev;
        else
diff --git a/ubus.c b/ubus.c
index 7e2d2ea875876dcd43fd58f28d93b59eb628cc92..ca5d11021c831bcc41fa9ba594fde6aa900ec893 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -308,6 +308,15 @@ static struct ubus_object_type iface_object_type =
        UBUS_OBJECT_TYPE("netifd_iface", iface_object_methods);
 
 
+void
+netifd_ubus_interface_event(struct interface *iface, bool up)
+{
+       blob_buf_init(&b, 0);
+       blobmsg_add_string(&b, "action", up ? "ifup" : "ifdown");
+       blobmsg_add_string(&b, "interface", iface->name);
+       ubus_send_event(ctx, "network.interface", b.head);
+}
+
 void
 netifd_ubus_add_interface(struct interface *iface)
 {
diff --git a/ubus.h b/ubus.h
index 668a34b21c5b5cbec0437a255aaef42175b45871..a9166c623f6e18644e5ad330c9fa74ec1e6a6791 100644 (file)
--- a/ubus.h
+++ b/ubus.h
@@ -5,5 +5,6 @@ int netifd_ubus_init(const char *path);
 void netifd_ubus_done(void);
 void netifd_ubus_add_interface(struct interface *iface);
 void netifd_ubus_remove_interface(struct interface *iface);
+void netifd_ubus_interface_event(struct interface *iface, bool up);
 
 #endif