Skip to content

Commit 115aa3e

Browse files
author
Tero Heinonen
authored
Delete all transactions when secure session is closed (#41)
When handshake fails, or DTLS session is closed, all transactions must be removed from coap protocol retransmission queue. Otherwise coap retransmission will start new handshake.
1 parent b4b5041 commit 115aa3e

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

source/coap_connection_handler.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static secure_session_t *secure_session_find_by_timer_id(int8_t timer_id)
9595
static void secure_session_delete(secure_session_t *this)
9696
{
9797
if (this) {
98+
transactions_delete_all(this->parent->dest_addr.address, this->parent->dest_addr.identifier);
9899
ns_list_remove(&secure_session_list, this);
99100
if( this->sec_handler ){
100101
coap_security_destroy(this->sec_handler);
@@ -529,6 +530,7 @@ static void secure_recv_sckt_msg(void *cb_res)
529530
internal_socket_t *sock = int_socket_find_by_socket_id(sckt_data->socket_id);
530531
ns_address_t src_address;
531532
uint8_t dst_address[16];
533+
memset(&src_address, 0, sizeof(ns_address_t));
532534

533535
if (sock && read_data(sckt_data, sock, &src_address, dst_address) == 0) {
534536
secure_session_t *session = secure_session_find(sock, src_address.address, src_address.identifier);

source/coap_message_handler.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ void transaction_delete(coap_transaction_t *this)
9393
return;
9494
}
9595

96+
void transactions_delete_all(uint8_t *address_ptr, uint16_t port)
97+
{
98+
coap_transaction_t *transaction = transaction_find_by_address(address_ptr, port);
99+
100+
while (transaction) {
101+
sn_coap_protocol_delete_retransmission(coap_service_handle->coap, transaction->msg_id);
102+
transaction_delete(transaction);
103+
transaction = transaction_find_by_address(address_ptr, port);
104+
}
105+
}
106+
96107
static int8_t coap_rx_function(sn_coap_hdr_s *resp_ptr, sn_nsdl_addr_s *address_ptr, void *param)
97108
{
98109
coap_transaction_t *this = NULL;

source/include/coap_message_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,6 @@ extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t cur
8888

8989
extern void transaction_delete(coap_transaction_t *this);
9090

91+
extern void transactions_delete_all(uint8_t *address_ptr, uint16_t port);
92+
9193
#endif

source/include/coap_service_api_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#ifndef __COAP_SERVICE_API_INTERNAL_H__
2020
#define __COAP_SERVICE_API_INTERNAL_H__
2121

22+
#include "coap_message_handler.h"
23+
24+
25+
extern coap_msg_handler_t *coap_service_handle;
2226

2327
uint32_t coap_service_get_internal_timer_ticks(void);
2428

test/coap-service/unittest/coap_connection_handler/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TEST_SRC_FILES = \
1818
../stub/socket_api_stub.c \
1919
../stub/coap_security_handler_stub.c \
2020
../stub/coap_service_api_stub.c \
21+
../stub/coap_message_handler_stub.c \
2122

2223
include ../MakefileWorker.mk
2324

test/coap-service/unittest/stub/coap_message_handler_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ void transaction_delete(coap_transaction_t *this)
2222

2323
}
2424

25+
void transactions_delete_all(uint8_t *address_ptr, uint16_t port)
26+
{
27+
28+
}
2529
int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
2630
{
2731
return coap_message_handler_stub.int8_value;

test/coap-service/unittest/stub/coap_service_api_stub.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "common_functions.h"
1919
#include "net_interface.h"
2020

21+
coap_msg_handler_t *coap_service_handle = NULL;
22+
2123
int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options,
2224
coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *coap_security_done_cb)
2325
{

test/coap-service/unittest/stub/sn_coap_protocol_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ coap_send_msg_s *sn_coap_protocol_allocate_mem_for_msg(struct coap_s *handle, sn
9494
return sn_coap_protocol_stub.expectedSendMsg;
9595
}
9696

97+
int8_t sn_coap_protocol_delete_retransmission(struct coap_s *handle, uint16_t msg_id)
98+
{
99+
return 0;
100+
}

0 commit comments

Comments
 (0)