From: Samuel Ortiz Date: Fri, 25 Feb 2011 18:36:33 +0000 (+0100) Subject: openconnect: Support IPv6 settings X-Git-Tag: 2.0_alpha~1679 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b26c668fd1ffbd32961a6c23e852ee346de4fa1a;p=framework%2Fconnectivity%2Fconnman.git openconnect: Support IPv6 settings --- diff --git a/plugins/openconnect.c b/plugins/openconnect.c index 45c78fe..94bfcfc 100644 --- a/plugins/openconnect.c +++ b/plugins/openconnect.c @@ -23,6 +23,7 @@ #include #endif +#include #include #include #include @@ -44,7 +45,9 @@ static int oc_notify(DBusMessage *msg, struct connman_provider *provider) DBusMessageIter iter, dict; const char *reason, *key, *value; const char *domain = NULL; - char *address = NULL, *netmask = NULL, *gateway = NULL; + char *addressv4 = NULL, *addressv6 = NULL; + char *netmask = NULL, *gateway = NULL; + unsigned char prefix_len = 0; struct connman_ipaddress *ipaddress; dbus_message_iter_init(msg, &iter); @@ -79,12 +82,32 @@ static int oc_notify(DBusMessage *msg, struct connman_provider *provider) gateway = g_strdup(value); if (!strcmp(key, "INTERNAL_IP4_ADDRESS")) - address = g_strdup(value); + addressv4 = g_strdup(value); + + if (!strcmp(key, "INTERNAL_IP6_ADDRESS")) { + addressv6 = g_strdup(value); + prefix_len = 128; + } if (!strcmp(key, "INTERNAL_IP4_NETMASK")) netmask = g_strdup(value); - if (!strcmp(key, "INTERNAL_IP4_DNS")) + if (!strcmp(key, "INTERNAL_IP6_NETMASK")) { + char *sep; + + /* The netmask contains the address and the prefix */ + sep = strchr(value, '/'); + if (sep != NULL) { + unsigned char ip_len = sep - value; + + addressv6 = g_strndup(value, ip_len); + prefix_len = (unsigned char) + strtol(sep + 1, NULL, 10); + } + } + + if (!strcmp(key, "INTERNAL_IP4_DNS") || + !strcmp(key, "INTERNAL_IP6_DNS")) connman_provider_set_nameservers(provider, value); if (!strcmp(key, "CISCO_PROXY_PAC")) @@ -100,20 +123,35 @@ static int oc_notify(DBusMessage *msg, struct connman_provider *provider) dbus_message_iter_next(&dict); } - ipaddress = connman_ipaddress_alloc(AF_INET); + DBG("%p %p", addressv4, addressv6); + + if (addressv4 != NULL) + ipaddress = connman_ipaddress_alloc(AF_INET); + else if (addressv6 != NULL) + ipaddress = connman_ipaddress_alloc(AF_INET6); + else + ipaddress = NULL; + if (ipaddress == NULL) { - g_free(address); + g_free(addressv4); + g_free(addressv6); g_free(netmask); g_free(gateway); return VPN_STATE_FAILURE; } - connman_ipaddress_set_ipv4(ipaddress, address, netmask, gateway); + if (addressv4 != NULL) + connman_ipaddress_set_ipv4(ipaddress, addressv4, + netmask, gateway); + else + connman_ipaddress_set_ipv6(ipaddress, addressv6, + gateway, prefix_len); connman_provider_set_ipaddress(provider, ipaddress); connman_provider_set_domain(provider, domain); - g_free(address); + g_free(addressv4); + g_free(addressv6); g_free(netmask); g_free(gateway); connman_ipaddress_free(ipaddress);