service: Return 6to4 tunnel status to dbus caller.
[platform/upstream/connman.git] / src / service.c
index 38111ee..ae1f6fd 100644 (file)
@@ -428,8 +428,7 @@ static connman_bool_t is_connecting_state(struct connman_service *service,
        case CONNMAN_SERVICE_STATE_IDLE:
        case CONNMAN_SERVICE_STATE_FAILURE:
                if (service->network != NULL)
-                       return __connman_network_get_connecting(
-                                                       service->network);
+                       return connman_network_get_connecting(service->network);
        case CONNMAN_SERVICE_STATE_DISCONNECT:
        case CONNMAN_SERVICE_STATE_READY:
        case CONNMAN_SERVICE_STATE_ONLINE:
@@ -619,6 +618,14 @@ int __connman_service_nameserver_remove(struct connman_service *service,
        return 0;
 }
 
+void __connman_service_nameserver_clear(struct connman_service *service)
+{
+       g_strfreev(service->nameservers);
+       service->nameservers = NULL;
+
+       update_nameservers(service);
+}
+
 static void nameserver_add_routes(int index, char **nameservers,
                                        const char *gw)
 {
@@ -995,7 +1002,8 @@ static void append_ipv6(DBusMessageIter *iter, void *user_data)
                return;
 
        if (service->ipconfig_ipv6 != NULL)
-               __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter);
+               __connman_ipconfig_append_ipv6(service->ipconfig_ipv6, iter,
+                                               service->ipconfig_ipv4);
 }
 
 static void append_ipv4config(DBusMessageIter *iter, void *user_data)
@@ -2530,9 +2538,21 @@ static void reply_pending(struct connman_service *service, int error)
                                                                error);
                        if (reply != NULL)
                                g_dbus_send_message(connection, reply);
-               } else
-                       g_dbus_send_reply(connection, service->pending,
+               } else {
+                       const char *sender;
+
+                       sender = dbus_message_get_interface(service->pending);
+
+                       DBG("sender %s", sender);
+
+                       if (g_strcmp0(sender, CONNMAN_MANAGER_INTERFACE) == 0)
+                               g_dbus_send_reply(connection, service->pending,
+                                       DBUS_TYPE_OBJECT_PATH, &service->path,
+                                                       DBUS_TYPE_INVALID);
+                       else
+                               g_dbus_send_reply(connection, service->pending,
                                                        DBUS_TYPE_INVALID);
+               }
 
                dbus_message_unref(service->pending);
                service->pending = NULL;
@@ -2790,8 +2810,6 @@ static DBusMessage *remove_service(DBusConnection *conn,
                __connman_network_disconnect(service->network);
        }
 
-       g_hash_table_destroy(service->counter_table);
-
        g_free(service->passphrase);
        service->passphrase = NULL;
 
@@ -2910,6 +2928,8 @@ static void service_free(gpointer user_data)
                g_free(path);
        }
 
+       g_hash_table_destroy(service->counter_table);
+
        if (service->network != NULL)
                connman_network_unref(service->network);
 
@@ -3239,6 +3259,18 @@ __connman_service_get_ip6config(struct connman_service *service)
        return service->ipconfig_ipv6;
 }
 
+struct connman_ipconfig *
+__connman_service_get_ipconfig(struct connman_service *service, int family)
+{
+       if (family == AF_INET)
+               return __connman_service_get_ip4config(service);
+       else if (family == AF_INET6)
+               return __connman_service_get_ip6config(service);
+       else
+               return NULL;
+
+}
+
 enum connman_service_security __connman_service_get_security(struct connman_service *service)
 {
        if (service == NULL)
@@ -3596,6 +3628,14 @@ int __connman_service_clear_error(struct connman_service *service)
        __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE,
                                        CONNMAN_IPCONFIG_TYPE_IPV6);
 
+       /*
+        * Toggling the IPv6 state to IDLE could trigger the auto connect
+        * machinery and consequently the IPv4 state.
+        */
+       if (service->state_ipv4 != CONNMAN_SERVICE_STATE_UNKNOWN &&
+                       service->state_ipv4 != CONNMAN_SERVICE_STATE_FAILURE)
+               return 0;
+
        return __connman_service_indicate_state(service,
                                                CONNMAN_SERVICE_STATE_IDLE,
                                                CONNMAN_IPCONFIG_TYPE_IPV4);
@@ -3848,6 +3888,8 @@ int __connman_service_disconnect(struct connman_service *service)
        if (err < 0 && err != -EINPROGRESS)
                return err;
 
+       __connman_6to4_remove(service->ipconfig_ipv4);
+
        if (service->ipconfig_ipv4)
                __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv4,
                                                        NULL);
@@ -3855,8 +3897,8 @@ int __connman_service_disconnect(struct connman_service *service)
                __connman_ipconfig_set_proxy_autoconfig(service->ipconfig_ipv6,
                                                        NULL);
 
-       __connman_ipconfig_clear_address(service->ipconfig_ipv4);
-       __connman_ipconfig_clear_address(service->ipconfig_ipv6);
+       __connman_ipconfig_address_remove(service->ipconfig_ipv4);
+       __connman_ipconfig_address_remove(service->ipconfig_ipv6);
 
        __connman_ipconfig_disable(service->ipconfig_ipv4);
        __connman_ipconfig_disable(service->ipconfig_ipv6);
@@ -4101,9 +4143,7 @@ done:
        if (err < 0 && err != -EINPROGRESS)
                goto failed;
 
-       g_dbus_send_reply(connection, msg,
-                               DBUS_TYPE_OBJECT_PATH, &service->path,
-                                                       DBUS_TYPE_INVALID);
+       service->pending = dbus_message_ref(msg);
 
        return 0;