Skip to content

Commit

Permalink
coap_openssl.c: Add in support for changing the DTLS retry timeout
Browse files Browse the repository at this point in the history
As done for GnuTLS and MbedTLS, add compile time support for changing
the DTLS retry timoouts.

$ ./configure CFLAGS=-DCOAP_DTLS_RETRANSMIT_MS=3000

to make it 3000 ms instead of the default of 1000ms.
  • Loading branch information
mrdeep1 committed Feb 20, 2024
1 parent 9510cf9 commit 7660069
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/coap_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,19 @@ coap_set_user_prefs(SSL_CTX *ctx) {
#endif
}

#if COAP_DTLS_RETRANSMIT_MS != 1000
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
static unsigned int
timer_cb(SSL *s, unsigned int timer_us) {
(void)s;
if (timer_us == 0)
return COAP_DTLS_RETRANSMIT_MS * 1000;
else
return 2 * timer_us;
}
#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
#endif /* COAP_DTLS_RETRANSMIT_MS != 1000 */

void *
coap_dtls_new_context(coap_context_t *coap_context) {
coap_openssl_context_t *context;
Expand Down Expand Up @@ -2957,6 +2970,13 @@ setup_client_ssl_session(coap_session_t *session, SSL *ssl
SSL_set_verify_depth(ssl, setup_data->cert_chain_verify_depth + 1);

}
#if COAP_DTLS_RETRANSMIT_MS != 1000
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
if (session->proto == COAP_PROTO_DTLS) {
DTLS_set_timer_cb(ssl, timer_cb);
}
#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
#endif /* COAP_DTLS_RETRANSMIT_MS != 1000 */
return 1;
}

Expand Down Expand Up @@ -3402,6 +3422,14 @@ coap_tls_new_server_session(coap_session_t *session) {
session->sock.lfunc[COAP_LAYER_TLS].l_establish(session);
}

#if COAP_DTLS_RETRANSMIT_MS != 1000
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
if (session->proto == COAP_PROTO_DTLS) {
DTLS_set_timer_cb(ssl, timer_cb);
}
#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
#endif /* COAP_DTLS_RETRANSMIT_MS != 1000 */

return ssl;

error:
Expand Down

0 comments on commit 7660069

Please sign in to comment.