chiark / gitweb /
remove unused includes
[elogind.git] / src / resolve / resolved-dns-query.c
index 57f7467667db68aa710be8b2ec5293bbef563108..d619fae725ba5b1516bee1cff1b9be34c8b5687b 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "af-list.h"
 
 #include "resolved-dns-query.h"
-#include "resolved-dns-domain.h"
 
 /* How long to wait for the query in total */
 #define QUERY_TIMEOUT_USEC (30 * USEC_PER_SEC)
@@ -54,6 +52,7 @@ DnsQuery *dns_query_free(DnsQuery *q) {
         dns_answer_unref(q->answer);
 
         sd_bus_message_unref(q->request);
+        sd_bus_track_unref(q->bus_track);
 
         if (q->manager) {
                 LIST_REMOVE(queries, q->manager->dns_queries, q);
@@ -65,7 +64,7 @@ DnsQuery *dns_query_free(DnsQuery *q) {
         return NULL;
 }
 
-int dns_query_new(Manager *m, DnsQuery **ret, DnsQuestion *question) {
+int dns_query_new(Manager *m, DnsQuery **ret, DnsQuestion *question, int ifindex, uint64_t flags) {
         _cleanup_(dns_query_freep) DnsQuery *q = NULL;
         unsigned i;
         int r;
@@ -85,6 +84,8 @@ int dns_query_new(Manager *m, DnsQuery **ret, DnsQuestion *question) {
                 return -ENOMEM;
 
         q->question = dns_question_ref(question);
+        q->ifindex = ifindex;
+        q->flags = flags;
 
         for (i = 0; i < question->n_keys; i++) {
                 _cleanup_free_ char *p;
@@ -141,7 +142,7 @@ static int dns_query_add_transaction(DnsQuery *q, DnsScope *s, DnsResourceKey *k
         assert(q);
         assert(s);
 
-        r = set_ensure_allocated(&q->transactions, NULL, NULL);
+        r = set_ensure_allocated(&q->transactions, NULL);
         if (r < 0)
                 return r;
 
@@ -156,14 +157,14 @@ static int dns_query_add_transaction(DnsQuery *q, DnsScope *s, DnsResourceKey *k
         } else
                 question = dns_question_ref(q->question);
 
-        t = dns_scope_find_transaction(s, question);
+        t = dns_scope_find_transaction(s, question, true);
         if (!t) {
                 r = dns_transaction_new(&t, s, question);
                 if (r < 0)
                         return r;
         }
 
-        r = set_ensure_allocated(&t->queries, NULL, NULL);
+        r = set_ensure_allocated(&t->queries, NULL);
         if (r < 0)
                 goto gc;
 
@@ -232,7 +233,7 @@ int dns_query_go(DnsQuery *q) {
         LIST_FOREACH(scopes, s, q->manager->dns_scopes) {
                 DnsScopeMatch match;
 
-                match = dns_scope_good_domain(s, name);
+                match = dns_scope_good_domain(s, q->ifindex, q->flags, name);
                 if (match < 0)
                         return match;
 
@@ -262,7 +263,7 @@ int dns_query_go(DnsQuery *q) {
         LIST_FOREACH(scopes, s, first->scopes_next) {
                 DnsScopeMatch match;
 
-                match = dns_scope_good_domain(s, name);
+                match = dns_scope_good_domain(s, q->ifindex, q->flags, name);
                 if (match < 0)
                         goto fail;
 
@@ -277,8 +278,15 @@ int dns_query_go(DnsQuery *q) {
         q->answer = dns_answer_unref(q->answer);
         q->answer_ifindex = 0;
         q->answer_rcode = 0;
-
-        r = sd_event_add_time(q->manager->event, &q->timeout_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + QUERY_TIMEOUT_USEC, 0, on_query_timeout, q);
+        q->answer_family = AF_UNSPEC;
+        q->answer_protocol = _DNS_PROTOCOL_INVALID;
+
+        r = sd_event_add_time(
+                        q->manager->event,
+                        &q->timeout_event_source,
+                        clock_boottime_or_monotonic(),
+                        now(clock_boottime_or_monotonic()) + QUERY_TIMEOUT_USEC, 0,
+                        on_query_timeout, q);
         if (r < 0)
                 goto fail;
 
@@ -416,6 +424,8 @@ void dns_query_ready(DnsQuery *q) {
                 q->answer = dns_answer_ref(answer);
                 q->answer_rcode = rcode;
                 q->answer_ifindex = (scope && scope->link) ? scope->link->ifindex : 0;
+                q->answer_protocol = scope ? scope->protocol : _DNS_PROTOCOL_INVALID;
+                q->answer_family = scope ? scope->family : AF_UNSPEC;
         }
 
         dns_query_complete(q, state);
@@ -445,3 +455,33 @@ int dns_query_cname_redirect(DnsQuery *q, const char *name) {
 
         return 0;
 }
+
+static int on_bus_track(sd_bus_track *t, void *userdata) {
+        DnsQuery *q = userdata;
+
+        assert(t);
+        assert(q);
+
+        log_debug("Client of active query vanished, aborting query.");
+        dns_query_complete(q, DNS_TRANSACTION_ABORTED);
+        return 0;
+}
+
+int dns_query_bus_track(DnsQuery *q, sd_bus *bus, sd_bus_message *m) {
+        int r;
+
+        assert(q);
+        assert(m);
+
+        if (!q->bus_track) {
+                r = sd_bus_track_new(bus, &q->bus_track, on_bus_track, q);
+                if (r < 0)
+                        return r;
+        }
+
+        r = sd_bus_track_add_sender(q->bus_track, m);
+        if (r < 0)
+                return r;
+
+        return 0;
+}