Skip to content

Commit

Permalink
Merge pull request #18443 from miri64/gcoap_dns/enh/implement-max_age…
Browse files Browse the repository at this point in the history
…-ttl-algorithm

gcoap_dns: implement Max-Age-based TTL calculation
  • Loading branch information
miri64 authored Sep 19, 2022
2 parents d5e63a5 + 6f18132 commit ff64898
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sys/net/application_layer/gcoap/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,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)) {
Expand Down

0 comments on commit ff64898

Please sign in to comment.