[IOT-2063] Enable endpoints filtering in CAIPGetInterfaceInformation() 21/19821/17
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Tue, 23 May 2017 04:03:48 +0000 (13:03 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 23 May 2017 07:10:24 +0000 (07:10 +0000)
https://gerrit.iotivity.org/gerrit/#/c/19355/ was modified to make
changes for all platforms.

Change-Id: Ib653daaad453556354b108c673b34c06a197c5f9
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19821
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/ip_adapter/tizen/caipnwmonitor.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/connectivity/test/ca_api_unittest.cpp

index 2a54e5c..df20a77 100644 (file)
@@ -484,14 +484,7 @@ CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, size_t *size)
     {
         OICFree(tempInfo);
         OICFree(tempSize);
-        if (res == CA_ADAPTER_NOT_ENABLED || res == CA_NOT_SUPPORTED)
-        {
-            return res;
-        }
-        else
-        {
-            return CA_STATUS_FAILED;
-        }
+        return res;
     }
 
     // #3. add data into result
index 7ee6696..5e13fa4 100644 (file)
@@ -239,12 +239,6 @@ static bool CAParsingNetorkInfo(int idx, u_arraylist_t *iflist)
             continue;
         }
 
-        if ((family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
-            (family == AF_INET && !caglobals.ip.ipv4enabled))
-        {
-            continue;
-        }
-
         int ifindex = if_nametoindex(ifa->ifa_name);
         if (idx && (ifindex != idx))
         {
index e88715c..f8c3e14 100644 (file)
@@ -1543,8 +1543,28 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size)
 #endif
 
     size_t interfaces = u_arraylist_length(iflist);
-    size_t totalEndpoints = interfaces * endpointsPerInterface;
+    for (size_t i = 0; i < interfaces; i++)
+    {
+        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
+        if (!ifitem)
+        {
+            continue;
+        }
+
+        if ((ifitem->family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (ifitem->family == AF_INET && !caglobals.ip.ipv4enabled))
+        {
+            interfaces--;
+        }
+    }
 
+    if (!interfaces)
+    {
+        OIC_LOG(DEBUG, TAG, "network interface size is zero");
+        return CA_STATUS_OK;
+    }
+
+    size_t totalEndpoints = interfaces * endpointsPerInterface;
     CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(totalEndpoints, sizeof (CAEndpoint_t));
     if (!eps)
     {
@@ -1553,10 +1573,16 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size)
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    for (size_t i = 0, j = 0; i < interfaces; i++)
+    for (size_t i = 0, j = 0; i < u_arraylist_length(iflist); i++)
     {
         CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
-        if(!ifitem)
+        if (!ifitem)
+        {
+            continue;
+        }
+
+        if ((ifitem->family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (ifitem->family == AF_INET && !caglobals.ip.ipv4enabled))
         {
             continue;
         }
index b870216..596b4a7 100644 (file)
@@ -444,12 +444,6 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex)
             continue;
         }
 
-        if ((family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
-            (family == AF_INET && !caglobals.ip.ipv4enabled))
-        {
-            continue;
-        }
-
         CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof(CAInterface_t));
         if (!ifitem)
         {
index 332b626..552c02d 100644 (file)
@@ -283,12 +283,6 @@ static bool CAIPGetAddrInfo(int idx, u_arraylist_t *iflist)
             continue;
         }
 
-        if ((family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
-            (family == AF_INET && !caglobals.ip.ipv4enabled))
-        {
-            continue;
-        }
-
         int ifindex = if_nametoindex(ifa->ifa_name);
         if (idx && (ifindex != idx))
         {
index 540d275..c96e09c 100644 (file)
@@ -1320,8 +1320,28 @@ CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, size_t *size)
 #endif
 
     size_t interfaces = u_arraylist_length(iflist);
-    size_t totalEndpoints = interfaces * endpointsPerInterface;
+    for (size_t i = 0; i < interfaces; i++)
+    {
+        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
+        if (!ifitem)
+        {
+            continue;
+        }
+
+        if ((ifitem->family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (ifitem->family == AF_INET && !caglobals.ip.ipv4enabled))
+        {
+            interfaces--;
+        }
+    }
+
+    if (!interfaces)
+    {
+        OIC_LOG(DEBUG, TAG, "network interface size is zero");
+        return CA_STATUS_OK;
+    }
 
+    size_t totalEndpoints = interfaces * endpointsPerInterface;
     CAEndpoint_t *ep = (CAEndpoint_t *)OICCalloc(totalEndpoints, sizeof (CAEndpoint_t));
     if (!ep)
     {
@@ -1330,7 +1350,7 @@ CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, size_t *size)
         return CA_MEMORY_ALLOC_FAILED;
     }
 
-    for (size_t i = 0, j = 0; i < interfaces; i++)
+    for (size_t i = 0, j = 0; i < u_arraylist_length(iflist); i++)
     {
         CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
         if (!ifitem)
@@ -1338,6 +1358,12 @@ CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, size_t *size)
             continue;
         }
 
+        if ((ifitem->family == AF_INET6 && !caglobals.ip.ipv6enabled) ||
+            (ifitem->family == AF_INET && !caglobals.ip.ipv4enabled))
+        {
+            continue;
+        }
+
         ep[j].adapter = CA_ADAPTER_TCP;
         ep[j].ifindex = ifitem->index;
 
index 8115ec9..39eccd6 100755 (executable)
@@ -504,7 +504,7 @@ TEST_F(CATests, HandlerRequestResponseTest)
 }
 
 // CAGetNetworkInformation TC
-TEST_F (CATests, GetNetworkInformationTest)
+TEST_F(CATests, GetNetworkInformationTest)
 {
     size_t tempSize = 0;
     CAEndpoint_t *tempInfo = NULL;
@@ -521,6 +521,71 @@ TEST_F (CATests, GetNetworkInformationTest)
     free(tempInfo);
 }
 
+// TODO: This is temporary disabled.
+TEST(CAGetNetworkInformationTest, DISABLED_EnableIPv6)
+{
+    CAInitialize(CA_DEFAULT_ADAPTER);
+    caglobals.ip.ipv6enabled = true;
+    caglobals.ip.ipv4enabled = false;
+
+    size_t tempSize = 0;
+    CAEndpoint_t *tempInfo = NULL;
+
+    EXPECT_EQ(CA_STATUS_OK, CASelectNetwork(CA_ADAPTER_IP));
+    EXPECT_EQ(CA_STATUS_OK, CAGetNetworkInformation(&tempInfo, &tempSize));
+
+    for (size_t index = 0; index < tempSize; index++)
+    {
+        EXPECT_TRUE((tempInfo[index].flags & CA_IPV6) != 0);
+    }
+
+    OICFree(tempInfo);
+    CATerminate();
+}
+
+TEST(CAGetNetworkInformationTest, DISABLED_EnableIPv4)
+{
+    CAInitialize(CA_DEFAULT_ADAPTER);
+    caglobals.ip.ipv6enabled = false;
+    caglobals.ip.ipv4enabled = true;
+
+    size_t tempSize = 0;
+    CAEndpoint_t *tempInfo = NULL;
+
+    EXPECT_EQ(CA_STATUS_OK, CASelectNetwork(CA_ADAPTER_IP));
+    EXPECT_EQ(CA_STATUS_OK, CAGetNetworkInformation(&tempInfo, &tempSize));
+
+    for (size_t index = 0; index < tempSize; index++)
+    {
+        EXPECT_TRUE((tempInfo[index].flags & CA_IPV4) != 0);
+    }
+
+    OICFree(tempInfo);
+    CATerminate();
+}
+
+TEST(CAGetNetworkInformationTest, DISABLED_EnableIPv4AndIPv6)
+{
+    CAInitialize(CA_DEFAULT_ADAPTER);
+    caglobals.ip.ipv6enabled = true;
+    caglobals.ip.ipv4enabled = true;
+
+    size_t tempSize = 0;
+    CAEndpoint_t *tempInfo = NULL;
+
+    EXPECT_EQ(CA_STATUS_OK, CASelectNetwork(CA_ADAPTER_IP));
+    EXPECT_EQ(CA_STATUS_OK, CAGetNetworkInformation(&tempInfo, &tempSize));
+
+    CATransportFlags_t flags = (CATransportFlags_t)(CA_IPV4|CA_IPV6);
+    for (size_t index = 0; index < tempSize; index++)
+    {
+        EXPECT_TRUE((tempInfo[index].flags & flags) != 0 );
+    }
+
+    OICFree(tempInfo);
+    CATerminate();
+}
+
 TEST_F(CATests, GetSelectedNetwork)
 {
     CATransportAdapter_t SelectedNetwork = CA_DEFAULT_ADAPTER;