Advertisement
Guest User

Untitled

a guest
Jul 10th, 2015
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.81 KB | None | 0 0
  1. /*
  2. * Copyright (C) 1999-2001 Internet Software Consortium.
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
  9. * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  10. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  11. * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  13. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  14. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  15. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17.  
  18. /* $Id: db.h,v 1.67 2001/08/28 03:58:13 marka Exp $ */
  19.  
  20. #ifndef DNS_DB_H
  21. #define DNS_DB_H 1
  22.  
  23. /*****
  24. ***** Module Info
  25. *****/
  26.  
  27. /*
  28. * DNS DB
  29. *
  30. * The DNS DB interface allows named rdatasets to be stored and retrieved.
  31. *
  32. * The dns_db_t type is like a "virtual class". To actually use
  33. * DBs, an implementation of the class is required.
  34. *
  35. * XXX <more> XXX
  36. *
  37. * MP:
  38. * The module ensures appropriate synchronization of data structures it
  39. * creates and manipulates.
  40. *
  41. * Reliability:
  42. * No anticipated impact.
  43. *
  44. * Resources:
  45. * <TBS>
  46. *
  47. * Security:
  48. * No anticipated impact.
  49. *
  50. * Standards:
  51. * None.
  52. */
  53.  
  54. /*****
  55. ***** Imports
  56. *****/
  57.  
  58. #include <isc/lang.h>
  59. #include <isc/magic.h>
  60. #include <isc/ondestroy.h>
  61. #include <isc/stdtime.h>
  62.  
  63. #include <dns/name.h>
  64. #include <dns/types.h>
  65.  
  66. ISC_LANG_BEGINDECLS
  67.  
  68. /*****
  69. ***** Types
  70. *****/
  71.  
  72. typedef struct dns_dbmethods {
  73. void (*attach)(dns_db_t *source, dns_db_t **targetp);
  74. void (*detach)(dns_db_t **dbp);
  75. isc_result_t (*beginload)(dns_db_t *db, dns_addrdatasetfunc_t *addp,
  76. dns_dbload_t **dbloadp);
  77. isc_result_t (*endload)(dns_db_t *db, dns_dbload_t **dbloadp);
  78. isc_result_t (*dump)(dns_db_t *db, dns_dbversion_t *version,
  79. const char *filename);
  80. void (*currentversion)(dns_db_t *db,
  81. dns_dbversion_t **versionp);
  82. isc_result_t (*newversion)(dns_db_t *db,
  83. dns_dbversion_t **versionp);
  84. void (*attachversion)(dns_db_t *db, dns_dbversion_t *source,
  85. dns_dbversion_t **targetp);
  86. void (*closeversion)(dns_db_t *db,
  87. dns_dbversion_t **versionp,
  88. isc_boolean_t commit);
  89. isc_result_t (*findnode)(dns_db_t *db, dns_name_t *name,
  90. isc_boolean_t create,
  91. dns_dbnode_t **nodep);
  92. isc_result_t (*find)(dns_db_t *db, dns_name_t *name,
  93. dns_dbversion_t *version,
  94. dns_rdatatype_t type, unsigned int options,
  95. isc_stdtime_t now,
  96. dns_dbnode_t **nodep, dns_name_t *foundname,
  97. dns_rdataset_t *rdataset,
  98. dns_rdataset_t *sigrdataset);
  99. isc_result_t (*findzonecut)(dns_db_t *db, dns_name_t *name,
  100. unsigned int options, isc_stdtime_t now,
  101. dns_dbnode_t **nodep,
  102. dns_name_t *foundname,
  103. dns_rdataset_t *rdataset,
  104. dns_rdataset_t *sigrdataset);
  105. void (*attachnode)(dns_db_t *db,
  106. dns_dbnode_t *source,
  107. dns_dbnode_t **targetp);
  108. void (*detachnode)(dns_db_t *db,
  109. dns_dbnode_t **targetp);
  110. isc_result_t (*expirenode)(dns_db_t *db, dns_dbnode_t *node,
  111. isc_stdtime_t now);
  112. void (*printnode)(dns_db_t *db, dns_dbnode_t *node,
  113. FILE *out);
  114. isc_result_t (*createiterator)(dns_db_t *db,
  115. isc_boolean_t relative_names,
  116. dns_dbiterator_t **iteratorp);
  117. isc_result_t (*findrdataset)(dns_db_t *db, dns_dbnode_t *node,
  118. dns_dbversion_t *version,
  119. dns_rdatatype_t type,
  120. dns_rdatatype_t covers,
  121. isc_stdtime_t now,
  122. dns_rdataset_t *rdataset,
  123. dns_rdataset_t *sigrdataset);
  124. isc_result_t (*allrdatasets)(dns_db_t *db, dns_dbnode_t *node,
  125. dns_dbversion_t *version,
  126. isc_stdtime_t now,
  127. dns_rdatasetiter_t **iteratorp);
  128. isc_result_t (*addrdataset)(dns_db_t *db, dns_dbnode_t *node,
  129. dns_dbversion_t *version,
  130. isc_stdtime_t now,
  131. dns_rdataset_t *rdataset,
  132. unsigned int options,
  133. dns_rdataset_t *addedrdataset);
  134. isc_result_t (*subtractrdataset)(dns_db_t *db, dns_dbnode_t *node,
  135. dns_dbversion_t *version,
  136. dns_rdataset_t *rdataset,
  137. unsigned int options,
  138. dns_rdataset_t *newrdataset);
  139. isc_result_t (*deleterdataset)(dns_db_t *db, dns_dbnode_t *node,
  140. dns_dbversion_t *version,
  141. dns_rdatatype_t type,
  142. dns_rdatatype_t covers);
  143. isc_boolean_t (*issecure)(dns_db_t *db);
  144. unsigned int (*nodecount)(dns_db_t *db);
  145. isc_boolean_t (*ispersistent)(dns_db_t *db);
  146. void (*overmem)(dns_db_t *db, isc_boolean_t overmem);
  147. } dns_dbmethods_t;
  148.  
  149. typedef isc_result_t
  150. (*dns_dbcreatefunc_t)(isc_mem_t *mctx, dns_name_t *name,
  151. dns_dbtype_t type, dns_rdataclass_t rdclass,
  152. unsigned int argc, char *argv[], void *driverarg,
  153. dns_db_t **dbp);
  154.  
  155. #define DNS_DB_MAGIC ISC_MAGIC('D','N','S','D')
  156. #define DNS_DB_VALID(db) ISC_MAGIC_VALID(db, DNS_DB_MAGIC)
  157.  
  158. /*
  159. * This structure is actually just the common prefix of a DNS db
  160. * implementation's version of a dns_db_t.
  161. *
  162. * Direct use of this structure by clients is forbidden. DB implementations
  163. * may change the structure. 'magic' must be DNS_DB_MAGIC for any of the
  164. * dns_db_ routines to work. DB implementations must maintain all DB
  165. * invariants.
  166. */
  167. struct dns_db {
  168. unsigned int magic;
  169. unsigned int impmagic;
  170. dns_dbmethods_t * methods;
  171. isc_uint16_t attributes;
  172. dns_rdataclass_t rdclass;
  173. dns_name_t origin;
  174. isc_ondestroy_t ondest;
  175. isc_mem_t * mctx;
  176. };
  177.  
  178. #define DNS_DBATTR_CACHE 0x01
  179. #define DNS_DBATTR_STUB 0x02
  180.  
  181. /*
  182. * Options that can be specified for dns_db_find().
  183. */
  184. #define DNS_DBFIND_GLUEOK 0x01
  185. #define DNS_DBFIND_VALIDATEGLUE 0x02
  186. #define DNS_DBFIND_NOWILD 0x04
  187. #define DNS_DBFIND_PENDINGOK 0x08
  188. #define DNS_DBFIND_NOEXACT 0x10
  189.  
  190. /*
  191. * Options that can be specified for dns_db_addrdataset().
  192. */
  193. #define DNS_DBADD_MERGE 0x01
  194. #define DNS_DBADD_FORCE 0x02
  195. #define DNS_DBADD_EXACT 0x04
  196. #define DNS_DBADD_EXACTTTL 0x08
  197.  
  198. /*
  199. * Options that can be specified for dns_db_subtractrdataset().
  200. */
  201. #define DNS_DBSUB_EXACT 0x01
  202.  
  203. /*****
  204. ***** Methods
  205. *****/
  206.  
  207. /***
  208. *** Basic DB Methods
  209. ***/
  210.  
  211. isc_result_t
  212. dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
  213. dns_dbtype_t type, dns_rdataclass_t rdclass,
  214. unsigned int argc, char *argv[], dns_db_t **dbp);
  215. /*
  216. * Create a new database using implementation 'db_type'.
  217. *
  218. * Notes:
  219. * All names in the database must be subdomains of 'origin' and in class
  220. * 'rdclass'. The database makes its own copy of the origin, so the
  221. * caller may do whatever they like with 'origin' and its storage once the
  222. * call returns.
  223. *
  224. * DB implementation-specific parameters are passed using argc and argv.
  225. *
  226. * Requires:
  227. *
  228. * dbp != NULL and *dbp == NULL
  229. *
  230. * 'origin' is a valid absolute domain name.
  231. *
  232. * mctx is a valid memory context
  233. *
  234. * Ensures:
  235. *
  236. * A copy of 'origin' has been made for the databases use, and the
  237. * caller is free to do whatever they want with the name and storage
  238. * associated with 'origin'.
  239. *
  240. * Returns:
  241. *
  242. * ISC_R_SUCCESS
  243. * ISC_R_NOMEMORY
  244. * ISC_R_NOTFOUND db_type not found
  245. *
  246. * Many other errors are possible, depending on what db_type was
  247. * specified.
  248. */
  249.  
  250. void
  251. dns_db_attach(dns_db_t *source, dns_db_t **targetp);
  252. /*
  253. * Attach *targetp to source.
  254. *
  255. * Requires:
  256. *
  257. * 'source' is a valid database.
  258. *
  259. * 'targetp' points to a NULL dns_db_t *.
  260. *
  261. * Ensures:
  262. *
  263. * *targetp is attached to source.
  264. */
  265.  
  266. void
  267. dns_db_detach(dns_db_t **dbp);
  268. /*
  269. * Detach *dbp from its database.
  270. *
  271. * Requires:
  272. *
  273. * 'dbp' points to a valid database.
  274. *
  275. * Ensures:
  276. *
  277. * *dbp is NULL.
  278. *
  279. * If '*dbp' is the last reference to the database,
  280. *
  281. * All resources used by the database will be freed
  282. */
  283.  
  284. isc_result_t
  285. dns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp);
  286. /*
  287. * Causes 'eventp' to be sent to be sent to 'task' when the database is
  288. * destroyed.
  289. *
  290. * Note; ownrship of the eventp is taken from the caller (and *eventp is
  291. * set to NULL). The sender field of the event is set to 'db' before it is
  292. * sent to the task.
  293. */
  294.  
  295. isc_boolean_t
  296. dns_db_iscache(dns_db_t *db);
  297. /*
  298. * Does 'db' have cache semantics?
  299. *
  300. * Requires:
  301. *
  302. * 'db' is a valid database.
  303. *
  304. * Returns:
  305. * ISC_TRUE 'db' has cache semantics
  306. * ISC_FALSE otherwise
  307. */
  308.  
  309. isc_boolean_t
  310. dns_db_iszone(dns_db_t *db);
  311. /*
  312. * Does 'db' have zone semantics?
  313. *
  314. * Requires:
  315. *
  316. * 'db' is a valid database.
  317. *
  318. * Returns:
  319. * ISC_TRUE 'db' has zone semantics
  320. * ISC_FALSE otherwise
  321. */
  322.  
  323. isc_boolean_t
  324. dns_db_isstub(dns_db_t *db);
  325. /*
  326. * Does 'db' have stub semantics?
  327. *
  328. * Requires:
  329. *
  330. * 'db' is a valid database.
  331. *
  332. * Returns:
  333. * ISC_TRUE 'db' has zone semantics
  334. * ISC_FALSE otherwise
  335. */
  336.  
  337. isc_boolean_t
  338. dns_db_issecure(dns_db_t *db);
  339. /*
  340. * Is 'db' secure?
  341. *
  342. * Requires:
  343. *
  344. * 'db' is a valid database with zone semantics.
  345. *
  346. * Returns:
  347. * ISC_TRUE 'db' is secure.
  348. * ISC_FALSE 'db' is not secure.
  349. */
  350.  
  351. dns_name_t *
  352. dns_db_origin(dns_db_t *db);
  353. /*
  354. * The origin of the database.
  355. *
  356. * Note: caller must not try to change this name.
  357. *
  358. * Requires:
  359. *
  360. * 'db' is a valid database.
  361. *
  362. * Returns:
  363. *
  364. * The origin of the database.
  365. */
  366.  
  367. dns_rdataclass_t
  368. dns_db_class(dns_db_t *db);
  369. /*
  370. * The class of the database.
  371. *
  372. * Requires:
  373. *
  374. * 'db' is a valid database.
  375. *
  376. * Returns:
  377. *
  378. * The class of the database.
  379. */
  380.  
  381. isc_result_t
  382. dns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
  383. dns_dbload_t **dbloadp);
  384. /*
  385. * Begin loading 'db'.
  386. *
  387. * Requires:
  388. *
  389. * 'db' is a valid database.
  390. *
  391. * This is the first attempt to load 'db'.
  392. *
  393. * addp != NULL && *addp == NULL
  394. *
  395. * dbloadp != NULL && *dbloadp == NULL
  396. *
  397. * Ensures:
  398. *
  399. * On success, *addp will be a valid dns_addrdatasetfunc_t suitable
  400. * for loading 'db'. *dbloadp will be a valid DB load context which
  401. * should be used as 'arg' when *addp is called.
  402. *
  403. * Returns:
  404. *
  405. * ISC_R_SUCCESS
  406. * ISC_R_NOMEMORY
  407. *
  408. * Other results are possible, depending upon the database
  409. * implementation used, syntax errors in the master file, etc.
  410. */
  411.  
  412. isc_result_t
  413. dns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp);
  414. /*
  415. * Finish loading 'db'.
  416. *
  417. * Requires:
  418. *
  419. * 'db' is a valid database that is being loaded.
  420. *
  421. * dbloadp != NULL and *dbloadp is a valid database load context.
  422. *
  423. * Ensures:
  424. *
  425. * *dbloadp == NULL
  426. *
  427. * Returns:
  428. *
  429. * ISC_R_SUCCESS
  430. * ISC_R_NOMEMORY
  431. *
  432. * Other results are possible, depending upon the database
  433. * implementation used, syntax errors in the master file, etc.
  434. */
  435.  
  436. isc_result_t
  437. dns_db_load(dns_db_t *db, const char *filename);
  438. /*
  439. * Load master file 'filename' into 'db'.
  440. *
  441. * Notes:
  442. * This routine is equivalent to calling
  443. *
  444. * dns_db_beginload();
  445. * dns_master_loadfile();
  446. * dns_db_endload();
  447. *
  448. * Requires:
  449. *
  450. * 'db' is a valid database.
  451. *
  452. * This is the first attempt to load 'db'.
  453. *
  454. * Returns:
  455. *
  456. * ISC_R_SUCCESS
  457. * ISC_R_NOMEMORY
  458. *
  459. * Other results are possible, depending upon the database
  460. * implementation used, syntax errors in the master file, etc.
  461. */
  462.  
  463. isc_result_t
  464. dns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename);
  465. /*
  466. * Dump version 'version' of 'db' to master file 'filename'.
  467. *
  468. * Requires:
  469. *
  470. * 'db' is a valid database.
  471. *
  472. * 'version' is a valid version.
  473. *
  474. * Returns:
  475. *
  476. * ISC_R_SUCCESS
  477. * ISC_R_NOMEMORY
  478. *
  479. * Other results are possible, depending upon the database
  480. * implementation used, OS file errors, etc.
  481. */
  482.  
  483. /***
  484. *** Version Methods
  485. ***/
  486.  
  487. void
  488. dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp);
  489. /*
  490. * Open the current version for reading.
  491. *
  492. * Requires:
  493. *
  494. * 'db' is a valid database with zone semantics.
  495. *
  496. * versionp != NULL && *verisonp == NULL
  497. *
  498. * Ensures:
  499. *
  500. * On success, '*versionp' is attached to the current version.
  501. *
  502. */
  503.  
  504. isc_result_t
  505. dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp);
  506. /*
  507. * Open a new version for reading and writing.
  508. *
  509. * Requires:
  510. *
  511. * 'db' is a valid database with zone semantics.
  512. *
  513. * versionp != NULL && *verisonp == NULL
  514. *
  515. * Ensures:
  516. *
  517. * On success, '*versionp' is attached to the current version.
  518. *
  519. * Returns:
  520. *
  521. * ISC_R_SUCCESS
  522. * ISC_R_NOMEMORY
  523. *
  524. * Other results are possible, depending upon the database
  525. * implementation used.
  526. */
  527.  
  528. void
  529. dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
  530. dns_dbversion_t **targetp);
  531. /*
  532. * Attach '*targetp' to 'source'.
  533. *
  534. * Requires:
  535. *
  536. * 'db' is a valid database with zone semantics.
  537. *
  538. * source is a valid open version
  539. *
  540. * targetp != NULL && *targetp == NULL
  541. *
  542. * Ensures:
  543. *
  544. * '*targetp' is attached to source.
  545. */
  546.  
  547. void
  548. dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
  549. isc_boolean_t commit);
  550. /*
  551. * Close version '*versionp'.
  552. *
  553. * Note: if '*versionp' is a read-write version and 'commit' is ISC_TRUE,
  554. * then all changes made in the version will take effect, otherwise they
  555. * will be rolled back. The value if 'commit' is ignored for read-only
  556. * versions.
  557. *
  558. * Requires:
  559. *
  560. * 'db' is a valid database with zone semantics.
  561. *
  562. * '*versionp' refers to a valid version.
  563. *
  564. * If committing a writable version, then there must be no other
  565. * outstanding references to the version (e.g. an active rdataset
  566. * iterator).
  567. *
  568. * Ensures:
  569. *
  570. * *versionp == NULL
  571. *
  572. * If *versionp is a read-write version, and commit is ISC_TRUE, then
  573. * the version will become the current version. If !commit, then all
  574. * changes made in the version will be undone, and the version will
  575. * not become the current version.
  576. */
  577.  
  578. /***
  579. *** Node Methods
  580. ***/
  581.  
  582. isc_result_t
  583. dns_db_findnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
  584. dns_dbnode_t **nodep);
  585. /*
  586. * Find the node with name 'name'.
  587. *
  588. * Notes:
  589. * If 'create' is ISC_TRUE and no node with name 'name' exists, then
  590. * such a node will be created.
  591. *
  592. * This routine is for finding or creating a node with the specified
  593. * name. There are no partial matches. It is not suitable for use
  594. * in building responses to ordinary DNS queries; clients which wish
  595. * to do that should use dns_db_find() instead.
  596. *
  597. * Requires:
  598. *
  599. * 'db' is a valid database.
  600. *
  601. * 'name' is a valid, non-empty, absolute name that is a subdomain of
  602. * the database's origin. (It need not be a proper subdomain.)
  603. *
  604. * nodep != NULL && *nodep == NULL
  605. *
  606. * Ensures:
  607. *
  608. * On success, *nodep is attached to the node with name 'name'.
  609. *
  610. * Returns:
  611. *
  612. * ISC_R_SUCCESS
  613. * ISC_R_NOTFOUND If !create and name not found.
  614. * ISC_R_NOMEMORY Can only happen if create is ISC_TRUE.
  615. *
  616. * Other results are possible, depending upon the database
  617. * implementation used.
  618. */
  619.  
  620. isc_result_t
  621. dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
  622. dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
  623. dns_dbnode_t **nodep, dns_name_t *foundname,
  624. dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
  625. /*
  626. * Find the best match for 'name' and 'type' in version 'version' of 'db'.
  627. *
  628. * Notes:
  629. *
  630. * If type == dns_rdataset_any, then rdataset will not be bound.
  631. *
  632. * If 'options' does not have DNS_DBFIND_GLUEOK set, then no glue will
  633. * be returned. For zone databases, glue is as defined in RFC 2181.
  634. * For cache databases, glue is any rdataset with a trust of
  635. * dns_trust_glue.
  636. *
  637. * If 'options' does not have DNS_DBFIND_PENDINGOK set, then no
  638. * pending data will be returned. This option is only meaningful for
  639. * cache databases.
  640. *
  641. * If the DNS_DBFIND_NOWILD option is set, then wildcard matching will
  642. * be disabled. This option is only meaningful for zone databases.
  643. *
  644. * To respond to a query for SIG records, the caller should create a
  645. * rdataset iterator and extract the signatures from each rdataset.
  646. *
  647. * Making queries of type ANY with DNS_DBFIND_GLUEOK is not recommended,
  648. * because the burden of determining whether a given rdataset is valid
  649. * glue or not falls upon the caller.
  650. *
  651. * The 'now' field is ignored if 'db' is a zone database. If 'db' is a
  652. * cache database, an rdataset will not be found unless it expires after
  653. * 'now'. Any ANY query will not match unless at least one rdataset at
  654. * the node expires after 'now'. If 'now' is zero, then the current time
  655. * will be used.
  656. *
  657. * Requires:
  658. *
  659. * 'db' is a valid database.
  660. *
  661. * 'type' is not SIG, or a meta-RR type other than 'ANY' (e.g. 'OPT').
  662. *
  663. * 'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
  664. *
  665. * 'foundname' is a valid name with a dedicated buffer.
  666. *
  667. * 'rdataset' is NULL, or is a valid unassociated rdataset.
  668. *
  669. * Ensures:
  670. * On a non-error completion:
  671. *
  672. * If nodep != NULL, then it is bound to the found node.
  673. *
  674. * If foundname != NULL, then it contains the full name of the
  675. * found node.
  676. *
  677. * If rdataset != NULL and type != dns_rdatatype_any, then
  678. * rdataset is bound to the found rdataset.
  679. *
  680. * Returns:
  681. *
  682. * Non-error results are:
  683. *
  684. * ISC_R_SUCCESS The desired node and type were
  685. * found.
  686. *
  687. * DNS_R_GLUE The desired node and type were
  688. * found, but are glue. This
  689. * result can only occur if
  690. * the DNS_DBFIND_GLUEOK option
  691. * is set. This result can only
  692. * occur if 'db' is a zone
  693. * database. If type ==
  694. * dns_rdatatype_any, then the
  695. * node returned may contain, or
  696. * consist entirely of invalid
  697. * glue (i.e. data occluded by a
  698. * zone cut). The caller must
  699. * take care not to return invalid
  700. * glue to a client.
  701. *
  702. * DNS_R_DELEGATION The data requested is beneath
  703. * a zone cut. node, foundname,
  704. * and rdataset reference the
  705. * NS RRset of the zone cut.
  706. * If 'db' is a cache database,
  707. * then this is the deepest known
  708. * delegation.
  709. *
  710. * DNS_R_ZONECUT type == dns_rdatatype_any, and
  711. * the desired node is a zonecut.
  712. * The caller must take care not
  713. * to return inappropriate glue
  714. * to a client. This result can
  715. * only occur if 'db' is a zone
  716. * database and DNS_DBFIND_GLUEOK
  717. * is set.
  718. *
  719. * DNS_R_DNAME The data requested is beneath
  720. * a DNAME. node, foundname,
  721. * and rdataset reference the
  722. * DNAME RRset.
  723. *
  724. * DNS_R_CNAME The rdataset requested was not
  725. * found, but there is a CNAME
  726. * at the desired name. node,
  727. * foundname, and rdataset
  728. * reference the CNAME RRset.
  729. *
  730. * DNS_R_NXDOMAIN The desired name does not
  731. * exist.
  732. *
  733. * DNS_R_NXRRSET The desired name exists, but
  734. * the desired type does not.
  735. *
  736. * ISC_R_NOTFOUND The desired name does not
  737. * exist, and no delegation could
  738. * be found. This result can only
  739. * occur if 'db' is a cache
  740. * database. The caller should
  741. * use its nameserver(s) of last
  742. * resort (e.g. root hints).
  743. *
  744. * DNS_R_NCACHENXDOMAIN The desired name does not
  745. * exist. 'node' is bound to the
  746. * cache node with the desired
  747. * name, and 'rdataset' contains
  748. * the negative caching proof.
  749. *
  750. * DNS_R_NCACHENXRRSET The desired type does not
  751. * exist. 'node' is bound to the
  752. * cache node with the desired
  753. * name, and 'rdataset' contains
  754. * the negative caching proof.
  755. *
  756. * Error results:
  757. *
  758. * ISC_R_NOMEMORY
  759. *
  760. * DNS_R_BADDB Data that is required to be
  761. * present in the DB, e.g. an NXT
  762. * record in a secure zone, is not
  763. * present.
  764. *
  765. * Other results are possible, and should all be treated as
  766. * errors.
  767. */
  768.  
  769. isc_result_t
  770. dns_db_findzonecut(dns_db_t *db, dns_name_t *name,
  771. unsigned int options, isc_stdtime_t now,
  772. dns_dbnode_t **nodep, dns_name_t *foundname,
  773. dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
  774. /*
  775. * Find the deepest known zonecut which encloses 'name' in 'db'.
  776. *
  777. * Notes:
  778. *
  779. * If the DNS_DBFIND_NOEXACT option is set, then the zonecut returned
  780. * (if any) will be the deepest known ancestor of 'name'.
  781. *
  782. * If 'now' is zero, then the current time will be used.
  783. *
  784. * Requires:
  785. *
  786. * 'db' is a valid database with cache semantics.
  787. *
  788. * 'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
  789. *
  790. * 'foundname' is a valid name with a dedicated buffer.
  791. *
  792. * 'rdataset' is NULL, or is a valid unassociated rdataset.
  793. *
  794. * Ensures:
  795. * On a non-error completion:
  796. *
  797. * If nodep != NULL, then it is bound to the found node.
  798. *
  799. * If foundname != NULL, then it contains the full name of the
  800. * found node.
  801. *
  802. * If rdataset != NULL and type != dns_rdatatype_any, then
  803. * rdataset is bound to the found rdataset.
  804. *
  805. * Returns:
  806. *
  807. * Non-error results are:
  808. *
  809. * ISC_R_SUCCESS
  810. *
  811. * ISC_R_NOTFOUND
  812. *
  813. * Other results are possible, and should all be treated as
  814. * errors.
  815. */
  816.  
  817. void
  818. dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp);
  819. /*
  820. * Attach *targetp to source.
  821. *
  822. * Requires:
  823. *
  824. * 'db' is a valid database.
  825. *
  826. * 'source' is a valid node.
  827. *
  828. * 'targetp' points to a NULL dns_node_t *.
  829. *
  830. * Ensures:
  831. *
  832. * *targetp is attached to source.
  833. */
  834.  
  835. void
  836. dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep);
  837. /*
  838. * Detach *nodep from its node.
  839. *
  840. * Requires:
  841. *
  842. * 'db' is a valid database.
  843. *
  844. * 'nodep' points to a valid node.
  845. *
  846. * Ensures:
  847. *
  848. * *nodep is NULL.
  849. */
  850.  
  851. isc_result_t
  852. dns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now);
  853. /*
  854. * Mark as stale all records at 'node' which expire at or before 'now'.
  855. *
  856. * Note: if 'now' is zero, then the current time will be used.
  857. *
  858. * Requires:
  859. *
  860. * 'db' is a valid cache database.
  861. *
  862. * 'node' is a valid node.
  863. */
  864.  
  865. void
  866. dns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out);
  867. /*
  868. * Print a textual representation of the contents of the node to
  869. * 'out'.
  870. *
  871. * Note: this function is intended for debugging, not general use.
  872. *
  873. * Requires:
  874. *
  875. * 'db' is a valid database.
  876. *
  877. * 'node' is a valid node.
  878. */
  879.  
  880. /***
  881. *** DB Iterator Creation
  882. ***/
  883.  
  884. isc_result_t
  885. dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
  886. dns_dbiterator_t **iteratorp);
  887. /*
  888. * Create an iterator for version 'version' of 'db'.
  889. *
  890. * Notes:
  891. *
  892. * If 'relative_names' is ISC_TRUE, then node names returned by the
  893. * iterator will be relative to the iterator's current origin. If
  894. * ISC_FALSE, then the node names will be absolute.
  895. *
  896. * Requires:
  897. *
  898. * 'db' is a valid database.
  899. *
  900. * iteratorp != NULL && *iteratorp == NULL
  901. *
  902. * Ensures:
  903. *
  904. * On success, *iteratorp will be a valid database iterator.
  905. *
  906. * Returns:
  907. *
  908. * ISC_R_SUCCESS
  909. * ISC_R_NOMEMORY
  910. */
  911.  
  912. /***
  913. *** Rdataset Methods
  914. ***/
  915.  
  916. /*
  917. * XXXRTH Should we check for glue and pending data in dns_db_findrdataset()?
  918. */
  919.  
  920. isc_result_t
  921. dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
  922. dns_rdatatype_t type, dns_rdatatype_t covers,
  923. isc_stdtime_t now, dns_rdataset_t *rdataset,
  924. dns_rdataset_t *sigrdataset);
  925. /*
  926. * Search for an rdataset of type 'type' at 'node' that are in version
  927. * 'version' of 'db'. If found, make 'rdataset' refer to it.
  928. *
  929. * Notes:
  930. *
  931. * If 'version' is NULL, then the current version will be used.
  932. *
  933. * Care must be used when using this routine to build a DNS response:
  934. * 'node' should have been found with dns_db_find(), not
  935. * dns_db_findnode(). No glue checking is done. No checking for
  936. * pending data is done.
  937. *
  938. * The 'now' field is ignored if 'db' is a zone database. If 'db' is a
  939. * cache database, an rdataset will not be found unless it expires after
  940. * 'now'. If 'now' is zero, then the current time will be used.
  941. *
  942. * Requires:
  943. *
  944. * 'db' is a valid database.
  945. *
  946. * 'node' is a valid node.
  947. *
  948. * 'rdataset' is a valid, disassociated rdataset.
  949. *
  950. * 'sigrdataset' is a valid, disassociated rdataset, or it is NULL.
  951. *
  952. * If 'covers' != 0, 'type' must be SIG.
  953. *
  954. * 'type' is not a meta-RR type such as 'ANY' or 'OPT'.
  955. *
  956. * Ensures:
  957. *
  958. * On success, 'rdataset' is associated with the found rdataset.
  959. *
  960. * Returns:
  961. *
  962. * ISC_R_SUCCESS
  963. * ISC_R_NOTFOUND
  964. *
  965. * Other results are possible, depending upon the database
  966. * implementation used.
  967. */
  968.  
  969. isc_result_t
  970. dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
  971. isc_stdtime_t now, dns_rdatasetiter_t **iteratorp);
  972. /*
  973. * Make '*iteratorp' an rdataset iteratator for all rdatasets at 'node' in
  974. * version 'version' of 'db'.
  975. *
  976. * Notes:
  977. *
  978. * If 'version' is NULL, then the current version will be used.
  979. *
  980. * The 'now' field is ignored if 'db' is a zone database. If 'db' is a
  981. * cache database, an rdataset will not be found unless it expires after
  982. * 'now'. Any ANY query will not match unless at least one rdataset at
  983. * the node expires after 'now'. If 'now' is zero, then the current time
  984. * will be used.
  985. *
  986. * Requires:
  987. *
  988. * 'db' is a valid database.
  989. *
  990. * 'node' is a valid node.
  991. *
  992. * iteratorp != NULL && *iteratorp == NULL
  993. *
  994. * Ensures:
  995. *
  996. * On success, '*iteratorp' is a valid rdataset iterator.
  997. *
  998. * Returns:
  999. *
  1000. * ISC_R_SUCCESS
  1001. * ISC_R_NOTFOUND
  1002. *
  1003. * Other results are possible, depending upon the database
  1004. * implementation used.
  1005. */
  1006.  
  1007. isc_result_t
  1008. dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
  1009. isc_stdtime_t now, dns_rdataset_t *rdataset,
  1010. unsigned int options, dns_rdataset_t *addedrdataset);
  1011. /*
  1012. * Add 'rdataset' to 'node' in version 'version' of 'db'.
  1013. *
  1014. * Notes:
  1015. *
  1016. * If the database has zone semantics, the DNS_DBADD_MERGE option is set,
  1017. * and an rdataset of the same type as 'rdataset' already exists at
  1018. * 'node' then the contents of 'rdataset' will be merged with the existing
  1019. * rdataset. If the option is not set, then rdataset will replace any
  1020. * existing rdataset of the same type. If not merging and the
  1021. * DNS_DBADD_FORCE option is set, then the data will update the database
  1022. * without regard to trust levels. If not forcing the data, then the
  1023. * rdataset will only be added if its trust level is >= the trust level of
  1024. * any existing rdataset. Forcing is only meaningful for cache databases.
  1025. * If DNS_DBADD_EXACT is set then there must be no rdata in common between
  1026. * the old and new rdata sets. If DNS_DBADD_EXACTTTL is set then both
  1027. * the old and new rdata sets must have the same ttl.
  1028. *
  1029. * The 'now' field is ignored if 'db' is a zone database. If 'db' is
  1030. * a cache database, then the added rdataset will expire no later than
  1031. * now + rdataset->ttl.
  1032. *
  1033. * If 'addedrdataset' is not NULL, then it will be attached to the
  1034. * resulting new rdataset in the database, or to the existing data if
  1035. * the existing data was better.
  1036. *
  1037. * Requires:
  1038. *
  1039. * 'db' is a valid database.
  1040. *
  1041. * 'node' is a valid node.
  1042. *
  1043. * 'rdataset' is a valid, associated rdataset with the same class
  1044. * as 'db'.
  1045. *
  1046. * 'addedrdataset' is NULL, or a valid, unassociated rdataset.
  1047. *
  1048. * The database has zone semantics and 'version' is a valid
  1049. * read-write version, or the database has cache semantics
  1050. * and version is NULL.
  1051. *
  1052. * If the database has cache semantics, the DNS_DBADD_MERGE option must
  1053. * not be set.
  1054. *
  1055. * Returns:
  1056. *
  1057. * ISC_R_SUCCESS
  1058. * DNS_R_UNCHANGED The operation did not change anything.
  1059. * ISC_R_NOMEMORY
  1060. * DNS_R_NOTEXACT
  1061. *
  1062. * Other results are possible, depending upon the database
  1063. * implementation used.
  1064. */
  1065.  
  1066. isc_result_t
  1067. dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
  1068. dns_dbversion_t *version, dns_rdataset_t *rdataset,
  1069. unsigned int options, dns_rdataset_t *newrdataset);
  1070. /*
  1071. * Remove any rdata in 'rdataset' from 'node' in version 'version' of
  1072. * 'db'.
  1073. *
  1074. * Notes:
  1075. *
  1076. * If 'newrdataset' is not NULL, then it will be attached to the
  1077. * resulting new rdataset in the database, unless the rdataset has
  1078. * become nonexistent. If DNS_DBSUB_EXACT is set then all elements
  1079. * of 'rdataset' must exist at 'node'.
  1080. *
  1081. * Requires:
  1082. *
  1083. * 'db' is a valid database.
  1084. *
  1085. * 'node' is a valid node.
  1086. *
  1087. * 'rdataset' is a valid, associated rdataset with the same class
  1088. * as 'db'.
  1089. *
  1090. * 'newrdataset' is NULL, or a valid, unassociated rdataset.
  1091. *
  1092. * The database has zone semantics and 'version' is a valid
  1093. * read-write version.
  1094. *
  1095. * Returns:
  1096. *
  1097. * ISC_R_SUCCESS
  1098. * DNS_R_UNCHANGED The operation did not change anything.
  1099. * DNS_R_NXRRSET All rdata of the same type as those
  1100. * in 'rdataset' have been deleted.
  1101. * DNS_R_NOTEXACT Some part of 'rdataset' did not
  1102. * exist and DNS_DBSUB_EXACT was set.
  1103. *
  1104. * Other results are possible, depending upon the database
  1105. * implementation used.
  1106. */
  1107.  
  1108. isc_result_t
  1109. dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
  1110. dns_dbversion_t *version, dns_rdatatype_t type,
  1111. dns_rdatatype_t covers);
  1112. /*
  1113. * Make it so that no rdataset of type 'type' exists at 'node' in version
  1114. * version 'version' of 'db'.
  1115. *
  1116. * Notes:
  1117. *
  1118. * If 'type' is dns_rdatatype_any, then no rdatasets will exist in
  1119. * 'version' (provided that the dns_db_deleterdataset() isn't followed
  1120. * by one or more dns_db_addrdataset() calls).
  1121. *
  1122. * Requires:
  1123. *
  1124. * 'db' is a valid database.
  1125. *
  1126. * 'node' is a valid node.
  1127. *
  1128. * The database has zone semantics and 'version' is a valid
  1129. * read-write version, or the database has cache semantics
  1130. * and version is NULL.
  1131. *
  1132. * 'type' is not a meta-RR type, except for dns_rdatatype_any, which is
  1133. * allowed.
  1134. *
  1135. * If 'covers' != 0, 'type' must be SIG.
  1136. *
  1137. * Returns:
  1138. *
  1139. * ISC_R_SUCCESS
  1140. * DNS_R_UNCHANGED No rdatasets of 'type' existed before
  1141. * the operation was attempted.
  1142. *
  1143. * Other results are possible, depending upon the database
  1144. * implementation used.
  1145. */
  1146.  
  1147. isc_result_t
  1148. dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp);
  1149. /*
  1150. * Get the current SOA serial number from a zone database.
  1151. *
  1152. * Requires:
  1153. * 'db' is a valid database with zone semantics.
  1154. * 'ver' is a valid version.
  1155. */
  1156.  
  1157. void
  1158. dns_db_overmem(dns_db_t *db, isc_boolean_t overmem);
  1159. /*
  1160. * Enable / disable agressive cache cleaning.
  1161. */
  1162.  
  1163. unsigned int
  1164. dns_db_nodecount(dns_db_t *db);
  1165. /*
  1166. * Count the number of nodes in 'db'.
  1167. *
  1168. * Requires:
  1169. *
  1170. * 'db' is a valid database.
  1171. *
  1172. * Returns:
  1173. * The number of nodes in the database
  1174. */
  1175.  
  1176. isc_boolean_t
  1177. dns_db_ispersistent(dns_db_t *db);
  1178. /*
  1179. * Is 'db' persistent? A persistent database does not need to be loaded
  1180. * from disk or written to disk.
  1181. *
  1182. * Requires:
  1183. *
  1184. * 'db' is a valid database.
  1185. *
  1186. * Returns:
  1187. * ISC_TRUE 'db' is persistent.
  1188. * ISC_FALSE 'db' is not persistent.
  1189. */
  1190.  
  1191. isc_result_t
  1192. dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
  1193. isc_mem_t *mctx, dns_dbimplementation_t **dbimp);
  1194.  
  1195. /*
  1196. * Register a new database implementation and add it to the list of
  1197. * supported implementations.
  1198. *
  1199. * Requires:
  1200. *
  1201. * 'name' is not NULL
  1202. * 'order' is a valid function pointer
  1203. * 'mctx' is a valid memory context
  1204. * dbimp != NULL && *dbimp == NULL
  1205. *
  1206. * Returns:
  1207. * ISC_R_SUCCESS The registration succeeded
  1208. * ISC_R_NOMEMORY Out of memory
  1209. * ISC_R_EXISTS A database implementation with the same name exists
  1210. *
  1211. * Ensures:
  1212. *
  1213. * *dbimp points to an opaque structure which must be passed to
  1214. * dns_db_unregister().
  1215. */
  1216.  
  1217. void
  1218. dns_db_unregister(dns_dbimplementation_t **dbimp);
  1219. /*
  1220. * Remove a database implementation from the the list of supported
  1221. * implementations. No databases of this type can be active when this
  1222. * is called.
  1223. *
  1224. * Requires:
  1225. * dbimp != NULL && *dbimp == NULL
  1226. *
  1227. * Ensures:
  1228. *
  1229. * Any memory allocated in *dbimp will be freed.
  1230. */
  1231.  
  1232. ISC_LANG_ENDDECLS
  1233.  
  1234. #endif /* DNS_DB_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement