Skip to content

Commit 22cbb02

Browse files
author
Juha Heiskanen
authored
Merge pull request ARMmbed#1983 from ARMmbed/iothhd-2950
wi-sun Address select fix's
2 parents 0bee3db + 3835702 commit 22cbb02

File tree

12 files changed

+81
-4
lines changed

12 files changed

+81
-4
lines changed

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,13 @@ static int ws_bbr_static_ula_create(protocol_interface_info_entry_t *cur)
170170
tr_info("BBR generate ula prefix");
171171

172172
// This address is only used if no other address available.
173-
if_address_entry_t *add_entry = icmpv6_slaac_address_add(cur, static_dodag_prefix, 64, 0xffffffff, 0, true, SLAAC_IID_FIXED);
173+
if_address_entry_t *add_entry = icmpv6_slaac_address_add(cur, static_dodag_prefix, 64, 0xffffffff, 0xffffffff, true, SLAAC_IID_FIXED);
174174
if (!add_entry) {
175175
return -1;
176176
}
177177
memcpy(static_ula_address, add_entry->address, 16);
178178
tr_info("BBR generate ula prefix addr %s", trace_ipv6(static_ula_address));
179+
addr_policy_table_add_entry(static_dodag_prefix, 64, 2, WS_NON_PREFFRED_LABEL);
179180

180181
return 0;
181182
}
@@ -322,7 +323,7 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
322323
ws_dhcp_client_address_request(cur, global_id, ll);
323324

324325
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 7200, false);
325-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 0, false);
326+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 7200, false);
326327
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
327328
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, 7200, false);
328329
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, false);

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
144144
} else if (reason == ADDR_CALLBACK_DELETED) {
145145
// What to do?
146146
// Go through address list and check if there is global address still available
147+
//Discover prefix policy
148+
addr_policy_remove_by_label(WS_NON_PREFFRED_LABEL);
149+
147150
interface->global_address_available = false;
148151
ns_list_foreach(if_address_entry_t, addr_str, &interface->ip_addresses) {
149152
if (addr_ipv6_scope(addr_str->address, interface) > IPV6_SCOPE_LINK_LOCAL) {
@@ -1786,6 +1789,14 @@ static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t
17861789
if (prefix->options & PIO_A) {
17871790
if (icmpv6_slaac_prefix_update(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime) != 0) {
17881791
ipv6_interface_slaac_handler(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime);
1792+
/*
1793+
* Give SLAAC addresses a different label and low precedence to indicate that
1794+
* they probably shouldn't be used for external traffic. SLAAC use in Wi-SUN is non-standard,
1795+
* and we use it for mesh-local traffic we should prefer any DHCP-assigned addresses
1796+
* for talking to the outside world
1797+
*
1798+
*/
1799+
addr_policy_table_add_entry(prefix->prefix, prefix->prefix_len, 2, WS_NON_PREFFRED_LABEL);
17891800
}
17901801
} else if (prefix->prefix_len) {
17911802
if (prefix->preftime == 0) {

source/6LoWPAN/ws/ws_common_defines.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ typedef struct ws_bs_ie {
198198

199199
#define WS_NUD_RANDOM_COMPARE (WS_NUD_RAND_PROBABILITY*WS_NUD_RANDOM_SAMPLE_LENGTH) / 100
200200

201+
/**
202+
* Wi-sun spesific non-preferred prefix policy label
203+
*/
204+
205+
#define WS_NON_PREFFRED_LABEL 36
206+
201207
/*
202208
* Threshold (referenced to DEVICE_MIN_SENS) above which a neighbor node may be considered for inclusion into candidate parent set
203209
*/

source/Common_Protocols/icmpv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@ static buffer_t *icmpv6_echo_request_handler(buffer_t *buf)
325325

326326
if (addr_is_ipv6_multicast(buf->dst_sa.address)) {
327327
const uint8_t *ipv6_ptr;
328+
memcpy(buf->dst_sa.address, buf->src_sa.address, 16);
328329
ipv6_ptr = addr_select_source(cur, buf->dst_sa.address, 0);
329330
if (!ipv6_ptr) {
330331
tr_debug("No address");
331332
return buffer_free(buf);
332333
}
333-
memcpy(buf->dst_sa.address, buf->src_sa.address, 16);
334334
memcpy(buf->src_sa.address, ipv6_ptr, 16);
335335
} else {
336336
memswap(buf->dst_sa.address, buf->src_sa.address, 16);

source/Core/include/ns_address_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ struct if_address_entry *addr_get_entry(const struct protocol_interface_info_ent
178178
bool addr_is_assigned_to_interface(const struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]);
179179
bool addr_is_tentative_for_interface(const struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]);
180180

181+
void addr_policy_remove_by_label(uint8_t label);
182+
181183
void addr_duplicate_detected(struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]);
182184

183185
struct if_group_entry *addr_add_group(struct protocol_interface_info_entry *interface, const uint8_t group[__static 16]);

source/Core/ns_address_internal.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ const uint8_t *addr_select_source(protocol_interface_info_entry_t *interface, co
690690
}
691691
}
692692

693+
/* Rule 9 select most precated one */
694+
if (policy_SA->precedence > policy_SB->precedence) {
695+
PREFER_SA;
696+
} else if (policy_SB->precedence > policy_SA->precedence) {
697+
PREFER_SB;
698+
}
699+
693700
/* Tie */
694701
PREFER_SA;
695702
}
@@ -1398,6 +1405,21 @@ int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_
13981405
return ret_val;
13991406
}
14001407

1408+
void addr_policy_remove_by_label(uint8_t label)
1409+
{
1410+
ns_list_foreach_safe(addr_policy_table_entry_t, entry, &addr_policy_table) {
1411+
if (entry->label == label) {
1412+
/*
1413+
* Remove label policy if no local address matches"
1414+
*/
1415+
if (!protocol_interface_any_address_match(entry->prefix, entry->prefix_len)) {
1416+
ns_list_remove(&addr_policy_table, entry);
1417+
ns_dyn_mem_free(entry);
1418+
}
1419+
}
1420+
}
1421+
}
1422+
14011423
// This last function must always be compiled with tracing enabled
14021424
#ifndef FEA_TRACE_SUPPORT
14031425
#define FEA_TRACE_SUPPORT 1

source/NWK_INTERFACE/Include/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,5 @@ extern void protocol_core_dhcpv6_allocated_address_remove(protocol_interface_inf
514514
extern void nwk_bootsrap_state_update(arm_nwk_interface_status_type_e posted_event, protocol_interface_info_entry_t *cur);
515515
void bootsrap_next_state_kick(icmp_state_t new_state, protocol_interface_info_entry_t *cur);
516516
int8_t protocol_interface_address_compare(const uint8_t *addr);
517+
bool protocol_interface_any_address_match(const uint8_t *prefix, uint8_t prefix_len);
517518
#endif /* _NS_PROTOCOL_H */

source/NWK_INTERFACE/protocol_core.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,3 +1135,27 @@ int8_t protocol_interface_address_compare(const uint8_t *addr)
11351135
return -1;
11361136
}
11371137

1138+
static bool protocol_address_prefix_cmp(protocol_interface_info_entry_t *interface, const uint8_t *prefix, uint8_t prefix_len)
1139+
{
1140+
ns_list_foreach(if_address_entry_t, adr, &interface->ip_addresses) {
1141+
if (bitsequal(adr->address, prefix, prefix_len)) {
1142+
/* Prefix stil used at list so stop checking */
1143+
return true;
1144+
}
1145+
}
1146+
return false;
1147+
}
1148+
1149+
bool protocol_interface_any_address_match(const uint8_t *prefix, uint8_t prefix_len)
1150+
{
1151+
ns_list_foreach(protocol_interface_info_entry_t, cur, &protocol_interface_info_list) {
1152+
1153+
if (protocol_address_prefix_cmp(cur, prefix, prefix_len)) {
1154+
return true;
1155+
}
1156+
}
1157+
1158+
return false;
1159+
}
1160+
1161+

source/libDHCPv6/dhcp_service_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void recv_dhcp_relay_msg(void *cb_res)
441441
}
442442
uint8_t gp_address[16];
443443
//Get blobal address from interface
444-
if (arm_net_address_get(sckt_data->interface_id, ADDR_IPV6_GP, gp_address) != 0) {
444+
if (addr_interface_select_source(interface_ptr, gp_address, relay_srv->server_address, 0) != 0) {
445445
// No global prefix available
446446
tr_error("No GP address");
447447
goto cleanup;

test/nanostack/unittest/libDHCPv6/dhcp_service_api/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ TEST_SRC_FILES = \
2121
../../stub/system_timer_stub.c \
2222
../../stub/libDHCPv6_stub.c \
2323
../../stub/protocol_core_stub.c \
24+
../../stub/address_stub.c \
2425
../../stub/net_stub.c \
2526

2627
include ../../MakefileWorker.mk

test/nanostack/unittest/stub/address_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,7 @@ int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_
345345
void addr_multicast_fwd_set_forwarding(struct protocol_interface_info_entry *interface, bool enable)
346346
{
347347
}
348+
349+
void addr_policy_remove_by_label(uint8_t label)
350+
{
351+
}

test/nanostack/unittest/stub/protocol_core_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,8 @@ int8_t protocol_interface_address_compare(const uint8_t *addr)
239239
return protocol_core_stub.int8_value;
240240
}
241241

242+
bool protocol_interface_any_address_match(const uint8_t *prefix, uint8_t prefix_len)
243+
{
244+
return protocol_core_stub.bool_value;
245+
}
246+

0 commit comments

Comments
 (0)