From d989bb174c2e6c38e889467810926ed29e2d93c5 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 10 Jun 2015 17:55:36 +0200 Subject: [PATCH] net.c: Suppress RST and error responses for multicast requests When a request has been received via IP multicast, negative responses including RST should not be sent. This modification uses the new result code COAP_DROPPED_RESPONSE to indicate that the response was intentionally suppressed. As the error handling code only checks for COAP_INVALID_TID, no error messages will be emitted due to this new behavior. --- src/net.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/net.c b/src/net.c index bc8e5f86..6b671a2c 100644 --- a/src/net.c +++ b/src/net.c @@ -558,6 +558,13 @@ coap_send_impl(coap_context_t *context, if ( !context || !dst || !pdu ) return id; + /* Do not send error responses for requests that were received via + * IP multicast. */ + if (coap_is_mcast(&local_interface->addr) && + COAP_RESPONSE_CLASS(pdu->hdr->code) > 2) { + return COAP_DROPPED_RESPONSE; + } + bytes_written = context->network_send(context, local_interface, dst, (unsigned char *)pdu->hdr, pdu->length); @@ -1372,7 +1379,7 @@ handle_request(coap_context_t *context, coap_queue_t *node) { debug("unhandled request for unknown resource 0x%02x%02x%02x%02x\r\n", key[0], key[1], key[2], key[3]); - if (!coap_mcast_interface(&node->local_if)) + response = coap_new_error_response(node->pdu, COAP_RESPONSE_CODE(405), opt_filter); } @@ -1608,8 +1615,11 @@ coap_dispatch(coap_context_t *context, coap_queue_t *rcvd) { debug("dropped message with invalid code (%d.%02d)\n", COAP_RESPONSE_CLASS(rcvd->pdu->hdr->code), rcvd->pdu->hdr->code & 0x1f); - coap_send_message_type(context, &rcvd->local_if, &rcvd->remote, - rcvd->pdu, COAP_MESSAGE_RST); + + if (!coap_is_mcast(&rcvd->local_if.addr)) { + coap_send_message_type(context, &rcvd->local_if, &rcvd->remote, + rcvd->pdu, COAP_MESSAGE_RST); + } } }