1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gcoap_dns: implement Max-Age-based TTL calculation

This commit is contained in:
Martine Lenders 2022-08-11 14:38:03 +02:00
parent a93ba1ef80
commit 6f18132e98
No known key found for this signature in database
GPG Key ID: 2134D77A5336DD80

View File

@ -740,11 +740,17 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t *pdu,
switch (coap_get_content_type(pdu)) {
case COAP_FORMAT_DNS_MESSAGE:
case COAP_FORMAT_NONE: {
uint32_t ttl;
uint32_t ttl = 0;
context->res = dns_msg_parse_reply(data, data_len, family,
context->addr_out, &ttl);
if (context->res > 0) {
if (IS_USED(MODULE_DNS_CACHE) && (context->res > 0)) {
uint32_t max_age;
if (coap_opt_get_uint(pdu, COAP_OPT_MAX_AGE, &max_age) < 0) {
max_age = 60;
}
ttl += max_age;
dns_cache_add(_domain_name_from_ctx(context), context->addr_out, context->res, ttl);
}
else if (ENABLE_DEBUG && (context->res < 0)) {