resolved-dns-zone.c revision 57f5ad3149b604d07816da61e6aa7dcf1cc56b64
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "list.h"
#include "resolved-dns-zone.h"
#include "resolved-dns-domain.h"
#include "resolved-dns-packet.h"
/* Never allow more than 1K entries */
#define ZONE_MAX 1024
typedef struct DnsZoneItem DnsZoneItem;
struct DnsZoneItem {
bool verified;
};
static void dns_zone_item_free(DnsZoneItem *i) {
if (!i)
return;
free(i);
}
assert(z);
if (!i)
return;
if (first)
else
if (first)
else
}
void dns_zone_flush(DnsZone *z) {
DnsZoneItem *i;
assert(z);
while ((i = hashmap_first(z->by_key)))
hashmap_free(z->by_key);
hashmap_free(z->by_name);
}
DnsZoneItem *i;
assert(z);
return i;
return NULL;
}
DnsZoneItem *i;
assert(z);
i = dns_zone_get(z, rr);
if (i)
}
static int dns_zone_init(DnsZone *z) {
int r;
assert(z);
r = hashmap_ensure_allocated(&z->by_key, dns_resource_key_hash_func, dns_resource_key_compare_func);
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
int r;
if (first) {
} else {
if (r < 0)
return r;
}
if (first) {
} else {
if (r < 0)
return r;
}
return 0;
}
int r;
assert(z);
return -EINVAL;
return -EINVAL;
if (existing)
return 0;
r = dns_zone_init(z);
if (r < 0)
return r;
if (!i)
return -ENOMEM;
r = dns_zone_link_item(z, i);
if (r < 0)
return r;
i = NULL;
return 0;
}
int r;
assert(z);
assert(q);
if (q->n_keys <= 0) {
*ret_answer = NULL;
return 0;
}
/* First iteration, count what we have */
for (i = 0; i < q->n_keys; i++) {
DnsZoneItem *j;
int k;
/* If this is a generic match, then we have to
* go through the list by the name and look
* for everything manually */
LIST_FOREACH(by_name, j, j) {
if (k < 0)
return k;
if (k == 0)
n_soa++;
else
n_answer++;
}
} else {
if (j) {
LIST_FOREACH(by_key, j, j)
n_answer++;
} else {
n_soa ++;
}
}
}
*ret_answer = NULL;
return 0;
}
if (n_answer > 0) {
if (!answer)
return -ENOMEM;
}
if (n_soa > 0) {
if (!soa)
return -ENOMEM;
}
/* Second iteration, actually add the RRs to the answers */
for (i = 0; i < q->n_keys; i++) {
DnsZoneItem *j;
int k;
LIST_FOREACH(by_name, j, j) {
if (k < 0)
return k;
if (k == 0)
else
if (r < 0)
return r;
}
} else {
if (j) {
LIST_FOREACH(by_key, j, j) {
if (r < 0)
return r;
}
} else {
if (r < 0)
return r;
}
}
}
}
*ret_answer = answer;
return 1;
}