2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 05:28:00 +00:00

Create the new database for AXFR from the dns_zone API

The `axfr_makedb()` didn't set the loop on the newly created database,
effectively killing delayed cleaning on such database.  Move the
database creation into dns_zone API that knows all the gory details of
creating new database suitable for the zone.
This commit is contained in:
Ondřej Surý 2024-05-28 16:13:31 +02:00
parent 37ae380e97
commit 3310cac2b0
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41
3 changed files with 59 additions and 35 deletions

View File

@ -168,6 +168,19 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid);
*\li '*zonep' refers to a valid zone.
*/
isc_result_t
dns_zone_makedb(dns_zone_t *zone, dns_db_t **dbp);
/*%<
* Creates a new empty database for the 'zone'.
*
* Requires:
*\li 'zone' to be a valid zone.
*\li 'dbp' to point to NULL pointer.
*
* Returns:
*\li dns_db_create() error codes.
*/
void
dns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass);
/*%<

View File

@ -219,8 +219,6 @@ xfrin_create(isc_mem_t *mctx, dns_zone_t *zone, dns_db_t *db, isc_loop_t *loop,
static isc_result_t
axfr_init(dns_xfrin_t *xfr);
static isc_result_t
axfr_makedb(dns_xfrin_t *xfr, dns_db_t **dbp);
static isc_result_t
axfr_putdata(dns_xfrin_t *xfr, dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
dns_rdata_t *rdata);
static void
@ -285,7 +283,11 @@ axfr_init(dns_xfrin_t *xfr) {
dns_db_detach(&xfr->db);
}
CHECK(axfr_makedb(xfr, &xfr->db));
CHECK(dns_zone_makedb(xfr->zone, &xfr->db));
dns_zone_rpz_enable_db(xfr->zone, xfr->db);
dns_zone_catz_enable_db(xfr->zone, xfr->db);
dns_rdatacallbacks_init(&xfr->axfr);
CHECK(dns_db_beginload(xfr->db, &xfr->axfr));
result = ISC_R_SUCCESS;
@ -293,19 +295,6 @@ failure:
return (result);
}
static isc_result_t
axfr_makedb(dns_xfrin_t *xfr, dns_db_t **dbp) {
isc_result_t result;
result = dns_db_create(xfr->mctx, ZONEDB_DEFAULT, &xfr->name,
dns_dbtype_zone, xfr->rdclass, 0, NULL, dbp);
if (result == ISC_R_SUCCESS) {
dns_zone_rpz_enable_db(xfr->zone, *dbp);
dns_zone_catz_enable_db(xfr->zone, *dbp);
}
return (result);
}
static isc_result_t
axfr_putdata(dns_xfrin_t *xfr, dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
dns_rdata_t *rdata) {

View File

@ -2286,31 +2286,13 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) {
dns_zone_logc(zone, DNS_LOGCATEGORY_ZONELOAD, ISC_LOG_DEBUG(1),
"starting load");
result = dns_db_create(zone->mctx, zone->db_argv[0], &zone->origin,
(zone->type == dns_zone_stub) ? dns_dbtype_stub
: dns_dbtype_zone,
zone->rdclass, zone->db_argc - 1,
zone->db_argv + 1, &db);
result = dns_zone_makedb(zone, &db);
if (result != ISC_R_SUCCESS) {
dns_zone_logc(zone, DNS_LOGCATEGORY_ZONELOAD, ISC_LOG_ERROR,
"loading zone: creating database: %s",
isc_result_totext(result));
goto cleanup;
}
dns_db_setloop(db, zone->loop);
if (zone->type == dns_zone_primary ||
zone->type == dns_zone_secondary || zone->type == dns_zone_mirror)
{
result = dns_db_setgluecachestats(db, zone->gluecachestats);
if (result == ISC_R_NOTIMPLEMENTED) {
result = ISC_R_SUCCESS;
}
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
}
if (!dns_db_ispersistent(db)) {
if (zone->masterfile != NULL || zone->stream != NULL) {
@ -24073,3 +24055,43 @@ isc_loop_t *
dns_zone_getloop(dns_zone_t *zone) {
return (zone->loop);
}
isc_result_t
dns_zone_makedb(dns_zone_t *zone, dns_db_t **dbp) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(dbp != NULL && *dbp == NULL);
dns_db_t *db = NULL;
isc_result_t result = dns_db_create(
zone->mctx, zone->db_argv[0], &zone->origin,
(zone->type == dns_zone_stub) ? dns_dbtype_stub
: dns_dbtype_zone,
zone->rdclass, zone->db_argc - 1, zone->db_argv + 1, &db);
if (result != ISC_R_SUCCESS) {
return (result);
}
switch (zone->type) {
case dns_zone_primary:
case dns_zone_secondary:
case dns_zone_mirror:
result = dns_db_setgluecachestats(db, zone->gluecachestats);
if (result == ISC_R_NOTIMPLEMENTED) {
result = ISC_R_SUCCESS;
}
if (result != ISC_R_SUCCESS) {
dns_db_detach(&db);
return (result);
}
break;
default:
break;
}
dns_db_setloop(db, zone->loop);
*dbp = db;
return (ISC_R_SUCCESS);
}