From 77f4f73034b578e7f44c9b8a167cca9f2c62c3b0 Mon Sep 17 00:00:00 2001 From: "hyunuk.tak" Date: Mon, 30 May 2022 15:45:33 +0900 Subject: [PATCH] Remove iteration to get external route Change-Id: I592a54f0e54fc7a68beaab76bd75ae939f6f9f50 Signed-off-by: hyunuk.tak --- src/thread-br.c | 83 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/src/thread-br.c b/src/thread-br.c index 7fa9d07..791a13b 100644 --- a/src/thread-br.c +++ b/src/thread-br.c @@ -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, -- 2.7.4