#include <dns/fixedname.h>
#include <dns/forward.h>
#include <dns/geoip.h>
+#include <dns/hooks.h>
#include <dns/journal.h>
#include <dns/kasp.h>
#include <dns/keymgr.h>
#include <isccfg/namedconf.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/interfacemgr.h>
#include <ns/listenlist.h>
const char *parameters, void *callback_data) {
char full_path[PATH_MAX];
isc_result_t result;
- ns_hook_data_t *hookdata = callback_data;
+ dns_hook_data_t *hookdata = callback_data;
- result = ns_plugin_expandpath(plugin_path, full_path,
- sizeof(full_path));
+ result = dns_plugin_expandpath(plugin_path, full_path,
+ sizeof(full_path));
if (result != ISC_R_SUCCESS) {
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
ISC_LOG_ERROR,
return result;
}
- result = ns_plugin_register(full_path, parameters, config,
- cfg_obj_file(obj), cfg_obj_line(obj),
- isc_g_mctx, aclctx, hookdata);
+ result = dns_plugin_register(full_path, parameters, config,
+ cfg_obj_file(obj), cfg_obj_line(obj),
+ isc_g_mctx, aclctx, hookdata);
if (result != ISC_R_SUCCESS) {
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
ISC_LOG_ERROR,
}
if (plugin_list != NULL) {
- ns_hook_data_t hookdata = {
- .pluginctx = { .source = NS_HOOKSOURCE_VIEW }
+ dns_hook_data_t hookdata = {
+ .pluginctx = { .source = DNS_HOOKSOURCE_VIEW }
};
INSIST(view->hooktable == NULL);
- ns_hooktable_create(view->mctx, &hookdata.hooktable);
+ dns_hooktable_create(view->mctx, &hookdata.hooktable);
view->hooktable = hookdata.hooktable;
- view->hooktable_free = ns_hooktable_free;
+ view->hooktable_free = dns_hooktable_free;
- ns_plugins_create(view->mctx, &hookdata.plugins);
+ dns_plugins_create(view->mctx, &hookdata.plugins);
view->plugins = hookdata.plugins;
- view->plugins_free = ns_plugins_free;
+ view->plugins_free = dns_plugins_free;
CHECK(cfg_pluginlist_foreach(config, plugin_list, aclctx,
named_register_one_plugin,
#include <dns/acl.h>
#include <dns/db.h>
#include <dns/fixedname.h>
+#include <dns/hooks.h>
#include <dns/ipkeylist.h>
#include <dns/journal.h>
#include <dns/kasp.h>
#include <dns/zone.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <named/config.h>
#include <named/globals.h>
}
if (tpluginlist != NULL || zpluginlist != NULL) {
- ns_hook_data_t hookdata = {
- .pluginctx = { .source = NS_HOOKSOURCE_ZONE,
+ dns_hook_data_t hookdata = {
+ .pluginctx = { .source = DNS_HOOKSOURCE_ZONE,
.origin = dns_zone_getorigin(zone) }
};
isc_mem_t *zmctx = dns_zone_getmctx(zone);
- ns_hooktable_create(zmctx, &hookdata.hooktable);
+ dns_hooktable_create(zmctx, &hookdata.hooktable);
dns_zone_sethooktable(zone, hookdata.hooktable,
- ns_hooktable_free);
+ dns_hooktable_free);
- ns_plugins_create(zmctx, &hookdata.plugins);
- dns_zone_setplugins(zone, hookdata.plugins, ns_plugins_free);
+ dns_plugins_create(zmctx, &hookdata.plugins);
+ dns_zone_setplugins(zone, hookdata.plugins, dns_plugins_free);
result = cfg_pluginlist_foreach(config, tpluginlist, aclctx,
named_register_one_plugin,
#include <dns/acl.h>
#include <dns/db.h>
#include <dns/enumtype.h>
+#include <dns/hooks.h>
#include <dns/message.h>
#include <dns/rdataset.h>
#include <dns/types.h>
#include <isccfg/grammar.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/query.h>
#include <ns/types.h>
} filter_data_t;
typedef struct filter_instance {
- ns_plugin_t *module;
+ dns_plugin_t *module;
isc_mem_t *mctx;
/*
/*
* Forward declarations of functions referenced in install_hooks().
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_initialize(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_begin(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_any_found(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_prep_response_begin(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp);
/*%
* Register the functions to be called at each hook point in 'hooktable', using
* memory context 'mctx' for allocating copies of stack-allocated structures
- * passed to ns_hook_add(). Make sure 'inst' will be passed as the 'cbdata'
+ * passed to dns_hook_add(). Make sure 'inst' will be passed as the 'cbdata'
* argument to every callback.
*/
static void
-install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
+install_hooks(dns_hooktable_t *hooktable, isc_mem_t *mctx,
filter_instance_t *inst) {
- const ns_hook_t filter_init = {
+ const dns_hook_t filter_init = {
.action = filter_initialize,
.action_data = inst,
};
- const ns_hook_t filter_respbegin = {
+ const dns_hook_t filter_respbegin = {
.action = filter_respond_begin,
.action_data = inst,
};
- const ns_hook_t filter_respanyfound = {
+ const dns_hook_t filter_respanyfound = {
.action = filter_respond_any_found,
.action_data = inst,
};
- const ns_hook_t filter_prepresp = {
+ const dns_hook_t filter_prepresp = {
.action = filter_prep_response_begin,
.action_data = inst,
};
- const ns_hook_t filter_donesend = {
+ const dns_hook_t filter_donesend = {
.action = filter_query_done_send,
.action_data = inst,
};
- const ns_hook_t filter_reset = {
+ const dns_hook_t filter_reset = {
.action = filter_freeclientstate,
.action_data = inst,
};
- ns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &filter_init);
- ns_hook_add(hooktable, mctx, NS_QUERY_AUTHZONE_ATTACHED, &filter_init);
- ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_BEGIN, &filter_respbegin);
- ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_ANY_FOUND,
- &filter_respanyfound);
- ns_hook_add(hooktable, mctx, NS_QUERY_PREP_RESPONSE_BEGIN,
- &filter_prepresp);
- ns_hook_add(hooktable, mctx, NS_QUERY_DONE_SEND, &filter_donesend);
- ns_hook_add(hooktable, mctx, NS_QUERY_CLEANUP, &filter_reset);
+ dns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &filter_init);
+ dns_hook_add(hooktable, mctx, NS_QUERY_AUTHZONE_ATTACHED, &filter_init);
+ dns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_BEGIN,
+ &filter_respbegin);
+ dns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_ANY_FOUND,
+ &filter_respanyfound);
+ dns_hook_add(hooktable, mctx, NS_QUERY_PREP_RESPONSE_BEGIN,
+ &filter_prepresp);
+ dns_hook_add(hooktable, mctx, NS_QUERY_DONE_SEND, &filter_donesend);
+ dns_hook_add(hooktable, mctx, NS_QUERY_CLEANUP, &filter_reset);
}
/**
**/
/*
- * Called by ns_plugin_register() to initialize the plugin and
+ * Called by dns_plugin_register() to initialize the plugin and
* register hook functions into the view hook table.
*/
isc_result_t
plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
- ns_hooktable_t *hooktable, const ns_pluginctx_t *ctx,
+ dns_hooktable_t *hooktable, const dns_pluginctx_t *ctx,
void **instp) {
filter_instance_t *inst = NULL;
isc_result_t result = ISC_R_SUCCESS;
isc_result_t
plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
- const ns_pluginctx_t *ctx ISC_ATTR_UNUSED) {
+ const dns_pluginctx_t *ctx ISC_ATTR_UNUSED) {
isc_result_t result = ISC_R_SUCCESS;
cfg_obj_t *param_obj = NULL;
isc_buffer_t b;
}
/*
- * Called by ns_plugins_free(); frees memory allocated by
+ * Called by dns_plugins_free(); frees memory allocated by
* the module when it was registered.
*/
void
*/
int
plugin_version(void) {
- return NS_PLUGIN_VERSION;
+ return DNS_PLUGIN_VERSION;
}
/**
* the state will be initialized on the first call, and the function bails off
* early on the second call (the state is already initialized).
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_initialize(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
client_state_create(qctx, inst);
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* the client address family and the settings of filter-a-on-v6 and
* filter-a-on-v4.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_prep_response_begin(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
*resp = ISC_R_UNSET;
if (client_state == NULL) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (inst->v4_a != NONE || inst->v6_a != NONE) {
}
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* (This version is for processing answers to explicit A queries; ANY
* queries are handled in filter_respond_any_found().)
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_begin(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
*resp = ISC_R_UNSET;
if (client_state == NULL) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (client_state->mode != BREAK_DNSSEC &&
(WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL &&
dns_rdataset_isassociated(qctx->sigrdataset))))
{
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (qctx->qtype == dns_rdatatype_a) {
*resp = result;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
*resp = result;
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* When answering an ANY query, remove A if AAAA is present.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_any_found(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
process_section(&filter_answer);
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* hide NS in the authority section if A was filtered in the answer
* section.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
}
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* If the client is being detached, then we can delete our persistent data
* from hash table and return it to the memory pool.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
*resp = ISC_R_UNSET;
client_state_destroy(qctx, inst);
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
#include <dns/acl.h>
#include <dns/db.h>
#include <dns/enumtype.h>
+#include <dns/hooks.h>
#include <dns/message.h>
#include <dns/rdataset.h>
#include <dns/types.h>
#include <isccfg/grammar.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/query.h>
#include <ns/types.h>
} filter_data_t;
typedef struct filter_instance {
- ns_plugin_t *module;
+ dns_plugin_t *module;
isc_mem_t *mctx;
/*
/*
* Forward declarations of functions referenced in install_hooks().
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_initialize(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_begin(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_any_found(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_prep_response_begin(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp);
/*%
* Register the functions to be called at each hook point in 'hooktable', using
* memory context 'mctx' for allocating copies of stack-allocated structures
- * passed to ns_hook_add(). Make sure 'inst' will be passed as the 'cbdata'
+ * passed to dns_hook_add(). Make sure 'inst' will be passed as the 'cbdata'
* argument to every callback.
*/
static void
-install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
+install_hooks(dns_hooktable_t *hooktable, isc_mem_t *mctx,
filter_instance_t *inst) {
- const ns_hook_t filter_init = {
+ const dns_hook_t filter_init = {
.action = filter_initialize,
.action_data = inst,
};
- const ns_hook_t filter_respbegin = {
+ const dns_hook_t filter_respbegin = {
.action = filter_respond_begin,
.action_data = inst,
};
- const ns_hook_t filter_respanyfound = {
+ const dns_hook_t filter_respanyfound = {
.action = filter_respond_any_found,
.action_data = inst,
};
- const ns_hook_t filter_prepresp = {
+ const dns_hook_t filter_prepresp = {
.action = filter_prep_response_begin,
.action_data = inst,
};
- const ns_hook_t filter_donesend = {
+ const dns_hook_t filter_donesend = {
.action = filter_query_done_send,
.action_data = inst,
};
- const ns_hook_t filter_reset = {
+ const dns_hook_t filter_reset = {
.action = filter_freeclientstate,
.action_data = inst,
};
- ns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &filter_init);
- ns_hook_add(hooktable, mctx, NS_QUERY_AUTHZONE_ATTACHED, &filter_init);
- ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_BEGIN, &filter_respbegin);
- ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_ANY_FOUND,
- &filter_respanyfound);
- ns_hook_add(hooktable, mctx, NS_QUERY_PREP_RESPONSE_BEGIN,
- &filter_prepresp);
- ns_hook_add(hooktable, mctx, NS_QUERY_DONE_SEND, &filter_donesend);
- ns_hook_add(hooktable, mctx, NS_QUERY_CLEANUP, &filter_reset);
+ dns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &filter_init);
+ dns_hook_add(hooktable, mctx, NS_QUERY_AUTHZONE_ATTACHED, &filter_init);
+ dns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_BEGIN,
+ &filter_respbegin);
+ dns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_ANY_FOUND,
+ &filter_respanyfound);
+ dns_hook_add(hooktable, mctx, NS_QUERY_PREP_RESPONSE_BEGIN,
+ &filter_prepresp);
+ dns_hook_add(hooktable, mctx, NS_QUERY_DONE_SEND, &filter_donesend);
+ dns_hook_add(hooktable, mctx, NS_QUERY_CLEANUP, &filter_reset);
}
/**
**/
/*
- * Called by ns_plugin_register() to initialize the plugin and
+ * Called by dns_plugin_register() to initialize the plugin and
* register hook functions into the view hook table.
*/
isc_result_t
plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
- ns_hooktable_t *hooktable, const ns_pluginctx_t *ctx,
+ dns_hooktable_t *hooktable, const dns_pluginctx_t *ctx,
void **instp) {
filter_instance_t *inst = NULL;
isc_result_t result = ISC_R_SUCCESS;
isc_result_t
plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
- const ns_pluginctx_t *ctx ISC_ATTR_UNUSED) {
+ const dns_pluginctx_t *ctx ISC_ATTR_UNUSED) {
isc_result_t result = ISC_R_SUCCESS;
cfg_obj_t *param_obj = NULL;
isc_buffer_t b;
}
/*
- * Called by ns_plugins_free(); frees memory allocated by
+ * Called by dns_plugins_free(); frees memory allocated by
* the module when it was registered.
*/
void
*/
int
plugin_version(void) {
- return NS_PLUGIN_VERSION;
+ return DNS_PLUGIN_VERSION;
}
/**
* the state will be initialized on the first call, and the function bails off
* early on the second call (the state is already initialized).
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_initialize(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
client_state_create(qctx, inst);
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* the client address family and the settings of filter-aaaa-on-v4 and
* filter-aaaa-on-v6.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_prep_response_begin(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
*resp = ISC_R_UNSET;
if (client_state == NULL) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (inst->v4_aaaa != NONE || inst->v6_aaaa != NONE) {
}
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* (This version is for processing answers to explicit AAAA queries; ANY
* queries are handled in filter_respond_any_found().)
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_begin(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
*resp = ISC_R_UNSET;
if (client_state == NULL) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (client_state->mode != BREAK_DNSSEC &&
(WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL &&
dns_rdataset_isassociated(qctx->sigrdataset))))
{
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (qctx->qtype == dns_rdatatype_aaaa) {
*resp = result;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
*resp = result;
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* When answering an ANY query, remove AAAA if A is present.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_respond_any_found(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
process_section(&filter_answer);
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* hide NS in the authority section if AAAA was filtered in the answer
* section.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
}
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/*
* If the client is being detached, then we can delete our persistent data
* from hash table and return it to the memory pool.
*/
-static ns_hookresult_t
+static dns_hookresult_t
filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
filter_instance_t *inst = (filter_instance_t *)cbdata;
*resp = ISC_R_UNSET;
client_state_destroy(qctx, inst);
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
*/
#include <dns/byaddr.h>
+#include <dns/hooks.h>
#include <dns/rdatalist.h>
#include <dns/view.h>
#include <isccfg/cfg.h>
#include <isccfg/grammar.h>
-#include <ns/hooks.h>
+#include <ns/client.h>
+#include <ns/query.h>
#define CHECK(op) \
do { \
return false;
}
-static ns_hookresult_t
+static dns_hookresult_t
synthrecord_forward(synthrecord_t *inst, query_ctx_t *qctx,
isc_result_t *resp) {
isc_netaddr_t addr;
*resp = ISC_R_UNSET;
if (!synthrecord_parseforward(inst, qname, &addr)) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (!synthrecord_allowedsynth(inst, &addr)) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (qctx->qtype != dns_rdatatype_a &&
*/
qctx->client->message->rcode = dns_rcode_noerror;
*resp = ns_query_done(qctx);
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
if ((qctx->qtype == dns_rdatatype_a ||
*resp = ns_query_done(qctx);
}
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
-static ns_hookresult_t
+static dns_hookresult_t
synthrecord_reverse(synthrecord_t *inst, query_ctx_t *qctx,
isc_result_t *resp) {
isc_result_t result;
ISC_LOG_DEBUG(10),
"synthrecord ptr parsing error %s",
isc_result_totext(result));
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (!synthrecord_allowedsynth(inst, &qaddr)) {
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
if (qctx->qtype != dns_rdatatype_ptr &&
*/
qctx->client->message->rcode = dns_rcode_noerror;
*resp = ns_query_done(qctx);
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
isc_buffer_init(&anameb, anamebdata, sizeof(anamebdata));
ISC_LOG_DEBUG(1),
"synthrecord cannot create reverse answer name: %s",
isc_result_totext(result));
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
synthptrdata = (dns_rdata_ptr_t){
dns_rdatatype_ptr);
*resp = result;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
-static ns_hookresult_t
+static dns_hookresult_t
synthrecord_entry(void *arg, void *cbdata, isc_result_t *resp) {
synthrecord_t *inst = cbdata;
query_ctx_t *qctx = arg;
isc_result_t
plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
unsigned long cfgline, isc_mem_t *mctx, void *aclctx,
- ns_hooktable_t *hooktable, const ns_pluginctx_t *ctx,
+ dns_hooktable_t *hooktable, const dns_pluginctx_t *ctx,
void **instp) {
synthrecord_t *inst = NULL;
- ns_hook_t hook;
+ dns_hook_t hook;
isc_result_t result;
REQUIRE(cfg);
result = synthrecord_parseconfig(inst, parameters, cfg, cfgfile,
cfgline, aclctx, ctx->origin);
- hook = (ns_hook_t){ .action = synthrecord_entry, .action_data = inst };
- ns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &hook);
+ hook = (dns_hook_t){ .action = synthrecord_entry, .action_data = inst };
+ dns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &hook);
/*
* The qname with a different type might be defined in the zone. If
* there is a delegation, NS_QUERY_NODATA_BEGIN is never called.
*/
- ns_hook_add(hooktable, mctx, NS_QUERY_NODATA_BEGIN, &hook);
+ dns_hook_add(hooktable, mctx, NS_QUERY_NODATA_BEGIN, &hook);
return result;
}
isc_result_t
plugin_check(const char *parameters, const void *cfg, const char *cfgfile,
unsigned long cfgline, isc_mem_t *mctx, void *aclctx,
- const ns_pluginctx_t *ctx) {
+ const dns_pluginctx_t *ctx) {
isc_result_t result;
synthrecord_t *inst = NULL;
REQUIRE(ctx != NULL);
- if (ctx->source != NS_HOOKSOURCE_ZONE || ctx->origin == NULL) {
+ if (ctx->source != DNS_HOOKSOURCE_ZONE || ctx->origin == NULL) {
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
ISC_LOG_INFO,
"'synthrecord' must be configured "
int
plugin_version(void) {
- return NS_PLUGIN_VERSION;
+ return DNS_PLUGIN_VERSION;
}
#include <isc/types.h>
#include <isc/util.h>
+#include <dns/hooks.h>
+
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/query.h>
#include <ns/types.h>
* accessible until the client object is detached.
*/
typedef struct async_instance {
- ns_plugin_t *module;
+ dns_plugin_t *module;
isc_mem_t *mctx;
isc_ht_t *ht;
isc_mutex_t hlock;
typedef struct state {
bool async;
- ns_hook_resume_t *rev;
- ns_hookpoint_t hookpoint;
+ dns_hook_resume_t *rev;
+ dns_hookpoint_t hookpoint;
isc_result_t origresult;
} state_t;
/*
* Forward declarations of functions referenced in install_hooks().
*/
-static ns_hookresult_t
+static dns_hookresult_t
async_query_setup(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
async_query_done_begin(void *arg, void *cbdata, isc_result_t *resp);
-static ns_hookresult_t
+static dns_hookresult_t
async_query_reset(void *arg, void *cbdata, isc_result_t *resp);
/*%
* Register the functions to be called at each hook point in 'hooktable', using
* memory context 'mctx' for allocating copies of stack-allocated structures
- * passed to ns_hook_add(). Make sure 'inst' will be passed as the 'cbdata'
+ * passed to dns_hook_add(). Make sure 'inst' will be passed as the 'cbdata'
* argument to every callback.
*/
static void
-install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
+install_hooks(dns_hooktable_t *hooktable, isc_mem_t *mctx,
async_instance_t *inst) {
- const ns_hook_t async_setup = {
+ const dns_hook_t async_setup = {
.action = async_query_setup,
.action_data = inst,
};
- const ns_hook_t async_donebegin = {
+ const dns_hook_t async_donebegin = {
.action = async_query_done_begin,
.action_data = inst,
};
- const ns_hook_t async_reset = {
+ const dns_hook_t async_reset = {
.action = async_query_reset,
.action_data = inst,
};
- ns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &async_setup);
- ns_hook_add(hooktable, mctx, NS_QUERY_DONE_BEGIN, &async_donebegin);
- ns_hook_add(hooktable, mctx, NS_QUERY_CLEANUP, &async_reset);
+ dns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &async_setup);
+ dns_hook_add(hooktable, mctx, NS_QUERY_DONE_BEGIN, &async_donebegin);
+ dns_hook_add(hooktable, mctx, NS_QUERY_CLEANUP, &async_reset);
}
static void
**/
/*
- * Called by ns_plugin_register() to initialize the plugin and
+ * Called by dns_plugin_register() to initialize the plugin and
* register hook functions into the view hook table.
*/
isc_result_t
plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
- ns_hooktable_t *hooktable, const ns_pluginctx_t *ctx,
+ dns_hooktable_t *hooktable, const dns_pluginctx_t *ctx,
void **instp) {
async_instance_t *inst = NULL;
isc_result_t
plugin_check(const char *parameters, const void *cfg, const char *cfg_file,
unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
- const ns_pluginctx_t *ctx) {
+ const dns_pluginctx_t *ctx) {
UNUSED(parameters);
UNUSED(cfg);
UNUSED(cfg_file);
}
/*
- * Called by ns_plugins_free(); frees memory allocated by
+ * Called by dns_plugins_free(); frees memory allocated by
* the module when it was registered.
*/
void
*/
int
plugin_version(void) {
- return NS_PLUGIN_VERSION;
+ return DNS_PLUGIN_VERSION;
}
static state_t *
isc_mem_put(inst->mctx, state, sizeof(*state));
}
-static ns_hookresult_t
+static dns_hookresult_t
async_query_setup(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
async_instance_t *inst = (async_instance_t *)cbdata;
client_state_create(qctx, inst);
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
static void
-cancelasync(ns_hookasync_t *hctx) {
+cancelasync(dns_hookasync_t *hctx) {
UNUSED(hctx);
logmsg("cancelasync");
}
static void
-destroyasync(ns_hookasync_t **ctxp) {
- ns_hookasync_t *ctx = *ctxp;
+destroyasync(dns_hookasync_t **ctxp) {
+ dns_hookasync_t *ctx = *ctxp;
logmsg("destroyasync");
*ctxp = NULL;
static isc_result_t
doasync(query_ctx_t *qctx, isc_mem_t *mctx, void *arg, isc_loop_t *loop,
- isc_job_cb cb, void *evarg, ns_hookasync_t **ctxp) {
- ns_hook_resume_t *rev = isc_mem_get(mctx, sizeof(*rev));
- ns_hookasync_t *ctx = isc_mem_get(mctx, sizeof(*ctx));
+ isc_job_cb cb, void *evarg, dns_hookasync_t **ctxp) {
+ dns_hook_resume_t *rev = isc_mem_get(mctx, sizeof(*rev));
+ dns_hookasync_t *ctx = isc_mem_get(mctx, sizeof(*ctx));
state_t *state = (state_t *)arg;
logmsg("doasync");
- *ctx = (ns_hookasync_t){
+ *ctx = (dns_hookasync_t){
.cancel = cancelasync,
.destroy = destroyasync,
};
isc_mem_attach(mctx, &ctx->mctx);
qctx->result = DNS_R_NOTIMP;
- *rev = (ns_hook_resume_t){
+ *rev = (dns_hook_resume_t){
.hookpoint = state->hookpoint,
.origresult = qctx->result,
- .saved_qctx = qctx,
+ .context = qctx,
.ctx = ctx,
.arg = evarg,
};
return ISC_R_SUCCESS;
}
-static ns_hookresult_t
+static dns_hookresult_t
async_query_done_begin(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
async_instance_t *inst = (async_instance_t *)cbdata;
if (state->async) {
/* resuming */
state->async = false;
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
/* initial call */
state->hookpoint = NS_QUERY_DONE_BEGIN;
state->origresult = *resp;
ns_query_hookasync(qctx, doasync, state);
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
-static ns_hookresult_t
+static dns_hookresult_t
async_query_reset(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
async_instance_t *inst = (async_instance_t *)cbdata;
*resp = ISC_R_UNSET;
client_state_destroy(qctx, inst);
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
* information regarding copyright ownership.
*/
+#include <dns/hooks.h>
+
#include <isccfg/aclconf.h>
#include <isccfg/cfg.h>
#include <isccfg/grammar.h>
-#include <ns/hooks.h>
+#include <ns/client.h>
+#include <ns/query.h>
typedef struct {
isc_mem_t *mctx;
} \
} while (0)
-static ns_hookresult_t
+static dns_hookresult_t
syncplugin__hook(void *arg, void *cbdata, isc_result_t *resp) {
query_ctx_t *qctx = (query_ctx_t *)arg;
syncplugin_t *inst = cbdata;
if (strncmp(inst->firstlbl, (char *)label.base + 1,
strlen(inst->firstlbl)) == 0)
{
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
}
qctx->client->message->rcode = inst->rcode;
*resp = ns_query_done(qctx);
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
static cfg_clausedef_t syncplugin__cfgclauses[] = {
isc_result_t
plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
unsigned long cfgline, isc_mem_t *mctx, void *aclctx,
- ns_hooktable_t *hooktable, const ns_pluginctx_t *ctx,
+ dns_hooktable_t *hooktable, const dns_pluginctx_t *ctx,
void **instp) {
isc_result_t result;
cfg_obj_t *syncplugincfg = NULL;
const cfg_obj_t *obj = NULL;
isc_buffer_t b;
- ns_hook_t hook;
+ dns_hook_t hook;
syncplugin_t *inst = NULL;
char *sourcestr = NULL;
dns_name_t example2com = DNS_NAME_INITEMPTY;
sourcestr = obj->value.string.base;
if (strcmp(sourcestr, "zone") == 0) {
- if (ctx->source != NS_HOOKSOURCE_ZONE) {
+ if (ctx->source != DNS_HOOKSOURCE_ZONE) {
result = ISC_R_FAILURE;
goto cleanup;
}
}
} else if (strcmp(sourcestr, "view") == 0) {
- if (ctx->source != NS_HOOKSOURCE_VIEW) {
+ if (ctx->source != DNS_HOOKSOURCE_VIEW) {
result = ISC_R_FAILURE;
goto cleanup;
}
goto cleanup;
}
- hook = (ns_hook_t){ .action = syncplugin__hook, .action_data = inst };
- ns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &hook);
+ hook = (dns_hook_t){ .action = syncplugin__hook, .action_data = inst };
+ dns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &hook);
cleanup:
if (dns_name_dynamic(&example2com)) {
isc_result_t
plugin_check(const char *parameters, const void *cfg, const char *cfgfile,
unsigned long cfgline, isc_mem_t *mctx, void *aclctx,
- const ns_pluginctx_t *ctx) {
+ const dns_pluginctx_t *ctx) {
UNUSED(parameters);
UNUSED(cfg);
UNUSED(cfgfile);
int
plugin_version(void) {
- return NS_PLUGIN_VERSION;
+ return DNS_PLUGIN_VERSION;
}
#include <isc/util.h>
#include <isc/uv.h>
-#include <dns/view.h>
-
-#include <ns/hooks.h>
-#include <ns/query.h>
+#include <dns/hooks.h>
#define CHECK(op) \
do { \
} \
} while (0)
-struct ns_plugin {
+struct dns_plugin {
isc_mem_t *mctx;
uv_lib_t handle;
void *inst;
char *modpath;
- ns_plugin_check_t *check_func;
- ns_plugin_register_t *register_func;
- ns_plugin_destroy_t *destroy_func;
- ISC_LINK(ns_plugin_t) link;
+ dns_plugin_check_t *check_func;
+ dns_plugin_register_t *register_func;
+ dns_plugin_destroy_t *destroy_func;
+ ISC_LINK(dns_plugin_t) link;
};
-static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT];
-ns_hooktable_t *ns__hook_table = &default_hooktable;
+static dns_hooklist_t default_hooktable[DNS_HOOKPOINTS_COUNT];
+dns_hooktable_t *dns__hook_table = &default_hooktable;
static isc_result_t
plugin_expandpath(const char *src, char *dst, size_t dstsize, bool appendext) {
}
isc_result_t
-ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) {
+dns_plugin_expandpath(const char *src, char *dst, size_t dstsize) {
isc_result_t result;
result = plugin_expandpath(src, dst, dstsize, false);
}
static void
-unload_plugin(ns_plugin_t **pluginp);
+unload_plugin(dns_plugin_t **pluginp);
static isc_result_t
-load_plugin(isc_mem_t *mctx, const char *modpath, ns_plugin_t **pluginp) {
+load_plugin(isc_mem_t *mctx, const char *modpath, dns_plugin_t **pluginp) {
isc_result_t result;
- ns_plugin_t *plugin = NULL;
- ns_plugin_version_t *version_func = NULL;
+ dns_plugin_t *plugin = NULL;
+ dns_plugin_version_t *version_func = NULL;
int version;
int r;
REQUIRE(pluginp != NULL && *pluginp == NULL);
plugin = isc_mem_get(mctx, sizeof(*plugin));
- *plugin = (ns_plugin_t){
+ *plugin = (dns_plugin_t){
.modpath = isc_mem_strdup(mctx, modpath),
};
(void **)&version_func));
version = version_func();
- if (version < (NS_PLUGIN_VERSION - NS_PLUGIN_AGE) ||
- version > NS_PLUGIN_VERSION)
+ if (version < (DNS_PLUGIN_VERSION - DNS_PLUGIN_AGE) ||
+ version > DNS_PLUGIN_VERSION)
{
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS,
ISC_LOG_ERROR,
"plugin API version mismatch: %d/%d", version,
- NS_PLUGIN_VERSION);
+ DNS_PLUGIN_VERSION);
CHECK(ISC_R_FAILURE);
}
}
static void
-unload_plugin(ns_plugin_t **pluginp) {
- ns_plugin_t *plugin = NULL;
+unload_plugin(dns_plugin_t **pluginp) {
+ dns_plugin_t *plugin = NULL;
REQUIRE(pluginp != NULL && *pluginp != NULL);
}
isc_result_t
-ns_plugin_register(const char *modpath, const char *parameters, const void *cfg,
- const char *cfg_file, unsigned long cfg_line,
- isc_mem_t *mctx, void *aclctx, ns_hook_data_t *hookdata) {
+dns_plugin_register(const char *modpath, const char *parameters,
+ const void *cfg, const char *cfg_file,
+ unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
+ dns_hook_data_t *hookdata) {
isc_result_t result;
- ns_plugin_t *plugin = NULL;
+ dns_plugin_t *plugin = NULL;
REQUIRE(mctx != NULL);
REQUIRE(hookdata != NULL);
isc_log_write(NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_HOOKS, ISC_LOG_INFO,
"registering plugin '%s'", modpath);
- INSIST(hookdata->pluginctx.source != NS_HOOKSOURCE_UNDEFINED);
+ INSIST(hookdata->pluginctx.source != DNS_HOOKSOURCE_UNDEFINED);
CHECK(plugin->check_func(parameters, cfg, cfg_file, cfg_line, mctx,
aclctx, &hookdata->pluginctx));
}
isc_result_t
-ns_plugin_check(const char *modpath, const char *parameters, const void *cfg,
- const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx,
- void *aclctx, const ns_pluginctx_t *ctx) {
+dns_plugin_check(const char *modpath, const char *parameters, const void *cfg,
+ const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx,
+ void *aclctx, const dns_pluginctx_t *ctx) {
isc_result_t result;
- ns_plugin_t *plugin = NULL;
+ dns_plugin_t *plugin = NULL;
CHECK(load_plugin(mctx, modpath, &plugin));
}
void
-ns_hooktable_init(ns_hooktable_t *hooktable) {
+dns_hooktable_init(dns_hooktable_t *hooktable) {
int i;
- for (i = 0; i < NS_HOOKPOINTS_COUNT; i++) {
+ for (i = 0; i < DNS_HOOKPOINTS_COUNT; i++) {
ISC_LIST_INIT((*hooktable)[i]);
}
}
void
-ns_hooktable_create(isc_mem_t *mctx, ns_hooktable_t **tablep) {
- ns_hooktable_t *hooktable = NULL;
+dns_hooktable_create(isc_mem_t *mctx, dns_hooktable_t **tablep) {
+ dns_hooktable_t *hooktable = NULL;
REQUIRE(tablep != NULL && *tablep == NULL);
hooktable = isc_mem_get(mctx, sizeof(*hooktable));
- ns_hooktable_init(hooktable);
+ dns_hooktable_init(hooktable);
*tablep = hooktable;
}
void
-ns_hooktable_free(isc_mem_t *mctx, void **tablep) {
- ns_hooktable_t *table = NULL;
+dns_hooktable_free(isc_mem_t *mctx, void **tablep) {
+ dns_hooktable_t *table = NULL;
int i = 0;
REQUIRE(tablep != NULL && *tablep != NULL);
table = *tablep;
*tablep = NULL;
- for (i = 0; i < NS_HOOKPOINTS_COUNT; i++) {
+ for (i = 0; i < DNS_HOOKPOINTS_COUNT; i++) {
ISC_LIST_FOREACH((*table)[i], hook, link) {
ISC_LIST_UNLINK((*table)[i], hook, link);
if (hook->mctx != NULL) {
}
void
-ns_hook_add(ns_hooktable_t *hooktable, isc_mem_t *mctx,
- ns_hookpoint_t hookpoint, const ns_hook_t *hook) {
- ns_hook_t *copy = NULL;
+dns_hook_add(dns_hooktable_t *hooktable, isc_mem_t *mctx,
+ dns_hookpoint_t hookpoint, const dns_hook_t *hook) {
+ dns_hook_t *copy = NULL;
REQUIRE(hooktable != NULL);
REQUIRE(mctx != NULL);
- REQUIRE(hookpoint < NS_HOOKPOINTS_COUNT);
+ REQUIRE(hookpoint < DNS_HOOKPOINTS_COUNT);
REQUIRE(hook != NULL);
copy = isc_mem_get(mctx, sizeof(*copy));
- *copy = (ns_hook_t){
+ *copy = (dns_hook_t){
.action = hook->action,
.action_data = hook->action_data,
};
}
void
-ns_plugins_create(isc_mem_t *mctx, ns_plugins_t **listp) {
- ns_plugins_t *plugins = NULL;
+dns_plugins_create(isc_mem_t *mctx, dns_plugins_t **listp) {
+ dns_plugins_t *plugins = NULL;
REQUIRE(listp != NULL && *listp == NULL);
plugins = isc_mem_get(mctx, sizeof(*plugins));
- *plugins = (ns_plugins_t){ 0 };
+ *plugins = (dns_plugins_t){ 0 };
ISC_LIST_INIT(*plugins);
*listp = plugins;
}
void
-ns_plugins_free(isc_mem_t *mctx, void **listp) {
- ns_plugins_t *list = NULL;
+dns_plugins_free(isc_mem_t *mctx, void **listp) {
+ dns_plugins_t *list = NULL;
REQUIRE(listp != NULL && *listp != NULL);
#include <stdbool.h>
#include <isc/list.h>
+#include <isc/loop.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/result.h>
-#include <dns/rdatatype.h>
+#include <dns/types.h>
-#include <ns/client.h>
-#include <ns/query.h>
/*
* "Hooks" are a mechanism to call a defined function or set of functions once
* a certain place in code is reached. Hook actions can inspect and alter the
* where they are used to inspect state before and after certain functions have
* run.
*
- * Both of these uses are limited to libns, so hooks are currently defined in
- * the ns/hooks.h header file, and hook-related macro and function names are
- * prefixed with `NS_` and `ns_`. However, the design is fairly generic and
- * could be repurposed for general use, e.g. as part of libisc, after some
- * further customization.
+ * While these uses are limited to libns, there are future plans to add
+ * hooks in dns_resolver, so hooks are defined in the dns/hooks.h header
+ * file, and hook-related macro and function names that aren't specifically
+ * related to ns/query.c are prefixed with `DNS_` and `dns_`.
*
- * Hooks are created by defining a hook point identifier in the ns_hookpoint_t
+ * Hooks are created by defining a hook point identifier in the dns_hookpoint_t
* enum below, and placing a special call at a corresponding location in the
* code which invokes the action(s) for that hook; there are two such special
* calls currently implemented, namely the CALL_HOOK() and CALL_HOOK_NORETURN()
* 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
+ * hook table (dns__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:
*
- * - return an ns_hookresult_t value:
- * - if NS_HOOK_RETURN is returned by the hook action, the function
+ * - return a dns_hookresult_t value:
+ * - if DDNS_HOOK_RETURN is returned by the hook action, the function
* into which the hook is inserted will return and no further hook
* actions at the same hook point will be invoked,
- * - if NS_HOOK_CONTINUE is returned by the hook action and there are
+ * - if DDNS_HOOK_CONTINUE is returned by the hook action and there are
* further hook actions set up at the same hook point, they will be
- * processed; if NS_HOOK_CONTINUE is returned and there are no
+ * processed; if DDNS_HOOK_CONTINUE is returned and there are no
* further hook actions set up at the same hook point, execution of
* the function into which the hook has been inserted will be
* resumed.
* - a pointer specified upon inserting the action into the hook table,
* - a pointer to an isc_result_t value which will be returned by the
* function into which the hook is inserted if the action returns
- * NS_HOOK_RETURN.
+ * DDNS_HOOK_RETURN.
*
* In order for a hook action to be called for a given hook, a pointer to that
* action function (along with an optional pointer to action-specific data) has
* to be inserted into the relevant hook table entry for that hook using an
- * ns_hook_add() call. If multiple actions are set up at a single hook point
+ * dns_hook_add() call. If multiple actions are set up at a single hook point
* (e.g. by multiple plugin modules), they are processed in FIFO order, that is
- * they are performed in the same order in which their relevant ns_hook_add()
+ * they are performed in the same order in which their relevant dns_hook_add()
* calls were issued. Since the configuration is loaded from a single thread,
* this means that multiple actions at a single hook point are determined by
* the order in which the relevant plugin modules were declared in the
*
* CALL_HOOK(NS_QUERY_FOO_BEGIN, qctx);
*
- * ns_client_log(qctx->client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_QUERY,
+ * dns_client_log(qctx->client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_QUERY,
* ISC_LOG_DEBUG(99), "Lorem ipsum dolor sit amet...");
*
* result = ISC_R_COMPLETE;
* and the following hook action:
*
* ----------------------------------------------------------------------------
- * static ns_hookresult_t
+ * static dns_hookresult_t
* cause_failure(void *hook_data, void *action_data, isc_result_t *resultp) {
* UNUSED(hook_data);
* UNUSED(action_data);
*
* *resultp = ISC_R_FAILURE;
*
- * return (NS_HOOK_RETURN);
+ * return (DDNS_HOOK_RETURN);
* }
* ----------------------------------------------------------------------------
*
* If this hook action was installed in the hook table using:
*
* ----------------------------------------------------------------------------
- * const ns_hook_t foo_fail = {
+ * const dns_hook_t foo_fail = {
* .action = cause_failure,
* };
*
- * ns_hook_add(..., NS_QUERY_FOO_BEGIN, &foo_fail);
+ * dns_hook_add(..., NS_QUERY_FOO_BEGIN, &foo_fail);
* ----------------------------------------------------------------------------
*
* then query_foo() would return ISC_R_FAILURE every time it is called due
- * to the cause_failure() hook action returning NS_HOOK_RETURN and setting
+ * to the cause_failure() hook action returning DDNS_HOOK_RETURN and setting
* '*resultp' to ISC_R_FAILURE. query_foo() would also never log the
* "Lorem ipsum dolor sit amet..." message.
*
* Consider a different hook action:
*
* ----------------------------------------------------------------------------
- * static ns_hookresult_t
+ * static dns_hookresult_t
* log_qtype(void *hook_data, void *action_data, isc_result_t *resultp) {
* query_ctx_t *qctx = (query_ctx_t *)hook_data;
* FILE *stream = (FILE *)action_data;
*
* fprintf(stream, "QTYPE=%u\n", qctx->qtype);
*
- * return (NS_HOOK_CONTINUE);
+ * return (DDNS_HOOK_CONTINUE);
* }
* ----------------------------------------------------------------------------
*
* cause_failure(), using:
*
* ----------------------------------------------------------------------------
- * const ns_hook_t foo_log_qtype = {
+ * const dns_hook_t foo_log_qtype = {
* .action = log_qtype,
* .action_data = stderr,
* };
*
- * ns_hook_add(..., NS_QUERY_FOO_BEGIN, &foo_log_qtype);
+ * dns_hook_add(..., NS_QUERY_FOO_BEGIN, &foo_log_qtype);
* ----------------------------------------------------------------------------
*
* then the QTYPE stored in the query context passed to query_foo() would be
* logged to stderr upon each call to that function; 'qctx' would be passed to
* the hook action in 'hook_data' since it is specified in the CALL_HOOK() call
* inside query_foo() while stderr would be passed to the hook action in
- * 'action_data' since it is specified in the ns_hook_t structure passed to
- * ns_hook_add(). As the hook action returns NS_HOOK_CONTINUE,
+ * 'action_data' since it is specified in the dns_hook_t structure passed to
+ * dns_hook_add(). As the hook action returns DDNS_HOOK_CONTINUE,
* query_foo() would also be logging the "Lorem ipsum dolor sit amet..."
* message before returning ISC_R_COMPLETE.
*
* etc, it may take several seconds or more.
*
* In order to handle such a situation, a hook action can start an
- * asynchronous event by calling ns_query_hookasync(). This is similar
- * to ns_query_recurse(), but more generic. ns_query_hookasync() will
+ * asynchronous event by calling dns_query_hookasync(). This is similar
+ * to dns_query_recurse(), but more generic. dns_query_hookasync() will
* call the 'runasync' function with a specified 'arg' (both passed to
- * ns_query_hookasync()) and a set of loop and associated event arguments
+ * dns_query_hookasync()) and a set of loop and associated event arguments
* to be called to resume query handling upon completion of the
* asynchronous event.
*
* The implementation of 'runasync' is assumed to allocate and build an
- * instance of ns_hook_resume_t whose callback, arg, and loop are set to
- * the passed values from ns_query_hookasync(). Other fields of
- * ns_hook_resume_t must be correctly set in the hook implementation
+ * instance of dns_hook_resume_t whose callback, arg, and loop are set to
+ * the passed values from dns_query_hookasync(). Other fields of
+ * dns_hook_resume_t must be correctly set in the hook implementation
* by the time it's sent to the specified loop:
*
* - hookpoint: the point from which the query handling should be resumed
* The hook implementation should somehow maintain the created event
* instance so that it can eventually send the event.
*
- * 'runasync' then creates an instance of ns_hookasync_t with specifying its
- * own cancel and destroy function, and returns it to ns_query_hookasync()
+ * 'runasync' then creates an instance of dns_hookasync_t with specifying its
+ * own cancel and destroy function, and returns it to dns_query_hookasync()
* in the passed pointer.
*
- * On return from ns_query_hookasync(), the hook action MUST return
- * NS_HOOK_RETURN to suspend the query handling.
+ * On return from dns_query_hookasync(), the hook action MUST return
+ * DDNS_HOOK_RETURN to suspend the query handling.
*
* On the completion of the asynchronous event, the hook implementation is
* supposed to send the resumeevent to the corresponding loop. The query
*
* typedef struct hookstate {
* bool async;
- * ns_hook_resume_t *rev
- * ns_hookpoint_t hookpoint;
+ * dns_hook_resume_t *rev
+ * dns_hookpoint_t hookpoint;
* isc_result_t origresult;
* } hookstate_t;
*
* // complete the hook's action using the result of the
* // internal asynchronous event.
* state->async = false;
- * return (NS_HOOK_CONTINUE);
+ * return (DDNS_HOOK_CONTINUE);
* }
*
* // Initial call to the hook action. Start the internal
* // asynchronous event, and have the query module suspend
- * // its own handling by returning NS_HOOK_RETURN.
+ * // its own handling by returning DDNS_HOOK_RETURN.
* state->hookpoint = ...; // would be hook point for this hook
* state->origresult = *resultp;
- * ns_query_hookasync(hook_data, runasync, state);
+ * dns_query_hookasync(hook_data, runasync, state);
* state->async = true;
- * return (NS_HOOK_RETURN);
+ * return (DDNS_HOOK_RETURN);
* }
*
* And the 'runasync' function would be something like this:
*
* static isc_result_t
* runasync(query_ctx_t *qctx, void *arg, isc_job_cb cb, void *evarg,
- * isc_loop_t *loop, ns_hookasync_t **ctxp) {
+ * isc_loop_t *loop, dns_hookasync_t **ctxp) {
* hookstate_t *state = arg;
- * ns_hook_resume_t *rev isc_mem_get(mctx, sizeof(*rev));
- * ns_hookasync_t *ctx = isc_mem_get(mctx, sizeof(*ctx));
- *
- * *ctx = (ns_hookasync_t){ .private = NULL
- * .hookpoint = state->hookpoint,
- * .origresult = state->origresult,
- * .saved_ctx = qctx,
- * .ctx = ctx,
- * .loop = loop,
- * .cb = cb,
- * .arg = cbarg
+ * dns_hook_resume_t *rev isc_mem_get(mctx, sizeof(*rev));
+ * dns_hookasync_t *ctx = isc_mem_get(mctx, sizeof(*ctx));
+ *
+ * *ctx = (dns_hookasync_t){ .private = NULL
+ * .hookpoint = state->hookpoint,
+ * .origresult = state->origresult,
+ * .saved_ctx = qctx,
+ * .ctx = ctx,
+ * .loop = loop,
+ * .cb = cb,
+ * .arg = cbarg
* };
* isc_mem_attach(mctx, &ctx->mctx);
*
*
* - Zone plugin hooks are called first. Zone template hooks are called
* second. View hooks are called third. If any plugin hook at any level
- * returns NS_HOOK_RETURN, the whole calling chain is stopped and no
- * subsequent hooks are called. (See the `ns__query_hookchain` unit test
+ * returns DDNS_HOOK_RETURN, the whole calling chain is stopped and no
+ * subsequent hooks are called. (See the `dns__query_hookchain` unit test
* in `tests/ns/query_test.c`.)
*
* - When a query hook is called, the `qctx->client->query.authzone`
* pointer is checked to determine whether an authoritative zone is
* being used to answer the query; if so, the zone's hooktable is used to
* call the hooks. As a consequence, a zone plugin won't be called by all
- * the hook points defined below in `ns_hookpoint_t`. For instance,
+ * the hook points defined below in `dns_hookpoint_t`. For instance,
* `NS_QUERY_SETUP` and `NS_QUERY_QCTX_INITIALIZED` will never be
* called in a zone plugin, as they occur before the zone has been
* looked up. `NS_QUERY_DONE_BEGIN` could be called if an
* 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_pluginctx_t ctx` parameter.
+ * when the plugin is loaded) has a `dns_pluginctx_t ctx` parameter.
* This provides to the plugin registering function various contextual
- * informations about the plugin. For instance, the `ns_hooksource_t source`
+ * informations about the plugin. For instance, the `dns_hooksource_t source`
* property indicates whether the plugin has been loaded at the zone level
- * (`NS_HOOKSOURCE_ZONE`) or at the view level (`NS_HOOKSOURCE_VIEW`).
+ * (`DNS_HOOKSOURCE_ZONE`) or at the view level (`DNS_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. Another property is `dns_name_t *origin`
* which indicates the zone name to the plugin if it is loaded at the zone level
- * (this property is NULL otherwise). Note that `ns_pluginctx_t`
+ * (this property is NULL otherwise). Note that `dns_pluginctx_t`
* parameter is defined in a parent stack frame, thus, it is valid only during
* `plugin_register` execution.
*/
* order in which they are referenced in query.c.
*/
typedef enum {
- /* hookpoints from query.c */
+ /* hookpoints from ns/query.c */
NS_QUERY_SETUP,
NS_QUERY_CLEANUP,
NS_QUERY_START_BEGIN,
/* XXX other files could be added later */
- NS_HOOKPOINTS_COUNT /* MUST BE LAST */
-} ns_hookpoint_t;
+ DNS_HOOKPOINTS_COUNT /* MUST BE LAST */
+} dns_hookpoint_t;
/*
* Returned by a hook action to indicate how to proceed after it has
* been called: continue processing, or return immediately.
*/
typedef enum {
- NS_HOOK_CONTINUE,
- NS_HOOK_RETURN,
-} ns_hookresult_t;
+ DNS_HOOK_CONTINUE,
+ DNS_HOOK_RETURN,
+} dns_hookresult_t;
-typedef ns_hookresult_t (*ns_hook_action_t)(void *arg, void *data,
- isc_result_t *resultp);
+typedef dns_hookresult_t (*dns_hook_action_t)(void *arg, void *data,
+ isc_result_t *resultp);
-typedef struct ns_hook {
- isc_mem_t *mctx;
- ns_hook_action_t action;
- void *action_data;
- ISC_LINK(struct ns_hook) link;
-} ns_hook_t;
+typedef struct dns_hook {
+ isc_mem_t *mctx;
+ dns_hook_action_t action;
+ void *action_data;
+ ISC_LINK(struct dns_hook) link;
+} dns_hook_t;
-typedef ISC_LIST(ns_hook_t) ns_hooklist_t;
-typedef ns_hooklist_t ns_hooktable_t[NS_HOOKPOINTS_COUNT];
+typedef ISC_LIST(dns_hook_t) dns_hooklist_t;
+typedef dns_hooklist_t dns_hooktable_t[DNS_HOOKPOINTS_COUNT];
/*%
- * ns__hook_table is a global hook table, which is used if view->hooktable
+ * dns__hook_table is a global hook table, which is used if view->hooktable
* is NULL. It's intended only for use by unit tests.
*/
-extern ns_hooktable_t *ns__hook_table;
+extern dns_hooktable_t *dns__hook_table;
-typedef void (*ns_hook_cancelasync_t)(ns_hookasync_t *);
-typedef void (*ns_hook_destroyasync_t)(ns_hookasync_t **);
+typedef void (*dns_hook_cancelasync_t)(dns_hookasync_t *);
+typedef void (*dns_hook_destroyasync_t)(dns_hookasync_t **);
/*%
* Context for a hook-initiated asynchronous process. This works
* similarly to dns_fetch_t.
*/
-struct ns_hookasync {
+struct dns_hookasync {
isc_mem_t *mctx;
/*
* dns_resolver_destroyfetch, respectively, but specified as function
* pointers since they can be hook-specific.
*/
- ns_hook_cancelasync_t cancel;
- ns_hook_destroyasync_t destroy;
+ dns_hook_cancelasync_t cancel;
+ dns_hook_destroyasync_t destroy;
void *private; /* hook-specific data */
};
* isc_event to be sent on the completion of a hook-initiated asyncronous
* process, similar to dns_fetchresponse_t.
*/
-typedef struct ns_hook_resume {
- ns_hookasync_t *ctx; /* asynchronous processing context */
- ns_hookpoint_t hookpoint; /* hook point from which to resume */
+typedef struct dns_hook_resume {
+ dns_hookasync_t *ctx; /* asynchronous processing context */
+ dns_hookpoint_t hookpoint; /* hook point from which to resume */
isc_result_t origresult; /* result code at the point of call to hook */
- query_ctx_t *saved_qctx; /* qctx at the point of call to hook */
+ void *context; /* context and the point of call to hook */
isc_loop_t *loop; /* loopmgr loop to resume in */
isc_job_cb cb; /* callback function */
void *arg; /* argument to pass to the callback */
-} ns_hook_resume_t;
+} dns_hook_resume_t;
/*
* 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;
+ DNS_HOOKSOURCE_UNDEFINED,
+ DNS_HOOKSOURCE_VIEW,
+ DNS_HOOKSOURCE_ZONE
+} dns_hooksource_t;
-typedef struct ns_pluginctx {
+typedef struct dns_pluginctx {
/* is this a zone or a view plugin */
- ns_hooksource_t source;
+ dns_hooksource_t source;
/* origin of the zone if this is a zone plugin, NULL otherwise */
const dns_name_t *origin;
-} ns_pluginctx_t;
+} dns_pluginctx_t;
-typedef struct ns_hook_data {
- ns_hooktable_t *hooktable;
- ns_plugins_t *plugins;
- ns_pluginctx_t pluginctx;
-} ns_hook_data_t;
+typedef struct dns_hook_data {
+ dns_hooktable_t *hooktable;
+ dns_plugins_t *plugins;
+ dns_pluginctx_t pluginctx;
+} dns_hook_data_t;
/*
* Plugin API version
*
- * When the API changes, increment NS_PLUGIN_VERSION. If the
+ * When the API changes, increment DNS_PLUGIN_VERSION. If the
* change is backward-compatible (e.g., adding a new function call
- * but not changing or removing an old one), increment NS_PLUGIN_AGE
- * as well; if not, set NS_PLUGIN_AGE to 0.
+ * but not changing or removing an old one), increment DNS_PLUGIN_AGE
+ * as well; if not, set DNS_PLUGIN_AGE to 0.
*/
-#ifndef NS_PLUGIN_VERSION
-#define NS_PLUGIN_VERSION 3
-#define NS_PLUGIN_AGE 0
-#endif /* ifndef NS_PLUGIN_VERSION */
+#ifndef DNS_PLUGIN_VERSION
+#define DNS_PLUGIN_VERSION 3
+#define DNS_PLUGIN_AGE 0
+#endif /* ifndef DNS_PLUGIN_VERSION */
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 *aclctx,
- ns_hooktable_t *hooktable, const ns_pluginctx_t *ctx,
- void **instp);
+dns_plugin_register_t(const char *parameters, const void *cfg, const char *file,
+ unsigned long line, isc_mem_t *mctx, void *aclctx,
+ dns_hooktable_t *hooktable, const dns_pluginctx_t *ctx,
+ void **instp);
/*%<
* Called when registering a new plugin.
*
*/
typedef void
-ns_plugin_destroy_t(void **instp);
+dns_plugin_destroy_t(void **instp);
/*%<
* Destroy a plugin instance.
*
*/
typedef isc_result_t
-ns_plugin_check_t(const char *parameters, const void *cfg, const char *file,
- unsigned long line, isc_mem_t *mctx, void *aclctx,
- const ns_pluginctx_t *ctx);
+dns_plugin_check_t(const char *parameters, const void *cfg, const char *file,
+ unsigned long line, isc_mem_t *mctx, void *aclctx,
+ const dns_pluginctx_t *ctx);
/*%<
* Check the validity of 'parameters'.
*/
typedef int
-ns_plugin_version_t(void);
+dns_plugin_version_t(void);
/*%<
* Return the API version number a plugin was compiled with.
*
* If the returned version number is no greater than
- * NS_PLUGIN_VERSION, and no less than NS_PLUGIN_VERSION - NS_PLUGIN_AGE,
+ * DNS_PLUGIN_VERSION, and no less than DNS_PLUGIN_VERSION - DNS_PLUGIN_AGE,
* then the module is API-compatible with named.
*/
/*%
* Prototypes for API functions to be defined in each module.
*/
-ns_plugin_check_t plugin_check;
-ns_plugin_destroy_t plugin_destroy;
-ns_plugin_register_t plugin_register;
-ns_plugin_version_t plugin_version;
+dns_plugin_check_t plugin_check;
+dns_plugin_destroy_t plugin_destroy;
+dns_plugin_register_t plugin_register;
+dns_plugin_version_t plugin_version;
isc_result_t
-ns_plugin_expandpath(const char *src, char *dst, size_t dstsize);
+dns_plugin_expandpath(const char *src, char *dst, size_t dstsize);
/*%<
* Prepare the plugin location to be passed to dlopen() based on the plugin
* path or filename found in the configuration file ('src'). Store the result
*/
isc_result_t
-ns_plugin_register(const char *modpath, const char *parameters, const void *cfg,
- const char *cfg_file, unsigned long cfg_line,
- isc_mem_t *mctx, void *aclctx, ns_hook_data_t *hookdata);
+dns_plugin_register(const char *modpath, const char *parameters,
+ const void *cfg, const char *cfg_file,
+ unsigned long cfg_line, isc_mem_t *mctx, void *aclctx,
+ dns_hook_data_t *hookdata);
/*%<
* Load the plugin module specified from the file 'modpath', and
* register an instance using 'parameters'.
*/
isc_result_t
-ns_plugin_check(const char *modpath, const char *parameters, const void *cfg,
- const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx,
- void *aclctx, const ns_pluginctx_t *ctx);
+dns_plugin_check(const char *modpath, const char *parameters, const void *cfg,
+ const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx,
+ void *aclctx, const dns_pluginctx_t *ctx);
/*%<
* Open the plugin module at 'modpath' and check the validity of
* 'parameters', logging any errors or warnings found, then
*/
void
-ns_plugins_create(isc_mem_t *mctx, ns_plugins_t **listp);
+dns_plugins_create(isc_mem_t *mctx, dns_plugins_t **listp);
/*%<
* Create and initialize a plugin list.
*/
void
-ns_plugins_free(isc_mem_t *mctx, void **listp);
+dns_plugins_free(isc_mem_t *mctx, void **listp);
/*%<
* Close each plugin module in a plugin list, then free the list object.
*/
void
-ns_hooktable_free(isc_mem_t *mctx, void **tablep);
+dns_hooktable_free(isc_mem_t *mctx, void **tablep);
/*%<
* Free a hook table.
*/
void
-ns_hook_add(ns_hooktable_t *hooktable, isc_mem_t *mctx,
- ns_hookpoint_t hookpoint, const ns_hook_t *hook);
+dns_hook_add(dns_hooktable_t *hooktable, isc_mem_t *mctx,
+ dns_hookpoint_t hookpoint, const dns_hook_t *hook);
/*%<
* Allocate (using memory context 'mctx') a copy of the 'hook' structure
* describing a hook action and append it to the list of hooks at 'hookpoint'
*/
void
-ns_hooktable_init(ns_hooktable_t *hooktable);
+dns_hooktable_init(dns_hooktable_t *hooktable);
/*%<
* Initialize a hook table.
*/
void
-ns_hooktable_create(isc_mem_t *mctx, ns_hooktable_t **tablep);
+dns_hooktable_create(isc_mem_t *mctx, dns_hooktable_t **tablep);
/*%<
* Allocate and initialize a hook table.
*/
typedef struct dns_geoip_databases dns_geoip_databases_t;
typedef struct dns_glue dns_glue_t;
typedef struct dns_gluelist dns_gluelist_t;
+typedef struct dns_hookasync dns_hookasync_t;
typedef struct dns_iptable dns_iptable_t;
typedef uint32_t dns_iterations_t;
typedef struct dns_kasp dns_kasp_t;
typedef struct dns_notify dns_notify_t;
typedef struct dns_notifyctx dns_notifyctx_t;
typedef ISC_LIST(dns_notify_t) dns_notifylist_t;
-typedef struct dns_ntatable dns_ntatable_t;
-typedef struct dns_ntnode dns_ntnode_t;
-typedef enum dns_opcode dns_opcode_t;
-typedef struct dns_order dns_order_t;
-typedef struct dns_peer dns_peer_t;
-typedef struct dns_peerlist dns_peerlist_t;
+typedef struct dns_ntatable dns_ntatable_t;
+typedef struct dns_ntnode dns_ntnode_t;
+typedef enum dns_opcode dns_opcode_t;
+typedef struct dns_order dns_order_t;
+typedef struct dns_peer dns_peer_t;
+typedef struct dns_peerlist dns_peerlist_t;
+typedef struct dns_plugin dns_plugin_t;
+typedef ISC_LIST(dns_plugin_t) dns_plugins_t;
typedef struct dns_slabheader_proof dns_slabheader_proof_t;
typedef struct dns_rbt dns_rbt_t;
typedef struct dns_rbtdb dns_rbtdb_t;
void (*plugins_free)(isc_mem_t *, void **);
/* Hook table */
- void *hooktable; /* ns_hooktable */
+ void *hooktable; /* dns_hooktable */
void (*hooktable_free)(isc_mem_t *, void **);
};
'forward.c',
'gssapictx.c',
'hmac_link.c',
+ 'hooks.c',
'ipkeylist.c',
'iptable.c',
'journal.c',
#include <isc/md.h>
#include <isc/mem.h>
#include <isc/netaddr.h>
+#include <isc/netmgr.h>
#include <isc/parseint.h>
#include <isc/region.h>
#include <isc/result.h>
#include <dns/acl.h>
#include <dns/dnstap.h>
#include <dns/fixedname.h>
+#include <dns/hooks.h>
#include <dns/journal.h>
#include <dns/kasp.h>
#include <dns/keymgr.h>
#include <isccfg/kaspconf.h>
#include <isccfg/namedconf.h>
-#include <ns/hooks.h>
-
#define NAMED_CONTROL_PORT 953
static in_port_t dnsport = 53;
struct check_one_plugin_data {
isc_mem_t *mctx;
cfg_aclconfctx_t *aclctx;
- ns_hooksource_t source;
+ dns_hooksource_t source;
isc_result_t *check_result;
- const ns_pluginctx_t *ctx;
+ const dns_pluginctx_t *ctx;
};
/*%
UNUSED(aclctx);
- result = ns_plugin_expandpath(plugin_path, full_path,
- sizeof(full_path));
+ result = dns_plugin_expandpath(plugin_path, full_path,
+ sizeof(full_path));
if (result != ISC_R_SUCCESS) {
cfg_obj_log(obj, ISC_LOG_ERROR,
"%s: plugin check failed: "
return result;
}
- result = ns_plugin_check(full_path, parameters, config,
- cfg_obj_file(obj), cfg_obj_line(obj),
- data->mctx, data->aclctx, data->ctx);
+ result = dns_plugin_check(full_path, parameters, config,
+ cfg_obj_file(obj), cfg_obj_line(obj),
+ data->mctx, data->aclctx, data->ctx);
if (result != ISC_R_SUCCESS) {
cfg_obj_log(obj, ISC_LOG_ERROR, "%s: plugin check failed: %s",
full_path, isc_result_totext(result));
cfg_aclconfctx_t *aclctx, const dns_name_t *zname,
isc_mem_t *mctx) {
isc_result_t result = ISC_R_SUCCESS;
- ns_pluginctx_t ctx = {
- .source = (zname == NULL) ? NS_HOOKSOURCE_VIEW
- : NS_HOOKSOURCE_ZONE,
+ dns_pluginctx_t ctx = {
+ .source = (zname == NULL) ? DNS_HOOKSOURCE_VIEW
+ : DNS_HOOKSOURCE_ZONE,
.origin = zname,
};
struct check_one_plugin_data check_one_plugin_data = {
bool authdbset;
bool isreferral;
isc_mutex_t fetchlock;
- ns_hookasync_t *hookasyncctx;
+ dns_hookasync_t *hookasyncctx;
dns_rpz_st_t *rpz_st;
isc_bufferlist_t namebufs;
ISC_LIST(ns_dbversion_t) activeversions;
isc_mem_t *mctx, void *arg,
isc_loop_t *loop,
isc_job_cb cb, void *evarg,
- ns_hookasync_t **ctxp);
+ dns_hookasync_t **ctxp);
/*
* The following functions are expected to be used only within query.c
typedef struct ns_altsecret ns_altsecret_t;
typedef ISC_LIST(ns_altsecret_t) ns_altsecretlist_t;
-typedef struct ns_client ns_client_t;
-typedef struct ns_clientmgr ns_clientmgr_t;
-typedef struct ns_plugin ns_plugin_t;
-typedef ISC_LIST(ns_plugin_t) ns_plugins_t;
+typedef struct ns_client ns_client_t;
+typedef struct ns_clientmgr ns_clientmgr_t;
typedef struct ns_interface ns_interface_t;
typedef struct ns_interfacemgr ns_interfacemgr_t;
typedef struct ns_query ns_query_t;
typedef struct ns_server ns_server_t;
typedef struct ns_stats ns_stats_t;
-typedef struct ns_hookasync ns_hookasync_t;
typedef enum { ns_cookiealg_siphash24 } ns_cookiealg_t;
ns_srcset.add(
files(
'client.c',
- 'hooks.c',
'interfacemgr.c',
'listenlist.c',
'notify.c',
#include <dns/dns64.h>
#include <dns/dnssec.h>
#include <dns/ede.h>
+#include <dns/hooks.h>
#include <dns/keytable.h>
#include <dns/message.h>
#include <dns/ncache.h>
#include <dns/zt.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/interfacemgr.h>
#include <ns/server.h>
#include <ns/stats.h>
static void
release_recursionquota(ns_client_t *client);
-static inline ns_hookresult_t
+static inline dns_hookresult_t
ns__query_callhook(uint8_t id, query_ctx_t *qctx, isc_result_t *result,
- ns_hooktable_t *hooktab) {
+ dns_hooktable_t *hooktab) {
isc_result_t hookresult = *result;
- ns_hook_t *hook = ISC_LIST_HEAD((*hooktab)[id]);
+ dns_hook_t *hook = ISC_LIST_HEAD((*hooktab)[id]);
while (hook != NULL) {
- ns_hook_action_t func = hook->action;
+ dns_hook_action_t func = hook->action;
void *data = hook->action_data;
INSIST(func != NULL);
switch (func(qctx, data, &hookresult)) {
- case NS_HOOK_CONTINUE:
+ case DNS_HOOK_CONTINUE:
hook = ISC_LIST_NEXT(hook, link);
break;
- case NS_HOOK_RETURN:
+ case DNS_HOOK_RETURN:
*result = hookresult;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
default:
UNREACHABLE();
}
}
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
static inline void
ns__query_callhook_noreturn(uint8_t id, query_ctx_t *qctx,
- ns_hooktable_t *hooktab) {
- ns_hook_t *hook = ISC_LIST_HEAD((*hooktab)[id]);
+ dns_hooktable_t *hooktab) {
+ dns_hook_t *hook = ISC_LIST_HEAD((*hooktab)[id]);
while (hook != NULL) {
- ns_hook_action_t func = hook->action;
+ dns_hook_action_t func = hook->action;
void *data = hook->action_data;
isc_result_t dummyres;
/*
* Call the specified hook function in every configured module that
- * implements that function. If any hook function returns NS_HOOK_RETURN,
+ * implements that function. If any hook function returns DNS_HOOK_RETURN,
* we set 'result' and terminate processing by jumping to the 'cleanup' tag.
*
* Before any hook point is reached, qctx->view must be initialized to
* is a macro instead of a static function; it needs to be able to use
* 'goto cleanup' regardless of the return value.
*/
-#define CALL_HOOK(_id, _qctx) \
- if ((_qctx)->zhooks != NULL && \
- ns__query_callhook(_id, _qctx, &result, (_qctx)->zhooks) == \
- NS_HOOK_RETURN) \
- { \
- goto cleanup; \
- } \
- if ((_qctx)->view->hooktable != NULL && \
- ns__query_callhook(_id, _qctx, &result, \
- (_qctx)->view->hooktable) == NS_HOOK_RETURN) \
- { \
- goto cleanup; \
- } \
- if (ns__hook_table != NULL && \
- ns__query_callhook(_id, _qctx, &result, ns__hook_table) == \
- NS_HOOK_RETURN) \
- { \
- goto cleanup; \
+#define CALL_HOOK(_id, _qctx) \
+ if ((_qctx)->zhooks != NULL && \
+ ns__query_callhook(_id, _qctx, &result, (_qctx)->zhooks) == \
+ DNS_HOOK_RETURN) \
+ { \
+ goto cleanup; \
+ } \
+ if ((_qctx)->view->hooktable != NULL && \
+ ns__query_callhook(_id, _qctx, &result, \
+ (_qctx)->view->hooktable) == DNS_HOOK_RETURN) \
+ { \
+ goto cleanup; \
+ } \
+ if (dns__hook_table != NULL && \
+ ns__query_callhook(_id, _qctx, &result, dns__hook_table) == \
+ DNS_HOOK_RETURN) \
+ { \
+ goto cleanup; \
}
/*
ns__query_callhook_noreturn(_id, _qctx, \
(_qctx)->view->hooktable); \
} \
- if (ns__hook_table != NULL) { \
- ns__query_callhook_noreturn(_id, _qctx, ns__hook_table); \
+ if (dns__hook_table != NULL) { \
+ ns__query_callhook_noreturn(_id, _qctx, dns__hook_table); \
}
/*
static void
query_hookresume(void *arg) {
- ns_hook_resume_t *rev = (ns_hook_resume_t *)arg;
- ns_hookasync_t *hctx = NULL;
+ dns_hook_resume_t *rev = (dns_hook_resume_t *)arg;
+ dns_hookasync_t *hctx = NULL;
ns_client_t *client = rev->arg;
- query_ctx_t *qctx = rev->saved_qctx;
+ query_ctx_t *qctx = rev->context;
bool canceled;
CTRACE(ISC_LOG_DEBUG(3), "query_hookresume");
void *arg) {
isc_result_t result;
ns_client_t *client = qctx->client;
- query_ctx_t *saved_qctx = NULL;
+ query_ctx_t *context = NULL;
CTRACE(ISC_LOG_DEBUG(3), "ns_query_hookasync");
goto cleanup;
}
- qctx_save(qctx, &saved_qctx);
- result = runasync(saved_qctx, client->manager->mctx, arg,
+ qctx_save(qctx, &context);
+ result = runasync(context, client->manager->mctx, arg,
client->manager->loop, query_hookresume, client,
&client->query.hookasyncctx);
if (result != ISC_R_SUCCESS) {
/*
* Typically the runasync() function will trigger recursion, but
* there is no need to set NS_QUERYATTR_RECURSING. The calling hook
- * is expected to return NS_HOOK_RETURN, and the RECURSING
+ * is expected to return DNS_HOOK_RETURN, and the RECURSING
* attribute won't be checked anywhere.
*
* Hook-based asynchronous processing cannot coincide with normal
* simply return on failure of this function, so there's no other
* place for this to prevent leak.
*/
- if (saved_qctx != NULL) {
- qctx_clean(saved_qctx);
- qctx_freedata(saved_qctx);
- qctx_destroy(saved_qctx);
+ if (context != NULL) {
+ qctx_clean(context);
+ qctx_freedata(context);
+ qctx_destroy(context);
}
return result;
}
if (qctx->client->query.restarts <
qctx->client->inner.view->max_restarts)
{
- query_ctx_t *saved_qctx = NULL;
+ query_ctx_t *context = NULL;
qctx->client->query.restarts++;
- qctx_save(qctx, &saved_qctx);
+ qctx_save(qctx, &context);
isc_nmhandle_attach(qctx->client->inner.handle,
&qctx->client->inner.restarthandle);
isc_async_run(qctx->client->manager->loop,
- async_restart, saved_qctx);
+ async_restart, context);
return DNS_R_CONTINUE;
} else {
/*
/*
* We'd only get here if one of the hooks above
* (NS_QUERY_DONE_BEGIN or NS_QUERY_DONE_SEND) returned
- * NS_HOOK_RETURN. Some housekeeping may be needed.
+ * DNS_HOOK_RETURN. Some housekeeping may be needed.
*/
qctx_clean(qctx);
qctx_freedata(qctx);
'nsec3',
'nsec3param',
'private',
+ 'plugin',
'qp',
'qpdb',
'qpmulti',
#include <isc/types.h>
#include <isc/util.h>
+#include <dns/hooks.h>
#include <dns/lib.h>
+#include <tests/dns.h>
+
/*
* Mocking isc_file_exists() as it's used inside the tested
- * ns_plugin_expandpath() function defined in lib/ns/hooks.c
+ * dns_plugin_expandpath() function defined in lib/dns/hooks.c
*/
static bool
isc_file_exists(const char *pathname) {
return mock();
}
-#include "../ns/hooks.c"
-
-#include <tests/ns.h>
+#include "../../dns/hooks.c"
/*%
* Structure containing parameters for run_full_path_test().
*/
typedef struct {
- const ns_test_id_t id; /* libns test identifier */
- const char *input; /* source string - plugin name or path */
- bool exists; /* return of mocked isc_file_exists() */
- size_t output_size; /* size of target char array to
- * allocate */
- isc_result_t result; /* expected return value */
- const char *output; /* expected output string */
-} ns_plugin_expandpath_test_params_t;
+ const dns_test_id_t id; /* libns test identifier */
+ const char *input; /* source string - plugin name or path */
+ bool exists; /* return of mocked isc_file_exists() */
+ size_t output_size; /* size of target char array to
+ * allocate */
+ isc_result_t result; /* expected return value */
+ const char *output; /* expected output string */
+} dns_plugin_expandpath_test_params_t;
/*%
- * Perform a single ns_plugin_expandpath() check using given parameters.
+ * Perform a single dns_plugin_expandpath() check using given parameters.
*/
static void
-run_full_path_test(const ns_plugin_expandpath_test_params_t *test,
+run_full_path_test(const dns_plugin_expandpath_test_params_t *test,
void **state) {
char **target = (char **)state;
isc_result_t result;
*target = isc_mem_allocate(isc_g_mctx, test->output_size);
/*
- * Call ns_plugin_expandpath().
+ * Call dns_plugin_expandpath().
*/
- result = ns_plugin_expandpath(test->input, *target, test->output_size);
+ result = dns_plugin_expandpath(test->input, *target, test->output_size);
/*
* Check return value.
isc_mem_free(isc_g_mctx, *target);
}
-/* test ns_plugin_expandpath() */
-ISC_RUN_TEST_IMPL(ns_plugin_expandpath) {
+/* test dns_plugin_expandpath() */
+ISC_RUN_TEST_IMPL(dns_plugin_expandpath) {
size_t i;
- const ns_plugin_expandpath_test_params_t tests[] = {
+ const dns_plugin_expandpath_test_params_t tests[] = {
{
- NS_TEST_ID("correct use with an absolute path"),
+ DNS_TEST_ID("correct use with an absolute path"),
.input = "/usr/lib/named/foo.so",
.exists = true,
.output_size = PATH_MAX,
.output = "/usr/lib/named/foo.so",
},
{
- NS_TEST_ID("correct use with a relative path"),
+ DNS_TEST_ID("correct use with a relative path"),
.input = "../../foo.so",
.exists = true,
.output_size = PATH_MAX,
.output = "../../foo.so",
},
{
- NS_TEST_ID("correct use with a filename"),
+ DNS_TEST_ID("correct use with a filename"),
.input = "foo.so",
.exists = true,
.output_size = PATH_MAX,
.output = NAMED_PLUGINDIR "/foo.so",
},
{
- NS_TEST_ID("correct use with an absolute path and no "
- "extension"),
+ DNS_TEST_ID("correct use with an absolute path and no "
+ "extension"),
.input = "/usr/lib/named/foo",
.exists = false,
.output_size = PATH_MAX,
.output = "/usr/lib/named/foo" NAMED_PLUGINEXT,
},
{
- NS_TEST_ID("correct use with a relative path and no "
- "extension"),
+ DNS_TEST_ID("correct use with a relative path and no "
+ "extension"),
.input = "../../foo",
.exists = false,
.output_size = PATH_MAX,
.output = "../../foo" NAMED_PLUGINEXT,
},
{
- NS_TEST_ID("correct use with a filename and no "
- "extension"),
+ DNS_TEST_ID("correct use with a filename and no "
+ "extension"),
.input = "foo",
.exists = false,
.output_size = PATH_MAX,
.output = NAMED_PLUGINDIR "/foo" NAMED_PLUGINEXT,
},
{
- NS_TEST_ID("correct use with a filename and no "
- "extension but a name with dots"),
+ DNS_TEST_ID("correct use with a filename and no "
+ "extension but a name with dots"),
.input = "foo.bar",
.exists = false,
.output_size = PATH_MAX,
.output = NAMED_PLUGINDIR "/foo.bar" NAMED_PLUGINEXT,
},
{
- NS_TEST_ID("no space at all in target buffer"),
+ DNS_TEST_ID("no space at all in target buffer"),
.input = "/usr/lib/named/foo.so",
.exists = true,
.output_size = 0,
.result = ISC_R_NOSPACE,
},
{
- NS_TEST_ID("target buffer too small to fit input"),
+ DNS_TEST_ID("target buffer too small to fit input"),
.input = "/usr/lib/named/foo.so",
.exists = true,
.output_size = 1,
.result = ISC_R_NOSPACE,
},
{
- NS_TEST_ID("target buffer too small to fit NULL byte"),
+ DNS_TEST_ID("target buffer too small to fit NULL byte"),
.input = "/foo.so",
.exists = true,
.output_size = 7,
.result = ISC_R_NOSPACE,
},
{
- NS_TEST_ID("target buffer too small to fit full path"),
+ DNS_TEST_ID("target buffer too small to fit full path"),
.input = "foo.so",
.exists = true,
.output_size = 7,
}
ISC_TEST_LIST_START
-ISC_TEST_ENTRY(ns_plugin_expandpath)
+ISC_TEST_ENTRY(dns_plugin_expandpath)
ISC_TEST_LIST_END
ISC_TEST_MAIN
#include <tests/isc.h>
+typedef struct dns_test_id {
+ const char *description;
+ int lineno;
+} dns_test_id_t;
+
+#define DNS_TEST_ID(desc) { .description = desc, .lineno = __LINE__ }
+
extern dns_zonemgr_t *zonemgr;
typedef struct {
#include <isc/timer.h>
#include <isc/util.h>
+#include <dns/hooks.h>
#include <dns/zone.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/interfacemgr.h>
#include <tests/dns.h>
* Set a hooktable on the served zone
*/
void
-ns_test_serve_zone_sethooktab(ns_hooktable_t *hooktab);
+ns_test_serve_zone_sethooktab(dns_hooktable_t *hooktab);
/*%
* Release the zone loaded by ns_test_serve_zone().
/*%
* A hook callback interrupting execution at given hook's insertion point.
*/
-ns_hookresult_t
+dns_hookresult_t
ns_test_hook_catch_call(void *arg, void *data, isc_result_t *resultp);
#include <dns/db.h>
#include <dns/dispatch.h>
#include <dns/fixedname.h>
+#include <dns/hooks.h>
#include <dns/name.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/interfacemgr.h>
#include <ns/server.h>
static dns_zone_t *served_zone = NULL;
void
-ns_test_serve_zone_sethooktab(ns_hooktable_t *hooktab) {
- dns_zone_sethooktable(served_zone, hooktab, ns_hooktable_free);
+ns_test_serve_zone_sethooktab(dns_hooktable_t *hooktab) {
+ dns_zone_sethooktable(served_zone, hooktab, dns_hooktable_free);
}
isc_result_t
* "data". Causes execution to be interrupted at hook insertion
* point.
*/
-static ns_hookresult_t
+static dns_hookresult_t
extract_qctx(void *arg, void *data, isc_result_t *resultp) {
query_ctx_t **qctxp;
query_ctx_t *qctx;
*qctxp = qctx;
*resultp = ISC_R_UNSET;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
/*%
*/
static isc_result_t
create_qctx_for_client(ns_client_t *client, query_ctx_t **qctxp) {
- ns_hooktable_t *saved_hook_table = NULL, *query_hooks = NULL;
- const ns_hook_t hook = {
+ dns_hooktable_t *saved_hook_table = NULL, *query_hooks = NULL;
+ const dns_hook_t hook = {
.action = extract_qctx,
.action_data = qctxp,
};
* set hooks.
*/
- ns_hooktable_create(isc_g_mctx, &query_hooks);
- ns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_SETUP, &hook);
+ dns_hooktable_create(isc_g_mctx, &query_hooks);
+ dns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_SETUP, &hook);
- saved_hook_table = ns__hook_table;
- ns__hook_table = query_hooks;
+ saved_hook_table = dns__hook_table;
+ dns__hook_table = query_hooks;
ns_query_start(client, client->inner.handle);
- ns__hook_table = saved_hook_table;
- ns_hooktable_free(isc_g_mctx, (void **)&query_hooks);
+ dns__hook_table = saved_hook_table;
+ dns_hooktable_free(isc_g_mctx, (void **)&query_hooks);
isc_nmhandle_detach(&client->inner.reqhandle);
isc_mem_put(isc_g_mctx, qctx, sizeof(*qctx));
}
-ns_hookresult_t
+dns_hookresult_t
ns_test_hook_catch_call(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(data);
*resultp = ISC_R_UNSET;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
isc_result_t
foreach unit : [
'notify',
- 'plugin',
'query',
]
test_bin = executable(
#include <isc/util.h>
#include <dns/badcache.h>
+#include <dns/hooks.h>
#include <dns/lib.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <ns/client.h>
-#include <ns/hooks.h>
#include <ns/query.h>
#include <ns/server.h>
#include <ns/stats.h>
*/
static void
run_sfcache_test(const ns__query_sfcache_test_params_t *test) {
- ns_hooktable_t *query_hooks = NULL;
+ dns_hooktable_t *query_hooks = NULL;
query_ctx_t *qctx = NULL;
isc_result_t result;
- const ns_hook_t hook = {
+ const dns_hook_t hook = {
.action = ns_test_hook_catch_call,
};
* Interrupt execution if ns_query_done() is called.
*/
- ns_hooktable_create(isc_g_mctx, &query_hooks);
- ns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_DONE_BEGIN, &hook);
- ns__hook_table = query_hooks;
+ dns_hooktable_create(isc_g_mctx, &query_hooks);
+ dns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_DONE_BEGIN, &hook);
+ dns__hook_table = query_hooks;
/*
* Construct a query context for a ./NS query with given flags.
* Clean up.
*/
ns_test_qctx_destroy(&qctx);
- ns_hooktable_free(isc_g_mctx, (void **)&query_hooks);
+ dns_hooktable_free(isc_g_mctx, (void **)&query_hooks);
}
/* test ns__query_sfcache() */
*/
static void
run_start_test(const ns__query_start_test_params_t *test) {
- ns_hooktable_t *query_hooks = NULL;
+ dns_hooktable_t *query_hooks = NULL;
query_ctx_t *qctx = NULL;
isc_result_t result;
- const ns_hook_t hook = {
+ const dns_hook_t hook = {
.action = ns_test_hook_catch_call,
};
/*
* Interrupt execution if query_lookup() or ns_query_done() is called.
*/
- ns_hooktable_create(isc_g_mctx, &query_hooks);
- ns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_LOOKUP_BEGIN, &hook);
- ns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_DONE_BEGIN, &hook);
- ns__hook_table = query_hooks;
+ dns_hooktable_create(isc_g_mctx, &query_hooks);
+ dns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_LOOKUP_BEGIN, &hook);
+ dns_hook_add(query_hooks, isc_g_mctx, NS_QUERY_DONE_BEGIN, &hook);
+ dns__hook_table = query_hooks;
/*
* Construct a query context using the supplied parameters.
ns_test_cleanup_zone();
}
ns_test_qctx_destroy(&qctx);
- ns_hooktable_free(isc_g_mctx, (void **)&query_hooks);
+ dns_hooktable_free(isc_g_mctx, (void **)&query_hooks);
}
/* test ns__query_start() */
* Structure containing parameters for ns__query_hookasync_test().
*/
typedef struct {
- const ns_test_id_t id; /* libns test identifier */
- ns_hookpoint_t hookpoint; /* hook point specified for resume */
- ns_hookpoint_t hookpoint2; /* expected hook point used after resume */
- ns_hook_action_t action; /* action for the hook point */
- isc_result_t start_result; /* result of 'runasync' */
- bool quota_ok; /* true if recursion quota should be okay */
- bool do_cancel; /* true if query should be canceled
- * in test */
+ const ns_test_id_t id; /* libns test identifier */
+ dns_hookpoint_t hookpoint; /* hook point specified for resume */
+ dns_hookpoint_t hookpoint2; /* expected hook point used after resume */
+ dns_hook_action_t action; /* action for the hook point */
+ isc_result_t start_result; /* result of 'runasync' */
+ bool quota_ok; /* true if recursion quota should be okay */
+ bool do_cancel; /* true if query should be canceled
+ * in test */
} ns__query_hookasync_test_params_t;
/* Data structure passed from tests to hooks */
typedef struct hookasync_data {
- bool async; /* true if in a hook-triggered
- * asynchronous process */
- bool canceled; /* true if the query has been canceled */
- isc_result_t start_result; /* result of 'runasync' */
- ns_hook_resume_t *rev; /* resume state sent on completion */
- query_ctx_t qctx; /* shallow copy of qctx passed to hook */
- ns_hookpoint_t hookpoint; /* specifies where to resume */
- ns_hookpoint_t lasthookpoint; /* remember the last hook point called */
+ bool async; /* true if in a hook-triggered
+ * asynchronous process */
+ bool canceled; /* true if the query has been canceled */
+ isc_result_t start_result; /* result of 'runasync' */
+ dns_hook_resume_t *rev; /* resume state sent on completion */
+ query_ctx_t qctx; /* shallow copy of qctx passed to hook */
+ dns_hookpoint_t hookpoint; /* specifies where to resume */
+ dns_hookpoint_t lasthookpoint; /* remember the last hook point called */
} hookasync_data_t;
/*
* this is actually called; otherwise tests would fail due to memory leak.
*/
static void
-destroy_hookasyncctx(ns_hookasync_t **ctxp) {
- ns_hookasync_t *ctx = *ctxp;
+destroy_hookasyncctx(dns_hookasync_t **ctxp) {
+ dns_hookasync_t *ctx = *ctxp;
*ctxp = NULL;
isc_mem_putanddetach(&ctx->mctx, ctx, sizeof(*ctx));
/* 'cancel' callback of hook recursion ctx. */
static void
-cancel_hookasyncctx(ns_hookasync_t *ctx) {
+cancel_hookasyncctx(dns_hookasync_t *ctx) {
/* Mark the hook data so the test can confirm this is called. */
((hookasync_data_t *)ctx->private)->canceled = true;
}
/* 'runasync' callback passed to ns_query_hookasync */
static isc_result_t
test_hookasync(query_ctx_t *qctx, isc_mem_t *mctx, void *arg, isc_loop_t *loop,
- isc_job_cb cb, void *evarg, ns_hookasync_t **ctxp) {
+ isc_job_cb cb, void *evarg, dns_hookasync_t **ctxp) {
hookasync_data_t *asdata = arg;
- ns_hookasync_t *ctx = NULL;
- ns_hook_resume_t *rev = NULL;
+ dns_hookasync_t *ctx = NULL;
+ dns_hook_resume_t *rev = NULL;
if (asdata->start_result != ISC_R_SUCCESS) {
return asdata->start_result;
ctx = isc_mem_get(mctx, sizeof(*ctx));
rev = isc_mem_get(mctx, sizeof(*rev));
- *rev = (ns_hook_resume_t){
+ *rev = (dns_hook_resume_t){
.hookpoint = asdata->hookpoint,
.origresult = DNS_R_NXDOMAIN,
- .saved_qctx = qctx,
+ .context = qctx,
.ctx = ctx,
.loop = loop,
.cb = cb,
asdata->rev = rev;
- *ctx = (ns_hookasync_t){
+ *ctx = (dns_hookasync_t){
.destroy = destroy_hookasyncctx,
.cancel = cancel_hookasyncctx,
.private = asdata,
* remembered in the hook data, so that the test can confirm which hook point
* was last used.
*/
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_common(void *arg, void *data, isc_result_t *resultp,
- ns_hookpoint_t hookpoint) {
+ dns_hookpoint_t hookpoint) {
query_ctx_t *qctx = arg;
hookasync_data_t *asdata = data;
isc_result_t result;
}
*resultp = ISC_R_UNSET;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_setup(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_SETUP);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_start_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_START_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_lookup_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_LOOKUP_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_resume_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_RESUME_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_got_answer_begin(void *arg, void *data,
isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_GOT_ANSWER_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_respond_any_begin(void *arg, void *data,
isc_result_t *resultp) {
return hook_async_common(arg, data, resultp,
NS_QUERY_RESPOND_ANY_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_addanswer_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_ADDANSWER_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_notfound_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_NOTFOUND_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_prep_delegation_begin(void *arg, void *data,
isc_result_t *resultp) {
return hook_async_common(arg, data, resultp,
NS_QUERY_PREP_DELEGATION_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_zone_delegation_begin(void *arg, void *data,
isc_result_t *resultp) {
return hook_async_common(arg, data, resultp,
NS_QUERY_ZONE_DELEGATION_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_delegation_begin(void *arg, void *data,
isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_DELEGATION_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_delegation_recurse_begin(void *arg, void *data,
isc_result_t *resultp) {
return hook_async_common(arg, data, resultp,
NS_QUERY_DELEGATION_RECURSE_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_nodata_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_NODATA_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_nxdomain_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_NXDOMAIN_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_ncache_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_NCACHE_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_cname_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_CNAME_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_dname_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_DNAME_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_respond_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_RESPOND_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_response_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp,
NS_QUERY_PREP_RESPONSE_BEGIN);
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_query_done_begin(void *arg, void *data, isc_result_t *resultp) {
return hook_async_common(arg, data, resultp, NS_QUERY_DONE_BEGIN);
}
.start_result = test->start_result,
.hookpoint = test->hookpoint,
};
- const ns_hook_t testhook = {
+ const dns_hook_t testhook = {
.action = test->action,
.action_data = &asdata,
};
* Its action will specify various different resume points (unusual
* in practice, but that's fine for the testing purpose).
*/
- ns__hook_table = NULL;
- ns_hooktable_create(isc_g_mctx, &ns__hook_table);
- ns_hook_add(ns__hook_table, isc_g_mctx, NS_QUERY_START_BEGIN,
- &testhook);
+ dns__hook_table = NULL;
+ dns_hooktable_create(isc_g_mctx, &dns__hook_table);
+ dns_hook_add(dns__hook_table, isc_g_mctx, NS_QUERY_START_BEGIN,
+ &testhook);
if (test->hookpoint2 != NS_QUERY_START_BEGIN) {
/*
* unless testing START_BEGIN itself, specify the hook for the
* expected resume point, too.
*/
- ns_hook_add(ns__hook_table, isc_g_mctx, test->hookpoint2,
- &testhook);
+ dns_hook_add(dns__hook_table, isc_g_mctx, test->hookpoint2,
+ &testhook);
}
{
* qctx->client may have been invalidated while we still need it.
*/
ns_test_qctx_destroy(&qctx);
- ns_hooktable_free(isc_g_mctx, (void **)&ns__hook_table);
+ dns_hooktable_free(isc_g_mctx, (void **)&dns__hook_table);
if (!test->quota_ok) {
isc_quota_release(&sctx->recursionquota);
}
typedef struct {
const ns_test_id_t id; /* libns test identifier */
const char *qname; /* QNAME */
- ns_hookpoint_t hookpoint; /* hook point specified for resume */
+ dns_hookpoint_t hookpoint; /* hook point specified for resume */
isc_result_t start_result; /* result of 'runasync' */
bool do_cancel; /* true if query should be canceled
* in test */
typedef struct hookasync_e2e_data {
bool async; /* true if in a hook-triggered
* asynchronous process */
- ns_hook_resume_t *rev; /* resume state sent on completion */
- ns_hookpoint_t hookpoint; /* specifies where to resume */
+ dns_hook_resume_t *rev; /* resume state sent on completion */
+ dns_hookpoint_t hookpoint; /* specifies where to resume */
isc_result_t start_result; /* result of 'runasync' */
dns_rcode_t expected_rcode;
bool done; /* if SEND_DONE hook is called */
/* Cancel callback. Just need to be defined, it doesn't have to do anything. */
static void
-cancel_e2ehookasyncctx(ns_hookasync_t *ctx) {
+cancel_e2ehookasyncctx(dns_hookasync_t *ctx) {
UNUSED(ctx);
}
static isc_result_t
test_hookasync_e2e(query_ctx_t *qctx, isc_mem_t *mctx, void *arg,
isc_loop_t *loop, isc_job_cb cb, void *evarg,
- ns_hookasync_t **ctxp) {
- ns_hookasync_t *ctx = NULL;
- ns_hook_resume_t *rev = NULL;
+ dns_hookasync_t **ctxp) {
+ dns_hookasync_t *ctx = NULL;
+ dns_hook_resume_t *rev = NULL;
hookasync_e2e_data_t *asdata = arg;
if (asdata->start_result != ISC_R_SUCCESS) {
ctx = isc_mem_get(mctx, sizeof(*ctx));
rev = isc_mem_get(mctx, sizeof(*rev));
- *rev = (ns_hook_resume_t){
+ *rev = (dns_hook_resume_t){
.hookpoint = asdata->hookpoint,
- .saved_qctx = qctx,
+ .context = qctx,
.ctx = ctx,
.loop = loop,
.cb = cb,
asdata->rev = rev;
- *ctx = (ns_hookasync_t){
+ *ctx = (dns_hookasync_t){
.destroy = destroy_hookasyncctx,
.cancel = cancel_e2ehookasyncctx,
.private = asdata,
return ISC_R_SUCCESS;
}
-static ns_hookresult_t
+static dns_hookresult_t
hook_async_e2e(void *arg, void *data, isc_result_t *resultp) {
query_ctx_t *qctx = arg;
hookasync_e2e_data_t *asdata = data;
result = ns_query_hookasync(qctx, test_hookasync_e2e, asdata);
if (result != ISC_R_SUCCESS) {
*resultp = result;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
asdata->async = true;
asdata->rev->origresult = *resultp; /* save it for resume */
*resultp = ISC_R_UNSET;
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
} else {
/* Resume from the completion of async event */
asdata->async = false;
/* Don't touch 'resultp' */
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
}
* Check whether the final response has expected the RCODE according to
* the test scenario.
*/
-static ns_hookresult_t
+static dns_hookresult_t
hook_donesend(void *arg, void *data, isc_result_t *resultp) {
query_ctx_t *qctx = arg;
hookasync_e2e_data_t *asdata = data;
INSIST(qctx->client->message->rcode == asdata->expected_rcode);
asdata->done = true; /* Let the test know this hook is called */
*resultp = ISC_R_UNSET;
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
static void
.expected_rcode = test->expected_rcode,
.done = false,
};
- const ns_hook_t donesend_hook = {
+ const dns_hook_t donesend_hook = {
.action = hook_donesend,
.action_data = &asdata,
};
- const ns_hook_t hook = {
+ const dns_hook_t hook = {
.action = hook_async_e2e,
.action_data = &asdata,
};
.with_cache = true,
};
- ns__hook_table = NULL;
- ns_hooktable_create(isc_g_mctx, &ns__hook_table);
- ns_hook_add(ns__hook_table, isc_g_mctx, test->hookpoint, &hook);
- ns_hook_add(ns__hook_table, isc_g_mctx, NS_QUERY_DONE_SEND,
- &donesend_hook);
+ dns__hook_table = NULL;
+ dns_hooktable_create(isc_g_mctx, &dns__hook_table);
+ dns_hook_add(dns__hook_table, isc_g_mctx, test->hookpoint, &hook);
+ dns_hook_add(dns__hook_table, isc_g_mctx, NS_QUERY_DONE_SEND,
+ &donesend_hook);
result = ns_test_qctx_create(&qctx_params, &qctx);
INSIST(result == ISC_R_SUCCESS);
/* Cleanup */
ns_test_qctx_destroy(&qctx);
ns_test_cleanup_zone();
- ns_hooktable_free(isc_g_mctx, (void **)&ns__hook_table);
+ dns_hooktable_free(isc_g_mctx, (void **)&dns__hook_table);
}
ISC_LOOP_TEST_IMPL(ns__query_hookasync_e2e) {
/*
* Tests covering the correctness of hook call order, i.e. hooks from a zone are
* called first, then hooks from a view, then the default hook table. And any
- * hook returning NS_HOOK_RETURN interrupt the whole chain
+ * hook returning DNS_HOOK_RETURN interrupt the whole chain
*/
typedef struct {
- ns_hook_action_t zonehookactions[2];
- ns_hook_action_t viewhookactions[2];
- ns_hook_action_t defaulthookactions[2];
+ dns_hook_action_t zonehookactions[2];
+ dns_hook_action_t viewhookactions[2];
+ dns_hook_action_t defaulthookactions[2];
const char *expected;
} ns__query_hook_test_params_t;
snprintf(base, sizeof(b), "%s%s", b, tail);
}
-static ns_hookresult_t
+static dns_hookresult_t
ns__query_test_zonehook1(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(resultp);
ns__query_test_concat(data, "z1");
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
-static ns_hookresult_t
+static dns_hookresult_t
ns__query_test_zonehook2(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(resultp);
ns__query_test_concat(data, "z2");
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
-static ns_hookresult_t
+static dns_hookresult_t
ns__query_test_viewhook1(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(resultp);
ns__query_test_concat(data, "v1");
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
-static ns_hookresult_t
+static dns_hookresult_t
ns__query_test_viewhook2(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(resultp);
ns__query_test_concat(data, "v2");
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
-static ns_hookresult_t
+static dns_hookresult_t
ns__query_test_defaulthook1(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(resultp);
ns__query_test_concat(data, "d1");
- return NS_HOOK_CONTINUE;
+ return DNS_HOOK_CONTINUE;
}
-static ns_hookresult_t
+static dns_hookresult_t
ns__query_test_defaulthook2(void *arg, void *data, isc_result_t *resultp) {
UNUSED(arg);
UNUSED(resultp);
ns__query_test_concat(data, "d2");
- return NS_HOOK_RETURN;
+ return DNS_HOOK_RETURN;
}
static bool
-ns__query_test_setup_hooks(const ns_hook_t *h1, const ns_hook_t *h2,
- ns_hooktable_t **tp) {
+ns__query_test_setup_hooks(const dns_hook_t *h1, const dns_hook_t *h2,
+ dns_hooktable_t **tp) {
if (h1->action || h2->action) {
INSIST(*tp == NULL);
- ns_hooktable_create(isc_g_mctx, tp);
+ dns_hooktable_create(isc_g_mctx, tp);
if (h1->action) {
- ns_hook_add(*tp, isc_g_mctx, NS_QUERY_NXDOMAIN_BEGIN,
- h1);
+ dns_hook_add(*tp, isc_g_mctx, NS_QUERY_NXDOMAIN_BEGIN,
+ h1);
}
if (h2->action) {
- ns_hook_add(*tp, isc_g_mctx, NS_QUERY_NXDOMAIN_BEGIN,
- h2);
+ dns_hook_add(*tp, isc_g_mctx, NS_QUERY_NXDOMAIN_BEGIN,
+ h2);
}
return true;
isc_result_t result;
query_ctx_t *qctx = NULL;
char buffer[512] = { 0 };
- ns_hooktable_t *zone_hooktab = NULL;
- ns_hooktable_t *view_hooktab = NULL;
+ dns_hooktable_t *zone_hooktab = NULL;
+ dns_hooktable_t *view_hooktab = NULL;
const ns_test_qctx_create_params_t qctx_params = {
.qname = "idontexists.foo",
.with_cache = true,
};
- const ns_hook_t zonehook1 = { .action = test->zonehookactions[0],
- .action_data = buffer };
+ const dns_hook_t zonehook1 = { .action = test->zonehookactions[0],
+ .action_data = buffer };
- const ns_hook_t zonehook2 = { .action = test->zonehookactions[1],
- .action_data = buffer };
+ const dns_hook_t zonehook2 = { .action = test->zonehookactions[1],
+ .action_data = buffer };
- const ns_hook_t viewhook1 = { .action = test->viewhookactions[0],
- .action_data = buffer };
+ const dns_hook_t viewhook1 = { .action = test->viewhookactions[0],
+ .action_data = buffer };
- const ns_hook_t viewhook2 = { .action = test->viewhookactions[1],
- .action_data = buffer };
+ const dns_hook_t viewhook2 = { .action = test->viewhookactions[1],
+ .action_data = buffer };
- const ns_hook_t defaulthook1 = { .action = test->defaulthookactions[0],
- .action_data = buffer };
+ const dns_hook_t defaulthook1 = { .action = test->defaulthookactions[0],
+ .action_data = buffer };
- const ns_hook_t defaulthook2 = { .action = test->defaulthookactions[1],
- .action_data = buffer };
+ const dns_hook_t defaulthook2 = { .action = test->defaulthookactions[1],
+ .action_data = buffer };
/*
* Create a fake query context
* Setup the default hook table
*/
(void)ns__query_test_setup_hooks(&defaulthook1, &defaulthook2,
- &ns__hook_table);
+ &dns__hook_table);
/*
* Handling the response
ns_test_qctx_destroy(&qctx);
ns_test_cleanup_zone();
- if (ns__hook_table) {
- ns_hooktable_free(isc_g_mctx, (void **)&ns__hook_table);
+ if (dns__hook_table) {
+ dns_hooktable_free(isc_g_mctx, (void **)&dns__hook_table);
}
if (view_hooktab) {
- ns_hooktable_free(isc_g_mctx, (void **)&view_hooktab);
+ dns_hooktable_free(isc_g_mctx, (void **)&view_hooktab);
}
}