Skip to content

Commit 1cbced9

Browse files
author
Arto Kinnunen
authored
Merge pull request ARMmbed#1520 from ARMmbed/IOTTHD-2105_2
Clear network data from lost children
2 parents ffd8517 + 3d07365 commit 1cbced9

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,19 @@ static void thread_neighbor_remove(int8_t interface_id, mle_neigh_table_entry_t
170170
else{
171171
tr_debug("Delete REED Neighbor");
172172
if (thread_is_router_addr(cur->short_adr)) {
173-
tr_debug("Router Free");
174-
thread_routing_remove_link(cur_interface, cur->short_adr);
173+
tr_debug("Router Free");
174+
thread_routing_remove_link(cur_interface, cur->short_adr);
175175
}
176176
}
177177
}
178178
else if (thread_info(cur_interface)->thread_attached_state == THREAD_STATE_CONNECTED_ROUTER)
179179
{
180-
tr_debug("Delete Router Neighbor");
180+
tr_debug("Delete Router Neighbor %x", cur->short_adr);
181181
if (thread_is_router_addr(cur->short_adr)) {
182-
tr_debug("Router Free");
182+
tr_debug("Router free");
183183
thread_routing_remove_link(cur_interface, cur->short_adr);
184184
} else if (thread_addr_is_child(mac_helper_mac16_address_get(cur_interface), cur->short_adr)) {
185-
tr_debug("Child Free");
185+
tr_debug("Child free");
186186
/* 16-bit neighbour cache entries are mesh addresses, so remain potentially valid even if an
187187
* MLE link fails. This is the only exception - if it was the link from us as a router to a
188188
* child. That means that device must be off the mesh (at that 16-bit address, at least).
@@ -1163,6 +1163,8 @@ void thread_tasklet(arm_event_s *event)
11631163
thread_border_router_publish(cur->id);
11641164
}
11651165
thread_router_bootstrap_address_change_notify_send(cur);
1166+
// Validate network data after a short period
1167+
thread_border_router_resubmit_timer_set(cur->id, 5);
11661168
break;
11671169
case THREAD_ATTACH_ROUTER_ID_GET_FAIL:
11681170
tr_debug_extra("Thread SM THREAD_ATTACH_ROUTER_ID_GET_FAIL");

source/6LoWPAN/Thread/thread_border_router_api.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,61 @@ static bool thread_border_router_local_network_data_prefix_match(thread_network_
297297
return true;
298298
}
299299

300+
static void thread_border_router_child_network_data_clean(uint8_t interface_id, uint16_t child_id)
301+
{
302+
uint8_t addr16_buf[2];
303+
304+
common_write_16_bit(child_id, addr16_buf);
305+
if (mle_class_get_by_link_address(interface_id, addr16_buf, ADDR_802_15_4_SHORT)) {
306+
/* Child is available in mle, do nothing */
307+
return;
308+
}
309+
310+
// Child is not our child => network data contains data from lost children, remove it
311+
tr_debug("Remove nwk data from lost child: %04x", child_id);
312+
thread_management_client_network_data_unregister(interface_id, child_id);
313+
}
314+
315+
static void thread_border_router_lost_children_nwk_data_validate(protocol_interface_info_entry_t *cur, uint16_t router_short_addr)
316+
{
317+
318+
tr_debug("thread_border_router_lost_children_nwk_data_validate() %x", router_short_addr);
319+
if (!thread_is_router_addr(router_short_addr)) {
320+
// not validating children nwk data
321+
return;
322+
}
323+
324+
thread_network_data_cache_entry_t *network_data = &cur->thread_info->networkDataStorage;
325+
326+
ns_list_foreach(thread_network_data_prefix_cache_entry_t, curLP, &network_data->localPrefixList) {
327+
/* Go throgh all routes */
328+
ns_list_foreach(thread_network_server_data_entry_t, curRoute, &curLP->routeList) {
329+
if (thread_addr_is_child(router_short_addr, curRoute->routerID)) {
330+
// Router children found
331+
thread_border_router_child_network_data_clean(cur->id, curRoute->routerID);
332+
}
333+
}
334+
335+
/* Go through all BR's */
336+
ns_list_foreach(thread_network_server_data_entry_t, curBR, &curLP->borderRouterList) {
337+
if (thread_addr_is_child(router_short_addr, curBR->routerID)) {
338+
// Router children found
339+
thread_border_router_child_network_data_clean(cur->id, curBR->routerID);
340+
}
341+
}
342+
}
343+
344+
/* Go throgh all services */
345+
ns_list_foreach(thread_network_data_service_cache_entry_t, service, &network_data->service_list) {
346+
ns_list_foreach(thread_network_data_service_server_entry_t, server, &service->server_list) {
347+
if (thread_addr_is_child(router_short_addr, server->router_id)) {
348+
// Router children found
349+
thread_border_router_child_network_data_clean(cur->id, server->router_id);
350+
}
351+
}
352+
}
353+
}
354+
300355
static bool thread_border_router_local_network_data_service_match(thread_network_local_data_cache_entry_t *local_data, thread_network_data_service_cache_entry_t *service, uint16_t router_id)
301356
{
302357
bool instance_found = false;
@@ -372,6 +427,8 @@ static bool thread_border_router_local_srv_data_in_network_data_check(protocol_i
372427
}
373428
}
374429

430+
thread_border_router_lost_children_nwk_data_validate(cur, router_id);
431+
375432
return true;
376433
}
377434

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ static bool thread_child_id_request(protocol_interface_info_entry_t *cur, mle_ne
11941194
}
11951195

11961196
//allocate child address if current is router, 0xffff or not our child
1197-
if (!thread_addr_is_equal_or_child(mac_helper_mac16_address_get(cur), entry_temp->short_adr)) {
1197+
if (!thread_addr_is_child(mac_helper_mac16_address_get(cur), entry_temp->short_adr)) {
11981198
entry_temp->short_adr = thread_router_bootstrap_child_address_generate(cur);
11991199
}
12001200

source/6LoWPAN/Thread/thread_routing.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ THREAD_ROUTING_FN bool thread_is_router_addr(uint16_t addr)
163163
/* Return true if b is a child of a */
164164
THREAD_ROUTING_FN bool thread_addr_is_child(uint16_t a, uint16_t b)
165165
{
166+
if (thread_is_router_addr(b)) {
167+
return false;
168+
}
166169
return thread_router_addr_from_addr(b) == a;
167170
}
168171

0 commit comments

Comments
 (0)