From 704057e6834baa89b761d6323a58539fccd28891 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Tue, 8 Dec 2020 16:48:52 +0000 Subject: [PATCH] ICMP reporting: Call nack handler when ICMP unreachable is received coap_session_disconnected() does not call the nack handler for any outstanding CON requests when called with COAP_NACK_ICMP_ISSUE. src/coap_session.c: Call the nack handler if coap_session_disconnected is called with COAP_NACK_ICMP_ISSUE. --- src/coap_session.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/coap_session.c b/src/coap_session.c index d4f0ee28d5..5b945976a7 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -463,8 +463,13 @@ void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reaso && reason == COAP_NACK_ICMP_ISSUE) { /* Make sure that we try a re-transmit later on ICMP error */ - if (coap_wait_ack(session->context, session, q) >= 0) + if (coap_wait_ack(session->context, session, q) >= 0) { + if (session->context->nack_handler) { + session->context->nack_handler(session->context, session, q->pdu, + reason, q->id); + } q = NULL; + } } if (q && q->pdu->type == COAP_MESSAGE_CON && session->context->nack_handler) @@ -475,8 +480,19 @@ void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reaso if (q) coap_delete_node(q); } - if (reason != COAP_NACK_ICMP_ISSUE) + if (reason != COAP_NACK_ICMP_ISSUE) { coap_cancel_session_messages(session->context, session, reason); + } + else if (session->context->nack_handler) { + coap_queue_t *q = session->context->sendqueue; + while (q) { + if (q->session == session) { + session->context->nack_handler(session->context, session, q->pdu, + reason, q->id); + } + q = q->next; + } + } #if !COAP_DISABLE_TCP if (COAP_PROTO_RELIABLE(session->proto)) {