Skip to content

Commit 5fa004c

Browse files
address entry removal updated (#2013)
1 parent a8e3e73 commit 5fa004c

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

source/6LoWPAN/Thread/thread_extension.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
9898
(void) source_port;
9999

100100
uint16_t addr_len;
101-
uint8_t *bbr_status;
101+
uint8_t bbr_status;
102102
uint8_t *addr_data_ptr = NULL;
103103

104104
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,28 +112,30 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
112112
return -2;
113113
}
114114

115-
if (1 > thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &bbr_status)) {
116-
return -3;
117-
}
118-
119-
if (*bbr_status == 0) {
120-
// registration successful
115+
if (1 > thread_meshcop_tlv_data_get_uint8(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_STATUS, &bbr_status)) {
121116
return 0;
122117
}
123118

124119
addr_len = thread_meshcop_tlv_find(response_ptr->payload_ptr, response_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
125120

126121
if (addr_len < 16) {
127122
tr_warn("Invalid target eid in DUA.rsp cb message");
128-
return -4;
123+
return 0;
129124
}
130125

131-
// registration unsuccessful
132-
// processing for ourselves - if we have the address re register
133126
if_address_entry_t *addr_entry = addr_get_entry(cur, addr_data_ptr);
134127
if (addr_entry) {
135-
cur->dad_failures++;
136-
thread_extension_dua_address_generate(cur, addr_data_ptr, 64);
128+
// Own processing
129+
if (bbr_status == THREAD_EXTENSION_ST_DUA_SUCCESS) {
130+
addr_entry->preferred_lifetime = 0xffffffff;
131+
} else if (bbr_status == THREAD_EXTENSION_ST_DUA_DUPLICATE) {
132+
cur->dad_failures++;
133+
thread_extension_dua_address_generate(cur, addr_data_ptr, 64);
134+
} else if (bbr_status == THREAD_EXTENSION_ST_DUA_INVALID) {
135+
addr_delete(cur, addr_data_ptr);
136+
} else {
137+
addr_entry->preferred_lifetime = 0;
138+
}
137139
return 0;
138140
}
139141

@@ -142,20 +144,30 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
142144
uint16_t nce_short_addr;
143145
uint8_t destination_address[16] = {0};
144146

147+
if (bbr_status == THREAD_EXTENSION_ST_DUA_SUCCESS) {
148+
// registration successful
149+
return 0;
150+
}
151+
145152
neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, addr_data_ptr);
146153
if (!neighbour_entry) {
147154
return 0;
148155
}
149156

150157
nce_short_addr = common_read_16_bit(neighbour_entry->ll_address + 2);
151158
if (!thread_addr_is_child(cur->thread_info->routerShortAddress, nce_short_addr)) {
159+
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
152160
return 0;
153161
}
154-
thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info);
155162

156-
thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, *bbr_status);
163+
if (bbr_status == THREAD_EXTENSION_ST_DUA_DUPLICATE || bbr_status == THREAD_EXTENSION_ST_DUA_INVALID) {
164+
// remove invalid or duplicate child entry
165+
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
166+
}
167+
168+
thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info);
157169

158-
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
170+
thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, bbr_status);
159171

160172
return 0;
161173
}

source/6LoWPAN/Thread/thread_extension_constants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ typedef struct discovery_additional_info {
152152
*/
153153

154154
#define THREAD_EXTENSION_ST_DUA_SUCCESS 0
155-
#define THREAD_EXTENSION_ST_DUA_INVALID 2
156-
#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3
155+
#define THREAD_EXTENSION_ST_DUA_INVALID 2 //Fatal
156+
#define THREAD_EXTENSION_ST_DUA_DUPLICATE 3 //Fatal
157157
#define THREAD_EXTENSION_ST_DUA_NO_RESOURCES 4
158158
#define THREAD_EXTENSION_ST_DUA_BBR_NOT_PRIMARY 5
159159
#define THREAD_EXTENSION_ST_DUA_GENERAL_FAILURE 6

0 commit comments

Comments
 (0)