1355
1359
if (result != ISC_R_SUCCESS)
1357
1361
if (zone->db != NULL) {
1358
if (!isc_serial_ge(serial, zone->serial)) {
1363
* This is checked in zone_replacedb() for slave zones
1364
* as they don't reload from disk.
1366
if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IXFRFROMDIFFS) &&
1367
!isc_serial_gt(serial, zone->serial)) {
1368
isc_uint32_t serialmin, serialmax;
1370
INSIST(zone->type == dns_zone_master);
1372
serialmin = (zone->serial + 1) & 0xffffffffU;
1373
serialmax = (zone->serial + 0x7fffffffU) &
1375
dns_zone_log(zone, ISC_LOG_ERROR,
1376
"ixfr-from-differences: "
1377
"new serial (%u) out of range "
1378
"[%u - %u]", serial, serialmin,
1380
result = DNS_R_BADZONE;
1382
} else if (!isc_serial_ge(serial, zone->serial))
1359
1383
dns_zone_log(zone, ISC_LOG_ERROR,
1360
1384
"zone serial has gone backwards");
1385
else if (serial == zone->serial && !hasinclude)
1386
dns_zone_log(zone, ISC_LOG_ERROR,
1387
"zone serial unchanged");
1363
1389
zone->serial = serial;
1364
1390
zone->refresh = RANGE(refresh,
1972
1999
zone->masterscnt * sizeof(dns_name_t *));
1973
2000
zone->masterkeynames = NULL;
2002
if (zone->mastersok != NULL) {
2003
isc_mem_put(zone->mctx, zone->mastersok,
2004
zone->masterscnt * sizeof(isc_boolean_t));
2005
zone->mastersok = NULL;
1975
2007
zone->masterscnt = 0;
1977
* If count == 0, don't allocate any space for masters or keynames
1978
* so internally, those pointers are NULL if count == 0
2009
* If count == 0, don't allocate any space for masters, mastersok or
2010
* keynames so internally, those pointers are NULL if count == 0
1980
2012
if (count == 0)
1984
2016
* masters must countain count elements!
1986
new = isc_mem_get(zone->mctx,
1987
count * sizeof(isc_sockaddr_t));
2018
new = isc_mem_get(zone->mctx, count * sizeof(*new));
1988
2019
if (new == NULL) {
1989
2020
result = ISC_R_NOMEMORY;
1992
2023
memcpy(new, masters, count * sizeof(*new));
1993
zone->masters = new;
1994
zone->masterscnt = count;
1995
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOMASTERS);
2026
* Similarly for mastersok.
2028
newok = isc_mem_get(zone->mctx, count * sizeof(*newok));
2029
if (newok == NULL) {
2030
result = ISC_R_NOMEMORY;
2031
isc_mem_put(zone->mctx, new, count * sizeof(*new));
2034
for (i = 0; i < count; i++)
2035
newok[i] = ISC_FALSE;
1998
2038
* if keynames is non-NULL, it must contain count elements!
2000
2041
if (keynames != NULL) {
2001
newname = isc_mem_get(zone->mctx,
2002
count * sizeof(dns_name_t *));
2042
newname = isc_mem_get(zone->mctx, count * sizeof(*newname));
2003
2043
if (newname == NULL) {
2004
2044
result = ISC_R_NOMEMORY;
2005
isc_mem_put(zone->mctx, zone->masters,
2006
count * sizeof(*new));
2045
isc_mem_put(zone->mctx, new, count * sizeof(*new));
2046
isc_mem_put(zone->mctx, newok, count * sizeof(*newok));
2009
2049
for (i = 0; i < count; i++)
2027
isc_mem_put(zone->mctx, zone->masters,
2067
isc_mem_put(zone->mctx, new,
2028
2068
count * sizeof(*new));
2069
isc_mem_put(zone->mctx, newok,
2070
count * sizeof(*newok));
2029
2071
isc_mem_put(zone->mctx, newname,
2030
2072
count * sizeof(*newname));
2035
zone->masterkeynames = newname;
2080
* Everything is ok so attach to the zone.
2082
zone->masters = new;
2083
zone->mastersok = newok;
2084
zone->masterkeynames = newname;
2085
zone->masterscnt = count;
2086
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOMASTERS);
2038
2089
UNLOCK_ZONE(zone);
2039
2090
return (result);
3360
3415
isc_event_free(&event);
3361
3416
LOCK_ZONE(zone);
3362
3417
dns_request_destroy(&zone->request);
3419
* Skip to next failed / untried master.
3423
} while (zone->curmaster < zone->masterscnt &&
3424
zone->mastersok[zone->curmaster]);
3364
3425
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOEDNS);
3365
3426
if (exiting || zone->curmaster >= zone->masterscnt) {
3427
isc_boolean_t done = ISC_TRUE;
3366
3428
if (!exiting &&
3367
3429
DNS_ZONE_OPTION(zone, DNS_ZONEOPT_USEALTXFRSRC) &&
3368
3430
!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_USEALTXFRSRC)) {
3432
* Did we get a good answer from all the masters?
3434
for (j = 0; j < zone->masterscnt; j++)
3435
if (zone->mastersok[j] == ISC_FALSE) {
3369
3442
zone->curmaster = 0;
3444
* Find the next failed master.
3446
while (zone->curmaster < zone->masterscnt &&
3447
zone->mastersok[zone->curmaster])
3370
3449
DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC);
3372
3451
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH);
3688
3770
isc_event_free(&event);
3689
3771
LOCK_ZONE(zone);
3690
3772
dns_request_destroy(&zone->request);
3774
* Skip to next failed / untried master.
3778
} while (zone->curmaster < zone->masterscnt &&
3779
zone->mastersok[zone->curmaster]);
3692
3780
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOEDNS);
3693
3781
if (zone->curmaster >= zone->masterscnt) {
3782
isc_boolean_t done = ISC_TRUE;
3694
3783
if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_USEALTXFRSRC) &&
3695
3784
!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_USEALTXFRSRC)) {
3786
* Did we get a good answer from all the masters?
3788
for (j = 0; j < zone->masterscnt; j++)
3789
if (zone->mastersok[j] == ISC_FALSE) {
3696
3796
DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC);
3697
3797
zone->curmaster = 0;
3799
* Find the next failed master.
3801
while (zone->curmaster < zone->masterscnt &&
3802
zone->mastersok[zone->curmaster])
3700
3806
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH);
5275
5387
* is enabled in the configuration.
5277
5389
if (zone->db != NULL && zone->journal != NULL &&
5278
DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IXFRFROMDIFFS)) {
5279
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
5280
DNS_LOGMODULE_ZONE, ISC_LOG_DEBUG(3),
5281
"generating diffs");
5282
result = dns_db_diff(zone->mctx, db, ver,
5283
zone->db, NULL /* XXX */,
5390
DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IXFRFROMDIFFS) &&
5391
!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FORCEXFER)) {
5392
isc_uint32_t serial;
5394
dns_zone_log(zone, ISC_LOG_DEBUG(3), "generating diffs");
5396
result = dns_db_getsoaserial(db, ver, &serial);
5397
if (result != ISC_R_SUCCESS) {
5398
dns_zone_log(zone, ISC_LOG_ERROR,
5399
"ixfr-from-differences: unable to get "
5405
* This is checked in zone_postload() for master zones.
5407
if (zone->type == dns_zone_slave &&
5408
!isc_serial_gt(serial, zone->serial)) {
5409
isc_uint32_t serialmin, serialmax;
5410
serialmin = (zone->serial + 1) & 0xffffffffU;
5411
serialmax = (zone->serial + 0x7fffffffU) & 0xffffffffU;
5412
dns_zone_log(zone, ISC_LOG_ERROR,
5413
"ixfr-from-differences: failed: "
5414
"new serial (%u) out of range [%u - %u]",
5415
serial, serialmin, serialmax);
5416
result = ISC_R_RANGE;
5420
result = dns_db_diff(zone->mctx, db, ver, zone->db, NULL,
5284
5421
zone->journal);
5285
5422
if (result != ISC_R_SUCCESS)
5288
5425
zone_needdump(zone, DNS_DUMP_DELAY);
5289
5426
else if (zone->journalsize != -1) {
5290
isc_uint32_t serial;
5292
result = dns_db_getsoaserial(db, ver, &serial);
5293
if (result == ISC_R_SUCCESS) {
5294
result = dns_journal_compact(zone->mctx,
5301
case ISC_R_NOTFOUND:
5302
dns_zone_log(zone, ISC_LOG_DEBUG(3),
5303
"dns_journal_compact: %s",
5304
dns_result_totext(result));
5307
dns_zone_log(zone, ISC_LOG_ERROR,
5427
result = dns_journal_compact(zone->mctx, zone->journal,
5428
serial, zone->journalsize);
5432
case ISC_R_NOTFOUND:
5433
dns_zone_log(zone, ISC_LOG_DEBUG(3),
5434
"dns_journal_compact: %s",
5435
dns_result_totext(result));
5438
dns_zone_log(zone, ISC_LOG_ERROR,
5308
5439
"dns_journal_compact failed: %s",
5309
dns_result_totext(result));
5440
dns_result_totext(result));
5697
5837
"requesting AXFR of "
5698
5838
"initial version from %s", mastertext);
5699
5839
xfrtype = dns_rdatatype_axfr;
5700
} else if (dns_zone_isforced(zone)) {
5840
} else if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IXFRFROMDIFFS)) {
5841
dns_zone_log(zone, ISC_LOG_DEBUG(1), "ixfr-from-differences "
5842
"set, requesting AXFR from %s", mastertext);
5843
xfrtype = dns_rdatatype_axfr;
5844
} else if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FORCEXFER)) {
5701
5845
dns_zone_log(zone, ISC_LOG_DEBUG(1),
5702
5846
"forced reload, requesting AXFR of "
5703
5847
"initial version from %s", mastertext);