From 2cd785791d127c1f1286edcd175011ed538cb3e9 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Tue, 9 Aug 2022 16:18:57 +0200 Subject: [PATCH 1/3] gcoap: send empty RST on unknown CON response --- sys/net/application_layer/gcoap/gcoap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index c6fa2e4f10..c6bfb92bbd 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -487,6 +487,13 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ } else { DEBUG("gcoap: msg not found for ID: %u\n", coap_get_id(&pdu)); + if (coap_get_type(&pdu) == COAP_TYPE_CON) { + /* we might run into this if an ACK to a sender got lost + * see https://datatracker.ietf.org/doc/html/rfc7252#section-5.3.2 */ + messagelayer_emptyresponse_type = COAP_TYPE_RST; + DEBUG("gcoap: Answering unknown CON response with RST to " + "shut up sender\n"); + } } break; default: From b616c17e46706e515ea12fa3bc3df8dbb0925f14 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Tue, 9 Aug 2022 16:20:22 +0200 Subject: [PATCH 2/3] gcoap: expire memo if there is nothing to wait for --- sys/net/application_layer/gcoap/gcoap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index c6bfb92bbd..567e39b87a 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -579,6 +579,11 @@ static void _on_resp_timeout(void *arg) { */ static void _cease_retransmission(gcoap_request_memo_t *memo) { memo->state = GCOAP_MEMO_WAIT; + /* there is also no response handler to wait for => expire memo */ + if (memo->resp_handler == NULL) { + event_timeout_clear(&memo->resp_evt_tmout); + _expire_request(memo); + } } /* From f11c9e837db0d4b2b146f7328583640fd324e433 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Wed, 10 Aug 2022 16:05:44 +0200 Subject: [PATCH 3/3] gcoap: expire memo and stop retransmissions on RESET reception --- sys/net/application_layer/gcoap/gcoap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 567e39b87a..3c112bc9b2 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -381,6 +381,15 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ return; } + if (coap_get_type(&pdu) == COAP_TYPE_RST) { + DEBUG("gcoap: received RST, expiring potentially existing memo\n"); + _find_req_memo(&memo, &pdu, remote, true); + if (memo) { + event_timeout_clear(&memo->resp_evt_tmout); + _expire_request(memo); + } + } + /* validate class and type for incoming */ switch (coap_get_code_class(&pdu)) { /* incoming request or empty */