interface: Trigger interface update event when interface data is updated via ubus
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 17 Dec 2015 14:02:06 +0000 (15:02 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 19 Dec 2015 11:28:27 +0000 (12:28 +0100)
Interface update event will trigger an interface hotplug event and an ubus notify event
which will inform subscribers about the updated interface data field

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
interface.c
interface.h
ubus.c

index 2638342..2aab37c 100644 (file)
@@ -75,6 +75,8 @@ const struct uci_blob_param_list interface_attr_list = {
 
 static void
 set_config_state(struct interface *iface, enum interface_config_state s);
 
 static void
 set_config_state(struct interface *iface, enum interface_config_state s);
+static void
+interface_event(struct interface *iface, enum interface_event ev);
 
 static void
 interface_error_flush(struct interface *iface)
 
 static void
 interface_error_flush(struct interface *iface)
@@ -195,6 +197,25 @@ interface_add_data(struct interface *iface, const struct blob_attr *data)
        return 0;
 }
 
        return 0;
 }
 
+int interface_parse_data(struct interface *iface, const struct blob_attr *attr)
+{
+       struct blob_attr *cur;
+       int rem, ret;
+
+       iface->updated = 0;
+
+       blob_for_each_attr(cur, attr, rem) {
+               ret = interface_add_data(iface, cur);
+               if (ret)
+                       return ret;
+       }
+
+       if (iface->updated && iface->state == IFS_UP)
+               interface_event(iface, IFEV_UPDATE);
+
+       return 0;
+}
+
 static void
 interface_event(struct interface *iface, enum interface_event ev)
 {
 static void
 interface_event(struct interface *iface, enum interface_event ev)
 {
index 6f9112c..c2049f1 100644 (file)
@@ -193,6 +193,7 @@ void interface_add_error(struct interface *iface, const char *subsystem,
                         const char *code, const char **data, int n_data);
 
 int interface_add_data(struct interface *iface, const struct blob_attr *data);
                         const char *code, const char **data, int n_data);
 
 int interface_add_data(struct interface *iface, const struct blob_attr *data);
+int interface_parse_data(struct interface *iface, const struct blob_attr *attr);
 
 void interface_update_start(struct interface *iface);
 void interface_update_complete(struct interface *iface);
 
 void interface_update_start(struct interface *iface);
 void interface_update_complete(struct interface *iface);
diff --git a/ubus.c b/ubus.c
index 90ee795..454b42d 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -891,18 +891,10 @@ netifd_handle_set_data(struct ubus_context *ctx, struct ubus_object *obj,
                       struct blob_attr *msg)
 {
        struct interface *iface;
                       struct blob_attr *msg)
 {
        struct interface *iface;
-       struct blob_attr *cur;
-       int rem, ret;
 
        iface = container_of(obj, struct interface, ubus);
 
 
        iface = container_of(obj, struct interface, ubus);
 
-       blob_for_each_attr(cur, msg, rem) {
-               ret = interface_add_data(iface, cur);
-               if (ret)
-                       return ret;
-       }
-
-       return 0;
+       return interface_parse_data(iface, msg);
 }
 
 static struct ubus_method iface_object_methods[] = {
 }
 
 static struct ubus_method iface_object_methods[] = {