1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include "hashmap.h"
5 #include "list.h"
6 #include "prioq.h"
7 #include "resolve-util.h"
8 #include "resolved-dns-dnssec.h"
9 #include "time-util.h"
10 
11 typedef struct DnsCache {
12         Hashmap *by_key;
13         Prioq *by_expiry;
14         unsigned n_hit;
15         unsigned n_miss;
16 } DnsCache;
17 
18 #include "resolved-dns-answer.h"
19 #include "resolved-dns-packet.h"
20 #include "resolved-dns-question.h"
21 #include "resolved-dns-rr.h"
22 
23 void dns_cache_flush(DnsCache *c);
24 void dns_cache_prune(DnsCache *c);
25 
26 int dns_cache_put(
27                 DnsCache *c,
28                 DnsCacheMode cache_mode,
29                 DnsResourceKey *key,
30                 int rcode,
31                 DnsAnswer *answer,
32                 DnsPacket *full_packet,
33                 uint64_t query_flags,
34                 DnssecResult dnssec_result,
35                 uint32_t nsec_ttl,
36                 int owner_family,
37                 const union in_addr_union *owner_address);
38 
39 int dns_cache_lookup(
40                 DnsCache *c,
41                 DnsResourceKey *key,
42                 uint64_t query_flags,
43                 int *ret_rcode,
44                 DnsAnswer **ret_answer,
45                 DnsPacket **ret_full_packet,
46                 uint64_t *ret_query_flags,
47                 DnssecResult *ret_dnssec_result);
48 
49 int dns_cache_check_conflicts(DnsCache *cache, DnsResourceRecord *rr, int owner_family, const union in_addr_union *owner_address);
50 
51 void dns_cache_dump(DnsCache *cache, FILE *f);
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);
57