db.h 23.9 KB
Newer Older
Bob Halley's avatar
Bob Halley committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (C) 1999  Internet Software Consortium.
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#ifndef DNS_DB_H
#define DNS_DB_H 1

/*****
 ***** Module Info
 *****/

/*
 * DNS DB
 *
Bob Halley's avatar
Bob Halley committed
28
 * The DNS DB interface allows named rdatasets to be stored and retrieved.
Bob Halley's avatar
Bob Halley committed
29
30
31
32
33
34
35
 *
 * The dns_db_t type is like a "virtual class".  To actually use
 * DBs, an implementation of the class is required.
 *
 * XXX <more> XXX
 *
 * MP:
Bob Halley's avatar
Bob Halley committed
36
37
 *	The module ensures appropriate synchronization of data structures it
 *	creates and manipulates.
Bob Halley's avatar
Bob Halley committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 *
 * Reliability:
 *	No anticipated impact.
 *
 * Resources:
 *	<TBS>
 *
 * Security:
 *	No anticipated impact.
 *
 * Standards:
 *	None.
 */

Bob Halley's avatar
Bob Halley committed
52
53
54
55
/*****
 ***** Imports
 *****/

Bob Halley's avatar
Bob Halley committed
56
57
#include <stdio.h>

Bob Halley's avatar
Bob Halley committed
58
59
#include <isc/boolean.h>
#include <isc/mem.h>
60
#include <isc/lang.h>
61
#include <isc/stdtime.h>
Bob Halley's avatar
Bob Halley committed
62
63
64

#include <dns/types.h>
#include <dns/result.h>
Bob Halley's avatar
Bob Halley committed
65
#include <dns/name.h>
Bob Halley's avatar
Bob Halley committed
66
#include <dns/callbacks.h>
Bob Halley's avatar
Bob Halley committed
67

68
69
ISC_LANG_BEGINDECLS

Bob Halley's avatar
Bob Halley committed
70
71
72
73
/*****
 ***** Types
 *****/

Bob Halley's avatar
Bob Halley committed
74
75
76
typedef struct dns_dbmethods {
	void		(*attach)(dns_db_t *source, dns_db_t **targetp);
	void		(*detach)(dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
77
78
79
	dns_result_t	(*beginload)(dns_db_t *db, dns_addrdatasetfunc_t *addp,
				     dns_dbload_t **dbloadp);
	dns_result_t	(*endload)(dns_db_t *db, dns_dbload_t **dbloadp);
80
81
	dns_result_t	(*dump)(dns_db_t *db, dns_dbversion_t *version, 
				char *filename);
Bob Halley's avatar
Bob Halley committed
82
83
84
85
	void		(*currentversion)(dns_db_t *db,
					  dns_dbversion_t **versionp);
	dns_result_t	(*newversion)(dns_db_t *db,
				      dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
86
87
	void		(*attachversion)(dns_db_t *db, dns_dbversion_t *source,
					 dns_dbversion_t **targetp);
Bob Halley's avatar
Bob Halley committed
88
	void		(*closeversion)(dns_db_t *db,
Bob Halley's avatar
Bob Halley committed
89
90
					dns_dbversion_t **versionp,
					isc_boolean_t commit);
Bob Halley's avatar
Bob Halley committed
91
92
93
	dns_result_t	(*findnode)(dns_db_t *db, dns_name_t *name,
				    isc_boolean_t create,
				    dns_dbnode_t **nodep);
Bob Halley's avatar
Bob Halley committed
94
95
96
	dns_result_t	(*find)(dns_db_t *db, dns_name_t *name,
				dns_dbversion_t *version,
				dns_rdatatype_t type, unsigned int options,
97
				isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
98
99
				dns_dbnode_t **nodep, dns_name_t *foundname,
				dns_rdataset_t *rdataset);
Bob Halley's avatar
Bob Halley committed
100
101
102
103
104
	void		(*attachnode)(dns_db_t *db,
				      dns_dbnode_t *source,
				      dns_dbnode_t **targetp);
	void		(*detachnode)(dns_db_t *db,
				      dns_dbnode_t **targetp);
Bob Halley's avatar
Bob Halley committed
105
106
	dns_result_t	(*expirenode)(dns_db_t *db, dns_dbnode_t *node,
				      isc_stdtime_t now);
Bob Halley's avatar
Bob Halley committed
107
108
	void		(*printnode)(dns_db_t *db, dns_dbnode_t *node,
				     FILE *out);
Bob Halley's avatar
Bob Halley committed
109
110
111
	dns_result_t 	(*createiterator)(dns_db_t *db,
					  isc_boolean_t relative_names,
					  dns_dbiterator_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
112
113
114
	dns_result_t	(*findrdataset)(dns_db_t *db, dns_dbnode_t *node,
					dns_dbversion_t *version,
					dns_rdatatype_t type,
115
					isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
116
					dns_rdataset_t *rdataset);
Bob Halley's avatar
Bob Halley committed
117
118
	dns_result_t	(*allrdatasets)(dns_db_t *db, dns_dbnode_t *node,
					dns_dbversion_t *version,
119
					isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
120
					dns_rdatasetiter_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
121
122
	dns_result_t	(*addrdataset)(dns_db_t *db, dns_dbnode_t *node,
				       dns_dbversion_t *version,
123
				       isc_stdtime_t now,
124
				       dns_rdataset_t *rdataset,
Bob Halley's avatar
Bob Halley committed
125
				       isc_boolean_t merge,
126
				       dns_rdataset_t *addedrdataset);
Bob Halley's avatar
Bob Halley committed
127
128
129
130
	dns_result_t	(*subtractrdataset)(dns_db_t *db, dns_dbnode_t *node,
					    dns_dbversion_t *version,
					    dns_rdataset_t *rdataset,
					    dns_rdataset_t *newrdataset);
Bob Halley's avatar
Bob Halley committed
131
132
133
134
135
136
137
138
139
140
141
	dns_result_t	(*deleterdataset)(dns_db_t *db, dns_dbnode_t *node,
					  dns_dbversion_t *version,
					  dns_rdatatype_t type);
} dns_dbmethods_t;

#define DNS_DB_MAGIC			0x444E5344U		/* DNSD. */
#define DNS_DB_VALID(db)		((db) != NULL && \
					 (db)->magic == DNS_DB_MAGIC)

/*
 * This structure is actually just the common prefix of a DNS db
Bob Halley's avatar
Bob Halley committed
142
 * implementation's version of a dns_db_t.
Bob Halley's avatar
Bob Halley committed
143
144
145
 *
 * Direct use of this structure by clients is forbidden.  DB implementations
 * may change the structure.  'magic' must be DNS_DB_MAGIC for any of the
Bob Halley's avatar
Bob Halley committed
146
147
 * dns_db_ routines to work.  DB implementations must maintain all DB
 * invariants.
Bob Halley's avatar
Bob Halley committed
148
149
150
151
152
 */
struct dns_db {
	unsigned int			magic;
	unsigned int			impmagic;
	dns_dbmethods_t *		methods;
Bob Halley's avatar
Bob Halley committed
153
	isc_uint16_t			attributes;
154
	dns_rdataclass_t		rdclass;
Bob Halley's avatar
Bob Halley committed
155
	dns_name_t			origin;
Bob Halley's avatar
Bob Halley committed
156
	isc_mem_t *			mctx;
Bob Halley's avatar
Bob Halley committed
157
158
};

Bob Halley's avatar
Bob Halley committed
159
160
#define DNS_DBATTR_CACHE		0x01

Bob Halley's avatar
Bob Halley committed
161
162
163
164
165
/*
 * Options that can be specified for dns_db_find().
 */
#define DNS_DBFIND_GLUEOK		0x01
#define DNS_DBFIND_VALIDATEGLUE		0x02
Bob Halley's avatar
Bob Halley committed
166

Bob Halley's avatar
Bob Halley committed
167
168
169
170
171
172
173
174
/*****
 ***** Methods
 *****/

/***
 *** Basic DB Methods
 ***/

Bob Halley's avatar
Bob Halley committed
175
dns_result_t
Bob Halley's avatar
Bob Halley committed
176
dns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
177
	      isc_boolean_t cache, dns_rdataclass_t rdclass,
Bob Halley's avatar
Bob Halley committed
178
	      unsigned int argc, char *argv[], dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
179
180
181
182
183
/*
 * Create a new database using implementation 'db_type'.
 *
 * Notes:
 *	All names in the database must be subdomains of 'origin' and in class
184
 *	'rdclass'.  The database makes its own copy of the origin, so the caller
Bob Halley's avatar
Bob Halley committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 *	may do whatever they like with 'origin' and its storage once the
 *	call returns.
 *
 *	If 'cache' is ISC_TRUE, then cache semantics will be used, otherwise
 *	zone semantics will apply.
 *
 *	DB implementation-specific parameters are passed using argc and argv.
 *
 * Requires:
 *
 *	dbp != NULL and *dbp == NULL
 *
 *	'origin' is a valid absolute domain name.
 *
 *	mctx is a valid memory context
 *
 * Ensures:
 *
 *	A copy of 'origin' has been made for the databases use, and the
 *	caller is free to do whatever they want with the name and storage
 *	associated with 'origin'.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 *	DNS_R_NOTFOUND				db_type not found
 *
 *	Many other errors are possible, depending on what db_type was
 *	specified.
 */
Bob Halley's avatar
Bob Halley committed
216
217
218

void
dns_db_attach(dns_db_t *source, dns_db_t **targetp);
Bob Halley's avatar
Bob Halley committed
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
 * Attach *targetp to source.
 *
 * Requires:
 *
 *	'source' is a valid database.
 *
 *	'targetp' points to a NULL dns_db_t *.
 *
 * Ensures:
 *
 *	*targetp is attached to source.
 */
Bob Halley's avatar
Bob Halley committed
232
233
234

void
dns_db_detach(dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * Detach *dbp from its database.
 *
 * Requires:
 *
 *	'dbp' points to a valid database.
 *
 * Ensures:
 *
 *	*dbp is NULL.
 *
 *	If '*dbp' is the last reference to the database,
 *
 *		All resources used by the database will be freed
 */
Bob Halley's avatar
Bob Halley committed
250
251
252

isc_boolean_t
dns_db_iscache(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 * Does 'db' have cache semantics?
 *
 * Note: dns_db_iscache(db) == !dns_db_iszone(db)
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 * Returns:
 *	ISC_TRUE	'db' has cache semantics
 *	ISC_FALSE	otherwise
 */
Bob Halley's avatar
Bob Halley committed
266
267
268

isc_boolean_t
dns_db_iszone(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
 * Does 'db' have zone semantics?
 *
 * Note: dns_db_iszone(db) == !dns_db_iscache(db)
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 * Returns:
 *	ISC_TRUE	'db' has zone semantics
 *	ISC_FALSE	otherwise
 */
Bob Halley's avatar
Bob Halley committed
282

Bob Halley's avatar
Bob Halley committed
283
284
dns_name_t *
dns_db_origin(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
 * The origin of the database.
 *
 * Note: caller must not try to change this name.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 * Returns:
 *
 *	The origin of the database.
 */
Bob Halley's avatar
Bob Halley committed
298
299
300
301
302
303
304
305
306
307
308
309
310
311

dns_rdataclass_t
dns_db_class(dns_db_t *db);
/*
 * The class of the database.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 * Returns:
 *
 *	The class of the database.
 */
Bob Halley's avatar
Bob Halley committed
312

Bob Halley's avatar
Bob Halley committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
dns_result_t
dns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
		 dns_dbload_t **dbloadp);
/*
 * Begin loading 'db'.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	This is the first attempt to load 'db'.
 *
 *	addp != NULL && *addp == NULL
 *
 *	dbloadp != NULL && *dbloadp == NULL
 *
 * Ensures:
 *
 *	On success, *addp will be a valid dns_addrdatasetfunc_t suitable
 *	for loading 'db'.  *dbloadp will be a valid DB load context which
 *	should be used as 'arg' when *addp is called.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 *
 *	Other results are possible, depending upon the database
 *	implementation used, syntax errors in the master file, etc.
 */

dns_result_t
dns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp);
/*
 * Finish loading 'db'.
 *
 * Requires:
 *
 *	'db' is a valid database that is being loaded.
 *
 *	dbloadp != NULL and *dbloadp is a valid database load context.
 *
 * Ensures:
 *
 *	*dbloadp == NULL
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 *
 *	Other results are possible, depending upon the database
 *	implementation used, syntax errors in the master file, etc.
 */

Bob Halley's avatar
Bob Halley committed
368
369
dns_result_t
dns_db_load(dns_db_t *db, char *filename);
Bob Halley's avatar
Bob Halley committed
370
371
372
/*
 * Load master file 'filename' into 'db'.
 *
Bob Halley's avatar
Bob Halley committed
373
374
375
376
 * Notes:
 *	This routine is equivalent to calling
 *
 *		dns_db_beginload();
Bob Halley's avatar
Bob Halley committed
377
 *		dns_master_loadfile();
Bob Halley's avatar
Bob Halley committed
378
379
 *		dns_db_endload();
 *
Bob Halley's avatar
Bob Halley committed
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	This is the first attempt to load 'db'.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 *
 *	Other results are possible, depending upon the database
 *	implementation used, syntax errors in the master file, etc.
 */

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
dns_result_t
dns_db_dump(dns_db_t *db, dns_dbversion_t *version, char *filename);
/*
 * Dump version 'version' of 'db' to master file 'filename'.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'version' is a valid version.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 *
 *	Other results are possible, depending upon the database
 *	implementation used, OS file errors, etc.
 */

Bob Halley's avatar
Bob Halley committed
415
416
417
/***
 *** Version Methods
 ***/
Bob Halley's avatar
Bob Halley committed
418

Bob Halley's avatar
Bob Halley committed
419
420
void
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
421
422
423
424
425
/*
 * Open the current version for reading.
 *
 * Requires:
 *
426
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
427
428
429
430
431
432
433
434
 *
 *	versionp != NULL && *verisonp == NULL
 *
 * Ensures:
 *
 *	On success, '*versionp' is attached to the current version.
 *
 */
Bob Halley's avatar
Bob Halley committed
435
436
437

dns_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
438
439
440
441
442
/*
 * Open a new version for reading and writing.
 *
 * Requires:
 *
443
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
 *
 *	versionp != NULL && *verisonp == NULL
 *
 * Ensures:
 *
 *	On success, '*versionp' is attached to the current version.
 * 
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 *
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
459

Bob Halley's avatar
Bob Halley committed
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
void
dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
		     dns_dbversion_t **targetp);
/*
 * Attach '*targetp' to 'source'.
 *
 * Requires:
 *
 *	'db' is a valid database with zone semantics.
 *
 *	source is a valid open version
 *
 *	targetp != NULL && *targetp == NULL
 *
 * Ensures:
 *
 *	'*targetp' is attached to source.
 */

Bob Halley's avatar
Bob Halley committed
479
void
Bob Halley's avatar
Bob Halley committed
480
481
482
483
484
485
486
487
488
489
490
491
dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
		    isc_boolean_t commit);
/*
 * Close version '*versionp'.
 *
 * Note: if '*versionp' is a read-write version and 'commit' is ISC_TRUE,
 * then all changes made in the version will take effect, otherwise they
 * will be rolled back.  The value if 'commit' is ignored for read-only
 * versions.
 *
 * Requires:
 *
492
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
493
494
495
 *
 *	'*versionp' refers to a valid version.
 *
496
497
498
499
 *	If committing a writable version, then there must be no other
 *	outstanding references to the version (e.g. an active rdataset
 *	iterator).
 *
Bob Halley's avatar
Bob Halley committed
500
501
502
503
504
 * Ensures:
 *
 *	*versionp == NULL
 *
 *	If *versionp is a read-write version, and commit is ISC_TRUE, then
505
506
507
 *	the version will become the current version.  If !commit, then all
 *	changes made in the version will be undone, and the version will
 *	not become the current version.
Bob Halley's avatar
Bob Halley committed
508
509
510
511
512
 */

/***
 *** Node Methods
 ***/
Bob Halley's avatar
Bob Halley committed
513
514
515
516

dns_result_t
dns_db_findnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
		dns_dbnode_t **nodep);
Bob Halley's avatar
Bob Halley committed
517
518
519
/*
 * Find the node with name 'name'.
 *
Bob Halley's avatar
Bob Halley committed
520
521
522
 * Notes:
 *	If 'create' is ISC_TRUE and no node with name 'name' exists, then
 *	such a node will be created.
Bob Halley's avatar
Bob Halley committed
523
 *
Bob Halley's avatar
Bob Halley committed
524
525
526
527
 *	This routine is for finding or creating a node with the specified
 *	name.  There are no partial matches.  It is not suitable for use
 *	in building responses to ordinary DNS queries; clients which wish
 *	to do that should use dns_db_find() instead.
Bob Halley's avatar
Bob Halley committed
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'name' is a valid, non-empty, absolute name that is a subdomain of
 *	the database's origin.  (It need not be a proper subdomain.)
 *
 *	nodep != NULL && *nodep == NULL
 *
 * Ensures:
 *
 *	On success, *nodep is attached to the node with name 'name'.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOTFOUND			If !create and name not found.
 *	DNS_R_NOMEMORY		        Can only happen if create is ISC_TRUE.
 *
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
551

Bob Halley's avatar
Bob Halley committed
552
553
dns_result_t
dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
554
	    dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
555
556
557
	    dns_dbnode_t **nodep, dns_name_t *foundname,
	    dns_rdataset_t *rdataset);
/*
558
559
560
561
562
563
564
565
566
567
568
569
 * Find the best match for 'name' and 'type' in version 'version' of 'db'.
 *
 * Notes:
 *
 *	If type == dns_rdataset_any, then rdataset will not be bound.
 *
 *	If 'options' does not have DNS_DBFIND_GLUEOK set, then no glue will
 *	be returned.  This option is only meaningful for zone databases.
 *
 *	To respond to a query for SIG records, the caller should create a
 *	rdataset iterator and extract the signatures from each rdataset.
 *
Bob Halley's avatar
Bob Halley committed
570
571
572
573
 *	Making queries of type ANY with DNS_DBFIND_GLUEOK is not recommended,
 *	because the burden of determining whether a given rdataset is valid
 *	glue or not falls upon the caller.
 *
574
575
576
577
578
579
 *	The 'now' field is ignored if 'db' is a zone database.  If 'db' is a
 *	cache database, an rdataset will not be found unless it expires after
 *	'now'.  Any ANY query will not match unless at least one rdataset at
 *	the node expires after 'now'.  If 'now' is zero, then the current time
 *	will be used.
 *
580
581
582
583
 * Requires:
 *
 *	'db' is a valid database.
 *
584
 *	'type' is not SIG, or a meta-RR type other than 'ANY' (e.g. 'OPT').
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
 *
 *	'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
 *
 *	'foundname' is NULL, or is a valid name with a dedicated buffer.
 *
 *	'rdataset' is NULL, or is a valid unassociated rdataset.
 *
 * Ensures:
 *	On a non-error completion:
 *
 *		If nodep != NULL, then it is bound to the found node.
 *
 *		If foundname != NULL, then it contains the full name of the
 *		found node.
 *
 *		If rdataset != NULL and type != dns_rdatatype_any, then
 *		rdataset is bound to the found rdataset.
 *
 * Returns:
 *
 *	Non-error results are:
 *
 *		DNS_R_SUCCESS			The desired node and type were
 *						found.
 *
 *		DNS_R_GLUE			The desired node and type were
 *						found, but are glue.  This
 *						result can only occur if
 *						the DNS_DBFIND_GLUEOK option
 *						is set.  This result can only
 *						occur if 'db' is a zone
Bob Halley's avatar
Bob Halley committed
616
617
618
619
620
621
622
623
 *						database.  If type ==
 *						dns_rdatatype_any, then the
 *						node returned may contain, or
 *						consist entirely of invalid
 *						glue (i.e. data occluded by a
 *						zone cut).  The caller must
 *						take care not to return invalid
 *						glue to a client.
624
625
626
627
628
629
630
631
632
633
634
635
 *
 *		DNS_R_DELEGATION		The data requested is beneath
 *						a zone cut.  node, foundname,
 *						and rdataset reference the
 *						NS RRset of the zone cut.
 *						If 'db' is a cache database,
 *						then this is the deepest known
 *						delegation.
 *
 *		DNS_R_ZONECUT			type == dns_rdatatype_any, and
 *						the desired node is a zonecut.
 *						The caller must take care not
Bob Halley's avatar
Bob Halley committed
636
637
638
639
 *						to return inappropriate glue
 *						to a client.  This result can
 *						only occur if 'db' is a zone
 *						database.
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
 *
 *		DNS_R_DNAME			The data requested is beneath
 *						a DNAME.  node, foundname,
 *						and rdataset reference the
 *						DNAME RRset.
 *
 *		DNS_R_CNAME			The rdataset requested was not
 *						found, but there is a CNAME
 *						at the desired name.  node,
 *						foundname, and rdataset
 *						reference the CNAME RRset.
 *
 *		DNS_R_NXDOMAIN			The desired name does not
 *						exist.
 *
 *		DNS_R_NXRDATASET		The desired name exists, but
 *						the desired type does not.
 *
 *		DNS_R_NOTFOUND			The desired name does not
 *						exist, and no delegation could
 *						be found.  This result can only
 *						occur if 'db' is a cache
 *						database.  The caller should
 *						use its nameserver(s) of last
 *						resort (e.g. root hints).
 *
 *		XXX There will be a result like DNS_R_WILDCARD for wildcard
 *		matches.
 *
 *	Error results:
 *
 *		DNS_R_NOMEMORY
 *
 *		DNS_R_BADDB			Data that is required to be
 *						present in the DB, e.g. an NXT
 *						record in a secure zone, is not
 *						present.
 *
 *		Other results are possible, and should all be treated as
 *		errors.
Bob Halley's avatar
Bob Halley committed
680
681
 */

Bob Halley's avatar
Bob Halley committed
682
683
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp);
Bob Halley's avatar
Bob Halley committed
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/*
 * Attach *targetp to source.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'source' is a valid node.
 *
 *	'targetp' points to a NULL dns_node_t *.
 *
 * Ensures:
 *
 *	*targetp is attached to source.
 */
Bob Halley's avatar
Bob Halley committed
699
700
701

void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep);
Bob Halley's avatar
Bob Halley committed
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
 * Detach *nodep from its node.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'nodep' points to a valid node.
 *
 * Ensures:
 *
 *	*nodep is NULL.
 */

Bob Halley's avatar
Bob Halley committed
716
717
718
719
720
721
722
723
724
725
726
727
728
729
dns_result_t
dns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now);
/*
 * Mark as stale all records at 'node' which expire at or before 'now'.
 *
 * Note: if 'now' is zero, then the current time will be used.
 *
 * Requires:
 *
 *	'db' is a valid cache database.
 *
 *	'node' is a valid node.
 */

Bob Halley's avatar
Bob Halley committed
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
void
dns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out);
/*
 * Print a textual representation of the contents of the node to
 * 'out'.
 *
 * Note: this function is intended for debugging, not general use.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 */

Bob Halley's avatar
Bob Halley committed
745
746
747
748
749
/***
 *** DB Iterator Creation
 ***/

dns_result_t
750
dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
Bob Halley's avatar
Bob Halley committed
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
		      dns_dbiterator_t **iteratorp);
/*
 * Create an iterator for version 'version' of 'db'.
 *
 * Notes:
 *
 *	If 'relative_names' is ISC_TRUE, then node names returned by the
 *	iterator will be relative to the iterator's current origin.  If
 *	ISC_FALSE, then the node names will be absolute.
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	iteratorp != NULL && *iteratorp == NULL
 *
 * Ensures:
 *
 *	On success, *iteratorp will be a valid database iterator.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOMEMORY
 */

Bob Halley's avatar
Bob Halley committed
777
778
779
/***
 *** Rdataset Methods
 ***/
Bob Halley's avatar
Bob Halley committed
780
781
782

dns_result_t
dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
783
784
		    dns_rdatatype_t type, isc_stdtime_t now,
		    dns_rdataset_t *rdataset);
Bob Halley's avatar
Bob Halley committed
785
786
787
788
789
790
791
792
/*
 * Search for an rdataset of type 'type' at 'node' that are in version
 * 'version' of 'db'.  If found, make 'rdataset' refer to it.
 *
 * Notes:
 *
 *	If 'version' is NULL, then the current version will be used.
 *
Bob Halley's avatar
Bob Halley committed
793
794
795
796
 *	This routine is not suitable for use in building responses to
 *	ordinary DNS queries; clients which wish to do that should use
 *	dns_db_find() instead.
 *
797
798
 *	The 'now' field is ignored if 'db' is a zone database.  If 'db' is a
 *	cache database, an rdataset will not be found unless it expires after
799
 *	'now'.  If 'now' is zero, then the current time will be used.
800
 *
Bob Halley's avatar
Bob Halley committed
801
802
803
804
805
806
807
808
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
 *	'rdataset' is a valid, disassociated rdataset.
 *
809
 *	'type' is not SIG, or a meta-RR type such as 'ANY' or 'OPT'.
Bob Halley's avatar
Bob Halley committed
810
811
812
813
814
815
816
817
818
819
820
821
822
 *
 * Ensures:
 *
 *	On success, 'rdataset' is associated with the found rdataset.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOTFOUND
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
823

Bob Halley's avatar
Bob Halley committed
824
825
dns_result_t
dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
826
		    isc_stdtime_t now, dns_rdatasetiter_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
827
828
829
830
831
832
833
834
/*
 * Make '*iteratorp' an rdataset iteratator for all rdatasets at 'node' in
 * version 'version' of 'db'.
 *
 * Notes:
 *
 *	If 'version' is NULL, then the current version will be used.
 *
835
836
837
838
839
840
 *	The 'now' field is ignored if 'db' is a zone database.  If 'db' is a
 *	cache database, an rdataset will not be found unless it expires after
 *	'now'.  Any ANY query will not match unless at least one rdataset at
 *	the node expires after 'now'.  If 'now' is zero, then the current time
 *	will be used.
 *
Bob Halley's avatar
Bob Halley committed
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
 *	iteratorp != NULL && *iteratorp == NULL
 *
 * Ensures:
 *
 *	On success, '*iteratorp' is a valid rdataset iterator.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_NOTFOUND
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */

Bob Halley's avatar
Bob Halley committed
862
863
dns_result_t
dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
864
		   isc_stdtime_t now, dns_rdataset_t *rdataset,
Bob Halley's avatar
Bob Halley committed
865
		   isc_boolean_t merge, dns_rdataset_t *addedrdataset);
Bob Halley's avatar
Bob Halley committed
866
867
868
/*
 * Add 'rdataset' to 'node' in version 'version' of 'db'.
 *
869
870
 * Notes:
 *
Bob Halley's avatar
Bob Halley committed
871
872
873
874
875
876
 *	If the database has zone semantics, 'merge' is ISC_TRUE, and an
 *	rdataset of the same type as 'rdataset' already exists at 'node',
 *	then the contents of 'rdataset' will be merged with the existing
 *	rdataset.  If merge is ISC_FALSE, then rdataset will replace any
 *	existing rdataset of the same type.
 *
877
878
879
880
 *	The 'now' field is ignored if 'db' is a zone database.  If 'db' is
 *	a cache database, then the added rdataset will expire no later than
 *	now + rdataset->ttl.
 *
881
 *	If 'addedrdataset' is not NULL, then it will be attached to the
Andreas Gustafsson's avatar
Andreas Gustafsson committed
882
 *	resulting new rdataset in the database.
883
 *
Bob Halley's avatar
Bob Halley committed
884
885
886
887
888
889
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
890
891
 *	'rdataset' is a valid, associated rdataset with the same class
 *	as 'db'.
Bob Halley's avatar
Bob Halley committed
892
 *
893
894
 *	'addedrdataset' is NULL, or a valid, unassociated rdataset.
 *
895
896
897
 *	The database has zone semantics and 'version' is a valid
 *	read-write version, or the database has cache semantics
 *	and version is NULL.
Bob Halley's avatar
Bob Halley committed
898
 *
Bob Halley's avatar
Bob Halley committed
899
900
 *	If the database has cache semantics, 'merge' must be ISC_FALSE.
 *
Bob Halley's avatar
Bob Halley committed
901
902
903
 * Returns:
 *
 *	DNS_R_SUCCESS
Bob Halley's avatar
Bob Halley committed
904
 *	DNS_R_UNCHANGED			The operation did not change anything.
Bob Halley's avatar
Bob Halley committed
905
 *	DNS_R_NOMEMORY
Bob Halley's avatar
Bob Halley committed
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */

dns_result_t
dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
			dns_dbversion_t *version, dns_rdataset_t *rdataset,
			dns_rdataset_t *newrdataset);
/*
 * Remove any rdata in 'rdataset' from 'node' in version 'version' of
 * 'db'.
 *
 * Notes:
 *
 *	If 'newrdataset' is not NULL, then it will be attached to the
Andreas Gustafsson's avatar
Andreas Gustafsson committed
922
923
 *	resulting new rdataset in the database, unless the rdataset has 
 *	become nonexistent.
Bob Halley's avatar
Bob Halley committed
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
 *	'rdataset' is a valid, associated rdataset with the same class
 *	as 'db'.
 *
 *	'newrdataset' is NULL, or a valid, unassociated rdataset.
 *
 *	The database has zone semantics and 'version' is a valid
 *	read-write version.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
 *	DNS_R_UNCHANGED			The operation did not change anything.
 *	DNS_R_NXRDATASET		All rdata of the same type as those
 *					in 'rdataset' have been deleted.
Bob Halley's avatar
Bob Halley committed
945
946
947
948
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
949
950
951
952

dns_result_t
dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
		      dns_dbversion_t *version, dns_rdatatype_t type);
Bob Halley's avatar
Bob Halley committed
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
/*
 * Make it so that no rdataset of type 'type' exists at 'node' in version
 * version 'version' of 'db'.
 *
 * Notes:
 *
 *	If 'type' is dns_rdatatype_any, then no rdatasets will exist in
 *	'version' (provided that the dns_db_deleterdataset() isn't followed
 *	by one or more dns_db_addrdataset() calls).
 *
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
969
970
971
 *	The database has zone semantics and 'version' is a valid
 *	read-write version, or the database has cache semantics
 *	and version is NULL.
Bob Halley's avatar
Bob Halley committed
972
973
974
975
976
977
978
979
980
981
982
 *
 *	'type' is not a meta-RR type, except for dns_rdatatype_any, which is
 *	allowed.
 *
 * Ensures:
 *
 *	On success, 'rdataset' is associated with the found rdataset.
 *
 * Returns:
 *
 *	DNS_R_SUCCESS
Bob Halley's avatar
Bob Halley committed
983
984
 *	DNS_R_UNCHANGED			No rdatasets of 'type' existed before
 *					the operation was attempted.
Bob Halley's avatar
Bob Halley committed
985
986
987
988
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
989

990
991
ISC_LANG_ENDDECLS

Bob Halley's avatar
Bob Halley committed
992
#endif /* DNS_DB_H */