Use A(AAA) when querying for domain on cache expire
[project/mdnsd.git] / cache.c
diff --git a/cache.c b/cache.c
index 2bf8257df0982e82f98cb8c20371be8d30157317..756ae6859983c16653ddb7b26ca20101e72e57bb 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -89,7 +89,12 @@ cache_gc_timer(struct uloop_timeout *timeout)
                        continue;
                }
                s->refresh += 50;
-               dns_send_question(s->iface, s->entry, TYPE_PTR, 1);
+               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);
+               }
        }
 
        uloop_timeout_set(timeout, 10000);
@@ -121,14 +126,14 @@ void cache_cleanup(struct interface *iface)
 }
 
 void
-cache_scan(void)
+cache_update(void)
 {
        struct interface *iface;
        struct cache_service *s;
 
        vlist_for_each_element(&interfaces, iface, node)
                avl_for_each_element(&services, s, avl)
-                       dns_send_question(iface, s->entry, TYPE_PTR, 1);
+                       dns_send_question(iface, s->entry, TYPE_PTR, 0);
 }
 
 static struct cache_service*
@@ -143,6 +148,7 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl)
                if (!strcmp(s->entry, entry)) {
                        s->refresh = 50;
                        s->time = monotonic_time();
+                       s->ttl = ttl;
                        return s;
                }
 
@@ -167,7 +173,7 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl)
        avl_insert(&services, &s->avl);
 
        if (!hlen)
-               dns_send_question(iface, entry, TYPE_PTR, !iface->multicast);
+               dns_send_question(iface, entry, TYPE_PTR, iface->multicast);
 
        return s;
 }
@@ -239,6 +245,7 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
        void *rdata_ptr, *txt_ptr;
        int host_len = 0;
        static char *rdata_buffer = (char *) mdns_buf;
+       time_t now = monotonic_time();
 
        nlen = strlen(name);
 
@@ -322,9 +329,10 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
        if (r) {
                if (!a->ttl) {
                        DBG(1, "D -> %s %s ttl:%d\n", dns_type_string(r->type), r->record, r->ttl);
-                       r->time = monotonic_time() + 1 - r->ttl;
+                       r->time = now + 1 - r->ttl;
                } else {
                        r->ttl = a->ttl;
+                       r->time = now;
                        DBG(1, "A -> %s %s ttl:%d\n", dns_type_string(r->type), r->record, r->ttl);
                }
                return;
@@ -343,7 +351,7 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
        r->ttl = a->ttl;
        r->port = port;
        r->rdlength = dlen;
-       r->time = monotonic_time();
+       r->time = now;
        r->iface = iface;
 
        if (tlen)