resolved: query_process_cname - make fully recursive

This ensures we properly resolve the CNAME chain as far as we can, rather
than only CNAME chains of length one.
This commit is contained in:
Tom Gundersen 2016-01-05 17:56:45 +01:00
parent 16b85c51ed
commit 7588460aaf
3 changed files with 19 additions and 17 deletions

View 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) {

View 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) {

View 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);