Skip to content

Commit d196ffc

Browse files
author
Mika Tervonen
committed
Refactor Wi-SUN BBR stop function
Created routing stop for bbr to restart the Border router state machine Now following functions are always done Cleanup DHCP server Cleanup Backbone routes Delete all generated addressess
1 parent 35970d7 commit d196ffc

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,14 @@ static void ws_bbr_rpl_root_start(protocol_interface_info_entry_t *cur, uint8_t
158158

159159
}
160160

161+
161162
static void ws_bbr_rpl_root_stop(void)
162163
{
163164
tr_info("RPL root stop");
164165
if (protocol_6lowpan_rpl_root_dodag) {
165166
rpl_control_delete_dodag_root(protocol_6lowpan_rpl_domain, protocol_6lowpan_rpl_root_dodag);
166167
protocol_6lowpan_rpl_root_dodag = NULL;
167168
}
168-
memset(current_local_prefix, 0, 8);
169-
memset(current_global_prefix, 0, 8);
170-
memset(current_dodag_id, 0, 16);
171169
}
172170

173171
static int ws_border_router_proxy_validate(int8_t interface_id, uint8_t *address)
@@ -360,6 +358,31 @@ static void ws_bbr_dhcp_server_stop(protocol_interface_info_entry_t *cur, uint8_
360358

361359
}
362360

361+
static void ws_bbr_routing_stop(protocol_interface_info_entry_t *cur)
362+
{
363+
tr_info("BBR routing stop");
364+
if (memcmp(current_local_prefix, ADDR_UNSPECIFIED, 8) != 0) {
365+
ws_bbr_slaac_remove(cur, current_local_prefix);
366+
memset(current_local_prefix, 0, 8);
367+
}
368+
369+
if (memcmp(current_global_prefix, ADDR_UNSPECIFIED, 8) != 0) {
370+
ws_bbr_dhcp_server_stop(cur, current_global_prefix);
371+
if (backbone_interface_id >= 0) {
372+
// Delete route to backbone if it exists
373+
ipv6_route_add_with_info(current_global_prefix, 64, backbone_interface_id, NULL, ROUTE_THREAD_BBR, NULL, 0, 0, 0);
374+
}
375+
memset(current_global_prefix, 0, 8);
376+
}
377+
378+
if (memcmp(current_dodag_id, ADDR_UNSPECIFIED, 8) != 0) {
379+
ws_bbr_slaac_remove(cur, current_dodag_id);
380+
memset(current_dodag_id, 0, 16);
381+
}
382+
383+
ws_bbr_rpl_root_stop();
384+
}
385+
363386
static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
364387
{
365388

@@ -389,9 +412,8 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
389412
*/
390413
if (protocol_interface_address_compare(current_dodag_id) != 0) {
391414
//DODAGID is lost need to restart
392-
tr_warn("DODAGID lost restart RPL");
393-
memset(current_dodag_id, 0, 16);
394-
ws_bbr_rpl_root_stop();
415+
tr_warn("DODAGID lost restart BBR");
416+
ws_bbr_routing_stop(cur);
395417
return;
396418
}
397419

@@ -651,18 +673,11 @@ void ws_bbr_stop(int8_t interface_id)
651673
{
652674
#ifdef HAVE_WS_BORDER_ROUTER
653675

654-
backbone_interface_id = -1;
655676
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
656677

657-
ws_bbr_slaac_remove(cur, current_dodag_id);
658-
if (memcmp(current_local_prefix, ADDR_UNSPECIFIED, 8) != 0) {
659-
ws_bbr_slaac_remove(cur, current_local_prefix);
660-
}
661-
if (memcmp(current_global_prefix, ADDR_UNSPECIFIED, 8) != 0) {
662-
ws_bbr_dhcp_server_stop(cur, current_global_prefix);
663-
}
678+
ws_bbr_routing_stop(cur);
664679

665-
ws_bbr_rpl_root_stop();
680+
backbone_interface_id = -1;
666681
current_instance_id++;
667682

668683
#else
@@ -673,11 +688,12 @@ int ws_bbr_configure(int8_t interface_id, uint16_t options)
673688
{
674689
#ifdef HAVE_WS_BORDER_ROUTER
675690

676-
(void)interface_id;
691+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
692+
677693
if (protocol_6lowpan_rpl_root_dodag &&
678694
options != configuration) {
679695
//Configuration changed delete previous setup
680-
ws_bbr_rpl_root_stop();
696+
ws_bbr_routing_stop(cur);
681697
}
682698
configuration = options;
683699
return 0;

0 commit comments

Comments
 (0)