diff --git a/source/6LoWPAN/Thread/thread_bbr_api.c b/source/6LoWPAN/Thread/thread_bbr_api.c index 515ae1213111..9064b890d296 100644 --- a/source/6LoWPAN/Thread/thread_bbr_api.c +++ b/source/6LoWPAN/Thread/thread_bbr_api.c @@ -100,16 +100,6 @@ typedef struct { #define RFC6106_DNS_SEARCH_LIST_OPTION 31 static NS_LIST_DEFINE(bbr_instance_list, thread_bbr_t, link); -struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) { - ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL); - - if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) { - //Not found - return NULL; - } - return route; -} - static thread_bbr_t *thread_bbr_find_by_interface(int8_t interface_id) { thread_bbr_t *this = NULL; @@ -993,14 +983,14 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, if (!this || this->backbone_interface_id < 0) { return -1; } - ipv6_route_t *route = thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr); + ipv6_route_t *route = ipv6_route_lookup_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, NULL, 0); if (!route){ map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t)); if (!map) { goto error; } // We are using route info field to store BBR MLEID map - route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, NULL, 0, lifetime, 1); + route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, map, 0, lifetime, 0); if (!route) { // Direct route to host allows ND proxying to work ns_dyn_mem_free(map); @@ -1008,14 +998,12 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, } // Route info autofreed route->info_autofree = true; - route->info.info = map; } + map = route->info.info; + memcpy(map->mleid_ptr, mleid_ptr, 8); + map->last_contact_time = protocol_core_monotonic_time; + route->info.info = map; - if(!route->info.info) { - goto error; - } - memcpy(((thread_pbbr_dua_info_t *)route->info.info)->mleid_ptr, mleid_ptr, 8); - ((thread_pbbr_dua_info_t *)route->info.info)->last_contact_time = protocol_core_monotonic_time; // send NA thread_bbr_na_send(this->backbone_interface_id, addr_data_ptr); diff --git a/source/6LoWPAN/Thread/thread_bbr_api_internal.h b/source/6LoWPAN/Thread/thread_bbr_api_internal.h index 1732164ef356..9e4349903311 100644 --- a/source/6LoWPAN/Thread/thread_bbr_api_internal.h +++ b/source/6LoWPAN/Thread/thread_bbr_api_internal.h @@ -117,12 +117,6 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, */ int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16]); -/** - * \brief Find if bbr has dua entry - * - * \param interface_id addr_data_ptr - */ -struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr); #else #define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL) @@ -130,7 +124,6 @@ struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t #define thread_bbr_network_data_update_notify(cur) #define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info) (0) #define thread_bbr_dua_entry_add(interface_id, addr_data_ptr, lifetime, mleid_ptr) (0) -#define thread_bbr_dua_entry_find(interface_id, addr_data_ptr) (NULL) #define thread_bbr_na_send(interface_id, target) (0) #endif //HAVE_THREAD_BORDER_ROUTER diff --git a/source/6LoWPAN/Thread/thread_extension_bbr.c b/source/6LoWPAN/Thread/thread_extension_bbr.c index 5706c0433616..76cbc74494ba 100644 --- a/source/6LoWPAN/Thread/thread_extension_bbr.c +++ b/source/6LoWPAN/Thread/thread_extension_bbr.c @@ -542,7 +542,7 @@ static void thread_pbbr_pro_bb_ntf_process(protocol_interface_info_entry_t *cur, if (!this) { return; } - ipv6_route_t *route = thread_bbr_dua_entry_find(cur->id, addr_data_ptr); + ipv6_route_t *route = ipv6_route_lookup_with_info(addr_data_ptr, 128, this->interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, NULL, 0); if (!route || !route->info.info) { return; } @@ -899,7 +899,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address tr_debug("DUA.req addr:%s ml_eid:%s", trace_array(addr_data_ptr, addr_len), trace_array(ml_eid_ptr, ml_eid_len)); entry_keep_alive = false; - ipv6_route_t *route = thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr); + ipv6_route_t *route = ipv6_route_lookup_with_info(addr_data_ptr, 128, this->interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, NULL, 0); // new device has generated duplicate dua if (route != NULL && route->info.info != NULL && memcmp(((thread_pbbr_dua_info_t *)route->info.info)->mleid_ptr,ml_eid_ptr,8) != 0) { diff --git a/source/ipv6_stack/ipv6_routing_table.c b/source/ipv6_stack/ipv6_routing_table.c index 58c1dff535d0..484a41097b60 100644 --- a/source/ipv6_stack/ipv6_routing_table.c +++ b/source/ipv6_stack/ipv6_routing_table.c @@ -1589,11 +1589,6 @@ ipv6_route_t *ipv6_route_add_metric(const uint8_t *prefix, uint8_t prefix_len, i route->metric = metric; changed_info = UPDATED; } - // if we are updating the info. we need to delete the previous data - if(route->info.info != info && route->info.info && route->info_autofree) { - ns_dyn_mem_free(route->info.info); - } - route->info.info = info; }