[connman] Merged IPv6 related code. 70/115570/6
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 20 Feb 2017 10:36:21 +0000 (19:36 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 23 Feb 2017 06:34:42 +0000 (15:34 +0900)
1. Added code to set IPv6 gateway addess.
2. Fix IPv6 issue in case of auto-configuration.

Change-Id: Ie0e1d53dd269a09600d2f08e66d73cefd6dd3c29
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
src/connman.h
src/inet.c
src/ipconfig.c
src/network.c

index 2217cc4..077bc1c 100755 (executable)
@@ -169,6 +169,9 @@ int __connman_inet_ipv6_send_rs(int index, int timeout,
                        __connman_inet_rs_cb_t callback, void *user_data);
 int __connman_inet_ipv6_send_ra(int index, struct in6_addr *src_addr,
                                GSList *prefixes, int router_lifetime);
+#if defined TIZEN_EXT
+void __connman_network_set_auto_ipv6_gateway(char *gateway, void *user_data);
+#endif
 
 typedef void (*__connman_inet_ns_cb_t) (struct nd_neighbor_advert *reply,
                                        unsigned int length,
index 972fdff..fcffab8 100755 (executable)
@@ -1340,6 +1340,37 @@ static int icmpv6_recv(int fd, gpointer user_data)
                return -errno;
        }
 
+#if defined TIZEN_EXT
+       /* Set Received Source Address from router as IPv6 Gateway Address */
+       char src_addr[INET6_ADDRSTRLEN];
+       if(inet_ntop(AF_INET6, &(saddr.sin6_addr), src_addr, INET6_ADDRSTRLEN)
+                       == NULL) {
+               xs_cleanup(data);
+               return -errno;
+       }
+       DBG("Received Source Address %s from router", src_addr);
+
+       /* icmpv6_recv() function can be called in two scenarios :
+        * 1. When __connman_inet_ipv6_send_rs() is called from check_dhcpv6()
+        * 2. When __connman_inet_ipv6_send_rs() is called from
+        * __connman_6to4_probe()
+        * In the second case it is not  required to set DHCPv6 Gateway  Address
+        * as DHCPv6 was not started and  network structure was not passed as
+        * user_data. If it is tried  to add Source Address as  Gateway Address
+        * then it will lead to  crash because of  user_data being ip_address
+        * instead of network structure. So Adding Gateway Address in case 1st
+        * case only.
+        */
+       char *address = data->user_data;
+       int err = 0;
+       unsigned char buffer[sizeof(struct in6_addr)] = {0, };
+       /* Checking if user_data is an ip_address */
+       err = inet_pton(AF_INET, address, buffer);
+       /* Setting Received Source Address from
+        * router as Gateway Address */
+       if(err <= 0)
+               __connman_network_set_auto_ipv6_gateway(src_addr, data->user_data);
+#endif
        hdr = (struct nd_router_advert *)buf;
        DBG("code %d len %zd hdr %zd", hdr->nd_ra_code, len,
                                sizeof(struct nd_router_advert));
index 8987ab1..27d98b2 100755 (executable)
@@ -410,7 +410,20 @@ static void free_ipdevice(gpointer data)
 static void __connman_ipconfig_lower_up(struct connman_ipdevice *ipdevice)
 {
        DBG("ipconfig ipv4 %p ipv6 %p", ipdevice->config_ipv4,
-                                       ipdevice->config_ipv6);
+                       ipdevice->config_ipv6);
+#if defined TIZEN_EXT
+       if (ipdevice->config_ipv6 != NULL &&
+                       ipdevice->config_ipv6->enabled == TRUE)
+               return;
+
+       char *ifname = connman_inet_ifname(ipdevice->index);
+
+       if (__connman_device_isfiltered(ifname) == FALSE) {
+               ipdevice->ipv6_enabled = get_ipv6_state(ifname);
+               set_ipv6_state(ifname, FALSE);
+       }
+       g_free(ifname);
+#endif
 }
 
 static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice)
@@ -1708,6 +1721,11 @@ int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
        if (ipdevice->config_ipv6 == ipconfig) {
                ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
 
+#if defined TIZEN_EXT
+               if (ipdevice->config_ipv6->method ==
+                               CONNMAN_IPCONFIG_METHOD_AUTO)
+                       disable_ipv6(ipdevice->config_ipv6);
+#endif
                connman_ipaddress_clear(ipdevice->config_ipv6->system);
                __connman_ipconfig_unref(ipdevice->config_ipv6);
                ipdevice->config_ipv6 = NULL;
@@ -2123,7 +2141,10 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
 
        case CONNMAN_IPCONFIG_METHOD_OFF:
                ipconfig->method = method;
-
+#if defined TIZEN_EXT
+               if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
+                       disable_ipv6(ipconfig);
+#endif
                break;
 
        case CONNMAN_IPCONFIG_METHOD_AUTO:
@@ -2133,7 +2154,9 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
                ipconfig->method = method;
                if (privacy_string)
                        ipconfig->ipv6_privacy_config = privacy;
-
+#if defined TIZEN_EXT
+               enable_ipv6(ipconfig);
+#endif
                break;
 
        case CONNMAN_IPCONFIG_METHOD_MANUAL:
index 8687619..78ce229 100755 (executable)
@@ -1729,6 +1729,35 @@ int __connman_network_clear_ipconfig(struct connman_network *network,
        return 0;
 }
 
+#if defined TIZEN_EXT
+void __connman_network_set_auto_ipv6_gateway(char *gateway, void *user_data)
+{
+       DBG("");
+
+       struct connman_network *network = user_data;
+       struct connman_service *service;
+       struct connman_ipconfig *ipconfig = NULL;
+       int err;
+
+       service = connman_service_lookup_from_network(network);
+       if (service == NULL)
+               return;
+
+       ipconfig = __connman_service_get_ipconfig(service, AF_INET6);
+       if (ipconfig == NULL)
+               return;
+
+       __connman_ipconfig_set_gateway(ipconfig, gateway);
+       err = __connman_ipconfig_gateway_add(ipconfig, service);
+
+       if(err == 0)
+               __connman_connection_gateway_activate(service,
+                               CONNMAN_IPCONFIG_TYPE_IPV6);
+
+       return;
+}
+#endif
+
 int __connman_network_enable_ipconfig(struct connman_network *network,
                                struct connman_ipconfig *ipconfig)
 {