From 9bc0454d9972b92b1814856821d25366260709d7 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 18 Aug 2022 12:05:26 +0200 Subject: [PATCH 1/2] gcoap_forward_proxy: copy Max-Age from forwarded Valid if it exists --- sys/net/application_layer/gcoap/forward_proxy.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sys/net/application_layer/gcoap/forward_proxy.c b/sys/net/application_layer/gcoap/forward_proxy.c index 5beb915670..5e976c53c5 100644 --- a/sys/net/application_layer/gcoap/forward_proxy.c +++ b/sys/net/application_layer/gcoap/forward_proxy.c @@ -210,8 +210,19 @@ static void _forward_resp_handler(const gcoap_request_memo_t *memo, /* check if we can just send 2.03 Valid instead */ if ((cep->req_etag_len == coap_opt_get_opaque(pdu, COAP_OPT_ETAG, &resp_etag)) && (memcmp(cep->req_etag, resp_etag, cep->req_etag_len) == 0)) { + uint32_t max_age; + + if (coap_opt_get_uint(pdu, COAP_OPT_MAX_AGE, &max_age) < 0) { + /* use default, + * see https://datatracker.ietf.org/doc/html/rfc7252#section-5.10.5 */ + max_age = 60U; + } gcoap_resp_init(pdu, (uint8_t *)pdu->hdr, buf_len, COAP_CODE_VALID); coap_opt_add_opaque(pdu, COAP_OPT_ETAG, cep->req_etag, cep->req_etag_len); + if (max_age != 60U) { + /* only include Max-Age option if it is not the default value */ + coap_opt_add_uint(pdu, COAP_OPT_MAX_AGE, max_age); + } coap_opt_finish(pdu, COAP_OPT_FINISH_NONE); } } From 1135cc0f7e2c98c9bbbe5f3d108ad74d6cccfdac Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 18 Aug 2022 14:38:37 +0200 Subject: [PATCH 2/2] gcoap: fix swap-out of option length for ETag --- sys/net/application_layer/gcoap/gcoap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 8e3a53ab8d..016f02931b 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -1334,7 +1334,7 @@ static ssize_t _cache_check(const uint8_t *buf, size_t len, uint8_t *start = coap_find_option(&req, COAP_OPT_ETAG); /* option length must always be <= COAP_ETAG_LENGTH_MAX = 8 < 12, so the length * is encoded in the first byte, see also RFC 7252, section 3.1 */ - *start &= 0x0f; + *start &= 0xf0; /* first if around here should make sure we are <= 8 < 0xf, so we don't need to * bitmask resp_etag_len */ *start |= (uint8_t)resp_etag_len;