Skip to content

Commit c81e59c

Browse files
author
Mika Tervonen
committed
Fixes for Wi-SUN bbr behaviour
Learn prefix lifetimes and set them to addressess if changed in BBR Fixed DHCP server initialize Deleted dhcp server if address is removed set address timeouts for BBR when address is removed
1 parent c941fe6 commit c81e59c

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ static void ws_bbr_rpl_root_start(uint8_t *dodag_id)
9595

9696
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, t_flags, 0xffffffff, 0xffffffff, false);
9797
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, 0x18, 0xffffffff, false);
98-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 0xffffffff, false);
9998
}
10099

101100
static void ws_bbr_rpl_root_stop(void)
@@ -242,9 +241,16 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
242241

243242
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 7200, false);
244243
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
245-
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, 0, true);
246-
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, true);
247-
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 7200, 0);
244+
245+
// Old backbone information is deleted after 120 seconds
246+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 120, true);
247+
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, 0, true);
248+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, true);
249+
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 120, 0);
250+
DHCPv6_server_service_delete(cur->id, global_dodag_id, false);
251+
252+
// Set old addresses to deferred and timeout
253+
ws_dhcp_client_address_delete(cur, global_dodag_id);
248254
}
249255
// TODO add global prefix
250256
if (memcmp(global_id, ADDR_UNSPECIFIED,16) != 0) {
@@ -264,6 +270,7 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
264270
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
265271
ws_dhcp_client_address_request(cur, global_id, ll);
266272

273+
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 7200, false);
267274
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 0, false);
268275
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
269276
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, 7200, false);

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,11 @@ void ws_dhcp_client_address_request(protocol_interface_info_entry_t *cur, uint8_
15811581
}
15821582
}
15831583

1584+
void ws_dhcp_client_address_delete(protocol_interface_info_entry_t *cur, uint8_t *prefix)
1585+
{
1586+
dhcp_client_global_address_delete(cur->id, NULL, prefix);
1587+
}
1588+
15841589
static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t *parent_link_local)
15851590
{
15861591
protocol_interface_info_entry_t *cur = (protocol_interface_info_entry_t*) handle;
@@ -1593,8 +1598,22 @@ static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t
15931598
ipv6_interface_slaac_handler(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime);
15941599
}
15951600
} else if (prefix->prefix_len) {
1596-
ws_dhcp_client_address_request(cur, prefix->prefix, parent_link_local);
1597-
}
1601+
if (prefix->preftime == 0) {
1602+
// Delete all pending transactions from DHCP
1603+
// TODO this also deletes the address even when lifetime would allow it to be present
1604+
dhcp_client_global_address_delete(cur->id,NULL,prefix->prefix);
1605+
} else {
1606+
// Create new address using DHCP
1607+
ws_dhcp_client_address_request(cur, prefix->prefix, parent_link_local);
1608+
}
1609+
// If we have addresses generated we update the lifetimes always
1610+
ns_list_foreach(if_address_entry_t, entry, &cur->ip_addresses) {
1611+
if (entry->prefix_len == prefix->prefix_len && bitsequal(entry->address, prefix->prefix, prefix->prefix_len)) {
1612+
entry->preferred_lifetime = prefix->preftime;
1613+
entry->valid_lifetime = prefix->lifetime;
1614+
}
1615+
}
1616+
}
15981617
}
15991618

16001619
static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void ws_nud_active_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);
6464

6565
void ws_dhcp_client_address_request(protocol_interface_info_entry_t *cur, uint8_t *prefix, uint8_t *parent_link_local);
6666

67+
void ws_dhcp_client_address_delete(protocol_interface_info_entry_t *cur, uint8_t *prefix);
68+
6769
#else
6870

6971
#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)

source/DHCPv6_Server/DHCPv6_Server_service.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -236,28 +236,21 @@ int DHCPv6_server_service_init(int8_t interface, uint8_t guaPrefix[static 16], u
236236
//allocate Socket Service
237237
socketInstance = dhcp_service_init(interface, DHCP_INSTANCE_SERVER, DHCPV6_server_service_request_handler);
238238
cur = protocol_stack_interface_info_get_by_id(interface);
239-
if (cur) {
240-
if (dhcpv6_server_service_tasklet_generated() < 0) {
241-
retVal = -2;
242-
} else if (!DHCP_server_service_timer_start()) {
243-
retVal = -2;
244-
} else {
245-
//allocate server
246-
dhcpv6_gua_server_entry_s *serverInfo = libdhcpv6_gua_server_allocate(guaPrefix, interface, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE);
247-
if (serverInfo) {
248-
//if_address_entry_t *def_address = NULL;
249-
uint8_t temp[16];
250-
uint8_t *ptr = temp;
251-
//define address & Route advert's
252-
memcpy(ptr, guaPrefix, 8);
253-
ptr += 8;
254-
memcpy(ptr, cur->iid_slaac, 8);
255-
256-
serverInfo->socketInstance_id = socketInstance;
257-
socketInstance = 0;
258-
//Generate Address for current interface
259-
retVal = 0;
260-
}
239+
if (!cur) {
240+
return -1;
241+
}
242+
243+
if (dhcpv6_server_service_tasklet_generated() < 0) {
244+
retVal = -2;
245+
} else if (!DHCP_server_service_timer_start()) {
246+
retVal = -2;
247+
} else {
248+
//allocate server
249+
dhcpv6_gua_server_entry_s *serverInfo = libdhcpv6_gua_server_allocate(guaPrefix, interface, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE);
250+
if (serverInfo) {
251+
serverInfo->socketInstance_id = socketInstance;
252+
socketInstance = 0;
253+
retVal = 0;
261254
}
262255
}
263256
if (socketInstance > 0) {

source/libDHCPv6/libDHCPv6_server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ dhcpv6_gua_server_entry_s *libdhcpv6_server_data_get_by_prefix_and_socketinstanc
142142

143143
dhcpv6_gua_server_entry_s *libdhcpv6_gua_server_allocate(uint8_t *prefix, int8_t interfaceId, uint8_t *serverDUID, uint16_t serverDUIDType)
144144
{
145-
dhcpv6_gua_server_entry_s *entry = NULL;
146-
if (libdhcpv6_server_data_get_by_prefix_and_interfaceid(interfaceId, prefix) == NULL) {
145+
dhcpv6_gua_server_entry_s *entry = libdhcpv6_server_data_get_by_prefix_and_interfaceid(interfaceId, prefix);
146+
if (entry == NULL) {
147147
entry = libdhcpv6_server_entry_allocate();
148148
if (entry) {
149149
memcpy(entry->guaPrefix, prefix, 8);

0 commit comments

Comments
 (0)