Debian Codegraph @

src/resolve/resolved-dns-cache.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "resolved-forward.h"
5
6 /* Never cache more than 4K entries by default. RFC 1536, Section 5 suggests to
7 * leave DNS caches unbounded, but that's crazy. */
8 #define DEFAULT_CACHE_MAX 4096U
9 #define CACHE_MAX_UPPER_LIMIT (1U << 24)
10
11 typedef struct DnsCache {
12 Hashmap *by_key;
13 Prioq *by_expiry;
14 unsigned n_hit;
15 unsigned n_miss;
16 unsigned cache_max;
17 } DnsCache;
18
19 void dns_cache_flush(DnsCache *c);
20 void dns_cache_prune(DnsCache *c);
21
22 int dns_cache_put(
23 DnsCache *c,
24 DnsCacheMode cache_mode,
25 DnsProtocol protocol,
26 DnsResourceKey *key,
27 int rcode,
28 DnsAnswer *answer,
29 DnsPacket *full_packet,
30 uint64_t query_flags,
31 DnssecResult dnssec_result,
32 uint32_t nsec_ttl,
33 int owner_family,
34 const union in_addr_union *owner_address,
35 usec_t stale_retention_usec);
36
37 int dns_cache_lookup(
38 DnsCache *c,
39 DnsResourceKey *key,
40 uint64_t query_flags,
41 int *ret_rcode,
42 DnsAnswer **ret_answer,
43 DnsPacket **ret_full_packet,
44 uint64_t *ret_query_flags,
45 DnssecResult *ret_dnssec_result);
46
47 int dns_cache_check_conflicts(DnsCache *cache, DnsResourceRecord *rr, int owner_family, const union in_addr_union *owner_address);
48
49 void dns_cache_dump(DnsCache *cache, FILE *f);
50 int dns_cache_dump_to_json(DnsCache *cache, sd_json_variant **ret);
51
52 bool dns_cache_is_empty(DnsCache *cache);
53
54 unsigned dns_cache_size(DnsCache *cache);
55
56 int dns_cache_export_shared_to_packet(DnsCache *cache, DnsPacket *p, usec_t ts, unsigned max_rr);
57
58 bool dns_cache_expiry_in_one_second(DnsCache *c, usec_t t);