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 ba7405a..4661143 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 7e2d2ea..ca5d110 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -309,6 +309,15 @@ static struct ubus_object_type iface_object_type =
 
 
 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)
 {
        struct ubus_object *obj = &iface->ubus;
diff --git a/ubus.h b/ubus.h
index 668a34b..a9166c6 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