diff options
author | Tom Gundersen <teg@jklm.no> | 2015-07-28 21:36:37 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-07-28 21:36:37 +0200 |
commit | 0a05b6b760455a7bb50f8d5f3c9f6b74302547b7 (patch) | |
tree | 6da62cf7a3a4504769f7eae165e34d765764107b /src/resolve | |
parent | a494468652e2879741afb6c8d47c9218e3514df8 (diff) | |
parent | 1086182d83d4c02a75f96f0184d5e8e5d3af6528 (diff) |
Merge pull request #758 from poettering/dns-is-equal
resolved: compare dns question arrays properly
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-dns-question.c | 40 | ||||
-rw-r--r-- | src/resolve/resolved-dns-question.h | 2 | ||||
-rw-r--r-- | src/resolve/resolved-dns-transaction.c | 4 |
3 files changed, 44 insertions, 2 deletions
diff --git a/src/resolve/resolved-dns-question.c b/src/resolve/resolved-dns-question.c index 4d71f5e3d4..0efe740d1a 100644 --- a/src/resolve/resolved-dns-question.c +++ b/src/resolve/resolved-dns-question.c @@ -188,6 +188,46 @@ int dns_question_is_superset(DnsQuestion *q, DnsQuestion *other) { return 1; } +int dns_question_contains(DnsQuestion *a, DnsResourceKey *k) { + unsigned j; + int r; + + assert(a); + assert(k); + + for (j = 0; j < a->n_keys; j++) { + r = dns_resource_key_equal(a->keys[j], k); + if (r != 0) + return r; + } + + return 0; +} + +int dns_question_is_equal(DnsQuestion *a, DnsQuestion *b) { + unsigned j; + int r; + + assert(a); + assert(b); + + /* Checks if all keys in a are also contained b, and vice versa */ + + for (j = 0; j < a->n_keys; j++) { + r = dns_question_contains(b, a->keys[j]); + if (r <= 0) + return r; + } + + for (j = 0; j < b->n_keys; j++) { + r = dns_question_contains(a, b->keys[j]); + if (r <= 0) + return r; + } + + return 1; +} + int dns_question_cname_redirect(DnsQuestion *q, const char *name, DnsQuestion **ret) { _cleanup_(dns_question_unrefp) DnsQuestion *n = NULL; bool same = true; diff --git a/src/resolve/resolved-dns-question.h b/src/resolve/resolved-dns-question.h index 4ba2fe9f0e..fc98677798 100644 --- a/src/resolve/resolved-dns-question.h +++ b/src/resolve/resolved-dns-question.h @@ -43,6 +43,8 @@ int dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr); int dns_question_matches_cname(DnsQuestion *q, DnsResourceRecord *rr); int dns_question_is_valid(DnsQuestion *q); int dns_question_is_superset(DnsQuestion *q, DnsQuestion *other); +int dns_question_contains(DnsQuestion *a, DnsResourceKey *k); +int dns_question_is_equal(DnsQuestion *a, DnsQuestion *b); int dns_question_cname_redirect(DnsQuestion *q, const char *name, DnsQuestion **ret); diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index b235fda3d2..8a93b265c6 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -406,8 +406,8 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { } /* Only consider responses with equivalent query section to the request */ - if (!dns_question_is_superset(p->question, t->question) || - !dns_question_is_superset(t->question, p->question)) { + r = dns_question_is_equal(p->question, t->question); + if (r <= 0) { dns_transaction_complete(t, DNS_TRANSACTION_INVALID_REPLY); return; } |