Skip to content

Commit

Permalink
Merge pull request #20915 from fabian18/pr/gcoap_forward_proxy_timeout
Browse files Browse the repository at this point in the history
gcoap/forward_proxy: handle timeout case
  • Loading branch information
benpicco authored Oct 23, 2024
2 parents faa1003 + 224fdb2 commit d6759c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion sys/net/application_layer/gcoap/forward_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo,
/* No harm done in removing a timer that's not active */
ztimer_remove(ZTIMER_MSEC, &cep->empty_ack_timer);
buf_len = coap_get_total_len(pdu);
assert(memo->state == GCOAP_MEMO_RESP ||
memo->state == GCOAP_MEMO_RESP_TRUNC ||
memo->state == GCOAP_MEMO_TIMEOUT);
if (memo->state == GCOAP_MEMO_RESP) {
uint8_t req_etag_len = _cep_get_req_etag_len(cep);

Expand Down Expand Up @@ -304,6 +307,7 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo,
}
#endif
}
_set_response_type(pdu, _cep_get_response_type(cep));
/* we do not need to check if valid came from upstream as this is already automatically
* converted by the client-side to the cached response */
/* else forward the response packet as-is to the client */
Expand All @@ -315,8 +319,13 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo,
assert(buf_len >= (sizeof(*pdu->hdr) + 4U));
gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_INTERNAL_SERVER_ERROR);
coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
_set_response_type(pdu, _cep_get_response_type(cep));
}
else if (memo->state == GCOAP_MEMO_TIMEOUT) {
/* send RST */
gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_EMPTY);
coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
}
_set_response_type(pdu, _cep_get_response_type(cep));
/* don't use buf_len here, in case the above `gcoap_resp_init`s changed `pdu` */
_dispatch_msg(pdu->hdr, coap_get_total_len(pdu), &cep->ep, &cep->proxy_ep);
_free_client_ep(cep);
Expand Down
4 changes: 3 additions & 1 deletion sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,9 @@ static void _expire_request(gcoap_request_memo_t *memo)
/* Pass response to handler */
if (memo->resp_handler) {
coap_pkt_t req;

memset(&req, 0, sizeof(req));
/* 0 means there is an observe option value */
coap_clear_observe(&req);
req.hdr = gcoap_request_memo_get_hdr(memo);
memo->resp_handler(memo, &req, NULL);
}
Expand Down

0 comments on commit d6759c1

Please sign in to comment.