Skip to content

Commit bade70e

Browse files
Dua req changes (ARMmbed#1494)
DUA.req handling refactored.
1 parent 1979df8 commit bade70e

File tree

6 files changed

+92
-37
lines changed

6 files changed

+92
-37
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "thread_management_server.h"
6161
#include "socket_api.h"
6262
#include "coap_service_api.h"
63+
#include "Common_Protocols/icmpv6.h"
6364

6465
#define TRACE_GROUP "tBBR"
6566

@@ -942,6 +943,48 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
942943
#endif // HAVE_THREAD_ROUTER
943944

944945
#ifdef HAVE_THREAD_BORDER_ROUTER
946+
static int thread_bbr_na_send(int8_t interface_id, uint32_t lifetime, const uint8_t target[static 16])
947+
{
948+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
949+
if (!cur) {
950+
return -1;
951+
}
952+
953+
buffer_t *buffer = icmpv6_build_na(cur, false, true, true, target, NULL, ADDR_UNSPECIFIED);
954+
protocol_push(buffer);
955+
return 0;
956+
957+
}
958+
int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr) {
959+
(void) mleid_ptr;
960+
thread_bbr_t *this = thread_bbr_find_by_interface(interface_id);
961+
if (!this || this->backbone_interface_id < 0) {
962+
tr_err("bbr not ready");
963+
return -1;
964+
}
965+
ipv6_route_t *route = ipv6_route_add_with_info(addr_data_ptr, 128, interface_id, NULL, ROUTE_THREAD_PROXIED_HOST, info, 0, lifetime, 0);
966+
// We are using route info field to store sequence number
967+
if (!route) {
968+
// Direct route to host allows ND proxying to work
969+
tr_err("out of resources");
970+
return -2;
971+
}
972+
// send NA
973+
thread_bbr_na_send(this->backbone_interface_id, lifetime, addr_data_ptr);
974+
975+
return 0;
976+
}
977+
978+
int thread_bbr_nd_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr) {
979+
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, interface_id, NULL);
980+
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_HOST ) {
981+
//Not found
982+
return -1;
983+
}
984+
//TODO get information to route to parameters eq mleid, timeout
985+
return 0;
986+
}
987+
945988
int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_interface_id, bool status)
946989
{
947990
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(handler_interface_id);

source/6LoWPAN/Thread/thread_bbr_api_internal.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t tics);
6565
*/
6666
int thread_bbr_commissioner_proxy_service_update(int8_t interface_id);
6767

68+
6869
#else
6970
#define thread_bbr_init(interface_id, external_commisssioner_port)
7071
#define thread_bbr_delete(interface_id)
@@ -94,10 +95,26 @@ bool thread_bbr_routing_enabled(protocol_interface_info_entry_t *cur);
9495
*/
9596
void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur);
9697

98+
/**
99+
* \brief Add new nd entry to bbr
100+
*
101+
* \param interface_id addr_data_ptr lifetime info mleid_ptr
102+
*/
103+
int thread_bbr_nd_entry_add(int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr);
104+
105+
/**
106+
* \brief Find if bbr has nd entry
107+
*
108+
* \param interface_id addr_data_ptr
109+
*/
110+
int thread_bbr_nd_entry_find(int8_t interface_id, const uint8_t *addr_data_ptr);
111+
97112
#else
98113
#define thread_bbr_proxy_state_update(caller_interface_id , handler_interface_id, status) (NULL)
99114
#define thread_bbr_routing_enabled(cur) false
100115
#define thread_bbr_network_data_update_notify(cur)
116+
#define thread_bbr_nd_entry_add(interface_id, addr_data_ptr, lifetime, info, mleid_ptr) (0)
117+
#define thread_bbr_nd_entry_find(interface_id, addr_data_ptr) (0)
101118
#endif //HAVE_THREAD_BORDER_ROUTER
102119

103120

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "6LoWPAN/Thread/thread_discovery.h"
5252
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
5353
#include "6LoWPAN/Thread/thread_extension_constants.h"
54+
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
5455
#include "NWK_INTERFACE/Include/protocol.h"
5556
#include "Common_Protocols/ipv6.h"
5657

@@ -151,21 +152,6 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
151152
return this;
152153
}
153154

154-
static duplicate_dua_tr_t *thread_border_router_dup_tr_create(int8_t interface_id, uint8_t *target_eid_ptr, sn_coap_hdr_s *request_ptr)
155-
{
156-
duplicate_dua_tr_t *this = ns_dyn_mem_alloc(sizeof(duplicate_dua_tr_t));
157-
158-
if (!this) {
159-
return NULL;
160-
}
161-
ns_list_add_to_start(&duplicate_dua_tr_list, this);
162-
memcpy(this->target_eid, target_eid_ptr,16);
163-
this->interface_id = interface_id;
164-
this->request_msg_id = request_ptr->msg_id;
165-
this->ttl = 2;
166-
return this;
167-
}
168-
169155
static void thread_border_router_dup_tr_delete(duplicate_dua_tr_t *this)
170156
{
171157

@@ -422,7 +408,6 @@ static int thread_pbbr_nmkp_req_recv_cb(int8_t service_id, uint8_t source_addres
422408
static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16], uint16_t source_port, sn_coap_hdr_s *request_ptr)
423409
{
424410
(void)source_port;
425-
(void)source_address;
426411
uint16_t addr_len;
427412
uint8_t *addr_data_ptr;
428413
tr_info("Thread BBR BB_QRY.ntf Received");
@@ -633,6 +618,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
633618
uint8_t *ml_eid_ptr;
634619
uint8_t payload[2 + 16 + 2 + 2 + 1 + 8];
635620
uint8_t domain_prefix[8];
621+
uint8_t bbr_rloc_addr[16];
636622
uint8_t *ptr;
637623
bool entry_keep_alive = false;
638624
uint8_t bbr_status = THREAD_BBR_STATUS_SUCCESS;
@@ -663,6 +649,14 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
663649
goto send_response;
664650
}
665651
*/
652+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(this->interface_id);
653+
if (0 != thread_extension_primary_bbr_get(cur, bbr_rloc_addr, NULL, NULL, NULL) ||
654+
!addr_get_entry(cur,bbr_rloc_addr)) {
655+
// Primary BBR not present or I am not BBR
656+
bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR;
657+
goto send_response;
658+
}
659+
666660
addr_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_TARGET_EID, &addr_data_ptr);
667661
ml_eid_len = thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, TMFCOP_TLV_ML_EID, &ml_eid_ptr);
668662

@@ -683,11 +677,13 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
683677

684678
entry_keep_alive = true;
685679
// TODO add ml_eid to structure saved in info pointer to detect duplicates
686-
ipv6_route_t *route = ipv6_route_choose_next_hop(addr_data_ptr, this->interface_id, NULL);
687-
if (!route || route->prefix_len < 128 || !route->on_link || route->info.source != ROUTE_THREAD_PROXIED_HOST ) {
688-
//This is new registration
680+
if (thread_bbr_nd_entry_find(this->interface_id, addr_data_ptr) == 0) {
689681
entry_keep_alive = false;
690-
route = NULL;
682+
}
683+
684+
if (thread_bbr_nd_entry_add(this->interface_id, addr_data_ptr, this->dua_timeout + this->delay_timer/500, NULL, ml_eid_ptr) == -1) {
685+
bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE;
686+
goto send_response;
691687
}
692688
/*if (route && memcmp(route->info.next_hop_addr, ml_addr,16) != 0) {
693689
// MLEID not matching duplicate detected
@@ -696,14 +692,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
696692
goto send_response;
697693
}
698694
*/
699-
route = ipv6_route_add_with_info(addr_data_ptr, 128, this->interface_id, NULL, ROUTE_THREAD_PROXIED_HOST, NULL, 0, this->dua_timeout + this->delay_timer/500, 0);
700-
// We are using route info field to store sequence number
701-
if (!route) {
702-
// Direct route to host allows ND proxying to work
703-
tr_err("out of resources");
704-
bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE;
705-
goto send_response;
706-
}
695+
707696
// Update entry timeout value and sequence number needs to be stored
708697

709698
if (entry_keep_alive) {
@@ -713,10 +702,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
713702
// send BB.qry
714703
// TODO Delay and replay this meessage and answer the response after 2 seconds passed
715704
thread_border_router_bb_qry_send(this,addr_data_ptr,NULL);
716-
if (thread_border_router_dup_tr_create(this->interface_id, addr_data_ptr, request_ptr) ) {
717-
// Waiting for duplicate timeout
718-
return 0;
719-
}
720705
}
721706
// TODO
722707
// Save RLOC to destination cache with Last transaction time. Should these be made as sticky or should I have own table for these?

source/DHCPv6_Server/DHCPv6_Server_service.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "DHCPv6_Server/DHCPv6_server_service.h"
3535
#include "common_functions.h"
3636
#include "NWK_INTERFACE/Include/protocol.h"
37+
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
3738
#include "Common_Protocols/icmpv6.h"
3839
#include "dhcp_service_api.h"
3940

@@ -105,13 +106,16 @@ int DHCPv6_server_respond_client(dhcpv6_gua_server_entry_s *serverBase, dhcpv6_r
105106
// coverity[returned_null] for ignoring protocol_stack_interface_info_get_by_id NULL return
106107
DHCPV6_server_service_remove_GUA_from_neighcache(protocol_stack_interface_info_get_by_id(serverBase->interfaceId), nonTemporalAddress.requestedAddress);
107108
}
109+
if (thread_bbr_nd_entry_add(serverBase->interfaceId,dhcp_allocated_address->nonTemporalAddress, nonTemporalAddress.validLifeTime, serverBase->guaPrefix, NULL) == -1) {
110+
// No nanostack BBR present we will put entry for application implemented BBR
111+
ipv6_route_t *route = ipv6_route_add_with_info(dhcp_allocated_address->nonTemporalAddress, 128, serverBase->interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST,serverBase->guaPrefix,0, nonTemporalAddress.validLifeTime, 0);
112+
if (!route) {
113+
address_allocated = false;
114+
libdhcpv6_address_rm_from_allocated_list(serverBase,dhcp_allocated_address->nonTemporalAddress);
115+
}
108116

109-
ipv6_route_t *route = ipv6_route_add_with_info(dhcp_allocated_address->nonTemporalAddress, 128, serverBase->interfaceId, NULL, ROUTE_THREAD_PROXIED_HOST,serverBase->guaPrefix,0, nonTemporalAddress.validLifeTime, 0);
110-
if (!route) {
111-
address_allocated = false;
112-
libdhcpv6_address_rm_from_allocated_list(serverBase,dhcp_allocated_address->nonTemporalAddress);
113-
}
114117

118+
}
115119
}
116120

117121
response->responseLength = libdhcpv6_address_reply_message_len(replyPacket->clientDUID.linkType, replyPacket->serverDUID.linkType, 0, replyPacket->rapidCommit, address_allocated);

test/nanostack/unittest/DHCPv6_Server/dhcpv6_server_service/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ TEST_SRC_FILES = \
3030
../../stub/protocol_6lowpan_stub.c \
3131
../../stub/system_timer_stub.c \
3232
../../stub/dhcp_service_api_stub.c \
33+
../../stub/thread_bbr_api_stub.c \
3334

3435
include ../../MakefileWorker.mk
3536

test/nanostack/unittest/stub/thread_bbr_api_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,8 @@ int thread_bbr_proxy_state_update(int8_t caller_interface_id , int8_t handler_in
7878
{
7979
return -1;
8080
}
81+
82+
int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr, uint32_t lifetime, void *info, const uint8_t *mleid_ptr)
83+
{
84+
return -1;
85+
}

0 commit comments

Comments
 (0)