vendor/BIND: Update to 9.5.2-P3
[dragonfly.git] / contrib / bind / lib / dns / include / dns / rdataset.h
blob7fbd8d767ab32aaa7b67cae4a335a44c3d9b76d2
1 /*
2 * Copyright (C) 2004-2007, 2009, 2010 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: rdataset.h,v 1.62.128.2.2.2 2010/02/25 10:56:02 tbox Exp $ */
20 #ifndef DNS_RDATASET_H
21 #define DNS_RDATASET_H 1
23 /*****
24 ***** Module Info
25 *****/
27 /*! \file dns/rdataset.h
28 * \brief
29 * A DNS rdataset is a handle that can be associated with a collection of
30 * rdata all having a common owner name, class, and type.
32 * The dns_rdataset_t type is like a "virtual class". To actually use
33 * rdatasets, an implementation of the method suite (e.g. "slabbed rdata") is
34 * required.
36 * XXX <more> XXX
38 * MP:
39 *\li Clients of this module must impose any required synchronization.
41 * Reliability:
42 *\li No anticipated impact.
44 * Resources:
45 *\li TBS
47 * Security:
48 *\li No anticipated impact.
50 * Standards:
51 *\li None.
54 #include <isc/lang.h>
55 #include <isc/magic.h>
56 #include <isc/stdtime.h>
58 #include <dns/types.h>
60 ISC_LANG_BEGINDECLS
62 typedef enum {
63 dns_rdatasetadditional_fromauth,
64 dns_rdatasetadditional_fromcache,
65 dns_rdatasetadditional_fromglue
66 } dns_rdatasetadditional_t;
68 typedef struct dns_rdatasetmethods {
69 void (*disassociate)(dns_rdataset_t *rdataset);
70 isc_result_t (*first)(dns_rdataset_t *rdataset);
71 isc_result_t (*next)(dns_rdataset_t *rdataset);
72 void (*current)(dns_rdataset_t *rdataset,
73 dns_rdata_t *rdata);
74 void (*clone)(dns_rdataset_t *source,
75 dns_rdataset_t *target);
76 unsigned int (*count)(dns_rdataset_t *rdataset);
77 isc_result_t (*addnoqname)(dns_rdataset_t *rdataset,
78 dns_name_t *name);
79 isc_result_t (*getnoqname)(dns_rdataset_t *rdataset,
80 dns_name_t *name,
81 dns_rdataset_t *nsec,
82 dns_rdataset_t *nsecsig);
83 isc_result_t (*getadditional)(dns_rdataset_t *rdataset,
84 dns_rdatasetadditional_t type,
85 dns_rdatatype_t qtype,
86 dns_acache_t *acache,
87 dns_zone_t **zonep,
88 dns_db_t **dbp,
89 dns_dbversion_t **versionp,
90 dns_dbnode_t **nodep,
91 dns_name_t *fname,
92 dns_message_t *msg,
93 isc_stdtime_t now);
94 isc_result_t (*setadditional)(dns_rdataset_t *rdataset,
95 dns_rdatasetadditional_t type,
96 dns_rdatatype_t qtype,
97 dns_acache_t *acache,
98 dns_zone_t *zone,
99 dns_db_t *db,
100 dns_dbversion_t *version,
101 dns_dbnode_t *node,
102 dns_name_t *fname);
103 isc_result_t (*putadditional)(dns_acache_t *acache,
104 dns_rdataset_t *rdataset,
105 dns_rdatasetadditional_t type,
106 dns_rdatatype_t qtype);
107 void (*settrust)(dns_rdataset_t *rdataset,
108 dns_trust_t trust);
109 void (*expire)(dns_rdataset_t *rdataset);
110 } dns_rdatasetmethods_t;
112 #define DNS_RDATASET_MAGIC ISC_MAGIC('D','N','S','R')
113 #define DNS_RDATASET_VALID(set) ISC_MAGIC_VALID(set, DNS_RDATASET_MAGIC)
116 * Direct use of this structure by clients is strongly discouraged, except
117 * for the 'link' field which may be used however the client wishes. The
118 * 'private', 'current', and 'index' fields MUST NOT be changed by clients.
119 * rdataset implementations may change any of the fields.
121 struct dns_rdataset {
122 unsigned int magic; /* XXX ? */
123 dns_rdatasetmethods_t * methods;
124 ISC_LINK(dns_rdataset_t) link;
126 * XXX do we need these, or should they be retrieved by methods?
127 * Leaning towards the latter, since they are not frequently required
128 * once you have the rdataset.
130 dns_rdataclass_t rdclass;
131 dns_rdatatype_t type;
132 dns_ttl_t ttl;
133 dns_trust_t trust;
134 dns_rdatatype_t covers;
136 * attributes
138 unsigned int attributes;
140 * the counter provides the starting point in the "cyclic" order.
141 * The value ISC_UINT32_MAX has a special meaning of "picking up a
142 * random value." in order to take care of databases that do not
143 * increment the counter.
145 isc_uint32_t count;
146 /*@{*/
148 * These are for use by the rdataset implementation, and MUST NOT
149 * be changed by clients.
151 void * private1;
152 void * private2;
153 void * private3;
154 unsigned int privateuint4;
155 void * private5;
156 void * private6;
157 /*@}*/
161 * \def DNS_RDATASETATTR_RENDERED
162 * Used by message.c to indicate that the rdataset was rendered.
164 * \def DNS_RDATASETATTR_TTLADJUSTED
165 * Used by message.c to indicate that the rdataset's rdata had differing
166 * TTL values, and the rdataset->ttl holds the smallest.
168 * \def DNS_RDATASETATTR_LOADORDER
169 * Output the RRset in load order.
172 #define DNS_RDATASETATTR_QUESTION 0x00000001
173 #define DNS_RDATASETATTR_RENDERED 0x00000002 /*%< Used by message.c */
174 #define DNS_RDATASETATTR_ANSWERED 0x00000004 /*%< Used by server. */
175 #define DNS_RDATASETATTR_CACHE 0x00000008 /*%< Used by resolver. */
176 #define DNS_RDATASETATTR_ANSWER 0x00000010 /*%< Used by resolver. */
177 #define DNS_RDATASETATTR_ANSWERSIG 0x00000020 /*%< Used by resolver. */
178 #define DNS_RDATASETATTR_EXTERNAL 0x00000040 /*%< Used by resolver. */
179 #define DNS_RDATASETATTR_NCACHE 0x00000080 /*%< Used by resolver. */
180 #define DNS_RDATASETATTR_CHAINING 0x00000100 /*%< Used by resolver. */
181 #define DNS_RDATASETATTR_TTLADJUSTED 0x00000200 /*%< Used by message.c */
182 #define DNS_RDATASETATTR_FIXEDORDER 0x00000400
183 #define DNS_RDATASETATTR_RANDOMIZE 0x00000800
184 #define DNS_RDATASETATTR_CHASE 0x00001000 /*%< Used by resolver. */
185 #define DNS_RDATASETATTR_NXDOMAIN 0x00002000
186 #define DNS_RDATASETATTR_NOQNAME 0x00004000
187 #define DNS_RDATASETATTR_CHECKNAMES 0x00008000 /*%< Used by resolver. */
188 #define DNS_RDATASETATTR_REQUIREDGLUE 0x00010000
189 #define DNS_RDATASETATTR_LOADORDER 0x00020000
192 * _OMITDNSSEC:
193 * Omit DNSSEC records when rendering ncache records.
195 #define DNS_RDATASETTOWIRE_OMITDNSSEC 0x0001
197 void
198 dns_rdataset_init(dns_rdataset_t *rdataset);
199 /*%<
200 * Make 'rdataset' a valid, disassociated rdataset.
202 * Requires:
203 *\li 'rdataset' is not NULL.
205 * Ensures:
206 *\li 'rdataset' is a valid, disassociated rdataset.
209 void
210 dns_rdataset_invalidate(dns_rdataset_t *rdataset);
211 /*%<
212 * Invalidate 'rdataset'.
214 * Requires:
215 *\li 'rdataset' is a valid, disassociated rdataset.
217 * Ensures:
218 *\li If assertion checking is enabled, future attempts to use 'rdataset'
219 * without initializing it will cause an assertion failure.
222 void
223 dns_rdataset_disassociate(dns_rdataset_t *rdataset);
224 /*%<
225 * Disassociate 'rdataset' from its rdata, allowing it to be reused.
227 * Notes:
228 *\li The client must ensure it has no references to rdata in the rdataset
229 * before disassociating.
231 * Requires:
232 *\li 'rdataset' is a valid, associated rdataset.
234 * Ensures:
235 *\li 'rdataset' is a valid, disassociated rdataset.
238 isc_boolean_t
239 dns_rdataset_isassociated(dns_rdataset_t *rdataset);
240 /*%<
241 * Is 'rdataset' associated?
243 * Requires:
244 *\li 'rdataset' is a valid rdataset.
246 * Returns:
247 *\li #ISC_TRUE 'rdataset' is associated.
248 *\li #ISC_FALSE 'rdataset' is not associated.
251 void
252 dns_rdataset_makequestion(dns_rdataset_t *rdataset, dns_rdataclass_t rdclass,
253 dns_rdatatype_t type);
254 /*%<
255 * Make 'rdataset' a valid, associated, question rdataset, with a
256 * question class of 'rdclass' and type 'type'.
258 * Notes:
259 *\li Question rdatasets have a class and type, but no rdata.
261 * Requires:
262 *\li 'rdataset' is a valid, disassociated rdataset.
264 * Ensures:
265 *\li 'rdataset' is a valid, associated, question rdataset.
268 void
269 dns_rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target);
270 /*%<
271 * Make 'target' refer to the same rdataset as 'source'.
273 * Requires:
274 *\li 'source' is a valid, associated rdataset.
276 *\li 'target' is a valid, dissociated rdataset.
278 * Ensures:
279 *\li 'target' references the same rdataset as 'source'.
282 unsigned int
283 dns_rdataset_count(dns_rdataset_t *rdataset);
284 /*%<
285 * Return the number of records in 'rdataset'.
287 * Requires:
288 *\li 'rdataset' is a valid, associated rdataset.
290 * Returns:
291 *\li The number of records in 'rdataset'.
294 isc_result_t
295 dns_rdataset_first(dns_rdataset_t *rdataset);
296 /*%<
297 * Move the rdata cursor to the first rdata in the rdataset (if any).
299 * Requires:
300 *\li 'rdataset' is a valid, associated rdataset.
302 * Returns:
303 *\li #ISC_R_SUCCESS
304 *\li #ISC_R_NOMORE There are no rdata in the set.
307 isc_result_t
308 dns_rdataset_next(dns_rdataset_t *rdataset);
309 /*%<
310 * Move the rdata cursor to the next rdata in the rdataset (if any).
312 * Requires:
313 *\li 'rdataset' is a valid, associated rdataset.
315 * Returns:
316 *\li #ISC_R_SUCCESS
317 *\li #ISC_R_NOMORE There are no more rdata in the set.
320 void
321 dns_rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata);
322 /*%<
323 * Make 'rdata' refer to the current rdata.
325 * Notes:
327 *\li The data returned in 'rdata' is valid for the life of the
328 * rdataset; in particular, subsequent changes in the cursor position
329 * do not invalidate 'rdata'.
331 * Requires:
332 *\li 'rdataset' is a valid, associated rdataset.
334 *\li The rdata cursor of 'rdataset' is at a valid location (i.e. the
335 * result of last call to a cursor movement command was ISC_R_SUCCESS).
337 * Ensures:
338 *\li 'rdata' refers to the rdata at the rdata cursor location of
339 *\li 'rdataset'.
342 isc_result_t
343 dns_rdataset_totext(dns_rdataset_t *rdataset,
344 dns_name_t *owner_name,
345 isc_boolean_t omit_final_dot,
346 isc_boolean_t question,
347 isc_buffer_t *target);
348 /*%<
349 * Convert 'rdataset' to text format, storing the result in 'target'.
351 * Notes:
352 *\li The rdata cursor position will be changed.
354 *\li The 'question' flag should normally be #ISC_FALSE. If it is
355 * #ISC_TRUE, the TTL and rdata fields are not printed. This is
356 * for use when printing an rdata representing a question section.
358 *\li This interface is deprecated; use dns_master_rdatasettottext()
359 * and/or dns_master_questiontotext() instead.
361 * Requires:
362 *\li 'rdataset' is a valid rdataset.
364 *\li 'rdataset' is not empty.
367 isc_result_t
368 dns_rdataset_towire(dns_rdataset_t *rdataset,
369 dns_name_t *owner_name,
370 dns_compress_t *cctx,
371 isc_buffer_t *target,
372 unsigned int options,
373 unsigned int *countp);
374 /*%<
375 * Convert 'rdataset' to wire format, compressing names as specified
376 * in 'cctx', and storing the result in 'target'.
378 * Notes:
379 *\li The rdata cursor position will be changed.
381 *\li The number of RRs added to target will be added to *countp.
383 * Requires:
384 *\li 'rdataset' is a valid rdataset.
386 *\li 'rdataset' is not empty.
388 *\li 'countp' is a valid pointer.
390 * Ensures:
391 *\li On a return of ISC_R_SUCCESS, 'target' contains a wire format
392 * for the data contained in 'rdataset'. Any error return leaves
393 * the buffer unchanged.
395 *\li *countp has been incremented by the number of RRs added to
396 * target.
398 * Returns:
399 *\li #ISC_R_SUCCESS - all ok
400 *\li #ISC_R_NOSPACE - 'target' doesn't have enough room
402 *\li Any error returned by dns_rdata_towire(), dns_rdataset_next(),
403 * dns_name_towire().
406 isc_result_t
407 dns_rdataset_towiresorted(dns_rdataset_t *rdataset,
408 const dns_name_t *owner_name,
409 dns_compress_t *cctx,
410 isc_buffer_t *target,
411 dns_rdatasetorderfunc_t order,
412 const void *order_arg,
413 unsigned int options,
414 unsigned int *countp);
415 /*%<
416 * Like dns_rdataset_towire(), but sorting the rdatasets according to
417 * the integer value returned by 'order' when called with the rdataset
418 * and 'order_arg' as arguments.
420 * Requires:
421 *\li All the requirements of dns_rdataset_towire(), and
422 * that order_arg is NULL if and only if order is NULL.
425 isc_result_t
426 dns_rdataset_towirepartial(dns_rdataset_t *rdataset,
427 const dns_name_t *owner_name,
428 dns_compress_t *cctx,
429 isc_buffer_t *target,
430 dns_rdatasetorderfunc_t order,
431 const void *order_arg,
432 unsigned int options,
433 unsigned int *countp,
434 void **state);
435 /*%<
436 * Like dns_rdataset_towiresorted() except that a partial rdataset
437 * may be written.
439 * Requires:
440 *\li All the requirements of dns_rdataset_towiresorted().
441 * If 'state' is non NULL then the current position in the
442 * rdataset will be remembered if the rdataset in not
443 * completely written and should be passed on on subsequent
444 * calls (NOT CURRENTLY IMPLEMENTED).
446 * Returns:
447 *\li #ISC_R_SUCCESS if all of the records were written.
448 *\li #ISC_R_NOSPACE if unable to fit in all of the records. *countp
449 * will be updated to reflect the number of records
450 * written.
453 isc_result_t
454 dns_rdataset_additionaldata(dns_rdataset_t *rdataset,
455 dns_additionaldatafunc_t add, void *arg);
456 /*%<
457 * For each rdata in rdataset, call 'add' for each name and type in the
458 * rdata which is subject to additional section processing.
460 * Requires:
462 *\li 'rdataset' is a valid, non-question rdataset.
464 *\li 'add' is a valid dns_additionaldatafunc_t
466 * Ensures:
468 *\li If successful, dns_rdata_additionaldata() will have been called for
469 * each rdata in 'rdataset'.
471 *\li If a call to dns_rdata_additionaldata() is not successful, the
472 * result returned will be the result of dns_rdataset_additionaldata().
474 * Returns:
476 *\li #ISC_R_SUCCESS
478 *\li Any error that dns_rdata_additionaldata() can return.
481 isc_result_t
482 dns_rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
483 dns_rdataset_t *nsec, dns_rdataset_t *nsecsig);
484 /*%<
485 * Return the noqname proof for this record.
487 * Requires:
488 *\li 'rdataset' to be valid and #DNS_RDATASETATTR_NOQNAME to be set.
489 *\li 'name' to be valid.
490 *\li 'nsec' and 'nsecsig' to be valid and not associated.
493 isc_result_t
494 dns_rdataset_addnoqname(dns_rdataset_t *rdataset, dns_name_t *name);
495 /*%<
496 * Associate a noqname proof with this record.
497 * Sets #DNS_RDATASETATTR_NOQNAME if successful.
498 * Adjusts the 'rdataset->ttl' to minimum of the 'rdataset->ttl' and
499 * the 'nsec' and 'rrsig(nsec)' ttl.
501 * Requires:
502 *\li 'rdataset' to be valid and #DNS_RDATASETATTR_NOQNAME to be set.
503 *\li 'name' to be valid and have NSEC and RRSIG(NSEC) rdatasets.
506 isc_result_t
507 dns_rdataset_getadditional(dns_rdataset_t *rdataset,
508 dns_rdatasetadditional_t type,
509 dns_rdatatype_t qtype,
510 dns_acache_t *acache,
511 dns_zone_t **zonep,
512 dns_db_t **dbp,
513 dns_dbversion_t **versionp,
514 dns_dbnode_t **nodep,
515 dns_name_t *fname,
516 dns_message_t *msg,
517 isc_stdtime_t now);
518 /*%<
519 * Get cached additional information from the DB node for a particular
520 * 'rdataset.' 'type' is one of dns_rdatasetadditional_fromauth,
521 * dns_rdatasetadditional_fromcache, and dns_rdatasetadditional_fromglue,
522 * which specifies the origin of the information. 'qtype' is intended to
523 * be used for specifying a particular rdata type in the cached information.
525 * Requires:
526 * \li 'rdataset' is a valid rdataset.
527 * \li 'acache' can be NULL, in which case this function will simply return
528 * ISC_R_FAILURE.
529 * \li For the other pointers, see dns_acache_getentry().
531 * Ensures:
532 * \li See dns_acache_getentry().
534 * Returns:
535 * \li #ISC_R_SUCCESS
536 * \li #ISC_R_FAILURE - additional information caching is not supported.
537 * \li #ISC_R_NOTFOUND - the corresponding DB node has not cached additional
538 * information for 'rdataset.'
539 * \li Any error that dns_acache_getentry() can return.
542 isc_result_t
543 dns_rdataset_setadditional(dns_rdataset_t *rdataset,
544 dns_rdatasetadditional_t type,
545 dns_rdatatype_t qtype,
546 dns_acache_t *acache,
547 dns_zone_t *zone,
548 dns_db_t *db,
549 dns_dbversion_t *version,
550 dns_dbnode_t *node,
551 dns_name_t *fname);
552 /*%<
553 * Set cached additional information to the DB node for a particular
554 * 'rdataset.' See dns_rdataset_getadditional for the semantics of 'type'
555 * and 'qtype'.
557 * Requires:
558 * \li 'rdataset' is a valid rdataset.
559 * \li 'acache' can be NULL, in which case this function will simply return
560 * ISC_R_FAILURE.
561 * \li For the other pointers, see dns_acache_setentry().
563 * Ensures:
564 * \li See dns_acache_setentry().
566 * Returns:
567 * \li #ISC_R_SUCCESS
568 * \li #ISC_R_FAILURE - additional information caching is not supported.
569 * \li #ISC_R_NOMEMORY
570 * \li Any error that dns_acache_setentry() can return.
573 isc_result_t
574 dns_rdataset_putadditional(dns_acache_t *acache,
575 dns_rdataset_t *rdataset,
576 dns_rdatasetadditional_t type,
577 dns_rdatatype_t qtype);
578 /*%<
579 * Discard cached additional information stored in the DB node for a particular
580 * 'rdataset.' See dns_rdataset_getadditional for the semantics of 'type'
581 * and 'qtype'.
583 * Requires:
584 * \li 'rdataset' is a valid rdataset.
585 * \li 'acache' can be NULL, in which case this function will simply return
586 * ISC_R_FAILURE.
588 * Ensures:
589 * \li See dns_acache_cancelentry().
591 * Returns:
592 * \li #ISC_R_SUCCESS
593 * \li #ISC_R_FAILURE - additional information caching is not supported.
594 * \li #ISC_R_NOTFOUND - the corresponding DB node has not cached additional
595 * information for 'rdataset.'
598 void
599 dns_rdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust);
600 /*%<
601 * Set the trust of the 'rdataset' to trust in any in the backing database.
602 * The local trust level of 'rdataset' is also set.
605 void
606 dns_rdataset_expire(dns_rdataset_t *rdataset);
607 /*%<
608 * Mark the rdataset to be expired in the backing database.
611 ISC_LANG_ENDDECLS
613 #endif /* DNS_RDATASET_H */