Skip to content

Commit cfb2426

Browse files
bbr memory leak during keep alive fixed. (ARMmbed#1839)
1 parent c14343a commit cfb2426

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ typedef struct {
9797
#define RFC6106_DNS_SEARCH_LIST_OPTION 31
9898
static NS_LIST_DEFINE(bbr_instance_list, thread_bbr_t, link);
9999

100+
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
101+
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
102+
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
103+
//Not found
104+
return NULL;
105+
}
106+
return route;
107+
}
100108

101109
static thread_bbr_t *thread_bbr_find_by_interface(int8_t interface_id)
102110
{
@@ -979,25 +987,33 @@ int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
979987
int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, const uint8_t *mleid_ptr)
980988
{
981989
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
990+
thread_pbbr_dua_info_t *map;
982991
if (!this || this->backbone_interface_id < 0) {
983992
return -1;
984993
}
985-
thread_pbbr_dua_info_t *map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
986-
if (!map) {
987-
goto error;
994+
ipv6_route_t *route = thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr);
995+
if (!route){
996+
map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
997+
if (!map) {
998+
goto error;
999+
}
1000+
// We are using route info field to store BBR MLEID map
1001+
route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, map, 0, lifetime, 0);
1002+
if (!route) {
1003+
// Direct route to host allows ND proxying to work
1004+
ns_dyn_mem_free(map);
1005+
goto error;
1006+
}
1007+
// Route info autofreed
1008+
route->info_autofree = true;
9881009
}
1010+
1011+
map = route->info.info;
9891012
memcpy(map->mleid_ptr, mleid_ptr, 8);
9901013
map->last_contact_time = protocol_core_monotonic_time;
1014+
route->info.info = map;
1015+
9911016

992-
// We are using route info field to store BBR MLEID map
993-
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, map, 0, lifetime, 0);
994-
if (!route) {
995-
// Direct route to host allows ND proxying to work
996-
ns_dyn_mem_free(map);
997-
goto error;
998-
}
999-
// Route info autofreed
1000-
route->info_autofree = true;
10011017
// send NA
10021018
thread_bbr_na_send(this->backbone_interface_id, addr_data_ptr);
10031019

@@ -1007,15 +1023,6 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
10071023
return -2;
10081024
}
10091025

1010-
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
1011-
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
1012-
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
1013-
//Not found
1014-
return NULL;
1015-
}
1016-
return route;
1017-
}
1018-
10191026
int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)
10201027
{
10211028
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(handler_interface_id);

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ void thread_bootstrap_network_prefixes_process(protocol_interface_info_entry_t *
28152815
// don't add
28162816
tr_debug("Suppressing onlink %s for proxy", trace_ipv6_prefix(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen));
28172817
} else if (curBorderRouter->P_res1) {
2818-
ipv6_route_add(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen, cur->id, NULL, ROUTE_THREAD, 0xffffffff, 0);
2818+
ipv6_route_add(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen, cur->id, NULL, ROUTE_THREAD_PROXIED_DUA_HOST, 0xffffffff, 0);
28192819
} else {
28202820
//add
28212821
tr_debug("Adding onlink %s", trace_ipv6_prefix(curPrefix->servicesPrefix, curPrefix->servicesPrefixLen));

0 commit comments

Comments
 (0)