From 5fa004cdf46885dacd0e98cbbeac2222cf963545 Mon Sep 17 00:00:00 2001 From: Deepak Venugopal Date: Fri, 15 Mar 2019 11:34:04 +0200 Subject: [PATCH] address entry removal updated (#2013) --- source/6LoWPAN/Thread/thread_extension.c | 42 ++++++++++++------- .../Thread/thread_extension_constants.h | 4 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/source/6LoWPAN/Thread/thread_extension.c b/source/6LoWPAN/Thread/thread_extension.c index c2afd9937f1..3318b49190b 100644 --- a/source/6LoWPAN/Thread/thread_extension.c +++ b/source/6LoWPAN/Thread/thread_extension.c @@ -98,7 +98,7 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc (void) source_port; uint16_t addr_len; - uint8_t *bbr_status; + uint8_t bbr_status; uint8_t *addr_data_ptr = NULL; protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(thread_management_client_get_interface_id_by_service_id(service_id)); @@ -112,12 +112,7 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc return -2; } - if (1 > thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &bbr_status)) { - return -3; - } - - if (*bbr_status == 0) { - // registration successful + if (1 > thread_meshcop_tlv_data_get_uint8(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &bbr_status)) { return 0; } @@ -125,15 +120,22 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc if (addr_len < 16) { tr_warn("Invalid target eid in DUA.rsp cb message"); - return -4; + return 0; } - // registration unsuccessful - // processing for ourselves - if we have the address re register if_address_entry_t *addr_entry = addr_get_entry(cur, addr_data_ptr); if (addr_entry) { - cur->dad_failures++; - thread_extension_dua_address_generate(cur, addr_data_ptr, 64); + // Own processing + if (bbr_status == THREAD_EXTENSION_ST_DUA_SUCCESS) { + addr_entry->preferred_lifetime = 0xffffffff; + } else if (bbr_status == THREAD_EXTENSION_ST_DUA_DUPLICATE) { + cur->dad_failures++; + thread_extension_dua_address_generate(cur, addr_data_ptr, 64); + } else if (bbr_status == THREAD_EXTENSION_ST_DUA_INVALID) { + addr_delete(cur, addr_data_ptr); + } else { + addr_entry->preferred_lifetime = 0; + } return 0; } @@ -142,6 +144,11 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc uint16_t nce_short_addr; uint8_t destination_address[16] = {0}; + if (bbr_status == THREAD_EXTENSION_ST_DUA_SUCCESS) { + // registration successful + return 0; + } + neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, addr_data_ptr); if (!neighbour_entry) { return 0; @@ -149,13 +156,18 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc nce_short_addr = common_read_16_bit(neighbour_entry->ll_address + 2); if (!thread_addr_is_child(cur->thread_info->routerShortAddress, nce_short_addr)) { + ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry); return 0; } - thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info); - thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, *bbr_status); + if (bbr_status == THREAD_EXTENSION_ST_DUA_DUPLICATE || bbr_status == THREAD_EXTENSION_ST_DUA_INVALID) { + // remove invalid or duplicate child entry + ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry); + } + + thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info); - ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry); + thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, bbr_status); return 0; } diff --git a/source/6LoWPAN/Thread/thread_extension_constants.h b/source/6LoWPAN/Thread/thread_extension_constants.h index b2466037b82..ebb4382822a 100644 --- a/source/6LoWPAN/Thread/thread_extension_constants.h +++ b/source/6LoWPAN/Thread/thread_extension_constants.h @@ -152,8 +152,8 @@ typedef struct discovery_additional_info { */ #define THREAD_EXTENSION_ST_DUA_SUCCESS 0 -#define THREAD_EXTENSION_ST_DUA_INVALID 2 -#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3 +#define THREAD_EXTENSION_ST_DUA_INVALID 2 //Fatal +#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3 //Fatal #define THREAD_EXTENSION_ST_DUA_NO_RESOURCES 4 #define THREAD_EXTENSION_ST_DUA_BBR_NOT_PRIMARY 5 #define THREAD_EXTENSION_ST_DUA_GENERAL_FAILURE 6