1 /*	$NetBSD: ncache.h,v 1.5 2014/12/10 04:37:58 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2010, 2013  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1999-2002  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: ncache.h,v 1.29 2010/05/14 23:50:40 tbox Exp  */
21 
22 #ifndef DNS_NCACHE_H
23 #define DNS_NCACHE_H 1
24 
25 /*****
26  ***** Module Info
27  *****/
28 
29 /*! \file dns/ncache.h
30  *\brief
31  * DNS Ncache
32  *
33  * XXX TBS XXX
34  *
35  * MP:
36  *\li	The caller must ensure any required synchronization.
37  *
38  * Reliability:
39  *\li	No anticipated impact.
40  *
41  * Resources:
42  *\li	TBS
43  *
44  * Security:
45  *\li	No anticipated impact.
46  *
47  * Standards:
48  *\li	RFC2308
49  */
50 
51 #include <isc/lang.h>
52 #include <isc/stdtime.h>
53 
54 #include <dns/types.h>
55 
56 ISC_LANG_BEGINDECLS
57 
58 /*%
59  * _OMITDNSSEC:
60  *      Omit DNSSEC records when rendering.
61  */
62 #define DNS_NCACHETOWIRE_OMITDNSSEC   0x0001
63 
64 isc_result_t
65 dns_ncache_add(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
66 	       dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t maxttl,
67 	       dns_rdataset_t *addedrdataset);
68 isc_result_t
69 dns_ncache_addoptout(dns_message_t *message, dns_db_t *cache,
70 		     dns_dbnode_t *node, dns_rdatatype_t covers,
71 		     isc_stdtime_t now, dns_ttl_t maxttl,
72 		     isc_boolean_t optout, dns_rdataset_t *addedrdataset);
73 /*%<
74  * Convert the authority data from 'message' into a negative cache
75  * rdataset, and store it in 'cache' at 'node' with a TTL limited to
76  * 'maxttl'.
77  *
78  * \li dns_ncache_add produces a negative cache entry with a trust of no
79  *     more than answer
80  * \li dns_ncache_addoptout produces a negative cache entry which will have
81  *     a trust of secure if all the records that make up the entry are secure.
82  *
83  * The 'covers' argument is the RR type whose nonexistence we are caching,
84  * or dns_rdatatype_any when caching a NXDOMAIN response.
85  *
86  * 'optout' indicates a DNS_RDATASETATTR_OPTOUT should be set.
87  *
88  * Note:
89  *\li	If 'addedrdataset' is not NULL, then it will be attached to the added
90  *	rdataset.  See dns_db_addrdataset() for more details.
91  *
92  * Requires:
93  *\li	'message' is a valid message with a properly formatting negative cache
94  *	authority section.
95  *
96  *\li	The requirements of dns_db_addrdataset() apply to 'cache', 'node',
97  *	'now', and 'addedrdataset'.
98  *
99  * Returns:
100  *\li	#ISC_R_SUCCESS
101  *\li	#ISC_R_NOSPACE
102  *
103  *\li	Any result code of dns_db_addrdataset() is a possible result code
104  *	of dns_ncache_add().
105  */
106 
107 isc_result_t
108 dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx,
109 		  isc_buffer_t *target, unsigned int options,
110 		  unsigned int *countp);
111 /*%<
112  * Convert the negative caching rdataset 'rdataset' to wire format,
113  * compressing names as specified in 'cctx', and storing the result in
114  * 'target'.  If 'omit_dnssec' is set, DNSSEC records will not
115  * be added to 'target'.
116  *
117  * Notes:
118  *\li	The number of RRs added to target will be added to *countp.
119  *
120  * Requires:
121  *\li	'rdataset' is a valid negative caching rdataset.
122  *
123  *\li	'rdataset' is not empty.
124  *
125  *\li	'countp' is a valid pointer.
126  *
127  * Ensures:
128  *\li	On a return of ISC_R_SUCCESS, 'target' contains a wire format
129  *	for the data contained in 'rdataset'.  Any error return leaves
130  *	the buffer unchanged.
131  *
132  *\li	*countp has been incremented by the number of RRs added to
133  *	target.
134  *
135  * Returns:
136  *\li	#ISC_R_SUCCESS		- all ok
137  *\li	#ISC_R_NOSPACE		- 'target' doesn't have enough room
138  *
139  *\li	Any error returned by dns_rdata_towire(), dns_rdataset_next(),
140  *	dns_name_towire().
141  */
142 
143 isc_result_t
144 dns_ncache_getrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name,
145 		       dns_rdatatype_t type, dns_rdataset_t *rdataset);
146 /*%<
147  * Search the negative caching rdataset for an rdataset with the
148  * specified name and type.
149  *
150  * Requires:
151  *\li	'ncacherdataset' is a valid negative caching rdataset.
152  *
153  *\li	'ncacherdataset' is not empty.
154  *
155  *\li	'name' is a valid name.
156  *
157  *\li	'type' is not SIG, or a meta-RR type.
158  *
159  *\li	'rdataset' is a valid disassociated rdataset.
160  *
161  * Ensures:
162  *\li	On a return of ISC_R_SUCCESS, 'rdataset' is bound to the found
163  *	rdataset.
164  *
165  * Returns:
166  *\li	#ISC_R_SUCCESS		- the rdataset was found.
167  *\li	#ISC_R_NOTFOUND		- the rdataset was not found.
168  *
169  */
170 
171 isc_result_t
172 dns_ncache_getsigrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name,
173 			  dns_rdatatype_t covers, dns_rdataset_t *rdataset);
174 /*%<
175  * Similar to dns_ncache_getrdataset() but get the rrsig that matches.
176  */
177 
178 void
179 dns_ncache_current(dns_rdataset_t *ncacherdataset, dns_name_t *found,
180 		   dns_rdataset_t *rdataset);
181 
182 /*%<
183  * Extract the current rdataset and name from a ncache entry.
184  *
185  * Requires:
186  * \li	'ncacherdataset' to be valid and to be a negative cache entry
187  * \li	'found' to be valid.
188  * \li	'rdataset' to be unassociated.
189  */
190 
191 ISC_LANG_ENDDECLS
192 
193 #endif /* DNS_NCACHE_H */
194