From: Jukka Rissanen Date: Wed, 22 Jun 2011 10:37:42 +0000 (+0300) Subject: service: Set and clear IPv6 nameserver addresses properly. X-Git-Tag: 0.76~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b42703813bb42e57aae2fae0fbfa59ec488833f5;p=platform%2Fupstream%2Fconnman.git service: Set and clear IPv6 nameserver addresses properly. --- diff --git a/src/service.c b/src/service.c index 7c11cfa..51cda8f 100644 --- a/src/service.c +++ b/src/service.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "connman.h" @@ -611,22 +612,63 @@ void __connman_service_nameserver_clear(struct connman_service *service) static void nameserver_add_routes(int index, char **nameservers, const char *gw) { - int i; + int i, ret, family; + struct addrinfo hints; + struct addrinfo *addr; for (i = 0; nameservers[i] != NULL; i++) { - if (connman_inet_compare_subnet(index, nameservers[i])) + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_NUMERICHOST; + addr = NULL; + + ret = getaddrinfo(nameservers[i], NULL, &hints, &addr); + if (ret == EAI_NONAME) + family = AF_INET; /* use the IPv4 as a default */ + else if (ret != 0) continue; + else + family = addr->ai_family; + + if (family == AF_INET) { + if (connman_inet_compare_subnet(index, + nameservers[i]) != TRUE) + connman_inet_add_host_route(index, + nameservers[i], gw); + } else if (family == AF_INET6) + connman_inet_add_ipv6_host_route(index, + nameservers[i], gw); - connman_inet_add_host_route(index, nameservers[i], gw); + freeaddrinfo(addr); } } static void nameserver_del_routes(int index, char **nameservers) { - int i; + int i, ret, family; + struct addrinfo hints; + struct addrinfo *addr; + + for (i = 0; nameservers[i] != NULL; i++) { + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_NUMERICHOST; + addr = NULL; + + ret = getaddrinfo(nameservers[i], NULL, &hints, &addr); + if (ret == EAI_NONAME) + family = AF_INET; /* use the IPv4 as a default */ + else if (ret != 0) + continue; + else + family = addr->ai_family; - for (i = 0; nameservers[i] != NULL; i++) - connman_inet_del_host_route(index, nameservers[i]); + if (family == AF_INET) + connman_inet_del_host_route(index, nameservers[i]); + else if (family == AF_INET6) + connman_inet_del_ipv6_host_route(index, + nameservers[i]); + + freeaddrinfo(addr); + } } void __connman_service_nameserver_add_routes(struct connman_service *service,