Skip to content

Commit d1cf42d

Browse files
multicast handling updated(ARMmbed#1701)
1 parent 44110a1 commit d1cf42d

File tree

4 files changed

+58
-26
lines changed

4 files changed

+58
-26
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ typedef struct {
9191
ns_list_link_t link;
9292
} thread_bbr_t;
9393

94-
/*
95-
* Thread PBBR ML-EID map structure
96-
*/
97-
typedef struct {
98-
uint8_t mleid_ptr[8];
99-
uint32_t last_contact_time;
100-
} thread_bbr_mleid_map_t;
101-
10294
/* Neighbor discovery options according to RFC6106 (rfc4861) */
10395
#define RFC6106_RECURSIVE_DNS_SERVER_OPTION 25
10496
#define RFC6106_DNS_SEARCH_LIST_OPTION 31
@@ -989,7 +981,7 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
989981
if (!this || this->backbone_interface_id < 0) {
990982
return -1;
991983
}
992-
thread_bbr_mleid_map_t *map = ns_dyn_mem_alloc(sizeof(thread_bbr_mleid_map_t));
984+
thread_pbbr_dua_info_t *map = ns_dyn_mem_alloc(sizeof(thread_pbbr_dua_info_t));
993985
if (!map) {
994986
goto error;
995987
}
@@ -1014,13 +1006,13 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
10141006
return -2;
10151007
}
10161008

1017-
ipv6_route_info_t *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
1009+
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
10181010
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
10191011
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
10201012
//Not found
10211013
return NULL;
10221014
}
1023-
return route->info.info;
1015+
return route;
10241016
}
10251017

10261018
int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)

source/6LoWPAN/Thread/thread_bbr_api_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "net_interface.h"
3838
#ifdef HAVE_THREAD_ROUTER
39+
struct ipv6_route;
3940

4041
/**
4142
* \brief Initialize Thread Commissioner relay for BBR and Routers
@@ -115,7 +116,7 @@ int thread_bbr_dua_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
115116
*
116117
* \param interface_id addr_data_ptr
117118
*/
118-
ipv6_route_info_t *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
119+
struct ipv6_route *thread_bbr_dua_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
119120

120121
#else
121122
#define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL)

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,15 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
460460
return 0;
461461
}
462462
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, this->interface_id, NULL);
463-
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
463+
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_DUA_HOST || !route->info.info) {
464464
//address not in mesh
465465
return 0;
466466
}
467467
if (thread_meshcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_RLOC16, &rloc) > 1) {
468468
rloc_ptr = &rloc;
469469
}
470470

471-
uint32_t last_transaction_time = 30;
471+
uint32_t last_transaction_time = protocol_core_monotonic_time - ((thread_pbbr_dua_info_t *)route->info.info)->last_contact_time;
472472
uint8_t *ml_eid_ptr = &route->prefix[8];// TODO MLEID needs to be stored in own structure route->info.info and support for dealloc made
473473

474474
// This address is valid in our MESH
@@ -477,6 +477,44 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
477477
return 0;
478478
}
479479

480+
static void thread_pbbr_pro_bb_ntf_process(protocol_interface_info_entry_t *cur, uint8_t* network_name_ptr, uint8_t network_name_len, uint8_t *ml_eid_ptr, uint8_t *addr_data_ptr, uint32_t last_transaction_time)
481+
{
482+
(void) network_name_ptr;
483+
(void) network_name_len;
484+
thread_pbbr_dua_info_t *mleid_dua_map;
485+
thread_pbbr_t *this = thread_border_router_find_by_service(cur->id);
486+
if (!this) {
487+
return;
488+
}
489+
ipv6_route_t *route = thread_bbr_dua_entry_find(cur->id, addr_data_ptr);
490+
if (!route || !route->info.info) {
491+
return;
492+
}
493+
mleid_dua_map = route->info.info;
494+
if (memcmp(mleid_dua_map->mleid_ptr, ml_eid_ptr, 8) == 0) {
495+
// matching ml-eid present in our dua map, device has roamed
496+
if (last_transaction_time <= protocol_core_monotonic_time - mleid_dua_map->last_contact_time) {
497+
// remove entry
498+
goto remove_entry;
499+
} else {
500+
thread_border_router_bb_ans_send(this, this->pbbr_multicast_address, addr_data_ptr, ml_eid_ptr, protocol_core_monotonic_time - mleid_dua_map->last_contact_time, thread_joiner_application_network_name_get(cur->id), NULL);
501+
return;
502+
}
503+
}
504+
505+
// duplicate dua address detected
506+
// Address should be ML-prefix + MLeid TODO create spec issue
507+
uint8_t destination_address[16];
508+
thread_management_get_ml_prefix(cur->id, destination_address);
509+
memcpy(&destination_address[8], mleid_dua_map->mleid_ptr, 8);
510+
thread_resolution_client_address_error(cur->id, destination_address, addr_data_ptr, mleid_dua_map->mleid_ptr);
511+
512+
remove_entry:
513+
tr_info("Remove dua registration for %s", trace_ipv6(addr_data_ptr));
514+
ipv6_route_delete(route->prefix, route->prefix_len, cur->id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_DUA_HOST);
515+
return;
516+
}
517+
480518
static int thread_pbbr_dua_duplicate_address_detection(int8_t service_id, uint8_t *addr_data_ptr, uint8_t *ml_eid_ptr)
481519
{
482520
thread_pbbr_t *this = thread_border_router_find_by_service(service_id);
@@ -512,9 +550,6 @@ static int thread_pbbr_dua_duplicate_address_detection(int8_t service_id, uint8_
512550
ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_DUA_HOST);
513551
}
514552
return 0;
515-
516-
// TODO check last transaction time for migrated device if this answer is newer delete entry
517-
// ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_HOST);
518553
}
519554

520555
static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16], uint16_t source_port, sn_coap_hdr_s *request_ptr)
@@ -562,11 +597,7 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
562597

563598
// If rloc16 is present then a/an is sent to the thread device with the rloc
564599
if (thread_tmfcop_tlv_data_get_uint16(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_RLOC16, &rloc16) != 2) {
565-
// this is Pro active ANS to inform that device has moved in new network
566-
// This message was sent to multicast address
567-
// in spec there is checks for Last transaction time, but we always know that this message has zero and we have lower
568-
// TODO create function to process
569-
// Delete route to DUA as it is moved
600+
thread_pbbr_pro_bb_ntf_process(cur,network_name_ptr,network_name_len,ml_eid_ptr,addr_data_ptr,last_transaction_time);
570601
return 0;
571602
}
572603

@@ -787,8 +818,10 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
787818
tr_debug("DUA.req addr:%s ml_eid:%s", trace_array(addr_data_ptr, addr_len), trace_array(ml_eid_ptr, ml_eid_len));
788819

789820
entry_keep_alive = false;
790-
// TODO add ml_eid to structure saved in info pointer to detect duplicates
791-
if (thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr) != NULL) {
821+
ipv6_route_t *route = thread_bbr_dua_entry_find(this->interface_id, addr_data_ptr);
822+
823+
if ( route != NULL && route->info.info != NULL) {
824+
((thread_pbbr_dua_info_t *)route->info.info)->last_contact_time = protocol_core_monotonic_time;
792825
entry_keep_alive = true;
793826
}
794827
if (thread_bbr_dua_entry_add(this->interface_id, addr_data_ptr, 0xFFFFFFFF, ml_eid_ptr) != 0) {
@@ -803,8 +836,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
803836
}
804837
*/
805838

806-
// Update entry timeout value and sequence number needs to be stored
807-
808839
if (entry_keep_alive) {
809840
// send proactive BB_ans.ntf
810841
thread_border_router_bb_ans_send(this, this->pbbr_multicast_address, addr_data_ptr, ml_eid_ptr, 0, link_configuration_ptr->name, NULL);

source/6LoWPAN/Thread/thread_extension_bbr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
extern "C" {
3939
#endif
4040

41+
/*
42+
* Thread PBBR ML-EID map structure
43+
*/
44+
typedef struct thread_pbbr_dua_info {
45+
uint8_t mleid_ptr[8];
46+
uint32_t last_contact_time;
47+
} thread_pbbr_dua_info_t;
48+
4149
#if defined(HAVE_THREAD_V2) && defined(HAVE_THREAD_BORDER_ROUTER)
4250

4351
int8_t thread_extension_bbr_init(int8_t interface_id, int8_t backbone_interface_id);

0 commit comments

Comments
 (0)