]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
eliminate ns_hookctx structure, pass mctx/lctx/view directly
authorEvan Hunt <each@isc.org>
Fri, 30 Nov 2018 18:12:04 +0000 (10:12 -0800)
committerEvan Hunt <each@isc.org>
Thu, 6 Dec 2018 18:36:44 +0000 (10:36 -0800)
bin/hooks/filter-aaaa.c
bin/named/server.c
lib/bind9/check.c
lib/ns/hooks.c
lib/ns/include/ns/hooks.h
lib/ns/win32/libns.def

index 50e5d473acc836578523cb1cc893fe9c22cd849e..2fedc6301c93b825beed336b2e55a7df842e820f 100644 (file)
@@ -294,8 +294,8 @@ check_syntax(cfg_obj_t *fmap, const void *cfg,
 
 static isc_result_t
 parse_parameters(filter_instance_t *inst, const char *parameters,
-                const char *cfg_file, unsigned long cfg_line,
-                const void *cfg, void *actx, ns_hookctx_t *hctx)
+                const void *cfg, const char *cfg_file, unsigned long cfg_line,
+                isc_mem_t *mctx, isc_log_t *lctx, void *actx)
 {
        isc_result_t result = ISC_R_SUCCESS;
        cfg_parser_t *parser = NULL;
@@ -303,14 +303,14 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
        const cfg_obj_t *obj = NULL;
        isc_buffer_t b;
 
-       CHECK(cfg_parser_create(hctx->mctx, hctx->lctx, &parser));
+       CHECK(cfg_parser_create(mctx, lctx, &parser));
 
        isc_buffer_constinit(&b, parameters, strlen(parameters));
        isc_buffer_add(&b, strlen(parameters));
        CHECK(cfg_parse_buffer4(parser, &b, cfg_file, cfg_line,
                                &cfg_type_parameters, 0, &param_obj));
 
-       CHECK(check_syntax(param_obj, cfg, hctx->mctx, hctx->lctx, actx));
+       CHECK(check_syntax(param_obj, cfg, mctx, lctx, actx));
 
        CHECK(parse_filter_aaaa_on(param_obj, "filter-aaaa-on-v4",
                                   &inst->v4_aaaa));
@@ -320,10 +320,10 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
        result = cfg_map_get(param_obj, "filter-aaaa", &obj);
        if (result == ISC_R_SUCCESS) {
                CHECK(cfg_acl_fromconfig(obj, (const cfg_obj_t *) cfg,
-                                        hctx->lctx, (cfg_aclconfctx_t *) actx,
-                                        hctx->mctx, 0, &inst->aaaa_acl));
+                                        lctx, (cfg_aclconfctx_t *) actx,
+                                        mctx, 0, &inst->aaaa_acl));
        } else {
-               CHECK(dns_acl_any(hctx->mctx, &inst->aaaa_acl));
+               CHECK(dns_acl_any(mctx, &inst->aaaa_acl));
        }
 
  cleanup:
@@ -350,33 +350,32 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
  */
 isc_result_t
 hook_register(const char *parameters,
-             const char *cfg_file, unsigned long cfg_line,
-             const void *cfg, void *actx, ns_hookctx_t *hctx,
+             const void *cfg, const char *cfg_file, unsigned long cfg_line,
+             isc_mem_t *mctx, isc_log_t *lctx, void *actx,
              ns_hooktable_t *hooktable, void **instp)
 {
        filter_instance_t *inst = NULL;
        isc_result_t result;
 
 
-       isc_log_write(hctx->lctx, NS_LOGCATEGORY_GENERAL,
+       isc_log_write(lctx, NS_LOGCATEGORY_GENERAL,
                      NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
                      "registering 'filter-aaaa' "
                      "module from %s:%lu, %s parameters",
                      cfg_file, cfg_line, parameters != NULL ? "with" : "no");
 
-       inst = isc_mem_get(hctx->mctx, sizeof(*inst));
+       inst = isc_mem_get(mctx, sizeof(*inst));
        memset(inst, 0, sizeof(*inst));
-       isc_mem_attach(hctx->mctx, &inst->mctx);
+       isc_mem_attach(mctx, &inst->mctx);
 
        if (parameters != NULL) {
-               CHECK(parse_parameters(inst, parameters,
-                                      cfg_file, cfg_line,
-                                      cfg, actx, hctx));
+               CHECK(parse_parameters(inst, parameters, cfg, cfg_file,
+                                      cfg_line, mctx, lctx, actx));
        }
 
-       CHECK(isc_mempool_create(hctx->mctx, sizeof(filter_data_t),
+       CHECK(isc_mempool_create(mctx, sizeof(filter_data_t),
                                 &inst->datapool));
-       CHECK(isc_ht_init(&inst->ht, hctx->mctx, 16));
+       CHECK(isc_ht_init(&inst->ht, mctx, 16));
 
        /*
         * Fill the mempool with 1K filter_aaaa state objects at
@@ -394,7 +393,7 @@ hook_register(const char *parameters,
        /*
         * Set hook points in the view's hooktable.
         */
-       install_hooks(hooktable, hctx->mctx, inst);
+       install_hooks(hooktable, mctx, inst);
 
        *instp = inst;
 
@@ -407,8 +406,9 @@ hook_register(const char *parameters,
 }
 
 isc_result_t
-hook_check(const char *parameters, const char *cfg_file, unsigned long cfg_line,
-          const void *cfg, isc_mem_t *mctx, isc_log_t *lctx, void *actx)
+hook_check(const char *parameters,
+          const void *cfg, const char *cfg_file, unsigned long cfg_line,
+          isc_mem_t *mctx, isc_log_t *lctx, void *actx)
 {
        isc_result_t result = ISC_R_SUCCESS;
        cfg_parser_t *parser = NULL;
index 8204db5451cd047a8d63fd824a26de39934fbde9..1a1c443da39024c45ace96d7977c117420fad303 100644 (file)
@@ -1538,7 +1538,7 @@ configure_dyndb(const cfg_obj_t *dyndb, isc_mem_t *mctx,
 
 static isc_result_t
 configure_hook(dns_view_t *view, const cfg_obj_t *hook,
-              const cfg_obj_t *config, ns_hookctx_t *hctx)
+              const cfg_obj_t *config)
 {
        isc_result_t result = ISC_R_SUCCESS;
        const cfg_obj_t *obj;
@@ -1563,9 +1563,9 @@ configure_hook(dns_view_t *view, const cfg_obj_t *hook,
                parameters = cfg_obj_asstring(obj);
        }
        result = ns_module_load(library, parameters,
-                               cfg_obj_file(obj), cfg_obj_line(obj),
-                               config, named_g_aclconfctx,
-                               hctx, view->modlist, view->hooktable);
+                               config, cfg_obj_file(obj), cfg_obj_line(obj),
+                               named_g_mctx, named_g_lctx, named_g_aclconfctx,
+                               view);
        if (result != ISC_R_SUCCESS) {
                isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
                              NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
@@ -3755,7 +3755,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist,
        bool old_rpz_ok = false;
        isc_dscp_t dscp4 = -1, dscp6 = -1;
        dns_dyndbctx_t *dctx = NULL;
-       ns_hookctx_t *hctx = NULL;
        unsigned int resolver_param;
        dns_ntatable_t *ntatable = NULL;
        const char *qminmode = NULL;
@@ -5308,8 +5307,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist,
 
 #ifdef HAVE_DLOPEN
        if (hook_list != NULL) {
-               CHECK(ns_hook_createctx(mctx, view, &hctx));
-
                INSIST(view->hooktable == NULL);
                CHECK(ns_hooktable_create(view->mctx,
                                  (ns_hooktable_t **) &view->hooktable));
@@ -5325,7 +5322,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist,
        {
                const cfg_obj_t *hook = cfg_listelt_value(element);
 
-               CHECK(configure_hook(view, hook, config, hctx));
+               CHECK(configure_hook(view, hook, config));
        }
 #endif
 
@@ -5580,9 +5577,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist,
        if (dctx != NULL) {
                dns_dyndb_destroyctx(&dctx);
        }
-       if (hctx != NULL) {
-               ns_hook_destroyctx(&hctx);
-       }
 
        return (result);
 }
index efef37f00d0b5580687f67d99ed0971296897a97..af43a1d04d638c4d16c93dfe7a6f7ab38b826f17 100644 (file)
@@ -3703,9 +3703,9 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions,
                if (obj != NULL && cfg_obj_isstring(obj)) {
                        parameters = cfg_obj_asstring(obj);
                }
-               tresult = ns_module_check(library, parameters,
+               tresult = ns_module_check(library, parameters, config,
                                          cfg_obj_file(obj), cfg_obj_line(obj),
-                                         config, mctx, logctx, actx);
+                                         mctx, logctx, actx);
                if (tresult != ISC_R_SUCCESS) {
                        cfg_obj_log(obj, logctx, ISC_LOG_ERROR,
                                    "%s: module check failed: %s",
index 885b7fa25f2d20ac1d16ee4f8dd49a9ae00a680a..5ce67292f476368b5d39fad1503e299db5652b81 100644 (file)
@@ -348,32 +348,32 @@ unload_library(ns_module_t **hmodp) {
 #endif /* HAVE_DLFCN_H */
 
 isc_result_t
-ns_module_load(const char *modpath, const char *parameters,
-              const char *cfg_file, unsigned long cfg_line,
-              const void *cfg, void *actx, ns_hookctx_t *hctx,
-              ns_modlist_t *modlist, ns_hooktable_t *hooktable)
+ns_module_load(const char *modpath, const char *parameters, const void *cfg,
+              const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx,
+              isc_log_t *lctx, void *actx, dns_view_t *view)
 {
        isc_result_t result;
        ns_module_t *hmod = NULL;
 
-       REQUIRE(NS_HOOKCTX_VALID(hctx));
-       REQUIRE(modlist != NULL);
-       REQUIRE(hooktable != NULL);
+       REQUIRE(mctx != NULL);
+       REQUIRE(lctx != NULL);
+       REQUIRE(view != NULL);
 
        isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
                      NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
                      "loading module '%s'", modpath);
 
-       CHECK(load_library(hctx->mctx, modpath, &hmod));
+       CHECK(load_library(mctx, modpath, &hmod));
 
        isc_log_write(ns_lctx, NS_LOGCATEGORY_GENERAL,
                      NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
                      "registering module '%s'", modpath);
 
-       CHECK(hmod->register_func(parameters, cfg_file, cfg_line,
-                                 cfg, actx, hctx, hooktable, &hmod->inst));
+       CHECK(hmod->register_func(parameters, cfg, cfg_file, cfg_line,
+                                 mctx, lctx, actx, view->hooktable,
+                                 &hmod->inst));
 
-       ISC_LIST_APPEND(*modlist, hmod, link);
+       ISC_LIST_APPEND(*(ns_modlist_t *)view->modlist, hmod, link);
 
 cleanup:
        if (result != ISC_R_SUCCESS && hmod != NULL) {
@@ -385,16 +385,16 @@ cleanup:
 
 isc_result_t
 ns_module_check(const char *modpath, const char *parameters,
-               const char *cfg_file, unsigned long cfg_line,
-               const void *cfg, isc_mem_t *mctx, isc_log_t *lctx, void *actx)
+               const void *cfg, const char *cfg_file, unsigned long cfg_line,
+               isc_mem_t *mctx, isc_log_t *lctx, void *actx)
 {
        isc_result_t result;
        ns_module_t *hmod = NULL;
 
        CHECK(load_library(mctx, modpath, &hmod));
 
-       result = hmod->check_func(parameters, cfg_file, cfg_line,
-                                 cfg, mctx, lctx, actx);
+       result = hmod->check_func(parameters, cfg, cfg_file, cfg_line,
+                                 mctx, lctx, actx);
 
 cleanup:
        if (hmod != NULL) {
@@ -404,41 +404,6 @@ cleanup:
        return (result);
 }
 
-isc_result_t
-ns_hook_createctx(isc_mem_t *mctx, dns_view_t *view, ns_hookctx_t **hctxp) {
-       ns_hookctx_t *hctx = NULL;
-
-       REQUIRE(hctxp != NULL && *hctxp == NULL);
-
-       hctx = isc_mem_get(mctx, sizeof(*hctx));
-       memset(hctx, 0, sizeof(*hctx));
-       hctx->lctx = ns_lctx;
-
-       dns_view_attach(view, &hctx->view);
-
-       isc_mem_attach(mctx, &hctx->mctx);
-       hctx->magic = NS_HOOKCTX_MAGIC;
-
-       *hctxp = hctx;
-
-       return (ISC_R_SUCCESS);
-}
-
-void
-ns_hook_destroyctx(ns_hookctx_t **hctxp) {
-       ns_hookctx_t *hctx = NULL;
-
-       REQUIRE(hctxp != NULL && NS_HOOKCTX_VALID(*hctxp));
-
-       hctx = *hctxp;
-       *hctxp = NULL;
-
-       hctx->magic = 0;
-
-       dns_view_detach(&hctx->view);
-       isc_mem_putanddetach(&hctx->mctx, hctx, sizeof(*hctx));
-}
-
 void
 ns_hooktable_init(ns_hooktable_t *hooktable) {
        int i;
index 64f944a4f1f56ea4530796932bfeb7d234c3f013..a25a3365084ed3432e2f673ce71e8b3d73a2495a 100644 (file)
@@ -222,25 +222,6 @@ typedef ns_hooklist_t ns_hooktable_t[NS_HOOKPOINTS_COUNT];
  */
 LIBNS_EXTERNAL_DATA extern ns_hooktable_t *ns__hook_table;
 
-/*!
- * Context for initializing a hook module.
- *
- * This structure passes data to which a hook module will need
- * access -- server memory context, hash initializer, log context, etc.
- * The structure doesn't persist beyond configuring the hook module.
- * The module's register function should attach to all reference-counted
- * variables and its destroy function should detach from them.
- */
-typedef struct ns_hookctx {
-       unsigned int            magic;
-       dns_view_t              *view;
-       isc_mem_t               *mctx;
-       isc_log_t               *lctx;
-} ns_hookctx_t;
-
-#define NS_HOOKCTX_MAGIC       ISC_MAGIC('H', 'k', 'c', 'x')
-#define NS_HOOKCTX_VALID(h)    ISC_MAGIC_VALID(h, NS_HOOKCTX_MAGIC)
-
 /*
  * API version
  *
@@ -256,8 +237,8 @@ typedef struct ns_hookctx {
 
 typedef isc_result_t
 ns_hook_register_t(const char *parameters,
-                  const char *file, unsigned long line,
-                  const void *cfg, void *actx, ns_hookctx_t *hctx,
+                  const void *cfg, const char *file, unsigned long line,
+                  isc_mem_t *mctx, isc_log_t *lctx, void *actx,
                   ns_hooktable_t *hooktable, void **instp);
 /*%<
  * Called when registering a new module.
@@ -282,8 +263,9 @@ ns_hook_destroy_t(void **instp);
  */
 
 typedef isc_result_t
-ns_hook_check_t(const char *parameters, const char *file, unsigned long line,
-               const void *cfg, isc_mem_t *mctx, isc_log_t *lctx, void *actx);
+ns_hook_check_t(const char *parameters,
+               const void *cfg, const char *file, unsigned long line,
+               isc_mem_t *mctx, isc_log_t *lctx, void *actx);
 /*%<
  * Check the validity of 'parameters'.
  */
@@ -306,19 +288,11 @@ ns_hook_destroy_t hook_destroy;
 ns_hook_register_t hook_register;
 ns_hook_version_t hook_version;
 
-isc_result_t
-ns_hook_createctx(isc_mem_t *mctx, dns_view_t *view, ns_hookctx_t **hctxp);
-void
-ns_hook_destroyctx(ns_hookctx_t **hctxp);
-/*%<
- * Create/destroy a hook module context.
- */
-
 isc_result_t
 ns_module_load(const char *modpath, const char *parameters,
-              const char *cfg_file, unsigned long cfg_line,
-              const void *cfg, void *actx, ns_hookctx_t *hctx,
-              ns_modlist_t *modlist, ns_hooktable_t *hooktable);
+              const void *cfg, const char *cfg_file, unsigned long cfg_line,
+              isc_mem_t *mctx, isc_log_t *lctx, void *actx,
+              dns_view_t *view);
 /*%<
  * Load the module specified from the file 'modpath', and
  * register an instance using 'parameters'.
@@ -330,17 +304,14 @@ ns_module_load(const char *modpath, const char *parameters,
  * context, respectively; they are passed as void * here in order to
  * prevent this library from having a dependency on libisccfg).
  *
- * 'hctx' is the hook context and 'hooktable' is the hook table
- * into which hook points should be registered.
- *
  * 'instp' will be left pointing to the instance of the module
  * created by the module's hook_register function.
  */
 
 isc_result_t
 ns_module_check(const char *modpath, const char *parameters,
-               const char *cfg_file, unsigned long cfg_line,
-               const void *cfg, isc_mem_t *mctx, isc_log_t *lctx, void *actx);
+               const void *cfg, const char *cfg_file, unsigned long cfg_line,
+               isc_mem_t *mctx, isc_log_t *lctx, void *actx);
 /*%<
  * Open the module at 'modpath' and check the validity of
  * 'parameters', logging any errors or warnings found, then
index c7192933a67e96abeb976f9be92e8850a5bcdc87..d95f7980ba2100f919e449366c06ee1544f50b07 100644 (file)
@@ -44,8 +44,6 @@ ns_clientmgr_create
 ns_clientmgr_createclients
 ns_clientmgr_destroy
 ns_hook_add
-ns_hook_createctx
-ns_hook_destroyctx
 ns_hooktable_create
 ns_hooktable_free
 ns_hooktable_init