db.h 26.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
	dns_result_t	(*dump)(dns_db_t *db, dns_dbversion_t *version, 
Bob Halley's avatar
Bob Halley committed
81
				const 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
				dns_dbnode_t **nodep, dns_name_t *foundname,
Bob Halley's avatar
Bob Halley committed
99
100
				dns_rdataset_t *rdataset,
				dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
101
102
103
104
105
106
	dns_result_t	(*findzonecut)(dns_db_t *db, dns_name_t *name,
				       unsigned int options, isc_stdtime_t now,
				       dns_dbnode_t **nodep,
				       dns_name_t *foundname,
				       dns_rdataset_t *rdataset,
				       dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
107
108
109
110
111
	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
112
113
	dns_result_t	(*expirenode)(dns_db_t *db, dns_dbnode_t *node,
				      isc_stdtime_t now);
Bob Halley's avatar
Bob Halley committed
114
115
	void		(*printnode)(dns_db_t *db, dns_dbnode_t *node,
				     FILE *out);
Bob Halley's avatar
Bob Halley committed
116
117
118
	dns_result_t 	(*createiterator)(dns_db_t *db,
					  isc_boolean_t relative_names,
					  dns_dbiterator_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
119
120
121
	dns_result_t	(*findrdataset)(dns_db_t *db, dns_dbnode_t *node,
					dns_dbversion_t *version,
					dns_rdatatype_t type,
Bob Halley's avatar
Bob Halley committed
122
					dns_rdatatype_t covers,
123
					isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
124
125
					dns_rdataset_t *rdataset,
					dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
126
127
	dns_result_t	(*allrdatasets)(dns_db_t *db, dns_dbnode_t *node,
					dns_dbversion_t *version,
128
					isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
129
					dns_rdatasetiter_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
130
131
	dns_result_t	(*addrdataset)(dns_db_t *db, dns_dbnode_t *node,
				       dns_dbversion_t *version,
132
				       isc_stdtime_t now,
133
				       dns_rdataset_t *rdataset,
Bob Halley's avatar
Bob Halley committed
134
				       isc_boolean_t merge,
135
				       dns_rdataset_t *addedrdataset);
Bob Halley's avatar
Bob Halley committed
136
137
138
139
	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
140
141
142
	dns_result_t	(*deleterdataset)(dns_db_t *db, dns_dbnode_t *node,
					  dns_dbversion_t *version,
					  dns_rdatatype_t type);
Bob Halley's avatar
Bob Halley committed
143
	isc_boolean_t	(*issecure)(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
144
145
146
147
148
149
150
151
} 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
152
 * implementation's version of a dns_db_t.
Bob Halley's avatar
Bob Halley committed
153
154
155
 *
 * 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
156
157
 * dns_db_ routines to work.  DB implementations must maintain all DB
 * invariants.
Bob Halley's avatar
Bob Halley committed
158
159
160
161
162
 */
struct dns_db {
	unsigned int			magic;
	unsigned int			impmagic;
	dns_dbmethods_t *		methods;
Bob Halley's avatar
Bob Halley committed
163
	isc_uint16_t			attributes;
164
	dns_rdataclass_t		rdclass;
Bob Halley's avatar
Bob Halley committed
165
	dns_name_t			origin;
Bob Halley's avatar
Bob Halley committed
166
	isc_mem_t *			mctx;
Bob Halley's avatar
Bob Halley committed
167
168
};

Bob Halley's avatar
Bob Halley committed
169
170
#define DNS_DBATTR_CACHE		0x01

Bob Halley's avatar
Bob Halley committed
171
172
173
174
175
/*
 * Options that can be specified for dns_db_find().
 */
#define DNS_DBFIND_GLUEOK		0x01
#define DNS_DBFIND_VALIDATEGLUE		0x02
176
#define DNS_DBFIND_NOWILD		0x04
Bob Halley's avatar
Bob Halley committed
177
178
#define DNS_DBFIND_PENDINGOK		0x08

Bob Halley's avatar
Bob Halley committed
179
180
181
182
/*
 * Options that can be specified for dns_db_findzonecut().
 */
#define DNS_DBFIND_ONLYANCESTORS	0x08
Bob Halley's avatar
Bob Halley committed
183

Bob Halley's avatar
Bob Halley committed
184
185
186
187
188
189
190
191
/*****
 ***** Methods
 *****/

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

Bob Halley's avatar
Bob Halley committed
192
dns_result_t
Bob Halley's avatar
Bob Halley committed
193
dns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
194
	      isc_boolean_t cache, dns_rdataclass_t rdclass,
Bob Halley's avatar
Bob Halley committed
195
	      unsigned int argc, char *argv[], dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
196
197
198
199
200
/*
 * Create a new database using implementation 'db_type'.
 *
 * Notes:
 *	All names in the database must be subdomains of 'origin' and in class
201
 *	'rdclass'.  The database makes its own copy of the origin, so the caller
Bob Halley's avatar
Bob Halley committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
 *	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
233
234
235

void
dns_db_attach(dns_db_t *source, dns_db_t **targetp);
Bob Halley's avatar
Bob Halley committed
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * 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
249
250
251

void
dns_db_detach(dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
 * 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
267
268
269

isc_boolean_t
dns_db_iscache(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
 * 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
283
284
285

isc_boolean_t
dns_db_iszone(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
 * 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
299

Bob Halley's avatar
Bob Halley committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
isc_boolean_t
dns_db_issecure(dns_db_t *db);
/*
 * Is 'db' secure?
 *
 * Requires:
 *
 *	'db' is a valid database with zone semantics.
 *
 * Returns:
 *	ISC_TRUE	'db' is secure.
 *	ISC_FALSE	'db' is not secure.
 */

Bob Halley's avatar
Bob Halley committed
314
315
dns_name_t *
dns_db_origin(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
 * 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342

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
343

Bob Halley's avatar
Bob Halley committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
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
399
dns_result_t
Bob Halley's avatar
Bob Halley committed
400
dns_db_load(dns_db_t *db, const char *filename);
Bob Halley's avatar
Bob Halley committed
401
402
403
/*
 * Load master file 'filename' into 'db'.
 *
Bob Halley's avatar
Bob Halley committed
404
405
406
407
 * Notes:
 *	This routine is equivalent to calling
 *
 *		dns_db_beginload();
Bob Halley's avatar
Bob Halley committed
408
 *		dns_master_loadfile();
Bob Halley's avatar
Bob Halley committed
409
410
 *		dns_db_endload();
 *
Bob Halley's avatar
Bob Halley committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
 * 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.
 */

426
dns_result_t
Bob Halley's avatar
Bob Halley committed
427
dns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename);
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*
 * 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
446
447
448
/***
 *** Version Methods
 ***/
Bob Halley's avatar
Bob Halley committed
449

Bob Halley's avatar
Bob Halley committed
450
451
void
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
452
453
454
455
456
/*
 * Open the current version for reading.
 *
 * Requires:
 *
457
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
458
459
460
461
462
463
464
465
 *
 *	versionp != NULL && *verisonp == NULL
 *
 * Ensures:
 *
 *	On success, '*versionp' is attached to the current version.
 *
 */
Bob Halley's avatar
Bob Halley committed
466
467
468

dns_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
469
470
471
472
473
/*
 * Open a new version for reading and writing.
 *
 * Requires:
 *
474
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
 *
 *	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
490

Bob Halley's avatar
Bob Halley committed
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
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
510
void
Bob Halley's avatar
Bob Halley committed
511
512
513
514
515
516
517
518
519
520
521
522
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:
 *
523
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
524
525
526
 *
 *	'*versionp' refers to a valid version.
 *
527
528
529
530
 *	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
531
532
533
534
535
 * Ensures:
 *
 *	*versionp == NULL
 *
 *	If *versionp is a read-write version, and commit is ISC_TRUE, then
536
537
538
 *	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
539
540
541
542
543
 */

/***
 *** Node Methods
 ***/
Bob Halley's avatar
Bob Halley committed
544
545
546
547

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
548
549
550
/*
 * Find the node with name 'name'.
 *
Bob Halley's avatar
Bob Halley committed
551
552
553
 * 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
554
 *
Bob Halley's avatar
Bob Halley committed
555
556
557
558
 *	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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
 *
 * 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
582

Bob Halley's avatar
Bob Halley committed
583
584
dns_result_t
dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
585
	    dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
586
	    dns_dbnode_t **nodep, dns_name_t *foundname,
Bob Halley's avatar
Bob Halley committed
587
	    dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
588
/*
589
590
591
592
593
594
595
 * 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
596
597
598
 *	be returned.  For zone databases, glue is as defined in RFC 2181.
 *	For cache databases, glue is any rdataset with a trust of
 *	dns_trust_glue.
599
 *
Bob Halley's avatar
Bob Halley committed
600
601
602
603
 *	If 'options' does not have DNS_DBFIND_PENDINGOK set, then no
 *	pending data will be returned.  This option is only meaningful for
 *	cache databases.
 *
604
605
606
 *	If the DNS_DBFIND_NOWILD option is set, then wildcard matching will
 *	be disabled.  This option is only meaningful for zone databases.
 *
607
608
609
 *	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
610
611
612
613
 *	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.
 *
614
615
616
617
618
619
 *	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.
 *
620
621
622
623
 * Requires:
 *
 *	'db' is a valid database.
 *
624
 *	'type' is not SIG, or a meta-RR type other than 'ANY' (e.g. 'OPT').
625
626
627
 *
 *	'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
 *
628
 *	'foundname' is a valid name with a dedicated buffer.
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
 *
 *	'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
656
657
658
659
660
661
662
663
 *						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.
664
665
666
667
668
669
670
671
672
673
674
675
 *
 *		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
676
677
678
679
 *						to return inappropriate glue
 *						to a client.  This result can
 *						only occur if 'db' is a zone
 *						database.
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
 *
 *		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.
 *
Bob Halley's avatar
Bob Halley committed
695
 *		DNS_R_NXRRSET			The desired name exists, but
696
697
698
699
700
701
702
703
704
705
 *						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).
 *
Bob Halley's avatar
Bob Halley committed
706
707
708
709
710
711
712
713
714
715
716
 *		DNS_R_NCACHENXDOMAIN		The desired name does not
 *						exist.  'node' is bound to the
 *						cache node with the desired
 *						name, and 'rdataset' contains
 *						the negative caching proof.
 *
 *		DNS_R_NCACHENXRRSET		The desired type does not
 *						exist.  'node' is bound to the
 *						cache node with the desired
 *						name, and 'rdataset' contains
 *						the negative caching proof.
717
718
719
720
721
722
723
724
725
726
727
728
 *
 *	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
729
730
 */

Bob Halley's avatar
Bob Halley committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
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
777
778
dns_result_t
dns_db_findzonecut(dns_db_t *db, dns_name_t *name,
		   unsigned int options, isc_stdtime_t now,
		   dns_dbnode_t **nodep, dns_name_t *foundname,
		   dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
/*
 * Find the deepest known zonecut which encloses 'name' in 'db'.
 *
 * Notes:
 *
 *	If 'options' has DNS_DBFIND_ONLYANCESTORS set, then 'name' will
 *	be returned as the deepest match if it has an NS rdataset.
 *
 *	If 'now' is zero, then the current time will be used.
 *
 * Requires:
 *
 *	'db' is a valid database with cache semantics.
 *
 *	'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
 *
 *	'foundname' 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
 *
 *		DNS_R_NOTFOUND
 *
 *		Other results are possible, and should all be treated as
 *		errors.
 */

Bob Halley's avatar
Bob Halley committed
779
780
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp);
Bob Halley's avatar
Bob Halley committed
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*
 * 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
796
797
798

void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep);
Bob Halley's avatar
Bob Halley committed
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/*
 * 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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
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
842
843
844
845
846
/***
 *** DB Iterator Creation
 ***/

dns_result_t
847
dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
Bob Halley's avatar
Bob Halley committed
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
		      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
874
875
876
/***
 *** Rdataset Methods
 ***/
Bob Halley's avatar
Bob Halley committed
877

Bob Halley's avatar
Bob Halley committed
878
879
880
881
/*
 * XXXRTH  Should we check for glue and pending data in dns_db_findrdataset()?
 */

Bob Halley's avatar
Bob Halley committed
882
883
dns_result_t
dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
Bob Halley's avatar
Bob Halley committed
884
		    dns_rdatatype_t type, dns_rdatatype_t covers,
Bob Halley's avatar
Bob Halley committed
885
886
		    isc_stdtime_t now, dns_rdataset_t *rdataset,
		    dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
887
888
889
890
891
892
893
894
/*
 * 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
895
896
 *	Care must be used when using this routine to build a DNS response:
 *	'node' should have been found with dns_db_find(), not
Bob Halley's avatar
Bob Halley committed
897
898
 *	dns_db_findnode().  No glue checking is done.  No checking for
 *	pending data is done.
Bob Halley's avatar
Bob Halley committed
899
 *
900
901
 *	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
902
 *	'now'.  If 'now' is zero, then the current time will be used.
903
 *
Bob Halley's avatar
Bob Halley committed
904
905
906
907
908
909
910
911
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
 *	'rdataset' is a valid, disassociated rdataset.
 *
Bob Halley's avatar
Bob Halley committed
912
913
 *	'sigrdataset' is a valid, disassociated rdataset, or it is NULL.
 *
Bob Halley's avatar
Bob Halley committed
914
915
916
 *	If 'covers' != 0, 'type' must be SIG.
 *
 *	'type' is not a meta-RR type such as 'ANY' or 'OPT'.
Bob Halley's avatar
Bob Halley committed
917
918
919
920
921
922
923
924
925
926
927
928
929
 *
 * 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
930

Bob Halley's avatar
Bob Halley committed
931
932
dns_result_t
dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
933
		    isc_stdtime_t now, dns_rdatasetiter_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
934
935
936
937
938
939
940
941
/*
 * 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.
 *
942
943
944
945
946
947
 *	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
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
 * 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
969
970
dns_result_t
dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
971
		   isc_stdtime_t now, dns_rdataset_t *rdataset,
Bob Halley's avatar
Bob Halley committed
972
		   isc_boolean_t merge, dns_rdataset_t *addedrdataset);
Bob Halley's avatar
Bob Halley committed
973
974
975
/*
 * Add 'rdataset' to 'node' in version 'version' of 'db'.
 *
976
977
 * Notes:
 *
Bob Halley's avatar
Bob Halley committed
978
979
980
981
982
983
 *	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.
 *
984
985
986
987
 *	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.
 *
988
 *	If 'addedrdataset' is not NULL, then it will be attached to the
Andreas Gustafsson's avatar
Andreas Gustafsson committed
989
 *	resulting new rdataset in the database.
990
 *
Bob Halley's avatar
Bob Halley committed
991
992
993
994
995
996
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
997
998
 *	'rdataset' is a valid, associated rdataset with the same class
 *	as 'db'.
Bob Halley's avatar
Bob Halley committed
999
 *
1000
1001
 *	'addedrdataset' is NULL, or a valid, unassociated rdataset.
 *
1002
1003
1004
 *	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
1005
 *
Bob Halley's avatar
Bob Halley committed
1006
1007
 *	If the database has cache semantics, 'merge' must be ISC_FALSE.
 *
Bob Halley's avatar
Bob Halley committed
1008
1009
1010
 * Returns:
 *
 *	DNS_R_SUCCESS
Bob Halley's avatar
Bob Halley committed
1011
 *	DNS_R_UNCHANGED			The operation did not change anything.
Bob Halley's avatar
Bob Halley committed
1012
 *	DNS_R_NOMEMORY
Bob Halley's avatar
Bob Halley committed
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
 *	
 *	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
1029
1030
 *	resulting new rdataset in the database, unless the rdataset has 
 *	become nonexistent.
Bob Halley's avatar
Bob Halley committed
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
 *
 * 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
1052
1053
1054
1055
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
1056
1057
1058
1059

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
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
/*
 * 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.
 *
1076
1077
1078
 *	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
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
 *
 *	'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
1090
1091
 *	DNS_R_UNCHANGED			No rdatasets of 'type' existed before
 *					the operation was attempted.
Bob Halley's avatar
Bob Halley committed
1092
1093
1094
1095
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
1096

1097
1098
ISC_LANG_ENDDECLS

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