1*c0b5d9fbSchristos /*	$NetBSD: badcache.h,v 1.6 2022/09/23 12:15:30 christos Exp $	*/
2e2b1b9c0Schristos 
3e2b1b9c0Schristos /*
4e2b1b9c0Schristos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5e2b1b9c0Schristos  *
6*c0b5d9fbSchristos  * SPDX-License-Identifier: MPL-2.0
7*c0b5d9fbSchristos  *
8e2b1b9c0Schristos  * This Source Code Form is subject to the terms of the Mozilla Public
9e2b1b9c0Schristos  * License, v. 2.0. If a copy of the MPL was not distributed with this
1073584a28Schristos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11e2b1b9c0Schristos  *
12e2b1b9c0Schristos  * See the COPYRIGHT file distributed with this work for additional
13e2b1b9c0Schristos  * information regarding copyright ownership.
14e2b1b9c0Schristos  */
15e2b1b9c0Schristos 
16e2b1b9c0Schristos #ifndef DNS_BADCACHE_H
17e2b1b9c0Schristos #define DNS_BADCACHE_H 1
18e2b1b9c0Schristos 
19e2b1b9c0Schristos /*****
20e2b1b9c0Schristos ***** Module Info
21e2b1b9c0Schristos *****/
22e2b1b9c0Schristos 
23e2b1b9c0Schristos /*! \file dns/badcache.h
24e2b1b9c0Schristos  * \brief
25e2b1b9c0Schristos  * Defines dns_badcache_t, the "bad cache" object.
26e2b1b9c0Schristos  *
27e2b1b9c0Schristos  * Notes:
28e2b1b9c0Schristos  *\li 	A bad cache object is a hash table of name/type tuples,
29e2b1b9c0Schristos  *	indicating whether a given tuple known to be "bad" in some
30e2b1b9c0Schristos  *	sense (e.g., queries for that name and type have been
31e2b1b9c0Schristos  *	returning SERVFAIL). This is used for both the "bad server
32e2b1b9c0Schristos  *	cache" in the resolver and for the "servfail cache" in
33e2b1b9c0Schristos  *	the view.
34e2b1b9c0Schristos  *
35e2b1b9c0Schristos  * Reliability:
36e2b1b9c0Schristos  *
37e2b1b9c0Schristos  * Resources:
38e2b1b9c0Schristos  *
39e2b1b9c0Schristos  * Security:
40e2b1b9c0Schristos  *
41e2b1b9c0Schristos  * Standards:
42e2b1b9c0Schristos  */
43e2b1b9c0Schristos 
44e2b1b9c0Schristos /***
45e2b1b9c0Schristos  ***	Imports
46e2b1b9c0Schristos  ***/
47e2b1b9c0Schristos 
48f2e20987Schristos #include <inttypes.h>
49f2e20987Schristos #include <stdbool.h>
50f2e20987Schristos 
51e2b1b9c0Schristos #include <dns/types.h>
52e2b1b9c0Schristos 
53e2b1b9c0Schristos ISC_LANG_BEGINDECLS
54e2b1b9c0Schristos 
55e2b1b9c0Schristos /***
56e2b1b9c0Schristos  ***	Functions
57e2b1b9c0Schristos  ***/
58e2b1b9c0Schristos 
59e2b1b9c0Schristos isc_result_t
60e2b1b9c0Schristos dns_badcache_init(isc_mem_t *mctx, unsigned int size, dns_badcache_t **bcp);
61e2b1b9c0Schristos /*%
62e2b1b9c0Schristos  * Allocate and initialize a badcache and store it in '*bcp'.
63e2b1b9c0Schristos  *
64e2b1b9c0Schristos  * Requires:
65e2b1b9c0Schristos  * \li	mctx != NULL
66e2b1b9c0Schristos  * \li	bcp != NULL
67e2b1b9c0Schristos  * \li	*bcp == NULL
68e2b1b9c0Schristos  */
69e2b1b9c0Schristos 
70e2b1b9c0Schristos void
71e2b1b9c0Schristos dns_badcache_destroy(dns_badcache_t **bcp);
72e2b1b9c0Schristos /*%
73e2b1b9c0Schristos  * Flush and then free badcache in 'bcp'. '*bcp' is set to NULL on return.
74e2b1b9c0Schristos  *
75e2b1b9c0Schristos  * Requires:
76e2b1b9c0Schristos  * \li	'*bcp' to be a valid badcache
77e2b1b9c0Schristos  */
78e2b1b9c0Schristos 
79e2b1b9c0Schristos void
80e2b1b9c0Schristos dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name,
819742fdb4Schristos 		 dns_rdatatype_t type, bool update, uint32_t flags,
829742fdb4Schristos 		 isc_time_t *expire);
83e2b1b9c0Schristos /*%
84e2b1b9c0Schristos  * Adds a badcache entry to the badcache 'bc' for name 'name' and
85e2b1b9c0Schristos  * type 'type'.  If an entry already exists, then it will be updated if
86f2e20987Schristos  * 'update' is true.  The entry will be stored with flags 'flags'
87e2b1b9c0Schristos  * and expiration date 'expire'.
88e2b1b9c0Schristos  *
89e2b1b9c0Schristos  * Requires:
90e2b1b9c0Schristos  * \li	bc to be a valid badcache.
91e2b1b9c0Schristos  * \li	name != NULL
92e2b1b9c0Schristos  * \li	expire != NULL
93e2b1b9c0Schristos  */
94e2b1b9c0Schristos 
95f2e20987Schristos bool
96e2b1b9c0Schristos dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name,
979742fdb4Schristos 		  dns_rdatatype_t type, uint32_t *flagp, isc_time_t *now);
98e2b1b9c0Schristos /*%
99f2e20987Schristos  * Returns true if a record is found in the badcache 'bc' matching
100e2b1b9c0Schristos  * 'name' and 'type', with an expiration date later than 'now'.
101e2b1b9c0Schristos  * If 'flagp' is not NULL, then '*flagp' is updated to the flags
102f2e20987Schristos  * that were stored in the badcache entry.  Returns false if
103e2b1b9c0Schristos  * no matching record is found.
104e2b1b9c0Schristos  *
105e2b1b9c0Schristos  * Requires:
106e2b1b9c0Schristos  * \li	bc to be a valid badcache.
107e2b1b9c0Schristos  * \li	name != NULL
108e2b1b9c0Schristos  * \li	now != NULL
109e2b1b9c0Schristos  */
110e2b1b9c0Schristos 
111e2b1b9c0Schristos void
112e2b1b9c0Schristos dns_badcache_flush(dns_badcache_t *bc);
113e2b1b9c0Schristos /*%
114e2b1b9c0Schristos  * Flush the entire bad cache.
115e2b1b9c0Schristos  *
116e2b1b9c0Schristos  * Requires:
117e2b1b9c0Schristos  * \li	bc to be a valid badcache
118e2b1b9c0Schristos  */
119e2b1b9c0Schristos 
120e2b1b9c0Schristos void
121e2b1b9c0Schristos dns_badcache_flushname(dns_badcache_t *bc, const dns_name_t *name);
122e2b1b9c0Schristos /*%
123e2b1b9c0Schristos  * Flush the bad cache of all entries at 'name'.
124e2b1b9c0Schristos  *
125e2b1b9c0Schristos  * Requires:
126e2b1b9c0Schristos  * \li	bc to be a valid badcache
127e2b1b9c0Schristos  * \li	name != NULL
128e2b1b9c0Schristos  */
129e2b1b9c0Schristos 
130e2b1b9c0Schristos void
131e2b1b9c0Schristos dns_badcache_flushtree(dns_badcache_t *bc, const dns_name_t *name);
132e2b1b9c0Schristos /*%
133e2b1b9c0Schristos  * Flush the bad cache of all entries at or below 'name'.
134e2b1b9c0Schristos  *
135e2b1b9c0Schristos  * Requires:
136e2b1b9c0Schristos  * \li	bc to be a valid badcache
137e2b1b9c0Schristos  * \li	name != NULL
138e2b1b9c0Schristos  */
139e2b1b9c0Schristos 
140e2b1b9c0Schristos void
141e2b1b9c0Schristos dns_badcache_print(dns_badcache_t *bc, const char *cachename, FILE *fp);
142e2b1b9c0Schristos /*%
143e2b1b9c0Schristos  * Print the contents of badcache 'bc' (headed by the title 'cachename')
144e2b1b9c0Schristos  * to file pointer 'fp'.
145e2b1b9c0Schristos  *
146e2b1b9c0Schristos  * Requires:
147e2b1b9c0Schristos  * \li	bc to be a valid badcache
148e2b1b9c0Schristos  * \li	cachename != NULL
149e2b1b9c0Schristos  * \li	fp != NULL
150e2b1b9c0Schristos  */
151e2b1b9c0Schristos 
152e2b1b9c0Schristos ISC_LANG_ENDDECLS
153e2b1b9c0Schristos 
154e2b1b9c0Schristos #endif /* DNS_BADCACHE_H */
155