Skip to content

Commit dce4e25

Browse files
author
Juha Heiskanen
authored
Merge pull request #2068 from ARMmbed/ws_dhcp_update
Wi-sun DHCPV6, RPL DIO forwarding, dhcpv6 client update
2 parents 85f9a81 + 06fe62e commit dce4e25

File tree

18 files changed

+216
-89
lines changed

18 files changed

+216
-89
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ void thread_interface_init(protocol_interface_info_entry_t *cur)
888888
thread_discovery_reset(cur->id);
889889
thread_routing_set_mesh_callbacks(cur);
890890
dhcp_client_init(cur->id);
891+
dhcp_client_configure(cur->id, false, false, false);
891892
thread_management_client_init(cur->id);
892893
thread_address_registration_init();
893894
cur->mpl_seed_id_mode = MULTICAST_MPL_SEED_ID_MAC_SHORT;

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ static void ws_bbr_dhcp_server_stop(protocol_interface_info_entry_t *cur, uint8_
302302
tr_debug("DHCP server deactivate %s", trace_ipv6(global_id));
303303
DHCPv6_server_service_delete(cur->id, global_id, false);
304304

305-
// Set old addresses to deferred and timeout
306-
ws_dhcp_client_address_delete(cur, global_id);
307-
308305
}
309306

310307
static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
@@ -342,9 +339,9 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
342339
tr_info("RPL GUA deactivate %s", trace_ipv6(global_dodag_id));
343340

344341
// Old backbone information is deleted after 120 seconds
345-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 120, true);
346-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, 0, true);
347-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, true);
342+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 0, true);
343+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 0, 0, true);
344+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 0, true);
348345
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 120, 0);
349346

350347
ws_bbr_dhcp_server_stop(cur, global_dodag_id);
@@ -369,7 +366,7 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
369366

370367
if (configuration & BBR_GUA_C) {
371368
// Add also global prefix and route to RPL
372-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, t_flags, 7200, 7200, false);
369+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, t_flags, 0, 0, false);
373370
}
374371
if (configuration & BBR_GUA_ROUTE) {
375372
// Add also global prefix and route to RPL

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
171171
tr_info("Register ARO");
172172
ws_bootsrap_event_trig(WS_ADDRESS_ADDED, interface->bootStrapId, ARM_LIB_LOW_PRIORITY_EVENT, NULL);
173173
}
174-
} else {
175-
tr_debug("Address notification addr: %s reason: %d", trace_ipv6(addr->address), reason);
176174
}
177175
}
178176

@@ -725,7 +723,7 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
725723
cur->ipv6_neighbour_cache.send_nud_probes = false;
726724
cur->ipv6_neighbour_cache.probe_avoided_routers = true;
727725
dhcp_client_init(cur->id);
728-
dhcp_client_configure(cur->id, true); //RENEW uses SOLICIT
726+
dhcp_client_configure(cur->id, true, true, true); //RENEW uses SOLICIT, Interface will use 1 instance for address get, IAID address hint is not used.
729727
dhcp_client_solicit_timeout_set(cur->id, WS_DHCP_SOLICIT_TIMEOUT, WS_DHCP_SOLICIT_MAX_RT, WS_DHCP_SOLICIT_MAX_RC);
730728

731729

@@ -1815,31 +1813,11 @@ static void ws_dhcp_client_global_adress_cb(int8_t interface, uint8_t dhcp_addr[
18151813
tr_debug("DHCPv6 %s status %u", trace_ipv6(dhcp_addr), register_status);
18161814
}
18171815

1818-
static bool ws_address_entry_available(uint8_t *prefixPtr, if_address_list_t *list)
1819-
{
1820-
bool addressReady = false;
1821-
ns_list_foreach(if_address_entry_t, entry, list) {
1822-
if (prefixPtr) {
1823-
if (memcmp(entry->address, prefixPtr, 8) == 0) {
1824-
addressReady = true;
1825-
break;
1826-
}
1827-
} else {
1828-
if (entry->source == ADDR_SOURCE_DHCP) {
1829-
addressReady = true;
1830-
break;
1831-
}
1832-
}
1833-
}
1834-
return addressReady;
1835-
}
18361816

18371817
void ws_dhcp_client_address_request(protocol_interface_info_entry_t *cur, uint8_t *prefix, uint8_t *parent_link_local)
18381818
{
1839-
if (!ws_address_entry_available(prefix, &cur->ip_addresses)) {
1840-
if (dhcp_client_get_global_address(cur->id, parent_link_local, prefix, cur->mac, DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE, ws_dhcp_client_global_adress_cb) != 0) {
1841-
tr_error("DHCPp client request fail");
1842-
}
1819+
if (dhcp_client_get_global_address(cur->id, parent_link_local, prefix, cur->mac, DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE, ws_dhcp_client_global_adress_cb) != 0) {
1820+
tr_error("DHCPp client request fail");
18431821
}
18441822
}
18451823

@@ -1877,20 +1855,13 @@ static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t
18771855
addr_policy_table_add_entry(prefix->prefix, prefix->prefix_len, 2, WS_NON_PREFFRED_LABEL);
18781856
}
18791857
} else if (prefix->prefix_len) {
1880-
if (prefix->preftime == 0) {
1881-
// Delete all pending transactions from DHCP
1882-
// TODO this also deletes the address even when lifetime would allow it to be present
1883-
dhcp_client_global_address_delete(cur->id, NULL, prefix->prefix);
1884-
} else {
1885-
// Create new address using DHCP
1858+
// Create new address using DHCP
1859+
if (parent_link_local) {
18861860
ws_dhcp_client_address_request(cur, prefix->prefix, parent_link_local);
1887-
}
1888-
// If we have addresses generated we update the lifetimes always
1889-
ns_list_foreach(if_address_entry_t, entry, &cur->ip_addresses) {
1890-
if (entry->prefix_len == prefix->prefix_len && bitsequal(entry->address, prefix->prefix, prefix->prefix_len)) {
1891-
entry->preferred_lifetime = prefix->preftime;
1892-
entry->valid_lifetime = prefix->lifetime;
1893-
}
1861+
} else {
1862+
/* Deprecate address and remove client */
1863+
tr_debug("Prefix invalidation %s", trace_ipv6(prefix->prefix));
1864+
dhcp_client_global_address_delete(cur->id, NULL, prefix->prefix);
18941865
}
18951866
}
18961867
}

source/Common_Protocols/icmpv6.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,8 @@ int icmpv6_slaac_prefix_update(struct protocol_interface_info_entry *cur, const
570570
//Validate first current list If prefix is already defined adress
571571
ns_list_foreach_safe(if_address_entry_t, e, &cur->ip_addresses) {
572572
if (e->source == ADDR_SOURCE_SLAAC && (e->prefix_len == prefix_len) && bitsequal(e->address, prefix_ptr, prefix_len)) {
573-
//Update Current lifetimes (see RFC 4862 for rules detail)
574-
if (valid_lifetime > (2 * 60 * 60) || valid_lifetime > e->valid_lifetime) {
575-
addr_set_valid_lifetime(cur, e, valid_lifetime);
576-
} else if (e->valid_lifetime <= (2 * 60 * 60)) {
577-
//NOT Update Valid Lifetime
578-
} else {
579-
addr_set_valid_lifetime(cur, e, 2 * 60 * 60);
580-
}
581573

582-
addr_set_preferred_lifetime(cur, e, preferred_lifetime);
574+
addr_lifetime_update(cur, e, valid_lifetime, preferred_lifetime, 2 * 60 * 60);
583575
ret_val = 0;
584576
}
585577
}

source/Common_Protocols/icmpv6_prefix.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ prefix_entry_t *icmpv6_prefix_add(prefix_list_t *list, const uint8_t *prefixPtr,
3535

3636
entry = icmpv6_prefix_compare(list, prefixPtr, prefix_len);
3737
if (entry) {
38-
entry->options = flags;
39-
entry->lifetime = lifeTime;
40-
entry->preftime = prefTime;
38+
if (flags != 0xff) {
39+
entry->options = flags;
40+
entry->lifetime = lifeTime;
41+
entry->preftime = prefTime;
42+
}
4143
return entry;
4244
}
4345

source/Core/include/ns_address_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ void addr_fast_timer(struct protocol_interface_info_entry *cur, uint_fast16_t ti
156156
void addr_slow_timer(struct protocol_interface_info_entry *cur, uint_fast16_t seconds);
157157
struct if_address_entry *addr_add(struct protocol_interface_info_entry *cur, const uint8_t address[__static 16], uint_fast8_t prefix_len, if_address_source_t source, uint32_t valid_lifetime, uint32_t preferred_lifetime, bool skip_dad);
158158
int_fast8_t addr_delete(struct protocol_interface_info_entry *cur, const uint8_t address[__static 16]);
159+
int_fast8_t addr_deprecate(struct protocol_interface_info_entry *cur, const uint8_t address[__static 16]);
159160
void addr_delete_matching(struct protocol_interface_info_entry *cur, const uint8_t *prefix, uint8_t prefix_len, if_address_source_t source);
160161
void addr_delete_entry(struct protocol_interface_info_entry *cur, if_address_entry_t *addr);
161162
void addr_set_non_preferred(struct protocol_interface_info_entry *cur, if_address_source_t source);
@@ -166,6 +167,8 @@ void addr_cb(struct protocol_interface_info_entry *interface, if_address_entry_t
166167
void addr_set_valid_lifetime(struct protocol_interface_info_entry *interface, if_address_entry_t *entry, uint32_t valid_lifetime);
167168
void addr_set_preferred_lifetime(struct protocol_interface_info_entry *interface, if_address_entry_t *entry, uint32_t preferred_lifetime);
168169

170+
void addr_lifetime_update(struct protocol_interface_info_entry *interface, if_address_entry_t *address, uint32_t valid_lifetime, uint32_t preferred_lifetime, uint32_t threshold);
171+
169172
int_fast8_t addr_policy_table_add_entry(const uint8_t *prefix, uint8_t len, uint8_t precedence, uint8_t label);
170173
int_fast8_t addr_policy_table_delete_entry(const uint8_t *prefix, uint8_t len);
171174
uint8_t addr_len_from_type(addrtype_t addr_type);

source/Core/ns_address_internal.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,19 @@ int_fast8_t addr_delete(protocol_interface_info_entry_t *cur, const uint8_t addr
10101010
return -1;
10111011
}
10121012

1013+
int_fast8_t addr_deprecate(protocol_interface_info_entry_t *cur, const uint8_t address[static 16])
1014+
{
1015+
ns_list_foreach(if_address_entry_t, e, &cur->ip_addresses) {
1016+
if (memcmp(e->address, address, 16) == 0) {
1017+
tr_debug("Deprecate address %s", trace_ipv6(e->address));
1018+
addr_lifetime_update(cur, e, 0, 0, 30 * 60); //Accept max 30 min lifetime
1019+
return 0;
1020+
}
1021+
}
1022+
1023+
return -1;
1024+
}
1025+
10131026
void addr_delete_matching(protocol_interface_info_entry_t *cur, const uint8_t *prefix, uint8_t prefix_len, if_address_source_t source)
10141027
{
10151028
ns_list_foreach_safe(if_address_entry_t, e, &cur->ip_addresses) {
@@ -1099,6 +1112,20 @@ void addr_set_preferred_lifetime(protocol_interface_info_entry_t *interface, if_
10991112
}
11001113
}
11011114

1115+
void addr_lifetime_update(protocol_interface_info_entry_t *interface, if_address_entry_t *address, uint32_t valid_lifetime, uint32_t preferred_lifetime, uint32_t threshold)
1116+
{
1117+
//Update Current lifetimes (see RFC 4862 for rules detail)
1118+
if (valid_lifetime > threshold || valid_lifetime > address->valid_lifetime) {
1119+
addr_set_valid_lifetime(interface, address, valid_lifetime);
1120+
} else if (address->valid_lifetime <= threshold) {
1121+
//NOT Update Valid Lifetime
1122+
} else {
1123+
addr_set_valid_lifetime(interface, address, threshold);
1124+
}
1125+
1126+
addr_set_preferred_lifetime(interface, address, preferred_lifetime);
1127+
}
1128+
11021129
void memswap(uint8_t *restrict a, uint8_t *restrict b, uint_fast8_t len)
11031130
{
11041131
while (len--) {

source/DHCPv6_client/dhcpv6_client_api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ void dhcp_client_init(int8_t interface);
3838

3939
/* Set configurations for DHCP client
4040
*
41+
* /param interface Client Inteface ID
4142
* /param renew_uses_solicit Instead of renew message SOLICIT is used.
43+
* /param one_client_for_this_interface True Interface use oneinstance for allocate address
44+
* /param no_address_hint IAID use address at Solicit
4245
*/
43-
void dhcp_client_configure(int8_t interface, bool renew_uses_solicit);
46+
void dhcp_client_configure(int8_t interface, bool renew_uses_solicit, bool one_client_for_this_interface, bool no_address_hint);
4447

4548
/* Set Timeout parameters for SOLICIT transactions
4649
*

0 commit comments

Comments
 (0)