service: Allow removing only certain type nameservers
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Wed, 14 Mar 2012 15:28:52 +0000 (17:28 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 19 Mar 2012 11:08:41 +0000 (13:08 +0200)
When nameserver are removed by __connman_connection_gateway_remove()
then remove only certain type nameserver (IPv4 or IPv6). This is
needed so that we do not loose IPv4 routes if only IPv6 nameservers
are to be removed. This is needed when there are multiple connected
services.

src/connection.c
src/connman.h
src/service.c

index fde8f79..545b59f 100644 (file)
@@ -728,7 +728,7 @@ void __connman_connection_gateway_remove(struct connman_service *service,
        else
                do_ipv4 = do_ipv6 = TRUE;
 
-       __connman_service_nameserver_del_routes(service);
+       __connman_service_nameserver_del_routes(service, type);
 
        data = g_hash_table_lookup(gateway_hash, service);
        if (data == NULL)
index 8609614..617ad32 100644 (file)
@@ -583,7 +583,8 @@ int __connman_service_nameserver_remove(struct connman_service *service,
 void __connman_service_nameserver_clear(struct connman_service *service);
 void __connman_service_nameserver_add_routes(struct connman_service *service,
                                                const char *gw);
-void __connman_service_nameserver_del_routes(struct connman_service *service);
+void __connman_service_nameserver_del_routes(struct connman_service *service,
+                                       enum connman_ipconfig_type type);
 int __connman_service_timeserver_append(struct connman_service *service,
                                                const char *timeserver);
 int __connman_service_timeserver_remove(struct connman_service *service,
index 7787636..6c8cccc 100644 (file)
@@ -966,7 +966,8 @@ static void nameserver_add_routes(int index, char **nameservers,
        }
 }
 
-static void nameserver_del_routes(int index, char **nameservers)
+static void nameserver_del_routes(int index, char **nameservers,
+                               enum connman_ipconfig_type type)
 {
        int i, ret, family;
        struct addrinfo hints;
@@ -985,11 +986,18 @@ static void nameserver_del_routes(int index, char **nameservers)
                else
                        family = addr->ai_family;
 
-               if (family == AF_INET)
-                       connman_inet_del_host_route(index, nameservers[i]);
-               else if (family == AF_INET6)
-                       connman_inet_del_ipv6_host_route(index,
+               switch (family) {
+               case AF_INET:
+                       if (type != CONNMAN_IPCONFIG_TYPE_IPV6)
+                               connman_inet_del_host_route(index,
                                                        nameservers[i]);
+                       break;
+               case AF_INET6:
+                       if (type != CONNMAN_IPCONFIG_TYPE_IPV4)
+                               connman_inet_del_ipv6_host_route(index,
+                                                       nameservers[i]);
+                       break;
+               }
 
                freeaddrinfo(addr);
        }
@@ -1026,7 +1034,8 @@ void __connman_service_nameserver_add_routes(struct connman_service *service,
        }
 }
 
-void __connman_service_nameserver_del_routes(struct connman_service *service)
+void __connman_service_nameserver_del_routes(struct connman_service *service,
+                                       enum connman_ipconfig_type type)
 {
        int index = -1;
 
@@ -1039,9 +1048,10 @@ void __connman_service_nameserver_del_routes(struct connman_service *service)
                index = connman_provider_get_index(service->provider);
 
        if (service->nameservers_config != NULL)
-               nameserver_del_routes(index, service->nameservers_config);
+               nameserver_del_routes(index, service->nameservers_config,
+                                       type);
        else if (service->nameservers != NULL)
-               nameserver_del_routes(index, service->nameservers);
+               nameserver_del_routes(index, service->nameservers, type);
 }
 
 static struct connman_stats *stats_get(struct connman_service *service)
@@ -2672,7 +2682,8 @@ static DBusMessage *set_property(DBusConnection *conn,
                gw = __connman_ipconfig_get_gateway_from_index(index);
 
                if (gw && strlen(gw))
-                       __connman_service_nameserver_del_routes(service);
+                       __connman_service_nameserver_del_routes(service,
+                                               CONNMAN_IPCONFIG_TYPE_ALL);
 
                dbus_message_iter_recurse(&value, &entry);