]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add plugin_register param telling the source
authorColin Vidal <colin@isc.org>
Tue, 19 Aug 2025 12:38:36 +0000 (14:38 +0200)
committerColin Vidal <colin@isc.org>
Tue, 9 Sep 2025 07:42:34 +0000 (09:42 +0200)
The plugin `plugin_register` API has a new parameter `source` indicating
whether the plugin is loaded from a view or a zone.

This extra parameter enables the plugin to fail early during
initialization if a plugin written to be used in a zone exclusively
is loaded at a view level, or vice versa.

bin/named/server.c
bin/named/zoneconf.c
bin/plugins/filter-a.c
bin/plugins/filter-aaaa.c
lib/ns/hooks.c
lib/ns/include/ns/hooks.h

index e92ef449629f198df9c2d813c35d4ae76b1432d1..8448b3d71541f1535c88e9a9dfe0df4501630df1 100644 (file)
@@ -5417,7 +5417,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        }
 
        if (plugin_list != NULL) {
-               ns_hook_data_t hookdata = {};
+               ns_hook_data_t hookdata = { .source = NS_HOOKSOURCE_VIEW };
 
                INSIST(view->hooktable == NULL);
                ns_hooktable_create(view->mctx, &hookdata.hooktable);
index 729c3e8c59b7b7296c3ffde45ebd432dec3a3139..e4a4cf4b4295d36120d4be8e18db1f549da8838b 100644 (file)
@@ -2125,7 +2125,7 @@ named_zone_loadplugins(dns_zone_t *zone, const cfg_obj_t *config,
        }
 
        if (tpluginlist != NULL || zpluginlist != NULL) {
-               ns_hook_data_t hookdata = {};
+               ns_hook_data_t hookdata = { .source = NS_HOOKSOURCE_ZONE };
                isc_mem_t *zmctx = dns_zone_getmctx(zone);
 
                ns_hooktable_create(zmctx, &hookdata.hooktable);
index 2f684a2a45edcf26c948cd53f69240d9183b9318..7ff8048cde694618ad0f64c459cacc5d1b1b0551 100644 (file)
@@ -326,10 +326,13 @@ cleanup:
 isc_result_t
 plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
                unsigned long cfg_line, isc_mem_t *mctx, void *actx,
-               ns_hooktable_t *hooktable, void **instp) {
+               ns_hooktable_t *hooktable, ns_hooksource_t source,
+               void **instp) {
        filter_instance_t *inst = NULL;
        isc_result_t result = ISC_R_SUCCESS;
 
+       UNUSED(source);
+
        isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
                      "registering 'filter-a' "
                      "module from %s:%lu, %s parameters",
index d24a6ca80bca0abbefcc4b71178e0498054a9b48..b5d58a564090354b1e16fa60c2a208c7a77c5773 100644 (file)
@@ -329,10 +329,13 @@ cleanup:
 isc_result_t
 plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
                unsigned long cfg_line, isc_mem_t *mctx, void *actx,
-               ns_hooktable_t *hooktable, void **instp) {
+               ns_hooktable_t *hooktable, ns_hooksource_t source,
+               void **instp) {
        filter_instance_t *inst = NULL;
        isc_result_t result = ISC_R_SUCCESS;
 
+       UNUSED(source);
+
        isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
                      "registering 'filter-aaaa' "
                      "module from %s:%lu, %s parameters",
index 9c7957e81890d0f7c8a9886158299e78da60a7a2..7e6b307cfa9d1923c0e962e33f5b8bcd2cba8c04 100644 (file)
@@ -239,8 +239,10 @@ ns_plugin_register(const char *modpath, const char *parameters, const void *cfg,
        isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
                      "registering plugin '%s'", modpath);
 
+       INSIST(hookdata->source != NS_HOOKSOURCE_UNDEFINED);
        CHECK(plugin->register_func(parameters, cfg, cfg_file, cfg_line, mctx,
-                                   actx, hookdata->hooktable, &plugin->inst));
+                                   actx, hookdata->hooktable, hookdata->source,
+                                   &plugin->inst));
 
        ISC_LIST_APPEND(*hookdata->plugins, plugin, link);
 
index 98508938567c421c707fb2d05b570b081fcb3294..363e1ac3a5270e7d1e59ae172d4293718f154d09 100644 (file)
  * contains a function pointer to a hook action and a pointer to data which is
  * to be passed to the action function when it is called.
  *
- * Each view has its own separate hook table, populated by loading plugin
- * modules specified in the "plugin" statements in named.conf.  There is also a
- * special, global hook table (ns__hook_table) that is only used by libns unit
- * tests and whose existence can be safely ignored by plugin modules.
+ * Each view and zone has its own separate hook table, populated by loading
+ * plugin modules specified in the "plugin" statements in named.conf. (See
+ * `ZONE-SPECIFIC PLUGINS` section below.) There is also a special, global
+ * hook table (ns__hook_table) that is only used by libns unit tests and
+ * whose existence can be safely ignored by plugin modules.
  *
  * Hook actions are functions which:
  *
  *   looked up.  `NS_QUERY_DONE_BEGIN` could be called if an
  *   authoritative zone has been used, but in some flows (for
  *   instance, bad cookie handling), it would be skipped.
+ *
+ * The `plugin_register` function (defined by each plugin and called
+ * when the plugin is loaded) has a `ns_hooksource_t source` parameter.
+ * It indicates whether the plugin has been loaded at the zone level
+ * (`NS_HOOKSOURCE_ZONE`) or at the view level (`NS_HOOKSOURCE_VIEW`).
+ * While this can be ignored if it doesn't matter where the plugin is
+ * loaded, it can also be checked to enforce that the plugin is loaded
+ * only at the zone or view level.
  */
 
 /*!
@@ -476,9 +485,16 @@ typedef struct ns_hook_resume {
  * Wrapper struct holding hook/plugins owning data structures used and owned by
  * zones and views having registered plugins.
  */
+typedef enum {
+       NS_HOOKSOURCE_UNDEFINED,
+       NS_HOOKSOURCE_VIEW,
+       NS_HOOKSOURCE_ZONE
+} ns_hooksource_t;
+
 typedef struct ns_hook_data {
        ns_hooktable_t *hooktable;
        ns_plugins_t   *plugins;
+       ns_hooksource_t source;
 } ns_hook_data_t;
 
 /*
@@ -497,7 +513,8 @@ typedef struct ns_hook_data {
 typedef isc_result_t
 ns_plugin_register_t(const char *parameters, const void *cfg, const char *file,
                     unsigned long line, isc_mem_t *mctx, void *actx,
-                    ns_hooktable_t *hooktable, void **instp);
+                    ns_hooktable_t *hooktable, ns_hooksource_t source,
+                    void **instp);
 /*%<
  * Called when registering a new plugin.
  *