Remove iteration to get external route 63/276663/1
authorhyunuk.tak <hyunuk.tak@samsung.com>
Mon, 30 May 2022 06:45:33 +0000 (15:45 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Thu, 23 Jun 2022 02:21:00 +0000 (11:21 +0900)
Change-Id: I592a54f0e54fc7a68beaab76bd75ae939f6f9f50
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
src/thread-br.c

index 7fa9d07..791a13b 100644 (file)
@@ -95,7 +95,6 @@ static int __thread_br_get_external_route_cb(GVariant *val,
        THREAD_VALIDATE_INPUT_PARAMETER(callback);
        THREAD_VALIDATE_INPUT_PARAMETER(instance);
 
-       GVariantIter iter;
        uint8_t *prefix_address = NULL;
        uint8_t prefix_len = 0;
        uint16_t rloc16 = 0;
@@ -106,42 +105,41 @@ static int __thread_br_get_external_route_cb(GVariant *val,
        thread_instance_s *current_instance = instance;
 
        THREAD_DBG("Process callback for get external route");
-       g_variant_iter_init(&iter, val);
 
-       while (g_variant_iter_next(&iter, "((ayy)qybb)",
+       g_variant_get(val, "((ayy)qybb)",
                        &prefix_address, &prefix_len, &rloc16, &preference,
-                       &stable, &next_hop_is_self)) {
-
-               thread_route_info_s *route_info = _create_new_route();
-
-               THREAD_DBG("Got the external route...");
-
-               THREAD_DBG("prefix_address: %02x%02x:%02x%02x:%02x%02x:%02x%02x",
-                       prefix_address[0], prefix_address[1], prefix_address[2],
-                       prefix_address[3], prefix_address[4], prefix_address[5],
-                       prefix_address[6], prefix_address[7]);
-
-               THREAD_DBG("prefix_len: %u", prefix_len);
-               THREAD_DBG("rloc16: %u", rloc16);
-               THREAD_DBG("preference: %u", preference);
-               THREAD_DBG("stable: %s", stable ? "TRUE" : "FALSE");
-               THREAD_DBG("next_hop_is_self: %s", next_hop_is_self ?
-                                                       "TRUE" : "FALSE");
-               memcpy((route_info->prefix).ipv6.fields.m8, prefix_address,
-                                       THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
-               (route_info->prefix).length = prefix_len;
-               route_info->preference = preference;
-               route_info->is_stable = stable;
-               route_info->rloc16 = rloc16;
-               route_info->is_nexthop_this_device = next_hop_is_self;
-               current_instance->route_list = g_slist_append(
-                                               current_instance->route_list,
-                                               route_info);
+                       &stable, &next_hop_is_self);
+
+       thread_route_info_s *route_info = _create_new_route();
+
+       THREAD_DBG("Got the external route...");
+
+       THREAD_DBG("prefix_address: %02x%02x:%02x%02x:%02x%02x:%02x%02x",
+               prefix_address[0], prefix_address[1], prefix_address[2],
+               prefix_address[3], prefix_address[4], prefix_address[5],
+               prefix_address[6], prefix_address[7]);
+
+       THREAD_DBG("prefix_len: %u", prefix_len);
+       THREAD_DBG("rloc16: %u", rloc16);
+       THREAD_DBG("preference: %u", preference);
+       THREAD_DBG("stable: %s", stable ? "TRUE" : "FALSE");
+       THREAD_DBG("next_hop_is_self: %s", next_hop_is_self ?
+                                               "TRUE" : "FALSE");
+       memcpy((route_info->prefix).ipv6.fields.m8, prefix_address,
+                               THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
+       (route_info->prefix).length = prefix_len;
+       route_info->preference = preference;
+       route_info->is_stable = stable;
+       route_info->rloc16 = rloc16;
+       route_info->is_nexthop_this_device = next_hop_is_self;
+       current_instance->route_list = g_slist_append(
+                                       current_instance->route_list,
+                                       route_info);
+
+       if (callback)
+               (callback)(++count, (thread_route_info_h)route_info,
+                                                       user_data);
 
-               if (callback)
-                       (callback)(++count, (thread_route_info_h)route_info,
-                                                               user_data);
-       }
        THREAD_DBG("Exiting __thread_br_get_external_route_cb ...");
 
        FUNC_EXIT;
@@ -278,6 +276,23 @@ int thread_br_get_route_info(thread_route_info_h route,
        return THREAD_ERROR_NONE;
 }
 
+int thread_br_get_ipv6_prefix(thread_route_info_h route,
+       uint8_t *ipv6_prefix)
+{
+       FUNC_ENTRY;
+       THREAD_CHECK_SUPPORTED_FEATURE(THREAD_FEATURE_COMMON);
+       THREAD_CHECK_INIT_STATUS();
+       THREAD_VALIDATE_INPUT_PARAMETER(route);
+       THREAD_VALIDATE_INPUT_PARAMETER(ipv6_prefix);
+
+       thread_route_info_s *route_info = (thread_route_info_s*)route;
+       memcpy(ipv6_prefix, (route_info->prefix).ipv6.fields.m8,
+                       THREAD_IPV6_PREFIX_SIZE*sizeof(uint8_t));
+
+       FUNC_EXIT;
+       return THREAD_ERROR_NONE;
+}
+
 int thread_br_add_external_route(thread_instance_h instance,
        const uint8_t *ipv6_prefix, uint8_t ipv6_prefix_len,
        uint16_t rloc16, int8_t preference,