proto-shell: fix updating settings, only issue ifup event after configuration has...
authorFelix Fietkau <nbd@openwrt.org>
Thu, 13 Oct 2011 13:11:32 +0000 (15:11 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 13 Oct 2011 13:11:32 +0000 (15:11 +0200)
interface-ip.c
interface-ip.h
proto-shell.c
utils.h

index 8dae80d1883189c838193b09bab33a1f05007d3e..28c608ab661d0c0a18d09eb00bf753a8e192744b 100644 (file)
@@ -195,6 +195,21 @@ interface_write_resolv_conf(void)
        }
 }
 
+void
+interface_ip_update_start(struct interface *iface)
+{
+       interface_clear_dns(iface);
+       vlist_update(&iface->proto_route);
+       vlist_update(&iface->proto_addr);
+}
+
+void
+interface_ip_update_complete(struct interface *iface)
+{
+       vlist_flush(&iface->proto_route);
+       vlist_flush(&iface->proto_addr);
+}
+
 void
 interface_ip_init(struct interface *iface)
 {
index 91703a1d89787b6e5addd1e23a1d608a9efdfe0b..6049d144a1ca089bccab4a589a8373c16f1c5b90 100644 (file)
@@ -60,4 +60,8 @@ void interface_add_dns_server_list(struct interface *iface, struct blob_attr *li
 void interface_clear_dns(struct interface *iface);
 void interface_write_resolv_conf(void);
 
+void interface_ip_update_start(struct interface *iface);
+void interface_ip_update_complete(struct interface *iface);
+
+
 #endif
index 3ed4b8e738de79d965a0f70d1201460dbbc0d405..3dcfb696eefd09b148d952368175d759090a6164 100644 (file)
@@ -331,21 +331,23 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb)
                return UBUS_STATUS_INVALID_ARGUMENT;
 
        up = blobmsg_get_bool(tb[NOTIFY_LINK_UP]);
-       if (up) {
-               if (!tb[NOTIFY_IFNAME])
-                       return UBUS_STATUS_INVALID_ARGUMENT;
-
-               if (!state->l3_dev.dev) {
-                       device_add_user(&state->l3_dev,
-                               device_get(blobmsg_data(tb[NOTIFY_IFNAME]), true));
-                       device_claim(&state->l3_dev);
-                       state->proto.iface->l3_dev = &state->l3_dev;
-               }
-               state->proto.proto_event(&state->proto, IFPEV_UP);
-       } else {
+       if (!up) {
                state->proto.proto_event(&state->proto, IFPEV_LINK_LOST);
+               return 0;
        }
 
+       if (!tb[NOTIFY_IFNAME])
+               return UBUS_STATUS_INVALID_ARGUMENT;
+
+       if (!state->l3_dev.dev) {
+               device_add_user(&state->l3_dev,
+                       device_get(blobmsg_data(tb[NOTIFY_IFNAME]), true));
+               device_claim(&state->l3_dev);
+               state->proto.iface->l3_dev = &state->l3_dev;
+       }
+
+       interface_ip_update_start(state->proto.iface);
+
        if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL)
                addr_ext = blobmsg_get_bool(cur);
 
@@ -364,6 +366,10 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb)
        if ((cur = tb[NOTIFY_DNS]) != NULL)
                interface_add_dns_server_list(state->proto.iface, cur);
 
+       interface_ip_update_complete(state->proto.iface);
+
+       state->proto.proto_event(&state->proto, IFPEV_UP);
+
        return 0;
 }
 
diff --git a/utils.h b/utils.h
index 85d7dc6bdb0d23c6fd97641ac254eaa230558795..6500fdf80297b50841c06fc9e28c3e63c2c7e3dc 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -34,6 +34,11 @@ void __vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb up
 #define vlist_init(tree, cmp, update, type, node, key) \
        __vlist_init(tree, cmp, update, offsetof(type, key) - offsetof(type, node))
 
+static inline void vlist_update(struct vlist_tree *tree)
+{
+       tree->version++;
+}
+
 void vlist_add(struct vlist_tree *tree, struct vlist_node *node);
 void vlist_delete(struct vlist_tree *tree, struct vlist_node *node);
 void vlist_flush(struct vlist_tree *tree);