DTLS: Detect connection issues

Supports upstream reconnection attempt detections.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2025-05-05 09:11:20 +01:00
1 parent 97ab322f8d
commit d03c0d4145
5 files changed
+17 -3

No files matched your search

+2
View File
@@ -2052,6 +2052,8 @@ coap_dgram_write(gnutls_transport_ptr_t context, const void *send_buffer,
result, send_buffer_length);
errno = keep_errno;
if (result < 0) {
if (errno == ENOTCONN || errno == ECONNREFUSED)
c_session->dtls_event = COAP_EVENT_DTLS_ERROR;
return -1;
} else {
result = 0;
+2
View File
@@ -251,6 +251,8 @@ coap_dgram_write(void *ctx, const unsigned char *send_buffer,
result, send_buffer_length);
errno = keep_errno;
if (result < 0) {
if (errno == ENOTCONN || errno == ECONNREFUSED)
c_session->dtls_event = COAP_EVENT_DTLS_ERROR;
return -1;
} else {
result = 0;
+4 -1
View File
@@ -636,8 +636,11 @@ coap_dgram_write(BIO *a, const char *in, int inl) {
(const uint8_t *)in,
inl);
BIO_clear_retry_flags(a);
if (ret <= 0)
if (ret <= 0) {
if (ret < 0 && (errno == ENOTCONN || errno == ECONNREFUSED))
data->session->dtls_event = COAP_EVENT_DTLS_ERROR;
BIO_set_retry_write(a);
}
} else {
BIO_clear_retry_flags(a);
ret = -1;
+5 -2
View File
@@ -365,6 +365,7 @@ dtls_send_to_peer(struct dtls_context_t *dtls_context,
coap_context_t *coap_context = t_context ? t_context->coap_context : NULL;
coap_session_t *coap_session;
coap_address_t remote_addr;
int ret;
assert(coap_context);
get_session_addr(dtls_session, &remote_addr);
@@ -373,8 +374,10 @@ dtls_send_to_peer(struct dtls_context_t *dtls_context,
coap_log_warn("dtls_send_to_peer: cannot find local interface\n");
return -3;
}
return (int)coap_session->sock.lfunc[COAP_LAYER_TLS].l_write(coap_session,
data, len);
ret = (int)coap_session->sock.lfunc[COAP_LAYER_TLS].l_write(coap_session, data, len);
if (ret == -1 && (errno == ENOTCONN || errno == ECONNREFUSED))
coap_session->dtls_event = COAP_EVENT_DTLS_ERROR;
return ret;
}
static int
+4
View File
@@ -559,6 +559,9 @@ coap_dgram_write(WOLFSSL *ssl, char *in, int inl, void *ctx) {
if (ret > 0) {
coap_ticks(&now);
w_env->last_timeout = now;
} else if (ret < 0) {
if (errno == ENOTCONN || errno == ECONNREFUSED)
data->session->dtls_event = COAP_EVENT_DTLS_ERROR;
}
} else {
ret = -1;
@@ -2218,6 +2221,7 @@ coap_dtls_free_session(coap_session_t *session) {
coap_handle_event_lkd(session->context, COAP_EVENT_DTLS_CLOSED, session);
}
coap_dtls_free_wolfssl_env(w_env);
session->tls = NULL;
}
ssize_t