]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add template support for zone plugins
authorColin Vidal <colin@isc.org>
Wed, 4 Jun 2025 11:52:30 +0000 (13:52 +0200)
committerColin Vidal <colin@isc.org>
Tue, 9 Sep 2025 07:42:34 +0000 (09:42 +0200)
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.

bin/named/include/named/zoneconf.h
bin/named/server.c
bin/named/zoneconf.c

index ff5a326832e8613c4b69a76e15bfcc10025b6880..47fb9aeaebd3e2a98bd346ef9fa63f8a290685d5 100644 (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
  */
index 0a4f60beea11261303e9e296cd5c7e85bae3a863..e92ef449629f198df9c2d813c35d4ae76b1432d1 100644 (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) {
index ab7dad50d89d283cb540b4477fe69b3f8dfaae47..729c3e8c59b7b7296c3ffde45ebd432dec3a3139 100644 (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 (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);
        }