Skip to content

Commit 4b28192

Browse files
author
Mika Tervonen
committed
Added support for ARO registration failure
Added test API to set max child count Added blacklist for neighbors if ARO registration fails Added check for new neighbor creation Added Wisun processing for NA ARO messages
1 parent 9d251fa commit 4b28192

File tree

10 files changed

+150
-10
lines changed

10 files changed

+150
-10
lines changed

nanostack/net_ws_test.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern "C" {
4040
#include "ns_types.h"
4141

4242
/**
43-
* \brief Set extension name.
43+
* \brief Set Pan size.
4444
*
4545
* Pan size is reported to advertisement. Using this function
4646
* actual value can be overridden.
@@ -54,6 +54,24 @@ extern "C" {
5454
* \return <0 Failure
5555
*/
5656
int ws_test_pan_size_set(int8_t interface_id, uint16_t pan_size);
57+
58+
/**
59+
* \brief Set maximum child count.
60+
*
61+
* Maximum amount of children allowed for this device
62+
*
63+
* Values above MAC neighbor table - RPL parents - temporary entries will cause undefined behaviour
64+
*
65+
* Set child count to 0xffff to stop override
66+
*
67+
* \param interface_id Network Interface
68+
* \param child_count Pan size reported in advertisements
69+
*
70+
* \return 0 OK
71+
* \return <0 Failure
72+
*/
73+
int ws_test_max_child_count_set(int8_t interface_id, uint16_t child_count);
74+
5775
#ifdef __cplusplus
5876
}
5977
#endif

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "Service_Libs/etx/etx.h"
5858
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
5959
#include "Service_Libs/nd_proxy/nd_proxy.h"
60+
#include "Service_Libs/blacklist/blacklist.h"
6061
#include "platform/topo_trace.h"
6162
#include "libDHCPv6/libDHCPv6.h"
6263
#include "DHCPv6_client/dhcpv6_client_api.h"
@@ -149,6 +150,8 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
149150
break;
150151
}
151152
}
153+
} else {
154+
tr_debug("Address notification addr: %s reason: %d", trace_ipv6(addr->address), reason);
152155
}
153156
}
154157

@@ -636,6 +639,8 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
636639
cur->ipv6_neighbour_cache.use_eui64_as_slla_in_aro = true;
637640
/* Omit sending of NA if ARO SUCCESS */
638641
cur->ipv6_neighbour_cache.omit_aro_success = true;
642+
// do not process AROs from NA. This is overriden by Wi-SUN specific failure handling
643+
cur->ipv6_neighbour_cache.recv_na_aro = false;
639644
/* Disable NUD Probes */
640645
cur->ipv6_neighbour_cache.send_nud_probes = false;
641646
cur->ipv6_neighbour_cache.probe_avoided_routers = true;
@@ -646,6 +651,14 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
646651

647652
ws_nud_table_reset(cur);
648653

654+
blacklist_params_set(
655+
WS_BLACKLIST_ENTRY_LIFETIME,
656+
WS_BLACKLIST_TIMER_MAX_TIMEOUT,
657+
WS_BLACKLIST_TIMER_TIMEOUT,
658+
WS_BLACKLIST_ENTRY_MAX_NBR,
659+
WS_BLACKLIST_PURGE_NBR,
660+
WS_BLACKLIST_PURGE_TIMER_TIMEOUT);
661+
649662
ws_bootstrap_event_discovery_start(cur);
650663

651664
return 0;
@@ -670,6 +683,7 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur)
670683
ws_eapol_relay_delete(cur);
671684
ws_eapol_auth_relay_delete(cur);
672685
ws_pae_controller_stop(cur);
686+
blacklist_clear();
673687

674688
return nwk_6lowpan_down(cur);
675689
}
@@ -1235,6 +1249,17 @@ static bool ws_bootstrap_neighbor_info_request(struct protocol_interface_info_en
12351249
if (!request_new) {
12361250
return false;
12371251
}
1252+
uint8_t ll_target[16];
1253+
memcpy(ll_target, ADDR_LINK_LOCAL_PREFIX, 8);
1254+
memcpy(ll_target + 8, mac_64, 8);
1255+
ll_target[8] ^= 2;
1256+
1257+
1258+
if (blacklist_reject(ll_target)) {
1259+
// Rejected by blacklist
1260+
return false;
1261+
}
1262+
12381263
ws_bootstrap_neighbor_table_clean(interface);
12391264

12401265
neighbor_buffer->neighbor = ws_bootstrap_mac_neighbor_add(interface, mac_64);
@@ -1357,6 +1382,10 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
13571382
if (!etx_storage_list_allocate(cur->id, buffer.device_decription_table_size)) {
13581383
return -1;
13591384
}
1385+
if (blacklist_init() != 0) {
1386+
tr_err("MLE blacklist init failed.");
1387+
return -1;
1388+
}
13601389

13611390
switch (bootstrap_mode) {
13621391
// case NET_6LOWPAN_SLEEPY_HOST:
@@ -1494,6 +1523,23 @@ int ws_bootstrap_restart(int8_t interface_id)
14941523
return 0;
14951524
}
14961525

1526+
int ws_bootstrap_neighbor_remove(protocol_interface_info_entry_t *cur, const uint8_t *ll_address)
1527+
{
1528+
tr_warn("ARO registration Failure %s", trace_ipv6(ll_address));
1529+
1530+
blacklist_update(ll_address, false);
1531+
1532+
mac_neighbor_table_entry_t *mac_neighbor = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), ll_address, false, NULL);
1533+
1534+
if (mac_neighbor) {
1535+
ws_bootstrap_neighbor_delete(cur, mac_neighbor->index);
1536+
// TODO Add to blacklist
1537+
}
1538+
return 0;
1539+
}
1540+
1541+
1542+
14971543
static void ws_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, bool coordinator)
14981544
{
14991545
mlme_start_t start_req;

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur);
3737

3838
int ws_bootstrap_restart(int8_t interface_id);
3939

40+
int ws_bootstrap_neighbor_remove(protocol_interface_info_entry_t *cur, const uint8_t *ll_address);
41+
4042
/*State machine transactions*/
4143
void ws_bootstrap_event_discovery_start(protocol_interface_info_entry_t *cur);
4244

@@ -71,6 +73,7 @@ void ws_dhcp_client_address_delete(protocol_interface_info_entry_t *cur, uint8_t
7173
#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
7274
#define ws_bootstrap_state_machine(cur)
7375
#define ws_bootstrap_restart(cur)
76+
#define ws_bootstrap_neighbor_remove(cur, ll_address)
7477
#define ws_primary_parent_update(interface, neighbor)
7578
#define ws_secondary_parent_update(interface)
7679

source/6LoWPAN/ws/ws_common.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "6LoWPAN/ws/ws_bootstrap.h"
3030
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
3131
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
32+
#include "Service_Libs/blacklist/blacklist.h"
3233
#include "ws_management_api.h"
3334
#include "mac_api.h"
3435

@@ -62,7 +63,7 @@ static const trickle_params_t trickle_params_pan_discovery_small = {
6263
.TimerExpirations = TRICKLE_EXPIRATIONS_INFINITE
6364
};
6465

65-
66+
uint16_t test_max_child_count_override = 0xffff;
6667

6768

6869
int8_t ws_generate_channel_list(uint32_t *channel_mask, uint16_t number_of_channels, uint8_t regulatory_domain)
@@ -244,6 +245,7 @@ void ws_common_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seco
244245
{
245246
ws_bbr_seconds_timer(cur, seconds);
246247
ws_bootstrap_seconds_timer(cur, seconds);
248+
blacklist_ttl_update(seconds);
247249
}
248250

249251
void ws_common_fast_timer(protocol_interface_info_entry_t *cur, uint16_t ticks)
@@ -262,20 +264,33 @@ void ws_common_neighbor_update(protocol_interface_info_entry_t *cur, const uint8
262264
}
263265
}
264266

267+
void ws_common_aro_failure(protocol_interface_info_entry_t *cur, const uint8_t *ll_address)
268+
{
269+
//Neighbor connectected update
270+
ws_bootstrap_neighbor_remove(cur, ll_address);
271+
}
272+
265273
bool ws_common_allow_child_registration(protocol_interface_info_entry_t *interface)
266274
{
267275
uint8_t child_count = 0;
276+
uint8_t max_child_count = mac_neighbor_info(interface)->list_total_size - WS_NON_CHILD_NEIGHBOUR_COUNT;
277+
278+
// Test API to limit child count
279+
if (test_max_child_count_override != 0xffff) {
280+
max_child_count = test_max_child_count_override;
281+
}
282+
268283
ns_list_foreach_safe(mac_neighbor_table_entry_t, cur, &mac_neighbor_info(interface)->neighbour_list) {
269284

270285
if (ipv6_neighbour_has_registered_by_eui64(&interface->ipv6_neighbour_cache, cur->mac64)) {
271286
child_count++;
272-
if (child_count > (mac_neighbor_info(interface)->list_total_size - WS_NON_CHILD_NEIGHBOUR_COUNT)) {
273-
tr_warn("Child registration not allowed %d/%d, max:%d", child_count, (mac_neighbor_info(interface)->list_total_size - WS_NON_CHILD_NEIGHBOUR_COUNT), mac_neighbor_info(interface)->list_total_size);
274-
return false;
275-
}
276287
}
277288
}
278-
tr_info("Child registration allowed %d/%d, max:%d", child_count, (mac_neighbor_info(interface)->list_total_size - WS_NON_CHILD_NEIGHBOUR_COUNT), mac_neighbor_info(interface)->list_total_size);
289+
if (child_count >= max_child_count) {
290+
tr_warn("Child registration not allowed %d/%d, max:%d", child_count, max_child_count, mac_neighbor_info(interface)->list_total_size);
291+
return false;
292+
}
293+
tr_info("Child registration allowed %d/%d, max:%d", child_count, max_child_count, mac_neighbor_info(interface)->list_total_size);
279294
return true;
280295
}
281296

source/6LoWPAN/ws/ws_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include "6LoWPAN/ws/ws_neighbor_class.h"
2929
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
3030

31+
32+
extern uint16_t test_max_child_count_override;
33+
3134
struct ws_pan_information_s;
3235
struct ws_neighbor_class_s;
3336

@@ -110,13 +113,16 @@ void ws_common_fast_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);
110113

111114
void ws_common_neighbor_update(protocol_interface_info_entry_t *cur, const uint8_t *ll_address);
112115

116+
void ws_common_aro_failure(protocol_interface_info_entry_t *cur, const uint8_t *ll_address);
117+
113118
bool ws_common_allow_child_registration(protocol_interface_info_entry_t *cur);
114119

115120
#define ws_info(cur) ((cur)->ws_info)
116121
#else
117122
#define ws_info(cur) ((ws_info_t *) NULL)
118123
#define ws_common_seconds_timer(cur, seconds)
119124
#define ws_common_neighbor_update(cur, ll_address) ((void) 0)
125+
#define ws_common_aro_failure(cur, ll_address)
120126
#define ws_common_fast_timer(cur, ticks) ((void) 0)
121127
#define ws_common_allow_child_registration(cur) (false)
122128

source/6LoWPAN/ws/ws_config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,15 @@ extern int8_t DEVICE_MIN_SENS;
110110
#define WS_TEMPORARY_NEIGHBOUR_ENTRIES 7
111111
#define WS_NON_CHILD_NEIGHBOUR_COUNT (WS_RPL_CANDIDATE_PARENT_COUNT + WS_TEMPORARY_NEIGHBOUR_ENTRIES)
112112

113+
/*
114+
* Neighbour blacklist timers
115+
*/
116+
#define WS_BLACKLIST_ENTRY_LIFETIME 60*30 // initial value for reject
117+
#define WS_BLACKLIST_TIMER_MAX_TIMEOUT 60*60 // Can increase to this
118+
#define WS_BLACKLIST_TIMER_TIMEOUT 60*30 // Blacklist is valid this time after first accept
119+
#define WS_BLACKLIST_ENTRY_MAX_NBR 10
120+
#define WS_BLACKLIST_PURGE_NBR 3
121+
#define WS_BLACKLIST_PURGE_TIMER_TIMEOUT 60
122+
123+
113124
#endif /* WS_CONFIG_H_ */

source/6LoWPAN/ws/ws_test_api.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <net_ws_test.h>
2424
#include "NWK_INTERFACE/Include/protocol.h"
2525
#include "6LoWPAN/ws/ws_config.h"
26+
#include "6LoWPAN/ws/ws_common.h"
2627
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
2728
#include "randLIB.h"
2829

@@ -41,4 +42,12 @@ int ws_test_pan_size_set(int8_t interface_id, uint16_t pan_size)
4142
return 0;
4243
}
4344

45+
int ws_test_max_child_count_set(int8_t interface_id, uint16_t child_count)
46+
{
47+
48+
(void) interface_id;
49+
test_max_child_count_override = child_count;
50+
return 0;
51+
}
52+
4453
#endif // HAVE_WS

source/Common_Protocols/icmpv6.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,25 @@ static buffer_t *icmpv6_echo_request_handler(buffer_t *buf)
340340
}
341341

342342
#ifdef HAVE_IPV6_ND
343+
344+
static void icmpv6_na_wisun_aro_handler(protocol_interface_info_entry_t *cur_interface, const uint8_t *dptr, const uint8_t *src_addr)
345+
{
346+
dptr += 2;
347+
uint16_t life_time;
348+
uint8_t nd_status = *dptr;
349+
dptr += 4;
350+
life_time = common_read_16_bit(dptr);
351+
dptr += 2;
352+
if (memcmp(dptr, cur_interface->mac, 8) != 0) {
353+
return;
354+
}
355+
356+
(void)life_time;
357+
if (nd_status != ARO_SUCCESS) {
358+
ws_common_aro_failure(cur_interface, src_addr);
359+
}
360+
}
361+
343362
static void icmpv6_na_aro_handler(protocol_interface_info_entry_t *cur_interface, const uint8_t *dptr, const uint8_t *dst_addr)
344363
{
345364
(void)dst_addr;
@@ -985,11 +1004,14 @@ static buffer_t *icmpv6_na_handler(buffer_t *buf)
9851004
goto drop;
9861005
}
9871006

988-
if (cur->ipv6_neighbour_cache.recv_na_aro) {
989-
const uint8_t *aro = icmpv6_find_option_in_buffer(buf, 20, ICMPV6_OPT_ADDR_REGISTRATION, 2);
990-
if (aro) {
1007+
const uint8_t *aro = icmpv6_find_option_in_buffer(buf, 20, ICMPV6_OPT_ADDR_REGISTRATION, 2);
1008+
if (aro) {
1009+
if (cur->ipv6_neighbour_cache.recv_na_aro) {
9911010
icmpv6_na_aro_handler(cur, aro, buf->dst_sa.address);
9921011
}
1012+
if (ws_info(cur)) {
1013+
icmpv6_na_wisun_aro_handler(cur, aro, buf->src_sa.address);
1014+
}
9931015
}
9941016

9951017
/* No need to create a neighbour cache entry if one doesn't already exist */

test/nanostack/unittest/stub/ws_bootstrap_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ int ws_bootstrap_restart(int8_t interface_id)
4040
return 0;
4141
}
4242

43+
int ws_bootstrap_neighbor_remove(protocol_interface_info_entry_t *cur, const uint8_t *ll_address)
44+
{
45+
return 0;
46+
}
47+
4348
void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur)
4449
{
4550
(void) cur;

test/nanostack/unittest/stub/ws_common_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ bool ws_common_allow_child_registration(protocol_interface_info_entry_t *interfa
6767
(void) interface;
6868
return true;
6969
}
70+
void ws_common_aro_failure(protocol_interface_info_entry_t *cur, const uint8_t *ll_address)
71+
{
72+
(void) cur;
73+
(void) ll_address;
7074

75+
}

0 commit comments

Comments
 (0)