26 #include <arpa/nameser.h> 27 #include <arpa/inet.h> 75 #define DNS_ANSWER "Yes sirree" 76 #define DNS_ANSWER_SIZE strlen(DNS_ANSWER) 115 pthread_t resolver_thread;
188 struct timespec timeout;
209 qsdata->resolves_allowed = resolve;
210 qsdata->cancel_allowed =
cancel;
212 for (idx = 0; idx <
total; ++idx) {
228 if (cancel && (cancel == total)) {
234 if (qsdata->query_set_complete) {
249 timeout.tv_sec += 10;
252 while (!qsdata->query_set_complete) {
259 if (!qsdata->query_set_complete) {
291 info->name =
"query_set";
292 info->category =
"/main/dns/query_set/";
293 info->summary =
"Test nominal asynchronous DNS query set";
295 "This tests nominal query set in the following ways:\n" 296 "\t* Multiple queries are added to a query set\n" 297 "\t* The mock resolver is configured to respond to all queries\n" 298 "\t* Asynchronous resolution of the query set is started\n" 299 "\t* The mock resolver responds to all queries\n" 300 "\t* We ensure that the query set callback is invoked upon completion";
313 info->name =
"query_set_empty";
314 info->category =
"/main/dns/query_set/";
315 info->summary =
"Test nominal asynchronous empty DNS query set";
317 "This tests nominal query set in the following ways:\n" 318 "\t* No queries are added to a query set\n" 319 "\t* Asynchronous resolution of the query set is started\n" 320 "\t* We ensure that the query set callback is invoked upon completion";
333 info->name =
"query_set_nominal_cancel";
334 info->category =
"/main/dns/query_set/";
335 info->summary =
"Test nominal asynchronous DNS query set cancellation";
337 "This tests nominal query set cancellation in the following ways:\n" 338 "\t* Multiple queries are added to a query set\n" 339 "\t* The mock resolver is configured to NOT respond to any queries\n" 340 "\t* Asynchronous resolution of the query set is started\n" 341 "\t* The query set is canceled and is confirmed to return with success";
354 info->name =
"query_set_off_nominal_cancel";
355 info->category =
"/main/dns/query_set/";
356 info->summary =
"Test off-nominal asynchronous DNS query set cancellation";
358 "This tests nominal query set cancellation in the following ways:\n" 359 "\t* Multiple queries are added to a query set\n" 360 "\t* The mock resolver is configured to respond to half the queries\n" 361 "\t* Asynchronous resolution of the query set is started\n" 362 "\t* The query set is canceled and is confirmed to return failure\n" 363 "\t* The query set callback is confirmed to run, since it could not be fully canceled";
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_dns_query_get_name(const struct ast_dns_query *query)
Get the name queried in a DNS query.
int ast_dns_query_get_rr_class(const struct ast_dns_query *query)
Get the record resource class of a DNS query.
#define ast_pthread_create_detached(a, b, c, d)
void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver)
Unregister a DNS resolver.
void * user_data
User-specific data.
static void * resolution_thread(void *dns_query)
Thread that performs asynchronous resolution.
static void query_set_data_destructor(void *obj)
struct ast_dns_query_set * ast_dns_query_set_create(void)
Create a query set to hold queries.
static struct ast_dns_resolver query_set_resolver
#define AST_TEST_REGISTER(cb)
#define ast_cond_init(cond, attr)
#define ast_mutex_lock(a)
static enum ast_test_result_state query_set_test(struct ast_test *test, int resolve, int cancel)
Framework for running a query set DNS test.
#define ast_cond_signal(cond)
const char * name
The name of the resolver implementation.
pthread_cond_t ast_cond_t
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
void * ast_dns_query_get_data(const struct ast_dns_query *query)
Get the user specific data of a DNS query.
static int load_module(void)
struct ast_dns_query * ast_dns_query_set_get(const struct ast_dns_query_set *query_set, unsigned int index)
Retrieve a query from a query set.
int ast_dns_resolver_register(struct ast_dns_resolver *resolver)
Register a DNS resolver.
#define ao2_ref(o, delta)
static int query_set_cancel(struct ast_dns_query *query)
Resolver's cancel() method.
static int query_set_resolve(struct ast_dns_query *query)
Resolver's resolve() method.
void ast_dns_resolver_completed(struct ast_dns_query *query)
Mark a DNS query as having been completed.
#define AST_TEST_UNREGISTER(cb)
static struct query_set_data * query_set_data_alloc(void)
#define ast_cond_destroy(cond)
#define ao2_alloc(data_size, destructor_fn)
DNS resolver implementation.
Internal DNS structure definitions.
int ast_dns_query_set_resolve_cancel(struct ast_dns_query_set *query_set)
Cancel an asynchronous DNS query set resolution.
Vector container support.
static void * cleanup(void *unused)
int ast_dns_query_get_rr_type(const struct ast_dns_query *query)
Get the record resource type of a DNS query.
int ast_dns_query_set_add(struct ast_dns_query_set *query_set, const char *name, int rr_type, int rr_class)
Add a query to a query set.
static int unload_module(void)
struct timespec ast_tsnow(void)
Returns current timespec. Meant to avoid calling ast_tvnow() just to create a timespec from the timev...
#define ast_mutex_init(pmutex)
size_t ast_dns_query_set_num_queries(const struct ast_dns_query_set *query_set)
Retrieve the number of queries in a query set.
#define ast_mutex_destroy(a)
static void query_set_callback(const struct ast_dns_query_set *query_set)
Callback which is invoked upon query set completion.
#define ASTERISK_GPL_KEY
The text the key() function should return.
int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure, unsigned int bogus, unsigned int rcode, const char *canonical, const char *answer, size_t answer_size)
Set result information for a DNS query.
Asterisk module definitions.
#define ast_cond_timedwait(cond, mutex, time)
void ast_dns_query_set_resolve_async(struct ast_dns_query_set *query_set, ast_dns_query_set_callback callback, void *data)
Asynchronously resolve queries in a query set.
AST_TEST_DEFINE(query_set)
Structure for mutex and tracking information.
void * ast_dns_query_set_get_data(const struct ast_dns_query_set *query_set)
Retrieve user specific data from a query set.
#define ast_mutex_unlock(a)