Asterisk - The Open Source Telephony Project
18.5.0
|
#include "asterisk.h"
#include <signal.h>
#include <unbound.h>
#include <arpa/nameser.h>
#include "asterisk/module.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dns_core.h"
#include "asterisk/dns_resolver.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "asterisk/test.h"
#include "asterisk/dns_srv.h"
#include "asterisk/dns_naptr.h"
Go to the source code of this file.
Data Structures | |
struct | async_data |
Data required for an asynchronous callback. More... | |
struct | async_minimal_data |
Minimal data required to signal the completion of an async resolve. More... | |
struct | dns_record |
A DNS record to be used during a test. More... | |
struct | off_nominal_async_data |
User data for off-nominal async resolution test. More... | |
struct | unbound_config |
A container for config related information. More... | |
struct | unbound_config_state |
Unbound configuration state information. More... | |
struct | unbound_global_config |
A structure to hold global configuration-related options. More... | |
struct | unbound_resolver |
Structure for an unbound resolver. More... | |
struct | unbound_resolver_data |
Structure for query resolver data. More... | |
Typedefs | |
typedef int(* | off_nominal_resolve_fn) (struct ast_test *test, const char *domain, int rr_type, int rr_class, int expected_rcode) |
typedef int(* | resolve_fn) (struct ast_test *test, const char *domain, int rr_type, int rr_class, struct dns_record *records, size_t num_records) |
Resolution function for tests. More... | |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static | AO2_GLOBAL_OBJ_STATIC (globals) |
A global object container that will contain the global_config that gets swapped out on reloads. More... | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
AST_TEST_DEFINE (resolve_sync) | |
AST_TEST_DEFINE (resolve_async) | |
AST_TEST_DEFINE (resolve_sync_off_nominal) | |
AST_TEST_DEFINE (resolve_async_off_nominal) | |
AST_TEST_DEFINE (resolve_cancel_off_nominal) | |
AST_TEST_DEFINE (resolve_naptr) | |
AST_TEST_DEFINE (resolve_srv) | |
static void | async_callback (const struct ast_dns_query *query) |
Callback for asynchronous queries. More... | |
static struct async_data * | async_data_alloc (struct dns_record *records, size_t num_records) |
static void | async_data_destructor (void *obj) |
static struct async_minimal_data * | async_minimal_data_alloc (void) |
static void | async_minimal_data_destructor (void *obj) |
CONFIG_INFO_STANDARD (cfg_info, globals, unbound_config_alloc,.files=ACO_FILES(&resolver_unbound_conf),.pre_apply_config=unbound_config_preapply_callback,) | |
Register information about the configs being processed by this module. More... | |
static int | custom_nameserver_handler (const struct aco_option *opt, struct ast_variable *var, void *obj) |
static int | load_module (void) |
static void | minimal_callback (const struct ast_dns_query *query) |
Async callback for off-nominal cancellation test. More... | |
static int | nominal_async_run (struct ast_test *test, const char *domain, int rr_type, int rr_class, struct dns_record *records, size_t num_records) |
Pluggable function for performing an asynchronous query during a test. More... | |
static int | nominal_sync_run (struct ast_test *test, const char *domain, int rr_type, int rr_class, struct dns_record *records, size_t num_records) |
Pluggable function for running a synchronous query and checking its results. More... | |
static enum ast_test_result_state | nominal_test (struct ast_test *test, resolve_fn runner) |
Framework for running a nominal DNS test. More... | |
static void | off_nominal_async_callback (const struct ast_dns_query *query) |
Async callback for off-nominal async test. More... | |
static struct off_nominal_async_data * | off_nominal_async_data_alloc (int expected_rcode) |
static void | off_nominal_async_data_destructor (void *obj) |
static int | off_nominal_async_run (struct ast_test *test, const char *domain, int rr_type, int rr_class, int expected_rcode) |
static int | off_nominal_sync_run (struct ast_test *test, const char *domain, int rr_type, int rr_class, int expected_rcode) |
static enum ast_test_result_state | off_nominal_test (struct ast_test *test, off_nominal_resolve_fn runner) |
static int | reload_module (void) |
static void * | unbound_config_alloc (void) |
Allocate a unbound_config to hold a snapshot of the complete results of parsing a config. More... | |
static int | unbound_config_apply_default (void) |
static void | unbound_config_destructor (void *obj) |
static int | unbound_config_preapply (struct unbound_config *cfg) |
static int | unbound_config_preapply_callback (void) |
Finish initializing new configuration. More... | |
static void | unbound_config_state_destructor (void *obj) |
static void | unbound_global_config_destructor (void *obj) |
static struct unbound_resolver * | unbound_resolver_alloc (void) |
Allocator for unbound resolver. More... | |
static void | unbound_resolver_callback (void *data, int err, struct ub_result *ub_result) |
Callback invoked when resolution completes on a query. More... | |
static int | unbound_resolver_cancel (struct ast_dns_query *query) |
static void | unbound_resolver_data_dtor (void *vdoomed) |
static void | unbound_resolver_destroy (void *obj) |
Destructor for unbound resolver. More... | |
static int | unbound_resolver_resolve (struct ast_dns_query *query) |
static int | unbound_resolver_start (struct unbound_resolver *resolver) |
Start function for the unbound resolver. More... | |
static void | unbound_resolver_stop (struct unbound_resolver *resolver) |
Stop function for the unbound resolver. More... | |
static void * | unbound_resolver_thread (void *data) |
Resolver thread which waits and handles results. More... | |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Unbound DNS Resolver Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND - 4, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct aco_type | global_option |
An aco_type structure to link the "general" category to the unbound_global_config type. More... | |
static struct aco_type * | global_options [] = ACO_TYPES(&global_option) |
static struct aco_file | resolver_unbound_conf |
struct ast_dns_resolver | unbound_resolver |
typedef int(* off_nominal_resolve_fn) (struct ast_test *test, const char *domain, int rr_type, int rr_class, int expected_rcode) |
Definition at line 876 of file res_resolver_unbound.c.
typedef int(* resolve_fn) (struct ast_test *test, const char *domain, int rr_type, int rr_class, struct dns_record *records, size_t num_records) |
Resolution function for tests.
Several tests will have similar setups but will want to make use of a different means of actually making queries and checking their results. This pluggable function pointer allows for similar tests to be operated in different ways.
test | The test being run |
domain | The domain to look up |
rr_type | The record type to look up |
rr_class | The class of record to look up |
records | All records that exist for the test. |
num_records | Number of records in the records array. |
0 | The test has passed thus far. |
-1 | The test has failed. |
Definition at line 545 of file res_resolver_unbound.c.
|
static |
Definition at line 1474 of file res_resolver_unbound.c.
|
static |
Definition at line 1474 of file res_resolver_unbound.c.
|
static |
A global object container that will contain the global_config that gets swapped out on reloads.
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1474 of file res_resolver_unbound.c.
AST_TEST_DEFINE | ( | resolve_sync | ) |
Definition at line 827 of file res_resolver_unbound.c.
References AST_TEST_NOT_RUN, sip_to_pjsip::info(), nominal_sync_run(), nominal_test(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolve_async | ) |
Definition at line 852 of file res_resolver_unbound.c.
References AST_TEST_NOT_RUN, sip_to_pjsip::info(), nominal_async_run(), nominal_test(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolve_sync_off_nominal | ) |
Definition at line 1069 of file res_resolver_unbound.c.
References AST_TEST_NOT_RUN, sip_to_pjsip::info(), off_nominal_sync_run(), off_nominal_test(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolve_async_off_nominal | ) |
Definition at line 1088 of file res_resolver_unbound.c.
References AST_TEST_NOT_RUN, sip_to_pjsip::info(), off_nominal_async_run(), off_nominal_test(), TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolve_cancel_off_nominal | ) |
Definition at line 1154 of file res_resolver_unbound.c.
References ao2_cleanup, ast_cond_wait, ast_dns_resolve_async(), ast_dns_resolve_cancel(), ast_mutex_lock, ast_mutex_unlock, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, async_minimal_data_alloc(), sip_to_pjsip::info(), minimal_callback(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.
AST_TEST_DEFINE | ( | resolve_naptr | ) |
Definition at line 1199 of file res_resolver_unbound.c.
References ao2_bump, ao2_cleanup, ao2_global_obj_ref, ARRAY_LEN, ast_dns_naptr_get_flags(), ast_dns_naptr_get_order(), ast_dns_naptr_get_preference(), ast_dns_naptr_get_regexp(), ast_dns_naptr_get_replacement(), ast_dns_naptr_get_service(), ast_dns_record_get_next(), ast_dns_resolve(), ast_dns_result_free(), ast_dns_result_get_records(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, globals, sip_to_pjsip::info(), NULL, order, RAII_VAR, result, TEST_EXECUTE, TEST_INIT, and dns_record::visited.
AST_TEST_DEFINE | ( | resolve_srv | ) |
Definition at line 1316 of file res_resolver_unbound.c.
References ao2_bump, ao2_cleanup, ao2_global_obj_ref, ast_dns_resolve(), ast_dns_result_free(), ast_dns_result_get_records(), ast_dns_srv_get_host(), ast_dns_srv_get_port(), ast_dns_srv_get_priority(), ast_dns_srv_get_weight(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, cleanup(), globals, sip_to_pjsip::info(), NULL, RAII_VAR, result, TEST_EXECUTE, and TEST_INIT.
|
static |
Callback for asynchronous queries.
This query will check that the records in the DNS result match records that the test has created. The success or failure of the query is indicated through the async_data failed field.
query | The DNS query that has been resolved |
Definition at line 649 of file res_resolver_unbound.c.
References ast_cond_signal, ast_dns_query_get_data(), ast_dns_query_get_result(), ast_dns_record_get_data(), ast_dns_record_get_next(), ast_dns_record_get_rr_class(), ast_dns_record_get_rr_type(), ast_dns_record_get_ttl(), ast_dns_result_get_records(), ast_mutex_lock, ast_mutex_unlock, dns_record::buf, dns_record::bufsize, async_data::complete, async_data::cond, end, async_data::failed, async_data::lock, match(), async_data::num_records, async_data::records, result, dns_record::rr_class, dns_record::rr_type, dns_record::ttl, and dns_record::visited.
Referenced by nominal_async_run().
|
static |
Definition at line 623 of file res_resolver_unbound.c.
References ao2_alloc, ast_cond_init, ast_mutex_init, async_data_destructor(), async_data::cond, async_data::lock, NULL, async_data::num_records, records, and async_data::records.
Referenced by nominal_async_run().
|
static |
Definition at line 615 of file res_resolver_unbound.c.
References ast_cond_destroy, ast_mutex_destroy, async_data::cond, and async_data::lock.
Referenced by async_data_alloc().
|
static |
Definition at line 1124 of file res_resolver_unbound.c.
References ao2_alloc, ast_cond_init, ast_mutex_init, async_minimal_data_destructor(), async_minimal_data::cond, async_minimal_data::lock, and NULL.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 1116 of file res_resolver_unbound.c.
References ast_cond_destroy, ast_mutex_destroy, async_minimal_data::cond, and async_minimal_data::lock.
Referenced by async_minimal_data_alloc().
CONFIG_INFO_STANDARD | ( | cfg_info | , |
globals | , | ||
unbound_config_alloc | , | ||
. | files = ACO_FILES(&resolver_unbound_conf) , |
||
. | pre_apply_config = unbound_config_preapply_callback |
||
) |
Register information about the configs being processed by this module.
|
static |
Definition at line 1409 of file res_resolver_unbound.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ast_str_container_add(), ast_str_container_alloc_options(), global, unbound_global_config::nameservers, and ast_variable::value.
Referenced by load_module().
|
static |
Definition at line 1423 of file res_resolver_unbound.c.
References ACO_EXACT, aco_info_init(), aco_option_register, aco_option_register_custom, aco_process_config(), ACO_PROCESS_ERROR, ast_config_destroy(), ast_config_load, ast_dns_resolver_register(), AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CHANNEL_DEPEND, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_module_shutdown_ref, AST_MODULE_SUPPORT_CORE, AST_TEST_REGISTER, ASTERISK_GPL_KEY, custom_nameserver_handler(), debug, aco_file::filename, FLDSET, OPT_STRINGFIELD_T, OPT_UINT_T, reload(), reload_module(), ast_module_info::self, STRFLDSET, unbound_config_apply_default(), and unload_module().
|
static |
Async callback for off-nominal cancellation test.
This simply signals the testing thread that the query completed
Definition at line 1144 of file res_resolver_unbound.c.
References ast_cond_signal, ast_dns_query_get_data(), ast_mutex_lock, ast_mutex_unlock, async_minimal_data::complete, async_minimal_data::cond, and async_minimal_data::lock.
Referenced by AST_TEST_DEFINE().
|
static |
Pluggable function for performing an asynchronous query during a test.
Unlike the synchronous version, this does not check the records, instead leaving that to be done in the asynchronous callback.
Definition at line 695 of file res_resolver_unbound.c.
References ao2_cleanup, ast_cond_wait, ast_dns_resolve_async(), ast_mutex_lock, ast_mutex_unlock, ast_test_status_update, async_callback(), async_data_alloc(), NULL, RAII_VAR, and dns_record::visited.
Referenced by AST_TEST_DEFINE().
|
static |
Pluggable function for running a synchronous query and checking its results.
Definition at line 551 of file res_resolver_unbound.c.
References ast_dns_record_get_data(), ast_dns_record_get_next(), ast_dns_record_get_rr_class(), ast_dns_record_get_rr_type(), ast_dns_record_get_ttl(), ast_dns_resolve(), ast_dns_result_free(), ast_dns_result_get_records(), ast_test_status_update, buf, match(), NULL, RAII_VAR, result, dns_record::rr_class, dns_record::rr_type, dns_record::ttl, and dns_record::visited.
Referenced by AST_TEST_DEFINE().
|
static |
Framework for running a nominal DNS test.
Synchronous and asynchronous tests mostly have the same setup, so this function serves as a common way to set up both types of tests by accepting a pluggable function to determine which type of lookup is used
test | The test being run |
runner | The method for resolving queries on this test |
Definition at line 743 of file res_resolver_unbound.c.
References ao2_bump, ao2_cleanup, ao2_global_obj_ref, ARRAY_LEN, dns_record::as_string, AST_TEST_FAIL, AST_TEST_PASS, ast_test_status_update, cleanup(), globals, NULL, and RAII_VAR.
Referenced by AST_TEST_DEFINE().
|
static |
Async callback for off-nominal async test.
This test ensures that there is a result present on the query, then it checks that the rcode on the result is the expected value and that there are no records on the result.
Once completed, the testing thread is signaled that the async query has completed.
Definition at line 958 of file res_resolver_unbound.c.
References ast_cond_signal, ast_dns_query_get_data(), ast_dns_query_get_result(), ast_dns_result_get_rcode(), ast_dns_result_get_records(), ast_mutex_lock, ast_mutex_unlock, off_nominal_async_data::complete, off_nominal_async_data::cond, end, off_nominal_async_data::expected_rcode, off_nominal_async_data::failed, off_nominal_async_data::lock, and result.
Referenced by off_nominal_async_run().
|
static |
Definition at line 931 of file res_resolver_unbound.c.
References ao2_alloc, ast_cond_init, ast_mutex_init, off_nominal_async_data::cond, off_nominal_async_data::expected_rcode, off_nominal_async_data::lock, NULL, and off_nominal_async_data_destructor().
Referenced by off_nominal_async_run().
|
static |
Definition at line 923 of file res_resolver_unbound.c.
References ast_cond_destroy, ast_mutex_destroy, off_nominal_async_data::cond, and off_nominal_async_data::lock.
Referenced by off_nominal_async_data_alloc().
|
static |
Definition at line 983 of file res_resolver_unbound.c.
References ao2_cleanup, ast_cond_wait, ast_dns_resolve_async(), ast_mutex_lock, ast_mutex_unlock, ast_test_status_update, NULL, off_nominal_async_callback(), off_nominal_async_data_alloc(), and RAII_VAR.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 879 of file res_resolver_unbound.c.
References ast_dns_resolve(), ast_dns_result_free(), ast_dns_result_get_rcode(), ast_dns_result_get_records(), ast_test_status_update, and result.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 1015 of file res_resolver_unbound.c.
References ao2_bump, ao2_cleanup, ao2_global_obj_ref, ARRAY_LEN, dns_record::as_string, AST_TEST_FAIL, AST_TEST_PASS, globals, NULL, and RAII_VAR.
Referenced by AST_TEST_DEFINE().
|
static |
Definition at line 1385 of file res_resolver_unbound.c.
References aco_process_config(), ACO_PROCESS_ERROR, and AST_MODULE_RELOAD_ERROR.
Referenced by load_module().
|
static |
Allocate a unbound_config to hold a snapshot of the complete results of parsing a config.
Definition at line 365 of file res_resolver_unbound.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_string_field_init, error(), unbound_config::global, NULL, unbound_config_destructor(), and unbound_global_config_destructor().
Referenced by unbound_config_apply_default().
|
static |
Definition at line 472 of file res_resolver_unbound.c.
References aco_set_defaults(), ao2_global_obj_replace_unref, ao2_ref, ast_log, ast_verb, unbound_config::global, globals, LOG_ERROR, unbound_config_alloc(), and unbound_config_preapply().
Referenced by load_module().
|
static |
Definition at line 339 of file res_resolver_unbound.c.
References ao2_cleanup, and unbound_config::global.
Referenced by unbound_config_alloc().
|
static |
Definition at line 391 of file res_resolver_unbound.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_log, ast_strlen_zero, unbound_resolver::context, unbound_global_config::debug, unbound_config::global, unbound_global_config::hosts, LOG_ERROR, unbound_global_config::nameservers, NULL, unbound_global_config::resolv, unbound_config_state::resolver, unbound_global_config::state, unbound_global_config::ta_file, unbound_config_state_destructor(), unbound_resolver_alloc(), and unbound_resolver_start().
Referenced by unbound_config_apply_default(), and unbound_config_preapply_callback().
|
static |
Finish initializing new configuration.
Definition at line 497 of file res_resolver_unbound.c.
References aco_pending_config(), and unbound_config_preapply().
|
static |
Definition at line 355 of file res_resolver_unbound.c.
References ao2_ref, unbound_config_state::resolver, and unbound_resolver_stop().
Referenced by unbound_config_preapply().
|
static |
Definition at line 346 of file res_resolver_unbound.c.
References ao2_cleanup, ast_string_field_free_memory, global, unbound_global_config::nameservers, and unbound_global_config::state.
Referenced by unbound_config_alloc().
|
static |
Allocator for unbound resolver.
Definition at line 171 of file res_resolver_unbound.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, AST_PTHREADT_NULL, unbound_resolver::context, NULL, unbound_resolver::thread, and unbound_resolver_destroy().
Referenced by unbound_config_preapply().
|
static |
Callback invoked when resolution completes on a query.
Definition at line 256 of file res_resolver_unbound.c.
References ao2_ref, ast_dns_query_get_name(), ast_dns_resolver_add_record(), ast_dns_resolver_completed(), ast_dns_resolver_set_result(), and S_OR.
Referenced by unbound_resolver_resolve().
|
static |
Definition at line 316 of file res_resolver_unbound.c.
References ao2_ref, ast_dns_resolver_get_data(), unbound_resolver::context, unbound_resolver_data::id, and unbound_resolver_data::resolver.
|
static |
Definition at line 278 of file res_resolver_unbound.c.
References ao2_cleanup, and unbound_resolver_data::resolver.
Referenced by unbound_resolver_resolve().
|
static |
Destructor for unbound resolver.
Definition at line 161 of file res_resolver_unbound.c.
References unbound_resolver::context.
Referenced by unbound_resolver_alloc().
|
static |
Definition at line 285 of file res_resolver_unbound.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_global_obj_ref, ao2_ref, ast_dns_query_get_name(), ast_dns_query_get_rr_class(), ast_dns_query_get_rr_type(), ast_dns_resolver_set_data(), ast_log, unbound_resolver::context, unbound_config::global, globals, unbound_resolver_data::id, LOG_ERROR, unbound_resolver_data::resolver, unbound_config_state::resolver, unbound_global_config::state, unbound_resolver_callback(), and unbound_resolver_data_dtor().
|
static |
Start function for the unbound resolver.
Definition at line 217 of file res_resolver_unbound.c.
References ao2_bump, ao2_ref, ast_debug, ast_pthread_create, AST_PTHREADT_NULL, NULL, unbound_resolver::thread, and unbound_resolver_thread().
Referenced by unbound_config_preapply().
|
static |
Stop function for the unbound resolver.
Definition at line 237 of file res_resolver_unbound.c.
References ast_debug, AST_PTHREADT_NULL, AST_PTHREADT_STOP, NULL, and unbound_resolver::thread.
Referenced by unbound_config_state_destructor().
|
static |
Resolver thread which waits and handles results.
Definition at line 195 of file res_resolver_unbound.c.
References ao2_ref, ast_debug, AST_PTHREADT_STOP, ast_wait_for_input(), unbound_resolver::context, NULL, and unbound_resolver::thread.
Referenced by unbound_resolver_start().
|
static |
Definition at line 1394 of file res_resolver_unbound.c.
References aco_info_destroy(), ao2_global_obj_release, AST_TEST_UNREGISTER, and globals.
Referenced by load_module().
|
static |
Definition at line 1474 of file res_resolver_unbound.c.
|
static |
Definition at line 1474 of file res_resolver_unbound.c.
|
static |
An aco_type structure to link the "general" category to the unbound_global_config type.
Definition at line 130 of file res_resolver_unbound.c.
|
static |
Definition at line 138 of file res_resolver_unbound.c.
|
static |
Definition at line 140 of file res_resolver_unbound.c.
struct ast_dns_resolver unbound_resolver |
Definition at line 332 of file res_resolver_unbound.c.