]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: query_process_cname - make fully recursive 2284/head
authorTom Gundersen <teg@jklm.no>
Tue, 5 Jan 2016 16:56:45 +0000 (17:56 +0100)
committerTom Gundersen <teg@jklm.no>
Thu, 7 Jan 2016 13:43:24 +0000 (14:43 +0100)
This ensures we properly resolve the CNAME chain as far as we can, rather
than only CNAME chains of length one.

src/resolve/resolved-bus.c
src/resolve/resolved-dns-query.c
src/resolve/resolved-dns-query.h

index db180a51a3e0b2e6607997b19f7c83164ff62c8e..7193f639d4965bbdf71ad9d64832de11694cdf62 100644 (file)
@@ -160,7 +160,7 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
         }
         if (r < 0)
                 goto finish;
-        if (r > 0) /* This was a cname, and the query was restarted. */
+        if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
                 return;
 
         r = sd_bus_message_new_method_return(q->request, &reply);
@@ -315,7 +315,7 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
         }
         if (r < 0)
                 goto finish;
-        if (r > 0) /* This was a cname, and the query was restarted. */
+        if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
                 return;
 
         r = sd_bus_message_new_method_return(q->request, &reply);
@@ -481,7 +481,7 @@ static void bus_method_resolve_record_complete(DnsQuery *q) {
         }
         if (r < 0)
                 goto finish;
-        if (r > 0) /* Following a CNAME */
+        if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
                 return;
 
         r = sd_bus_message_new_method_return(q->request, &reply);
@@ -899,7 +899,7 @@ static void resolve_service_hostname_complete(DnsQuery *q) {
         }
 
         r = dns_query_process_cname(q);
-        if (r > 0) /* This was a cname, and the query was restarted. */
+        if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
                 return;
 
         /* This auxiliary lookup is finished or failed, let's see if all are finished now. */
@@ -975,7 +975,7 @@ static void bus_method_resolve_service_complete(DnsQuery *q) {
         }
         if (r < 0)
                 goto finish;
-        if (r > 0) /* This was a cname, and the query was restarted. */
+        if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
                 return;
 
         if (q->answer) {
index 610b914e74a92b6ae15ca63cf7945eb432643480..0f2f2599ab734370053e3a436524f277efaf4528 100644 (file)
@@ -1145,8 +1145,8 @@ int dns_query_process_cname(DnsQuery *q) {
 
         assert(q);
 
-        if (q->state != DNS_TRANSACTION_SUCCESS)
-                return 0;
+        if (!IN_SET(q->state, DNS_TRANSACTION_SUCCESS, DNS_TRANSACTION_NULL))
+                return DNS_QUERY_NOMATCH;
 
         DNS_ANSWER_FOREACH(rr, q->answer) {
 
@@ -1154,7 +1154,7 @@ int dns_query_process_cname(DnsQuery *q) {
                 if (r < 0)
                         return r;
                 if (r > 0)
-                        return 0; /* The answer matches directly, no need to follow cnames */
+                        return DNS_QUERY_MATCH; /* The answer matches directly, no need to follow cnames */
 
                 r = dns_question_matches_cname(q->question, rr, DNS_SEARCH_DOMAIN_NAME(q->answer_search_domain));
                 if (r < 0)
@@ -1164,7 +1164,7 @@ int dns_query_process_cname(DnsQuery *q) {
         }
 
         if (!cname)
-                return 0; /* No cname to follow */
+                return DNS_QUERY_NOMATCH; /* No match and no cname to follow */
 
         if (q->flags & SD_RESOLVED_NO_CNAME)
                 return -ELOOP;
@@ -1176,20 +1176,16 @@ int dns_query_process_cname(DnsQuery *q) {
 
         /* Let's see if the answer can already answer the new
          * redirected question */
-        DNS_ANSWER_FOREACH(rr, q->answer) {
-                r = dns_question_matches_rr(q->question, rr, NULL);
-                if (r < 0)
-                        return r;
-                if (r > 0)
-                        return 0; /* It can answer it, yay! */
-        }
+        r = dns_query_process_cname(q);
+        if (r != DNS_QUERY_NOMATCH)
+                return r;
 
         /* OK, it cannot, let's begin with the new query */
         r = dns_query_go(q);
         if (r < 0)
                 return r;
 
-        return 1; /* We return > 0, if we restarted the query for a new cname */
+        return DNS_QUERY_RESTARTED; /* We restarted the query for a new cname */
 }
 
 static int on_bus_track(sd_bus_track *t, void *userdata) {
index 44edd5bfff2d113a66252171db90e132ade26970..4a0d265a2d30aecb4b6c5e37ccf54f1f83a3aa08 100644 (file)
@@ -95,6 +95,12 @@ struct DnsQuery {
         LIST_FIELDS(DnsQuery, auxiliary_queries);
 };
 
+enum {
+        DNS_QUERY_MATCH,
+        DNS_QUERY_NOMATCH,
+        DNS_QUERY_RESTARTED,
+};
+
 DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c);
 void dns_query_candidate_notify(DnsQueryCandidate *c);