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

Bob Halley's avatar
Bob Halley committed
163
164
#define DNS_DBATTR_CACHE		0x01

Bob Halley's avatar
Bob Halley committed
165
166
167
168
169
/*
 * Options that can be specified for dns_db_find().
 */
#define DNS_DBFIND_GLUEOK		0x01
#define DNS_DBFIND_VALIDATEGLUE		0x02
170
#define DNS_DBFIND_NOWILD		0x04
Bob Halley's avatar
Bob Halley committed
171

Bob Halley's avatar
Bob Halley committed
172
173
174
175
176
177
178
179
/*****
 ***** Methods
 *****/

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

Bob Halley's avatar
Bob Halley committed
180
dns_result_t
Bob Halley's avatar
Bob Halley committed
181
dns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
182
	      isc_boolean_t cache, dns_rdataclass_t rdclass,
Bob Halley's avatar
Bob Halley committed
183
	      unsigned int argc, char *argv[], dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
184
185
186
187
188
/*
 * Create a new database using implementation 'db_type'.
 *
 * Notes:
 *	All names in the database must be subdomains of 'origin' and in class
189
 *	'rdclass'.  The database makes its own copy of the origin, so the caller
Bob Halley's avatar
Bob Halley committed
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
216
217
218
219
220
 *	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
221
222
223

void
dns_db_attach(dns_db_t *source, dns_db_t **targetp);
Bob Halley's avatar
Bob Halley committed
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * 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
237
238
239

void
dns_db_detach(dns_db_t **dbp);
Bob Halley's avatar
Bob Halley committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
 * 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
255
256
257

isc_boolean_t
dns_db_iscache(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 * 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
271
272
273

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

Bob Halley's avatar
Bob Halley committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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
302
303
dns_name_t *
dns_db_origin(dns_db_t *db);
Bob Halley's avatar
Bob Halley committed
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 * 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330

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
331

Bob Halley's avatar
Bob Halley committed
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
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
387
388
dns_result_t
dns_db_load(dns_db_t *db, char *filename);
Bob Halley's avatar
Bob Halley committed
389
390
391
/*
 * Load master file 'filename' into 'db'.
 *
Bob Halley's avatar
Bob Halley committed
392
393
394
395
 * Notes:
 *	This routine is equivalent to calling
 *
 *		dns_db_beginload();
Bob Halley's avatar
Bob Halley committed
396
 *		dns_master_loadfile();
Bob Halley's avatar
Bob Halley committed
397
398
 *		dns_db_endload();
 *
Bob Halley's avatar
Bob Halley committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
 * 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.
 */

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
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
434
435
436
/***
 *** Version Methods
 ***/
Bob Halley's avatar
Bob Halley committed
437

Bob Halley's avatar
Bob Halley committed
438
439
void
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
440
441
442
443
444
/*
 * Open the current version for reading.
 *
 * Requires:
 *
445
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
446
447
448
449
450
451
452
453
 *
 *	versionp != NULL && *verisonp == NULL
 *
 * Ensures:
 *
 *	On success, '*versionp' is attached to the current version.
 *
 */
Bob Halley's avatar
Bob Halley committed
454
455
456

dns_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp);
Bob Halley's avatar
Bob Halley committed
457
458
459
460
461
/*
 * Open a new version for reading and writing.
 *
 * Requires:
 *
462
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
 *
 *	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
478

Bob Halley's avatar
Bob Halley committed
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
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
498
void
Bob Halley's avatar
Bob Halley committed
499
500
501
502
503
504
505
506
507
508
509
510
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:
 *
511
 *	'db' is a valid database with zone semantics.
Bob Halley's avatar
Bob Halley committed
512
513
514
 *
 *	'*versionp' refers to a valid version.
 *
515
516
517
518
 *	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
519
520
521
522
523
 * Ensures:
 *
 *	*versionp == NULL
 *
 *	If *versionp is a read-write version, and commit is ISC_TRUE, then
524
525
526
 *	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
527
528
529
530
531
 */

/***
 *** Node Methods
 ***/
Bob Halley's avatar
Bob Halley committed
532
533
534
535

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
536
537
538
/*
 * Find the node with name 'name'.
 *
Bob Halley's avatar
Bob Halley committed
539
540
541
 * 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
542
 *
Bob Halley's avatar
Bob Halley committed
543
544
545
546
 *	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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
 *
 * 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
570

Bob Halley's avatar
Bob Halley committed
571
572
dns_result_t
dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
573
	    dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
Bob Halley's avatar
Bob Halley committed
574
	    dns_dbnode_t **nodep, dns_name_t *foundname,
Bob Halley's avatar
Bob Halley committed
575
	    dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
576
/*
577
578
579
580
581
582
583
584
585
 * 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.
 *
586
587
588
 *	If the DNS_DBFIND_NOWILD option is set, then wildcard matching will
 *	be disabled.  This option is only meaningful for zone databases.
 *
589
590
591
 *	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
592
593
594
595
 *	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.
 *
596
597
598
599
600
601
 *	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.
 *
602
603
604
605
 * Requires:
 *
 *	'db' is a valid database.
 *
606
 *	'type' is not SIG, or a meta-RR type other than 'ANY' (e.g. 'OPT').
607
608
609
 *
 *	'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
 *
610
 *	'foundname' is a valid name with a dedicated buffer.
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
 *
 *	'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
638
639
640
641
642
643
644
645
 *						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.
646
647
648
649
650
651
652
653
654
655
656
657
 *
 *		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
658
659
660
661
 *						to return inappropriate glue
 *						to a client.  This result can
 *						only occur if 'db' is a zone
 *						database.
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
 *
 *		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).
 *
688
689
 *		XXX There will be a result codes for negative cache entries
 *		    in the future.
690
691
692
693
694
695
696
697
698
699
700
701
 *
 *	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
702
703
 */

Bob Halley's avatar
Bob Halley committed
704
705
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp);
Bob Halley's avatar
Bob Halley committed
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
/*
 * 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
721
722
723

void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep);
Bob Halley's avatar
Bob Halley committed
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*
 * 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
738
739
740
741
742
743
744
745
746
747
748
749
750
751
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
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
767
768
769
770
771
/***
 *** DB Iterator Creation
 ***/

dns_result_t
772
dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
Bob Halley's avatar
Bob Halley committed
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
		      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
799
800
801
/***
 *** Rdataset Methods
 ***/
Bob Halley's avatar
Bob Halley committed
802
803
804

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
805
		    dns_rdatatype_t type, dns_rdatatype_t covers,
Bob Halley's avatar
Bob Halley committed
806
807
		    isc_stdtime_t now, dns_rdataset_t *rdataset,
		    dns_rdataset_t *sigrdataset);
Bob Halley's avatar
Bob Halley committed
808
809
810
811
812
813
814
815
/*
 * 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
816
817
818
 *	Care must be used when using this routine to build a DNS response:
 *	'node' should have been found with dns_db_find(), not
 *	dns_db_findnode().  No glue checking is done.
Bob Halley's avatar
Bob Halley committed
819
 *
820
821
 *	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
822
 *	'now'.  If 'now' is zero, then the current time will be used.
823
 *
Bob Halley's avatar
Bob Halley committed
824
825
826
827
828
829
830
831
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
 *	'rdataset' is a valid, disassociated rdataset.
 *
Bob Halley's avatar
Bob Halley committed
832
833
 *	'sigrdataset' is a valid, disassociated rdataset, or it is NULL.
 *
Bob Halley's avatar
Bob Halley committed
834
835
836
 *	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
837
838
839
840
841
842
843
844
845
846
847
848
849
 *
 * 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
850

Bob Halley's avatar
Bob Halley committed
851
852
dns_result_t
dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
853
		    isc_stdtime_t now, dns_rdatasetiter_t **iteratorp);
Bob Halley's avatar
Bob Halley committed
854
855
856
857
858
859
860
861
/*
 * 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.
 *
862
863
864
865
866
867
 *	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
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
 * 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
889
890
dns_result_t
dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
891
		   isc_stdtime_t now, dns_rdataset_t *rdataset,
Bob Halley's avatar
Bob Halley committed
892
		   isc_boolean_t merge, dns_rdataset_t *addedrdataset);
Bob Halley's avatar
Bob Halley committed
893
894
895
/*
 * Add 'rdataset' to 'node' in version 'version' of 'db'.
 *
896
897
 * Notes:
 *
Bob Halley's avatar
Bob Halley committed
898
899
900
901
902
903
 *	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.
 *
904
905
906
907
 *	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.
 *
908
 *	If 'addedrdataset' is not NULL, then it will be attached to the
Andreas Gustafsson's avatar
Andreas Gustafsson committed
909
 *	resulting new rdataset in the database.
910
 *
Bob Halley's avatar
Bob Halley committed
911
912
913
914
915
916
 * Requires:
 *
 *	'db' is a valid database.
 *
 *	'node' is a valid node.
 *
917
918
 *	'rdataset' is a valid, associated rdataset with the same class
 *	as 'db'.
Bob Halley's avatar
Bob Halley committed
919
 *
920
921
 *	'addedrdataset' is NULL, or a valid, unassociated rdataset.
 *
922
923
924
 *	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
925
 *
Bob Halley's avatar
Bob Halley committed
926
927
 *	If the database has cache semantics, 'merge' must be ISC_FALSE.
 *
Bob Halley's avatar
Bob Halley committed
928
929
930
 * Returns:
 *
 *	DNS_R_SUCCESS
Bob Halley's avatar
Bob Halley committed
931
 *	DNS_R_UNCHANGED			The operation did not change anything.
Bob Halley's avatar
Bob Halley committed
932
 *	DNS_R_NOMEMORY
Bob Halley's avatar
Bob Halley committed
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
 *	
 *	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
949
950
 *	resulting new rdataset in the database, unless the rdataset has 
 *	become nonexistent.
Bob Halley's avatar
Bob Halley committed
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
 *
 * 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
972
973
974
975
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
976
977
978
979

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
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
/*
 * 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.
 *
996
997
998
 *	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
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
 *
 *	'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
1010
1011
 *	DNS_R_UNCHANGED			No rdatasets of 'type' existed before
 *					the operation was attempted.
Bob Halley's avatar
Bob Halley committed
1012
1013
1014
1015
 *	
 *	Other results are possible, depending upon the database
 *	implementation used.
 */
Bob Halley's avatar
Bob Halley committed
1016

1017
1018
ISC_LANG_ENDDECLS

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