summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-cache.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-29 14:24:02 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-29 20:57:58 +0200
commit623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbf (patch)
tree2590cdcc3e9a36ea63d75407c178253ff2669261 /src/resolve/resolved-dns-cache.c
parent359017c1aec9596e9d3c4c19bd62d34a6f3366b8 (diff)
resolve: add llmnr responder side for UDP and TCP
Name defending is still missing.
Diffstat (limited to 'src/resolve/resolved-dns-cache.c')
-rw-r--r--src/resolve/resolved-dns-cache.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index 6ea5d49fc4..8c859d19b5 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -28,6 +28,24 @@
/* We never keep any item longer than 10min in our cache */
#define CACHE_TTL_MAX_USEC (10 * USEC_PER_MINUTE)
+typedef enum DnsCacheItemType DnsCacheItemType;
+typedef struct DnsCacheItem DnsCacheItem;
+
+enum DnsCacheItemType {
+ DNS_CACHE_POSITIVE,
+ DNS_CACHE_NODATA,
+ DNS_CACHE_NXDOMAIN,
+};
+
+struct DnsCacheItem {
+ DnsResourceKey *key;
+ DnsResourceRecord *rr;
+ usec_t until;
+ DnsCacheItemType type;
+ unsigned prioq_idx;
+ LIST_FIELDS(DnsCacheItem, by_key);
+};
+
static void dns_cache_item_free(DnsCacheItem *i) {
if (!i)
return;
@@ -157,9 +175,11 @@ static int dns_cache_item_prioq_compare_func(const void *a, const void *b) {
return 0;
}
-static int init_cache(DnsCache *c) {
+static int dns_cache_init(DnsCache *c) {
int r;
+ assert(c);
+
r = prioq_ensure_allocated(&c->by_expiry, dns_cache_item_prioq_compare_func);
if (r < 0)
return r;
@@ -258,7 +278,7 @@ static int dns_cache_put_positive(DnsCache *c, DnsResourceRecord *rr, usec_t tim
}
/* Otherwise, add the new RR */
- r = init_cache(c);
+ r = dns_cache_init(c);
if (r < 0)
return r;
@@ -294,7 +314,7 @@ static int dns_cache_put_negative(DnsCache *c, DnsResourceKey *key, int rcode, u
if (!IN_SET(rcode, DNS_RCODE_SUCCESS, DNS_RCODE_NXDOMAIN))
return 0;
- r = init_cache(c);
+ r = dns_cache_init(c);
if (r < 0)
return r;
@@ -394,6 +414,7 @@ int dns_cache_lookup(DnsCache *c, DnsQuestion *q, int *rcode, DnsAnswer **ret) {
assert(c);
assert(q);
+ assert(rcode);
assert(ret);
if (q->n_keys <= 0) {