From f453902425b3a29d1559413eba5407ddba7c4cae Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Fri, 9 Mar 2018 15:08:14 +0000 Subject: [PATCH] src/net.c: Support RFC8323 for empty messages and rate limit RSTs Do not send back a RST is there is receipt of an empty message and using TCP. Otherwise, rate limit RST packets to 4 a second when receiving empty messages --- src/net.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/net.c b/src/net.c index bd2fc11f..70ac3a3e 100644 --- a/src/net.c +++ b/src/net.c @@ -2144,7 +2144,19 @@ coap_dispatch(coap_context_t *context, coap_session_t *session, pdu->code & 0x1f); if (!coap_is_mcast(&session->local_addr)) { - coap_send_message_type(session, pdu, COAP_MESSAGE_RST); + if (COAP_PDU_IS_EMPTY(pdu)) { + if (session->proto != COAP_PROTO_TCP && session->proto != COAP_PROTO_TLS) { + coap_tick_t now; + coap_ticks(&now); + if (session->last_tx_rst + COAP_TICKS_PER_SECOND/4 < now) { + coap_send_message_type(session, pdu, COAP_MESSAGE_RST); + session->last_tx_rst = now; + } + } + } + else { + coap_send_message_type(session, pdu, COAP_MESSAGE_RST); + } } }