[systemd-commits] 3 commits - src/resolve

Lennart Poettering lennart at kemper.freedesktop.org
Mon Aug 4 16:58:21 PDT 2014


 src/resolve/resolved-dns-query.c       |    2 -
 src/resolve/resolved-dns-scope.c       |   14 ++++++++++--
 src/resolve/resolved-dns-scope.h       |    2 -
 src/resolve/resolved-dns-transaction.c |   37 ++++++++++++++++++---------------
 src/resolve/resolved-dns-zone.c        |   34 ++++++++++++++++++++++++------
 5 files changed, 62 insertions(+), 27 deletions(-)

New commits:
commit dc4d47e2c79aafa3ef646e32ff3422c4ce935c1b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 5 01:51:40 2014 +0200

    resolved: never reuse transactions for probing that are already completed based on cached data

diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c
index 36cfc02..ae285ef 100644
--- a/src/resolve/resolved-dns-query.c
+++ b/src/resolve/resolved-dns-query.c
@@ -156,7 +156,7 @@ 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)
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 0f654a6..f1de9bc 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -546,7 +546,7 @@ void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p) {
         }
 }
 
-DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *question) {
+DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *question, bool cache_ok) {
         DnsTransaction *t;
 
         assert(scope);
@@ -555,9 +555,19 @@ DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *questio
         /* Try to find an ongoing transaction that is a equal or a
          * superset of the specified question */
 
-        LIST_FOREACH(transactions_by_scope, t, scope->transactions)
+        LIST_FOREACH(transactions_by_scope, t, scope->transactions) {
+
+                /* Refuse reusing transactions that completed based on
+                 * cached data instead of a real packet, if that's
+                 * requested. */
+                if (!cache_ok &&
+                    IN_SET(t->state, DNS_TRANSACTION_SUCCESS, DNS_TRANSACTION_FAILURE) &&
+                    !t->received)
+                        continue;
+
                 if (dns_question_is_superset(t->question, question) > 0)
                         return t;
+        }
 
         return NULL;
 }
diff --git a/src/resolve/resolved-dns-scope.h b/src/resolve/resolved-dns-scope.h
index 313c617..7c18bff 100644
--- a/src/resolve/resolved-dns-scope.h
+++ b/src/resolve/resolved-dns-scope.h
@@ -77,4 +77,4 @@ int dns_scope_llmnr_membership(DnsScope *s, bool b);
 
 void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p);
 
-DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *question);
+DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsQuestion *question, bool cache_ok);
diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c
index d4e0552..649cc5c 100644
--- a/src/resolve/resolved-dns-zone.c
+++ b/src/resolve/resolved-dns-zone.c
@@ -187,7 +187,7 @@ static int dns_zone_item_probe_start(DnsZoneItem *i)  {
         if (r < 0)
                 return r;
 
-        t = dns_scope_find_transaction(i->scope, question);
+        t = dns_scope_find_transaction(i->scope, question, false);
         if (!t) {
                 r = dns_transaction_new(&t, i->scope, question);
                 if (r < 0)

commit 4d926a69bc27b8fbd4891bb10c03336bd8d93b7a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 5 01:42:15 2014 +0200

    resolved: bypass local cache when we issue a transaction for verification purposes

diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index 48da432..83933c6 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -465,24 +465,29 @@ int dns_transaction_go(DnsTransaction *t) {
         t->cached = dns_answer_unref(t->cached);
         t->cached_rcode = 0;
 
-        /* Before trying the cache, let's make sure we figured out a
-         * server to use. Should this cause a change of server this
-         * might flush the cache. */
-        dns_scope_get_dns_server(t->scope);
+        /* Check the cache, but only if this transaction is not used
+         * for probing or verifying a zone item. */
+        if (set_isempty(t->zone_items)) {
 
-        /* Let's then prune all outdated entries */
-        dns_cache_prune(&t->scope->cache);
+                /* Before trying the cache, let's make sure we figured out a
+                 * server to use. Should this cause a change of server this
+                 * might flush the cache. */
+                dns_scope_get_dns_server(t->scope);
 
-        r = dns_cache_lookup(&t->scope->cache, t->question, &t->cached_rcode, &t->cached);
-        if (r < 0)
-                return r;
-        if (r > 0) {
-                log_debug("Cache hit!");
-                if (t->cached_rcode == DNS_RCODE_SUCCESS)
-                        dns_transaction_complete(t, DNS_TRANSACTION_SUCCESS);
-                else
-                        dns_transaction_complete(t, DNS_TRANSACTION_FAILURE);
-                return 0;
+                /* Let's then prune all outdated entries */
+                dns_cache_prune(&t->scope->cache);
+
+                r = dns_cache_lookup(&t->scope->cache, t->question, &t->cached_rcode, &t->cached);
+                if (r < 0)
+                        return r;
+                if (r > 0) {
+                        log_debug("Cache hit!");
+                        if (t->cached_rcode == DNS_RCODE_SUCCESS)
+                                dns_transaction_complete(t, DNS_TRANSACTION_SUCCESS);
+                        else
+                                dns_transaction_complete(t, DNS_TRANSACTION_FAILURE);
+                        return 0;
+                }
         }
 
         log_debug("Cache miss!");

commit cd1b20f90abb1e49d60d8c3f4a7665ca93bea436
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Aug 5 01:38:13 2014 +0200

    resolved: if there's already an RR established that has the same name of an RR to be established, skip probing the name
    
    After all, what has been probed once, doesn't need to be probed again.

diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c
index b577fd6..d4e0552 100644
--- a/src/resolve/resolved-dns-zone.c
+++ b/src/resolve/resolved-dns-zone.c
@@ -260,14 +260,34 @@ int dns_zone_put(DnsZone *z, DnsScope *s, DnsResourceRecord *rr, bool probe) {
                 return r;
 
         if (probe) {
-                r = dns_zone_item_probe_start(i);
-                if (r < 0) {
-                        dns_zone_item_remove_and_free(z, i);
-                        i = NULL;
-                        return r;
+                DnsZoneItem *first, *j;
+                bool established = false;
+
+                /* Check if there's already an RR with the same name
+                 * established. If so, it has been probed already, and
+                 * we don't ned to probe again. */
+
+                LIST_FIND_HEAD(by_name, i, first);
+                LIST_FOREACH(by_name, j, first) {
+                        if (i == j)
+                                continue;
+
+                        if (j->state == DNS_ZONE_ITEM_ESTABLISHED)
+                                established = true;
                 }
 
-                i->state = DNS_ZONE_ITEM_PROBING;
+                if (established)
+                        i->state = DNS_ZONE_ITEM_ESTABLISHED;
+                else {
+                        r = dns_zone_item_probe_start(i);
+                        if (r < 0) {
+                                dns_zone_item_remove_and_free(z, i);
+                                i = NULL;
+                                return r;
+                        }
+
+                        i->state = DNS_ZONE_ITEM_PROBING;
+                }
         } else
                 i->state = DNS_ZONE_ITEM_ESTABLISHED;
 



More information about the systemd-commits mailing list