Skip to content

Commit 350d20e

Browse files
SeppoTakalommahadevan108
authored andcommitted
net: lib: coap_client: Send RST for unknown queries
When receiving unknown response, respond with CoAP Reset. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 1dc2487 commit 350d20e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,26 @@ static int send_ack(struct coap_client *client, const struct coap_packet *req,
651651
return 0;
652652
}
653653

654+
static int send_rst(struct coap_client *client, const struct coap_packet *req)
655+
{
656+
int ret;
657+
struct coap_packet rst;
658+
659+
ret = coap_rst_init(&rst, req, client->send_buf, MAX_COAP_MSG_LEN);
660+
if (ret < 0) {
661+
LOG_ERR("Failed to initialize CoAP RST-message");
662+
return ret;
663+
}
664+
665+
ret = send_request(client->fd, rst.data, rst.offset, 0, &client->address, client->socklen);
666+
if (ret < 0) {
667+
LOG_ERR("Error sending a CoAP RST-message");
668+
return ret;
669+
}
670+
671+
return 0;
672+
}
673+
654674
static struct coap_client_internal_request *get_request_with_token(
655675
struct coap_client *client, const struct coap_packet *resp)
656676
{
@@ -750,6 +770,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet
750770
internal_req = get_request_with_token(client, response);
751771
if (!internal_req) {
752772
LOG_WRN("No matching request for response");
773+
(void) send_rst(client, response); /* Ignore errors, unrelated to our queries */
753774
return 0;
754775
}
755776

0 commit comments

Comments
 (0)