add template support for zone plugins

The zone plugin loading code now also looks into the zone template
configuration property of a zone. If it exists, it checks whether there
is a plugin sub-tree defined in the template and, if that exists, loads
the plugin definition from the template.
This commit is contained in:
Colin Vidal 2025-06-04 13:52:30 +02:00
parent 1114b1eac0
commit bd46aecd22
3 changed files with 22 additions and 8 deletions

View file

@ -84,7 +84,7 @@ named_zone_templateopts(const cfg_obj_t *config, const cfg_obj_t *zoptions);
isc_result_t
named_zone_loadplugins(dns_zone_t *zone, const cfg_obj_t *config,
const cfg_obj_t *zoptions);
const cfg_obj_t *toptions, const cfg_obj_t *zoptions);
/*%<
* Load plugins that should run for this specific zone. Take care of cleaning
* up any pre-existing plugins first, if the zone is re-used.
@ -93,4 +93,6 @@ named_zone_loadplugins(dns_zone_t *zone, const cfg_obj_t *config,
* \li 'zone' to be a valid zone
* \li 'config' to be a valid named.conf configuration tree
* \li 'zoptions' to be a valid zone configuration tree
* \li 'toptions' to be NULL or valid template configuration tree
* \li 'zoptions' to be NULL or a valid zone configuration tree
*/

View file

@ -6660,7 +6660,7 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig,
dns_zone_rekey(zone, fullsign, false);
}
result = named_zone_loadplugins(zone, config, zoptions);
result = named_zone_loadplugins(zone, config, toptions, zoptions);
cleanup:
if (zone != NULL) {

View file

@ -2101,9 +2101,10 @@ named_zone_templateopts(const cfg_obj_t *config, const cfg_obj_t *zoptions) {
isc_result_t
named_zone_loadplugins(dns_zone_t *zone, const cfg_obj_t *config,
const cfg_obj_t *zoptions) {
const cfg_obj_t *toptions, const cfg_obj_t *zoptions) {
isc_result_t result = ISC_R_SUCCESS;
const cfg_obj_t *pluginlist = NULL;
const cfg_obj_t *zpluginlist = NULL;
const cfg_obj_t *tpluginlist = NULL;
/*
* If the zone previously had any loaded plugins, unload them:
@ -2115,11 +2116,15 @@ named_zone_loadplugins(dns_zone_t *zone, const cfg_obj_t *config,
/*
* Load zone-specific plugin instances.
*/
if (zoptions != NULL) {
(void)cfg_map_get(zoptions, "plugin", &pluginlist);
if (toptions != NULL) {
(void)cfg_map_get(toptions, "plugin", &tpluginlist);
}
if (pluginlist != NULL) {
if (zoptions != NULL) {
(void)cfg_map_get(zoptions, "plugin", &zpluginlist);
}
if (tpluginlist != NULL || zpluginlist != NULL) {
ns_hook_data_t hookdata = {};
isc_mem_t *zmctx = dns_zone_getmctx(zone);
@ -2130,7 +2135,14 @@ named_zone_loadplugins(dns_zone_t *zone, const cfg_obj_t *config,
ns_plugins_create(zmctx, &hookdata.plugins);
dns_zone_setplugins(zone, hookdata.plugins, ns_plugins_free);
result = cfg_pluginlist_foreach(config, pluginlist,
result = cfg_pluginlist_foreach(config, tpluginlist,
named_register_one_plugin,
&hookdata);
if (result != ISC_R_SUCCESS) {
return result;
}
result = cfg_pluginlist_foreach(config, zpluginlist,
named_register_one_plugin,
&hookdata);
}