summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-packet.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-17 19:38:37 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-17 19:39:50 +0200
commit322345fdb9865ef2477fba8e4bdde0e1183ef505 (patch)
tree6ac6b255f03e86c6b0029d0119eede7f4317d62c /src/resolve/resolved-dns-packet.c
parentc5ed93163e6ef51a7462aa558a7e0912b17c4951 (diff)
resolved: add DNS cache
Diffstat (limited to 'src/resolve/resolved-dns-packet.c')
-rw-r--r--src/resolve/resolved-dns-packet.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index 5597ffd969..499683ac1d 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -91,6 +91,9 @@ static void dns_packet_free(DnsPacket *p) {
assert(p);
+ if (p->rrs)
+ dns_resource_record_freev(p->rrs, DNS_PACKET_RRCOUNT(p));
+
while ((s = hashmap_steal_first_key(p->names)))
free(s);
hashmap_free(p->names);
@@ -726,11 +729,13 @@ fail:
}
int dns_packet_skip_question(DnsPacket *p) {
+ unsigned i, n;
int r;
- unsigned i, n;
assert(p);
+ dns_packet_rewind(p, DNS_PACKET_HEADER_SIZE);
+
n = DNS_PACKET_QDCOUNT(p);
for (i = 0; i < n; i++) {
_cleanup_(dns_resource_key_free) DnsResourceKey key = {};
@@ -743,6 +748,49 @@ int dns_packet_skip_question(DnsPacket *p) {
return 0;
}
+int dns_packet_extract_rrs(DnsPacket *p) {
+ DnsResourceRecord **rrs = NULL;
+ size_t saved_rindex;
+ unsigned n, added = 0;
+ int r;
+
+ if (p->rrs)
+ return (int) DNS_PACKET_RRCOUNT(p);
+
+ saved_rindex = p->rindex;
+
+ r = dns_packet_skip_question(p);
+ if (r < 0)
+ goto finish;
+
+ n = DNS_PACKET_RRCOUNT(p);
+ if (n <= 0) {
+ r = 0;
+ goto finish;
+ }
+
+ rrs = new0(DnsResourceRecord*, n);
+ if (!rrs) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ for (added = 0; added < n; added++) {
+ r = dns_packet_read_rr(p, &rrs[added], NULL);
+ if (r < 0) {
+ dns_resource_record_freev(rrs, added);
+ goto finish;
+ }
+ }
+
+ p->rrs = rrs;
+ r = (int) n;
+
+finish:
+ p->rindex = saved_rindex;
+ return r;
+}
+
static const char* const dns_rcode_table[_DNS_RCODE_MAX_DEFINED] = {
[DNS_RCODE_SUCCESS] = "SUCCESS",
[DNS_RCODE_FORMERR] = "FORMERR",