Skip to content

Commit a20a0ba

Browse files
author
Arto Kinnunen
authored
Update Thread MLE neighbor list cleanup (#1637)
-Device needs to clean MLE neighbors (routers and their children) when moving to new partition. Own children can be moved to new partition. -Device is not allowed to update MLE cache based on advertisements from other partition. MLE entries belonging to other partition can be removed from MLE table. -Update traces
1 parent 32cfb6b commit a20a0ba

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,14 +1159,14 @@ void thread_bootstrap_ready(protocol_interface_info_entry_t *cur)
11591159
mac_data_poll_protocol_poll_mode_decrement(cur);
11601160
}
11611161

1162-
void thread_clean_all_routers_from_neighbor_list(int8_t interface_id)
1163-
{
1164-
mle_neigh_table_list_t *neig_list = mle_class_active_list_get(interface_id);
1165-
/* Init Double linked Routing Table */
1166-
ns_list_foreach_safe(mle_neigh_table_entry_t, cur, neig_list) {
1167-
if (thread_is_router_addr(cur->short_adr)) {
1168-
tr_debug("Free Router %x", cur->short_adr);
1169-
mle_class_remove_entry(interface_id, cur);
1162+
void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur)
1163+
{
1164+
mle_neigh_table_list_t *neig_list = mle_class_active_list_get(cur->id);
1165+
1166+
ns_list_foreach_safe(mle_neigh_table_entry_t, cur_entry, neig_list) {
1167+
if (!thread_addr_is_equal_or_child(cur->thread_info->routerShortAddress, cur_entry->short_adr)) {
1168+
tr_debug("Free ID %x", cur_entry->short_adr);
1169+
mle_class_remove_entry(cur->id, cur_entry);
11701170
}
11711171
}
11721172
}

source/6LoWPAN/Thread/thread_bootstrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void thread_general_mle_receive_cb(int8_t interface_id, mle_message_t *mle_msg,
106106
int thread_bootstrap_reset_child_info(protocol_interface_info_entry_t *cur, struct mle_neigh_table_entry_t *child);
107107
void thread_bootstrap_ready(struct protocol_interface_info_entry *cur);
108108
int thread_bootstrap_reset(struct protocol_interface_info_entry *cur);
109-
void thread_clean_all_routers_from_neighbor_list(int8_t interface_id);
109+
void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur);
110110
bool thread_bootstrap_request_network_data(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, uint16_t short_address);
111111
bool thread_check_is_this_my_parent(struct protocol_interface_info_entry *cur, struct mle_neigh_table_entry_t *entry_temp);
112112
void thread_clean_old_16_bit_address_based_addresses(struct protocol_interface_info_entry *cur);

source/6LoWPAN/Thread/thread_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ int8_t thread_bootstrap_down(protocol_interface_info_entry_t *cur)
233233
tr_debug("SET thread Idle");
234234
//stop polling
235235
mac_data_poll_disable(cur);
236-
//Clean routers from mle table
237-
thread_clean_all_routers_from_neighbor_list(cur->id);
236+
//Clean mle table
237+
thread_neighbor_list_clean(cur);
238238
// store frame counters
239239
if (cur->thread_info) {
240240
thread_nvm_fast_data_t fast_data;
@@ -1848,8 +1848,8 @@ void thread_reset_neighbour_info(protocol_interface_info_entry_t *cur, mle_neigh
18481848
thread_parent_info_t *thread_endnode_parent = thread_info(cur)->thread_endnode_parent;
18491849

18501850
if (!thread_i_am_router(cur) && thread_endnode_parent && thread_endnode_parent->shortAddress == neighbour->short_adr) {
1851-
tr_warn("End device lost Parent!\n");
18521851
if(cur->nwk_bootstrap_state != ER_CHILD_ID_REQ) {
1852+
tr_warn("End device lost parent, reset!\n");
18531853
thread_bootstrap_connection_error(cur->id, CON_PARENT_CONNECT_DOWN, NULL);
18541854
}
18551855
}

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void thread_child_synch_receive_cb(int8_t interface_id, mle_message_t *ml
393393
messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
394394

395395
if (messageId == 0) {
396-
tr_debug("Not for me");
396+
tr_debug("No matching challenge");
397397
return;
398398
}
399399

@@ -471,7 +471,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
471471
return;
472472
}
473473

474-
tr_debug("Thread MLE Parent request response Handler");
474+
tr_debug("MLE Parent response handler");
475475
//State machine What packet should accept in this case
476476
switch (mle_msg->message_type) {
477477
case MLE_COMMAND_PARENT_RESPONSE: {
@@ -496,7 +496,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
496496
messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
497497

498498
if (messageId == 0) {
499-
tr_debug("Not for me");
499+
tr_debug("No matching challenge");
500500
return;
501501
}
502502

@@ -747,7 +747,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
747747
return;
748748
}
749749

750-
tr_debug("Thread MLE Child request response Handler");
750+
tr_debug("Thread MLE Child ID response handler");
751751

752752
switch (mle_msg->message_type) {
753753

@@ -762,7 +762,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
762762
thread_scanned_parent_t *scan_result = thread_info(cur)->thread_attach_scanned_parent;
763763
bool new_entry_created;
764764

765-
tr_info("Received Child ID Response");
765+
tr_info("Recv Child ID Response");
766766

767767
// Validate that response is coming from the scanned parent candidate
768768
memcpy(src_mac64, (mle_msg->packet_src_address + 8), 8);
@@ -779,7 +779,7 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
779779

780780
cur->thread_info->localServerDataBase.release_old_address = true;
781781

782-
thread_clean_all_routers_from_neighbor_list(cur->id);
782+
thread_neighbor_list_clean(cur);
783783
thread_leader_service_stop(interface_id);
784784
thread_leader_service_leader_data_free(cur->thread_info);
785785
thread_merge_prepare(cur);

source/6LoWPAN/Thread/thread_leader_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ static int thread_leader_service_leader_init(protocol_interface_info_entry_t *cu
12701270
thread_nd_service_delete(cur->id);
12711271
mpl_clear_realm_scope_seeds(cur);
12721272
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
1273-
thread_clean_all_routers_from_neighbor_list(cur->id);
1273+
thread_neighbor_list_clean(cur);
12741274
cur->mesh_callbacks = NULL;
12751275
cur->lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE;
12761276

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
351351
thread_management_key_synch_req(cur->id, common_read_32_bit(security_headers->Keysource));
352352
}
353353

354+
if (entry_temp && !thread_instance_id_matches(cur, &leaderData)) {
355+
// Remove MLE entries that are located in other partition
356+
mle_class_remove_entry(cur->id, entry_temp);
357+
entry_temp = NULL;
358+
}
359+
354360
// Check parent status
355361
if (!thread_attach_active_router(cur)) {
356362
//processing for non routers
@@ -428,7 +434,7 @@ static void thread_parse_accept(protocol_interface_info_entry_t *cur, mle_messag
428434
messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
429435

430436
if (messageId == 0) {
431-
tr_debug("Not for me");
437+
tr_debug("No matching challenge");
432438
return;
433439
}
434440

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static void thread_router_synch_receive_cb(int8_t interface_id, mle_message_t *m
340340
uint16_t messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
341341

342342
if (messageId == 0) {
343-
tr_debug("Not for me");
343+
tr_debug("No matching challenge");
344344
return;
345345
}
346346
/*Link accept command has an optional MLE Frame counter TLV, if this is not present use link layer frame counter TLV
@@ -894,7 +894,7 @@ static int thread_attach_parent_response_build(protocol_interface_info_entry_t *
894894
if (bufId == 0) {
895895
return -1;
896896
}
897-
tr_debug("MLE ATTACHED 2. Packet");
897+
tr_debug("Build MLE Parent response");
898898

899899
uint32_t keySequence;
900900
uint8_t *ptr = mle_service_get_data_pointer(bufId);
@@ -1357,7 +1357,6 @@ void thread_router_bootstrap_child_id_handler(protocol_interface_info_entry_t *c
13571357
thread_nd_address_registration(cur, tempIPv6Address, entry_temp->short_adr, cur->mac_parameters->pan_id, entry_temp->mac64);
13581358
}
13591359

1360-
tr_debug("Response Child Id Request");
13611360
mle_attach_child_id_response_build(cur,ll64,req, entry_temp);
13621361

13631362
free_request:
@@ -1591,7 +1590,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
15911590
uint16_t messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
15921591

15931592
if (messageId == 0) {
1594-
tr_debug("Not for me");
1593+
tr_debug("No matching challenge");
15951594
return;
15961595
}
15971596

@@ -1606,6 +1605,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
16061605
mle_msg->packet_src_address[8] ^= 2;
16071606

16081607
if (!id_req) {
1608+
tr_debug("No room for child id req");
16091609
return;
16101610
}
16111611

@@ -1627,6 +1627,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
16271627
(!mle_tlv_read_32_bit_tlv(MLE_TYPE_LL_FRAME_COUNTER, mle_msg->data_ptr, mle_msg->data_length, &id_req->frameCounter)) ||
16281628
(!mle_tlv_read_tlv(MLE_TYPE_TLV_REQUEST, mle_msg->data_ptr, mle_msg->data_length, &tlvRequest))) {
16291629
thread_child_id_request_entry_remove(cur, id_req);
1630+
tr_debug("Illegal child id req");
16301631
return;
16311632
}
16321633
//If MLE MLE_TYPE_MLE_FRAME_COUNTER TLV is present then use it for validating further messages else use link layer frame counter
@@ -1827,7 +1828,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
18271828
uint16_t messageId = mle_tlv_validate_response(mle_msg->data_ptr, mle_msg->data_length);
18281829

18291830
if (messageId == 0) {
1830-
tr_debug("Not for me");
1831+
tr_debug("No matching challenge");
18311832
return;
18321833
}
18331834

test/nanostack/unittest/stub/thread_bootstrap_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int8_t thread_mle_class_init(int8_t interface_id)
257257
return 0;
258258
}
259259

260-
void thread_clean_all_routers_from_neighbor_list(int8_t interface_id)
260+
void thread_neighbor_list_clean(protocol_interface_info_entry_t *cur)
261261
{
262262

263263
}

0 commit comments

Comments
 (0)