From: Colin Vidal Date: Wed, 4 Jun 2025 11:52:30 +0000 (+0200) Subject: add template support for zone plugins X-Git-Tag: v9.21.14~56^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd46aecd223e3267c0baa5e12d17fe84b87d5218;p=thirdparty%2Fbind9.git 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. --- diff --git a/bin/named/include/named/zoneconf.h b/bin/named/include/named/zoneconf.h index ff5a326832e..47fb9aeaebd 100644 --- a/bin/named/include/named/zoneconf.h +++ b/bin/named/include/named/zoneconf.h @@ -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 */ diff --git a/bin/named/server.c b/bin/named/server.c index 0a4f60beea1..e92ef449629 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -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) { diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index ab7dad50d89..729c3e8c59b 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -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 (toptions != NULL) { + (void)cfg_map_get(toptions, "plugin", &tpluginlist); + } + if (zoptions != NULL) { - (void)cfg_map_get(zoptions, "plugin", &pluginlist); + (void)cfg_map_get(zoptions, "plugin", &zpluginlist); } - if (pluginlist != NULL) { + 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); }