Skip to content

Commit 3835702

Browse files
author
Juha Heiskanen
committed
Address policy update's
Wi-sun create own non preferred address policy for SLAAC. Added new function for remove label if there is not exist any address interface anymore. WS address remove calback handler use new policy label remove function. Change-Id: I2781917855d6cf4572e23ff6a2436b66c42db158
1 parent aba9dd6 commit 3835702

File tree

10 files changed

+70
-0
lines changed

10 files changed

+70
-0
lines changed

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int ws_bbr_static_ula_create(protocol_interface_info_entry_t *cur)
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
}

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/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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,21 @@ int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_
14051405
return ret_val;
14061406
}
14071407

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+
14081423
// This last function must always be compiled with tracing enabled
14091424
#ifndef FEA_TRACE_SUPPORT
14101425
#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+

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)