Enable notification for IP configuration changes
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 21 Dec 2009 05:39:36 +0000 (21:39 -0800)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 21 Dec 2009 05:39:36 +0000 (21:39 -0800)
src/ipconfig.c
src/service.c

index 2fff6c7..335a93e 100644 (file)
@@ -435,6 +435,9 @@ update:
                if (index != ipconfig->index)
                        continue;
 
+               if (ipconfig->ops == NULL)
+                       continue;
+
                if (up == TRUE && ipconfig->ops->up)
                        ipconfig->ops->up(ipconfig);
                if (lower_up == TRUE && ipconfig->ops->lower_up)
@@ -472,6 +475,9 @@ void __connman_ipconfig_dellink(int index)
 
                ipconfig->index = -1;
 
+               if (ipconfig->ops == NULL)
+                       continue;
+
                if (ipconfig->ops->lower_down)
                        ipconfig->ops->lower_down(ipconfig);
                if (ipconfig->ops->down)
@@ -525,6 +531,9 @@ void __connman_ipconfig_newaddr(int index, const char *label,
                if (index != ipconfig->index)
                        continue;
 
+               if (ipconfig->ops == NULL)
+                       continue;
+
                if (ipconfig->ops->ip_bound)
                        ipconfig->ops->ip_bound(ipconfig);
        }
@@ -568,6 +577,9 @@ void __connman_ipconfig_deladdr(int index, const char *label,
                if (index != ipconfig->index)
                        continue;
 
+               if (ipconfig->ops == NULL)
+                       continue;
+
                if (ipconfig->ops->ip_release)
                        ipconfig->ops->ip_release(ipconfig);
        }
@@ -748,6 +760,8 @@ struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
 void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
 {
        if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
+               __connman_ipconfig_disable(ipconfig);
+
                connman_ipconfig_set_ops(ipconfig, NULL);
 
                if (ipconfig->origin != NULL) {
@@ -830,13 +844,7 @@ const char *connman_ipconfig_get_ifname(struct connman_ipconfig *ipconfig)
 void connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
                                const struct connman_ipconfig_ops *ops)
 {
-       if (ipconfig->ops != NULL)
-               ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
-
        ipconfig->ops = ops;
-
-       if (ops != NULL)
-               ipconfig_list = g_list_append(ipconfig_list, ipconfig);
 }
 
 /**
@@ -888,6 +896,8 @@ int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
                return -ENXIO;
 
        if (ipdevice->config != NULL) {
+               ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
+
                connman_ipaddress_clear(ipdevice->config->system);
 
                connman_ipconfig_unref(ipdevice->config);
@@ -895,6 +905,8 @@ int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
 
        ipdevice->config = connman_ipconfig_ref(ipconfig);
 
+       ipconfig_list = g_list_append(ipconfig_list, ipconfig);
+
        return 0;
 }
 
@@ -915,6 +927,8 @@ int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
        if (ipdevice->config == NULL || ipdevice->config != ipconfig)
                return -EINVAL;
 
+       ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
+
        connman_ipaddress_clear(ipdevice->config->system);
 
        connman_ipconfig_unref(ipdevice->config);
index d3089a0..34c4e47 100644 (file)
@@ -1440,8 +1440,6 @@ int __connman_service_indicate_state(struct connman_service *service,
                g_get_current_time(&service->modified);
                __connman_storage_save_service(service);
 
-               settings_changed(service);
-
                __connman_notifier_connect(service->type);
 
                default_changed();
@@ -1931,12 +1929,20 @@ static void service_lower_down(struct connman_ipconfig *ipconfig)
 
 static void service_ip_bound(struct connman_ipconfig *ipconfig)
 {
+       struct connman_service *service = connman_ipconfig_get_data(ipconfig);
+
        connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
+
+       settings_changed(service);
 }
 
 static void service_ip_release(struct connman_ipconfig *ipconfig)
 {
+       struct connman_service *service = connman_ipconfig_get_data(ipconfig);
+
        connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
+
+       settings_changed(service);
 }
 
 static const struct connman_ipconfig_ops service_ops = {
@@ -1965,7 +1971,6 @@ static void setup_ipconfig(struct connman_service *service, int index)
        connman_ipconfig_set_data(service->ipconfig, service);
 
        connman_ipconfig_set_ops(service->ipconfig, &service_ops);
-       connman_ipconfig_set_ops(service->ipconfig, NULL);
 }
 
 /**