make "origin" optional for forward zones

The "origin" parameter for synthrecord is now mandatory for reverse
zones, but when configured in a non-reverse zone, it will default to
the zone name.
This commit is contained in:
Evan Hunt 2025-09-26 21:59:52 -07:00 committed by Colin Vidal
parent c4b5deb750
commit a8f2f41013
4 changed files with 54 additions and 24 deletions

View file

@ -422,6 +422,8 @@ synthrecord_initprefix(synthrecord_t *inst, const cfg_obj_t *synthrecordcfg) {
result = cfg_map_get(synthrecordcfg, "prefix", &obj);
if (result != ISC_R_SUCCESS) {
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
ISC_LOG_ERROR, "synthrecord: prefix not found");
return result;
}
@ -452,33 +454,42 @@ synthrecord_initprefix(synthrecord_t *inst, const cfg_obj_t *synthrecordcfg) {
}
static isc_result_t
synthrecord_initorigin(synthrecord_t *inst, const cfg_obj_t *synthrecordcfg) {
synthrecord_initorigin(synthrecord_t *inst, const cfg_obj_t *synthrecordcfg,
const dns_name_t *zname) {
isc_result_t result;
const cfg_obj_t *obj = NULL;
const char *originstr = NULL;
result = cfg_map_get(synthrecordcfg, "origin", &obj);
if (result != ISC_R_SUCCESS) {
return result;
}
originstr = cfg_obj_asstring(obj);
dns_name_init(&inst->origin);
result = dns_name_fromstring(&inst->origin, originstr, NULL, 0,
inst->mctx);
if (result != ISC_R_SUCCESS) {
return result;
}
if (!dns_name_isabsolute(&inst->origin)) {
if (inst->mode == REVERSE && result != ISC_R_SUCCESS) {
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
ISC_LOG_ERROR,
"synthrecord: origin '%s' is not absolute",
originstr);
return ISC_R_FAILURE;
"'origin' must be set when configuring "
"'synthrecord' for a reverse zone");
return result;
}
return result;
dns_name_init(&inst->origin);
if (result == ISC_R_SUCCESS) {
originstr = cfg_obj_asstring(obj);
result = dns_name_fromstring(&inst->origin, originstr, NULL, 0,
inst->mctx);
if (result != ISC_R_SUCCESS) {
return result;
}
if (!dns_name_isabsolute(&inst->origin)) {
isc_log_write(NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_HOOKS, ISC_LOG_ERROR,
"synthrecord: origin '%s' not absolute",
originstr);
return ISC_R_FAILURE;
}
} else {
dns_name_dup(zname, inst->mctx, &inst->origin);
}
return ISC_R_SUCCESS;
}
static void
@ -571,7 +582,7 @@ synthrecord_parseconfig(synthrecord_t *inst, const char *parameters,
&synthrecord_cfgparams, 0, &synthrecordcfg));
synthrecord_setconfigmode(inst, zname);
CHECK(synthrecord_initorigin(inst, synthrecordcfg));
CHECK(synthrecord_initorigin(inst, synthrecordcfg, zname));
CHECK(synthrecord_initprefix(inst, synthrecordcfg));
CHECK(synthrecord_parseallowsynth(inst, cfg, aclctx, synthrecordcfg));
CHECK(synthrecord_parsettl(inst, synthrecordcfg));

View file

@ -108,17 +108,15 @@ and an A query for ``dynamic-192-168-1-5.example`` would receive
Parameters
~~~~~~~~~~
The following parameters are mandatory:
``prefix``
Specifies the prefix of the synthesized name. It must be a single-label
name.
name. This parameter is mandatory.
``origin``
Specifies the origin of the synthesized name. This may be the same as
the zone origin, or a descendent. It cannot be below a delegation point.
The following parameters are optional:
This parameter is mandatory for reverse zones, but when configured in
forward mode, it defaults to the zone name.
``allow-synth``
This option is an address-match list, which can be used to restrict

View file

@ -0,0 +1,21 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
zone 10.in-addr.arpa {
type primary;
file "file";
plugin query "@TOP_BUILDDIR@/synthrecord.so" {
prefix "dynamic-";
ttl 60;
};
};