Fix sending unicast questions on cache expire
authorRafał Miłecki <rafal@milecki.pl>
Mon, 20 Mar 2017 23:00:16 +0000 (00:00 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 21 Mar 2017 21:55:56 +0000 (22:55 +0100)
Sending unicast questions requires passing IP address. Pass the one that
was cached when caching DNS record.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
announce.c
cache.c
dns.c
dns.h
interface.c
ubus.c

index fed1b212fe2fb5a754a7429a5a9c7f8a5179c9e3..3c8ea1623f53c9e7c7c137ead855cde6e7e1c8a2 100644 (file)
@@ -46,7 +46,7 @@ announce_timer(struct uloop_timeout *timeout)
                case STATE_PROBE1:
                case STATE_PROBE2:
                case STATE_PROBE3:
-                       dns_send_question(iface, mdns_hostname_local, TYPE_ANY, 1);
+                       dns_send_question(iface, NULL, mdns_hostname_local, TYPE_ANY, 1);
                        uloop_timeout_set(timeout, 250);
                        iface->announce_state++;
                        break;
diff --git a/cache.c b/cache.c
index fea9035609253b67172e332e2aca3ac6a70e51a3..7d2aa8fdba2d467320c74cc4db53990dfc9db01c 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -89,7 +89,7 @@ cache_gc_timer(struct uloop_timeout *timeout)
                        continue;
                }
                r->refresh += 50;
-               dns_send_question(r->iface, r->record, r->type, 0);
+               dns_send_question(r->iface, (struct sockaddr *)&r->from, r->record, r->type, 0);
        }
 
        avl_for_each_element_safe(&services, s, avl, t) {
@@ -102,7 +102,7 @@ cache_gc_timer(struct uloop_timeout *timeout)
                        continue;
                }
                s->refresh += 50;
-               dns_send_question(s->iface, s->entry, TYPE_PTR, 0);
+               dns_send_question(s->iface, NULL, s->entry, TYPE_PTR, 0);
        }
 
        uloop_timeout_set(timeout, 10000);
@@ -141,7 +141,7 @@ cache_update(void)
 
        vlist_for_each_element(&interfaces, iface, node)
                avl_for_each_element(&services, s, avl)
-                       dns_send_question(iface, s->entry, TYPE_PTR, 0);
+                       dns_send_question(iface, NULL, s->entry, TYPE_PTR, 0);
 }
 
 static struct cache_service*
@@ -181,7 +181,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, NULL, entry, TYPE_PTR, iface->multicast);
 
        return s;
 }
diff --git a/dns.c b/dns.c
index 899b1245f61c4e8d1877d614d5b1921454c44389..d384f58e62a85f2724e2e2f7f86476a2bb34e7f9 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -68,7 +68,8 @@ dns_type_string(uint16_t type)
 }
 
 void
-dns_send_question(struct interface *iface, const char *question, int type, int multicast)
+dns_send_question(struct interface *iface, struct sockaddr *to,
+                 const char *question, int type, int multicast)
 {
        static struct dns_header h;
        static struct dns_question q;
@@ -98,7 +99,7 @@ dns_send_question(struct interface *iface, const char *question, int type, int m
        iov[1].iov_len = len;
 
        DBG(1, "Q <- %s %s\n", dns_type_string(type), question);
-       if (interface_send_packet(iface, NULL, iov, ARRAY_SIZE(iov)) < 0)
+       if (interface_send_packet(iface, to, iov, ARRAY_SIZE(iov)) < 0)
                perror("failed to send question");
 }
 
diff --git a/dns.h b/dns.h
index 38ab41f85b8df4e05fed15af21bde1226140d6c0..f1f021203697a56689e9553e6684c8757ac0edba 100644 (file)
--- a/dns.h
+++ b/dns.h
@@ -73,7 +73,8 @@ struct interface;
 extern int cfg_proto;
 extern int cfg_no_subnet;
 
-void dns_send_question(struct interface *iface, const char *question, int type, int multicast);
+void dns_send_question(struct interface *iface, struct sockaddr *to,
+                      const char *question, int type, int multicast);
 void dns_init_answer(void);
 void dns_add_answer(int type, const uint8_t *rdata, uint16_t rdlength, int ttl);
 void dns_send_answer(struct interface *iface, struct sockaddr *to, const char *answer);
index e8987842584d0ca61f71ae0ad0ed9100dc882d31..3904c8918125d786e7119f56c8dfdcb1d8cd608f 100644 (file)
@@ -441,7 +441,7 @@ reconnect_socket4(struct uloop_timeout *timeout)
 
        uloop_fd_add(&iface->fd, ULOOP_READ);
        if (iface->multicast) {
-               dns_send_question(iface, C_DNS_SD, TYPE_PTR, 0);
+               dns_send_question(iface, NULL, C_DNS_SD, TYPE_PTR, 0);
                announce_init(iface);
        }
 
@@ -489,7 +489,7 @@ reconnect_socket6(struct uloop_timeout *timeout)
        uloop_fd_add(&iface->fd, ULOOP_READ);
 
        if (iface->multicast) {
-               dns_send_question(iface, C_DNS_SD, TYPE_PTR, 0);
+               dns_send_question(iface, NULL, C_DNS_SD, TYPE_PTR, 0);
                announce_init(iface);
        }
 
diff --git a/ubus.c b/ubus.c
index ba89fdd7cb3b302c1e006b6aca35b5319cef3095..7b1c811c67fb4699778370f48ee37ef5b89029de 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -201,10 +201,10 @@ umdns_query(struct ubus_context *ctx, struct ubus_object *obj,
 
        if (!strcmp(method, "query")) {
                if (iface_v4)
-                       dns_send_question(iface_v4, question, type, 1);
+                       dns_send_question(iface_v4, NULL, question, type, 1);
 
                if (iface_v6)
-                       dns_send_question(iface_v6, question, type, 1);
+                       dns_send_question(iface_v6, NULL, question, type, 1);
 
                return UBUS_STATUS_OK;
        } else if (!strcmp(method, "fetch")) {