From 80dd246024800b3f33bacc6cf01184da6f57dfa4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 10 Mar 2017 08:59:22 +0100 Subject: [PATCH] Refresh DNS records A and AAAA directly MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit So far records A and AAAA were being connected and stored as a single *service*. It's possible to handle these records directly without this service trick and it also provides better control over them (some corner cases like different TTL values). Signed-off-by: Rafał Miłecki --- cache.c | 25 +++++++++++++++++-------- cache.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cache.c b/cache.c index 3f3f617..08f6308 100644 --- a/cache.c +++ b/cache.c @@ -75,9 +75,21 @@ cache_gc_timer(struct uloop_timeout *timeout) struct cache_record *r, *p; struct cache_service *s, *t; - avl_for_each_element_safe(&records, r, avl, p) - if (cache_is_expired(r->time, r->ttl, 100)) + avl_for_each_element_safe(&records, r, avl, p) { + if (!cache_is_expired(r->time, r->ttl, 100)) + continue; + /* Records other and A(AAA) are handled as services */ + if (r->type != TYPE_A && r->type != TYPE_AAAA) { + cache_record_free(r); + continue; + } + if (r->refresh >= 100) { cache_record_free(r); + continue; + } + r->refresh += 50; + dns_send_question(r->iface, r->record, r->type, 0); + } avl_for_each_element_safe(&services, s, avl, t) { if (!s->host) @@ -89,12 +101,9 @@ cache_gc_timer(struct uloop_timeout *timeout) continue; } s->refresh += 50; - if (cache_service_is_host(s)) { - dns_send_question(s->iface, s->entry, TYPE_A, 0); - dns_send_question(s->iface, s->entry, TYPE_AAAA, 0); - } else { - dns_send_question(s->iface, s->entry, TYPE_PTR, 0); - } + if (cache_service_is_host(s)) + continue; + dns_send_question(s->iface, s->entry, TYPE_PTR, 0); } uloop_timeout_set(timeout, 10000); diff --git a/cache.h b/cache.h index cfd6368..1315aad 100644 --- a/cache.h +++ b/cache.h @@ -44,6 +44,7 @@ struct cache_record { uint16_t rdlength; time_t time; struct interface *iface; + int refresh; }; extern struct avl_tree services; -- 2.11.0