Skip to content

Commit

Permalink
Fixes for Wi-SUN bbr behaviour
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mika Tervonen committed Oct 31, 2018
1 parent c941fe6 commit c81e59c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
15 changes: 11 additions & 4 deletions source/6LoWPAN/ws/ws_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ static void ws_bbr_rpl_root_start(uint8_t *dodag_id)

rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, t_flags, 0xffffffff, 0xffffffff, false);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, dodag_id, 64, 0x18, 0xffffffff, false);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 0xffffffff, false);
}

static void ws_bbr_rpl_root_stop(void)
Expand Down Expand Up @@ -242,9 +241,16 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)

rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 7200, false);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, 0, true);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 7200, true);
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 7200, 0);

// Old backbone information is deleted after 120 seconds
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 120, true);
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, 0, true);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, global_dodag_id, 64, 0, 120, true);
ipv6_route_add_with_info(global_dodag_id, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 120, 0);
DHCPv6_server_service_delete(cur->id, global_dodag_id, false);

// Set old addresses to deferred and timeout
ws_dhcp_client_address_delete(cur, global_dodag_id);
}
// TODO add global prefix
if (memcmp(global_id, ADDR_UNSPECIFIED,16) != 0) {
Expand All @@ -264,6 +270,7 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
tr_info("RPL GUA activate %s", trace_ipv6(global_id));
ws_dhcp_client_address_request(cur, global_id, ll);

rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, NULL, 0, 0, 7200, false);
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, PIO_A, 7200, 0, false);
rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, static_dodag_id, 64, 0x18, 7200, false);
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_id, 64, 0, 7200, 7200, false);
Expand Down
23 changes: 21 additions & 2 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,11 @@ void ws_dhcp_client_address_request(protocol_interface_info_entry_t *cur, uint8_
}
}

void ws_dhcp_client_address_delete(protocol_interface_info_entry_t *cur, uint8_t *prefix)
{
dhcp_client_global_address_delete(cur->id, NULL, prefix);
}

static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t *parent_link_local)
{
protocol_interface_info_entry_t *cur = (protocol_interface_info_entry_t*) handle;
Expand All @@ -1593,8 +1598,22 @@ static void ws_rpl_prefix_callback(prefix_entry_t *prefix, void *handle, uint8_t
ipv6_interface_slaac_handler(cur, prefix->prefix, prefix->prefix_len, prefix->lifetime, prefix->preftime);
}
} else if (prefix->prefix_len) {
ws_dhcp_client_address_request(cur, prefix->prefix, parent_link_local);
}
if (prefix->preftime == 0) {
// Delete all pending transactions from DHCP
// TODO this also deletes the address even when lifetime would allow it to be present
dhcp_client_global_address_delete(cur->id,NULL,prefix->prefix);
} else {
// Create new address using DHCP
ws_dhcp_client_address_request(cur, prefix->prefix, parent_link_local);
}
// If we have addresses generated we update the lifetimes always
ns_list_foreach(if_address_entry_t, entry, &cur->ip_addresses) {
if (entry->prefix_len == prefix->prefix_len && bitsequal(entry->address, prefix->prefix, prefix->prefix_len)) {
entry->preferred_lifetime = prefix->preftime;
entry->valid_lifetime = prefix->lifetime;
}
}
}
}

static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
Expand Down
2 changes: 2 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void ws_nud_active_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);

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

void ws_dhcp_client_address_delete(protocol_interface_info_entry_t *cur, uint8_t *prefix);

#else

#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
Expand Down
37 changes: 15 additions & 22 deletions source/DHCPv6_Server/DHCPv6_Server_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,21 @@ int DHCPv6_server_service_init(int8_t interface, uint8_t guaPrefix[static 16], u
//allocate Socket Service
socketInstance = dhcp_service_init(interface, DHCP_INSTANCE_SERVER, DHCPV6_server_service_request_handler);
cur = protocol_stack_interface_info_get_by_id(interface);
if (cur) {
if (dhcpv6_server_service_tasklet_generated() < 0) {
retVal = -2;
} else if (!DHCP_server_service_timer_start()) {
retVal = -2;
} else {
//allocate server
dhcpv6_gua_server_entry_s *serverInfo = libdhcpv6_gua_server_allocate(guaPrefix, interface, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE);
if (serverInfo) {
//if_address_entry_t *def_address = NULL;
uint8_t temp[16];
uint8_t *ptr = temp;
//define address & Route advert's
memcpy(ptr, guaPrefix, 8);
ptr += 8;
memcpy(ptr, cur->iid_slaac, 8);

serverInfo->socketInstance_id = socketInstance;
socketInstance = 0;
//Generate Address for current interface
retVal = 0;
}
if (!cur) {
return -1;
}

if (dhcpv6_server_service_tasklet_generated() < 0) {
retVal = -2;
} else if (!DHCP_server_service_timer_start()) {
retVal = -2;
} else {
//allocate server
dhcpv6_gua_server_entry_s *serverInfo = libdhcpv6_gua_server_allocate(guaPrefix, interface, cur->mac, DHCPV6_DUID_HARDWARE_EUI64_TYPE);
if (serverInfo) {
serverInfo->socketInstance_id = socketInstance;
socketInstance = 0;
retVal = 0;
}
}
if (socketInstance > 0) {
Expand Down
4 changes: 2 additions & 2 deletions source/libDHCPv6/libDHCPv6_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ dhcpv6_gua_server_entry_s *libdhcpv6_server_data_get_by_prefix_and_socketinstanc

dhcpv6_gua_server_entry_s *libdhcpv6_gua_server_allocate(uint8_t *prefix, int8_t interfaceId, uint8_t *serverDUID, uint16_t serverDUIDType)
{
dhcpv6_gua_server_entry_s *entry = NULL;
if (libdhcpv6_server_data_get_by_prefix_and_interfaceid(interfaceId, prefix) == NULL) {
dhcpv6_gua_server_entry_s *entry = libdhcpv6_server_data_get_by_prefix_and_interfaceid(interfaceId, prefix);
if (entry == NULL) {
entry = libdhcpv6_server_entry_allocate();
if (entry) {
memcpy(entry->guaPrefix, prefix, 8);
Expand Down

0 comments on commit c81e59c

Please sign in to comment.