Skip to content

Commit

Permalink
Address policy update's
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Juha Heiskanen committed Feb 25, 2019
1 parent aba9dd6 commit 3835702
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/6LoWPAN/ws/ws_bbr_api.c
Expand Up @@ -176,6 +176,7 @@ static int ws_bbr_static_ula_create(protocol_interface_info_entry_t *cur)
}
memcpy(static_ula_address, add_entry->address, 16);
tr_info("BBR generate ula prefix addr %s", trace_ipv6(static_ula_address));
addr_policy_table_add_entry(static_dodag_prefix, 64, 2, WS_NON_PREFFRED_LABEL);

return 0;
}
Expand Down
11 changes: 11 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.c
Expand Up @@ -144,6 +144,9 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
} else if (reason == ADDR_CALLBACK_DELETED) {
// What to do?
// Go through address list and check if there is global address still available
//Discover prefix policy
addr_policy_remove_by_label(WS_NON_PREFFRED_LABEL);

interface->global_address_available = false;
ns_list_foreach(if_address_entry_t, addr_str, &interface->ip_addresses) {
if (addr_ipv6_scope(addr_str->address, interface) > IPV6_SCOPE_LINK_LOCAL) {
Expand Down Expand Up @@ -1786,6 +1789,14 @@ static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t
if (prefix->options & PIO_A) {
if (icmpv6_slaac_prefix_update(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime) != 0) {
ipv6_interface_slaac_handler(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime);
/*
* Give SLAAC addresses a different label and low precedence to indicate that
* they probably shouldn't be used for external traffic. SLAAC use in Wi-SUN is non-standard,
* and we use it for mesh-local traffic we should prefer any DHCP-assigned addresses
* for talking to the outside world
*
*/
addr_policy_table_add_entry(prefix->prefix, prefix->prefix_len, 2, WS_NON_PREFFRED_LABEL);
}
} else if (prefix->prefix_len) {
if (prefix->preftime == 0) {
Expand Down
6 changes: 6 additions & 0 deletions source/6LoWPAN/ws/ws_common_defines.h
Expand Up @@ -198,6 +198,12 @@ typedef struct ws_bs_ie {

#define WS_NUD_RANDOM_COMPARE (WS_NUD_RAND_PROBABILITY*WS_NUD_RANDOM_SAMPLE_LENGTH) / 100

/**
* Wi-sun spesific non-preferred prefix policy label
*/

#define WS_NON_PREFFRED_LABEL 36

/*
* Threshold (referenced to DEVICE_MIN_SENS) above which a neighbor node may be considered for inclusion into candidate parent set
*/
Expand Down
2 changes: 2 additions & 0 deletions source/Core/include/ns_address_internal.h
Expand Up @@ -178,6 +178,8 @@ struct if_address_entry *addr_get_entry(const struct protocol_interface_info_ent
bool addr_is_assigned_to_interface(const struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]);
bool addr_is_tentative_for_interface(const struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]);

void addr_policy_remove_by_label(uint8_t label);

void addr_duplicate_detected(struct protocol_interface_info_entry *interface, const uint8_t addr[__static 16]);

struct if_group_entry *addr_add_group(struct protocol_interface_info_entry *interface, const uint8_t group[__static 16]);
Expand Down
15 changes: 15 additions & 0 deletions source/Core/ns_address_internal.c
Expand Up @@ -1405,6 +1405,21 @@ int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_
return ret_val;
}

void addr_policy_remove_by_label(uint8_t label)
{
ns_list_foreach_safe(addr_policy_table_entry_t, entry, &addr_policy_table) {
if (entry->label == label) {
/*
* Remove label policy if no local address matches"
*/
if (!protocol_interface_any_address_match(entry->prefix, entry->prefix_len)) {
ns_list_remove(&addr_policy_table, entry);
ns_dyn_mem_free(entry);
}
}
}
}

// This last function must always be compiled with tracing enabled
#ifndef FEA_TRACE_SUPPORT
#define FEA_TRACE_SUPPORT 1
Expand Down
1 change: 1 addition & 0 deletions source/NWK_INTERFACE/Include/protocol.h
Expand Up @@ -514,4 +514,5 @@ extern void protocol_core_dhcpv6_allocated_address_remove(protocol_interface_inf
extern void nwk_bootsrap_state_update(arm_nwk_interface_status_type_e posted_event, protocol_interface_info_entry_t *cur);
void bootsrap_next_state_kick(icmp_state_t new_state, protocol_interface_info_entry_t *cur);
int8_t protocol_interface_address_compare(const uint8_t *addr);
bool protocol_interface_any_address_match(const uint8_t *prefix, uint8_t prefix_len);
#endif /* _NS_PROTOCOL_H */
24 changes: 24 additions & 0 deletions source/NWK_INTERFACE/protocol_core.c
Expand Up @@ -1135,3 +1135,27 @@ int8_t protocol_interface_address_compare(const uint8_t *addr)
return -1;
}

static bool protocol_address_prefix_cmp(protocol_interface_info_entry_t *interface, const uint8_t *prefix, uint8_t prefix_len)
{
ns_list_foreach(if_address_entry_t, adr, &interface->ip_addresses) {
if (bitsequal(adr->address, prefix, prefix_len)) {
/* Prefix stil used at list so stop checking */
return true;
}
}
return false;
}

bool protocol_interface_any_address_match(const uint8_t *prefix, uint8_t prefix_len)
{
ns_list_foreach(protocol_interface_info_entry_t, cur, &protocol_interface_info_list) {

if (protocol_address_prefix_cmp(cur, prefix, prefix_len)) {
return true;
}
}

return false;
}


Expand Up @@ -21,6 +21,7 @@ TEST_SRC_FILES = \
../../stub/system_timer_stub.c \
../../stub/libDHCPv6_stub.c \
../../stub/protocol_core_stub.c \
../../stub/address_stub.c \
../../stub/net_stub.c \

include ../../MakefileWorker.mk
Expand Down
4 changes: 4 additions & 0 deletions test/nanostack/unittest/stub/address_stub.c
Expand Up @@ -345,3 +345,7 @@ int8_t addr_interface_select_source(protocol_interface_info_entry_t *cur, uint8_
void addr_multicast_fwd_set_forwarding(struct protocol_interface_info_entry *interface, bool enable)
{
}

void addr_policy_remove_by_label(uint8_t label)
{
}
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/protocol_core_stub.c
Expand Up @@ -239,3 +239,8 @@ int8_t protocol_interface_address_compare(const uint8_t *addr)
return protocol_core_stub.int8_value;
}

bool protocol_interface_any_address_match(const uint8_t *prefix, uint8_t prefix_len)
{
return protocol_core_stub.bool_value;
}

0 comments on commit 3835702

Please sign in to comment.