summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-30 02:06:09 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-30 02:06:09 +0200
commitd532366133a29136ad2dd95cb9268c7bbbb4d3ee (patch)
tree066dbbab7b38292dc929dc0c5a786933523cc89c
parent0e2bcd6a1783008a94bdef4c828c5f8e0eba1706 (diff)
resolved: respond to ANY queries from our zone
-rw-r--r--src/resolve/resolved-dns-zone.c70
1 files changed, 56 insertions, 14 deletions
diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c
index 12a8512c7e..65dc17764b 100644
--- a/src/resolve/resolved-dns-zone.c
+++ b/src/resolve/resolved-dns-zone.c
@@ -194,9 +194,9 @@ int dns_zone_put(DnsZone *z, DnsResourceRecord *rr) {
int dns_zone_lookup(DnsZone *z, DnsQuestion *q, DnsAnswer **ret) {
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
- int r;
- unsigned i, n = 0;
bool has_other_rrs = false;
+ unsigned i, n = 0;
+ int r;
assert(z);
assert(q);
@@ -210,16 +210,39 @@ int dns_zone_lookup(DnsZone *z, DnsQuestion *q, DnsAnswer **ret) {
for (i = 0; i < q->n_keys; i++) {
DnsZoneItem *j;
- j = hashmap_get(z->by_key, q->keys[i]);
- if (!j) {
- if (hashmap_get(z->by_name, DNS_RESOURCE_KEY_NAME(q->keys[i])))
+ if (q->keys[i]->type == DNS_TYPE_ANY ||
+ q->keys[i]->class == DNS_CLASS_ANY) {
+ int k;
+
+ /* If this is a generic match, then we have to
+ * go through the list by the name and look
+ * for everything manually */
+
+ j = hashmap_get(z->by_name, DNS_RESOURCE_KEY_NAME(q->keys[i]));
+ LIST_FOREACH(by_name, j, j) {
has_other_rrs = true;
- continue;
- }
+ k = dns_resource_key_match_rr(q->keys[i], j->rr);
+ if (k < 0)
+ return k;
+ if (k == 0)
+ continue;
+
+ n++;
+ }
+
+ } else {
+ j = hashmap_get(z->by_key, q->keys[i]);
+ if (!j) {
+ if (hashmap_get(z->by_name, DNS_RESOURCE_KEY_NAME(q->keys[i])))
+ has_other_rrs = true;
- LIST_FOREACH(by_name, j, j)
- n++;
+ continue;
+ }
+
+ LIST_FOREACH(by_key, j, j)
+ n++;
+ }
}
if (n <= 0) {
@@ -234,11 +257,30 @@ int dns_zone_lookup(DnsZone *z, DnsQuestion *q, DnsAnswer **ret) {
for (i = 0; i < q->n_keys; i++) {
DnsZoneItem *j;
- j = hashmap_get(z->by_key, q->keys[i]);
- LIST_FOREACH(by_key, j, j) {
- r = dns_answer_add(answer, j->rr);
- if (r < 0)
- return r;
+ if (q->keys[i]->type == DNS_TYPE_ANY ||
+ q->keys[i]->class == DNS_CLASS_ANY) {
+ int k;
+
+ j = hashmap_get(z->by_name, DNS_RESOURCE_KEY_NAME(q->keys[i]));
+ LIST_FOREACH(by_name, j, j) {
+ k = dns_resource_key_match_rr(q->keys[i], j->rr);
+ if (k < 0)
+ return k;
+ if (k == 0)
+ continue;
+
+ r = dns_answer_add(answer, j->rr);
+ if (r < 0)
+ return r;
+ }
+ } else {
+
+ j = hashmap_get(z->by_key, q->keys[i]);
+ LIST_FOREACH(by_key, j, j) {
+ r = dns_answer_add(answer, j->rr);
+ if (r < 0)
+ return r;
+ }
}
}