26 #include <arpa/nameser.h> 27 #include <arpa/inet.h> 80 #define DNS_ANSWER "Yes sirree" 81 #define DNS_ANSWER_SIZE strlen(DNS_ANSWER) 97 static const char *ADDR1 =
"127.0.0.1";
98 static const size_t ADDR1_BUFSIZE =
sizeof(
struct in_addr);
99 char addr1_buf[ADDR1_BUFSIZE];
101 static const char *ADDR2 =
"192.168.0.1";
102 static const size_t ADDR2_BUFSIZE =
sizeof(
struct in_addr);
103 char addr2_buf[ADDR2_BUFSIZE];
134 inet_pton(AF_INET, ADDR1, addr1_buf);
137 inet_pton(AF_INET, ADDR2, addr2_buf);
159 pthread_t resolver_thread;
186 .
name =
"test_recurring",
206 int expected_lapse,
int num_resolves,
int num_completed,
int canceled)
208 struct timespec begin;
210 struct timespec timeout;
215 timeout.tv_sec = begin.tv_sec + 20;
216 timeout.tv_nsec = begin.tv_nsec;
234 secdiff = end.tv_sec - begin.tv_sec;
237 if (secdiff < expected_lapse - 2 || secdiff > expected_lapse + 2) {
279 info->name =
"recurring_query";
280 info->category =
"/main/dns/recurring/";
281 info->summary =
"Test nominal asynchronous recurring DNS queries";
283 "This tests nominal recurring queries in the following ways:\n" 284 "\t* An asynchronous query is sent to a mock resolver\n" 285 "\t* The mock resolver returns two records with different TTLs\n" 286 "\t* We ensure that the query re-occurs according to the lower of the TTLs\n" 287 "\t* The mock resolver returns two records, this time with different TTLs\n" 288 "\t from the first time the query was resolved\n" 289 "\t* We ensure that the query re-occurs according to the new lower TTL";
312 if (!recurring_query) {
324 expected_lapse = rdata->ttl1;
334 expected_lapse = rdata->ttl2;
343 if (recurring_query) {
371 .
name =
"Harold P. Warren's Filmography",
379 struct dns_resolve_data {
386 {
"asterisk.org", -1, C_IN, stub_callback },
387 {
"asterisk.org", 65536 + 1, C_IN, stub_callback },
388 {
"asterisk.org", T_A, -1, stub_callback },
389 {
"asterisk.org", T_A, 65536 + 1, stub_callback },
390 {
"asterisk.org", T_A, C_IN,
NULL },
397 info->name =
"recurring_query_off_nominal";
398 info->category =
"/main/dns/recurring/";
399 info->summary =
"Test off-nominal recurring DNS resolution";
401 "This test performs several off-nominal recurring DNS resolutions:\n" 402 "\t* Attempt resolution with NULL name\n" 403 "\t* Attempt resolution with invalid RR type\n" 404 "\t* Attempt resolution with invalid RR class\n" 405 "\t* Attempt resolution with NULL callback pointer\n" 406 "\t* Attempt resolution with resolver that returns an error";
455 struct timespec timeout;
459 info->name =
"recurring_query_cancel_between";
460 info->category =
"/main/dns/recurring/";
461 info->summary =
"Test canceling a recurring DNS query during the downtime between queries";
462 info->description =
"This test does the following:\n" 463 "\t* Issue a recurring DNS query.\n" 464 "\t* Once results have been returned, cancel the recurring query.\n" 465 "\t* Wait a while to ensure that no more queries are occurring.";
487 if (!recurring_query) {
508 timeout.tv_sec += 10;
511 while (!rdata->query_complete) {
518 if (rdata->query_complete) {
536 struct timespec timeout;
540 info->name =
"recurring_query_cancel_during";
541 info->category =
"/main/dns/recurring/";
542 info->summary =
"Cancel a recurring DNS query while a query is actually happening";
543 info->description =
"This test does the following:\n" 544 "\t* Initiate a recurring DNS query.\n" 545 "\t* Allow the initial query to complete, and a second query to start\n" 546 "\t* Cancel the recurring query while the second query is executing\n" 547 "\t* Ensure that the resolver's cancel() method was called\n" 548 "\t* Wait a while to make sure that recurring queries are no longer occurring";
570 if (!recurring_query) {
582 rdata->cancel_expected = 1;
586 while (!rdata->cancel_ready) {
589 rdata->cancel_expected = 0;
606 timeout.tv_sec += 10;
609 while (!rdata->query_complete) {
616 if (rdata->query_complete) {
static int recurring_resolve(struct ast_dns_query *query)
Resolver's resolve() method.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
int ast_dns_resolver_add_record(struct ast_dns_query *query, int rr_type, int rr_class, int ttl, const char *data, const size_t size)
Add a DNS record to the result of a DNS query.
static struct ast_dns_resolver recurring_resolver
#define ast_pthread_create_detached(a, b, c, d)
static int unload_module(void)
void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver)
Unregister a DNS resolver.
void(* ast_dns_resolve_callback)(const struct ast_dns_query *query)
Callback invoked when a query completes.
#define AST_TEST_REGISTER(cb)
static struct recurring_data * recurring_data_alloc(void)
#define ast_cond_wait(cond, mutex)
#define ast_cond_init(cond, attr)
#define ast_mutex_lock(a)
#define ast_cond_signal(cond)
const char * name
The name of the resolver implementation.
struct ast_dns_query_recurring * ast_dns_resolve_recurring(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
Asynchronously resolve a DNS query, and continue resolving it according to the lowest TTL available...
pthread_cond_t ast_cond_t
int ast_dns_resolve_recurring_cancel(struct ast_dns_query_recurring *recurring)
Cancel an asynchronous recurring DNS resolution.
void * user_data
User-specific data.
#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 wait_for_resolution(struct ast_test *test, struct recurring_data *rdata, int expected_lapse, int num_resolves, int num_completed, int canceled)
Wait for a successful resolution to complete.
int ast_dns_resolver_register(struct ast_dns_resolver *resolver)
Register a DNS resolver.
#define ao2_ref(o, delta)
void ast_dns_resolver_completed(struct ast_dns_query *query)
Mark a DNS query as having been completed.
#define AST_TEST_UNREGISTER(cb)
static int fail_resolve(struct ast_dns_query *query)
static void stub_callback(const struct ast_dns_query *query)
#define ast_cond_destroy(cond)
#define ao2_alloc(data_size, destructor_fn)
static void recurring_data_destructor(void *obj)
DNS resolver implementation.
Internal DNS structure definitions.
AST_TEST_DEFINE(recurring_query)
static void async_callback(const struct ast_dns_query *query)
static void * cleanup(void *unused)
static int load_module(void)
struct timespec ast_tsnow(void)
Returns current timespec. Meant to avoid calling ast_tvnow() just to create a timespec from the timev...
static int recurring_cancel(struct ast_dns_query *query)
Resolver's cancel() method.
static int stub_cancel(struct ast_dns_query *query)
#define ast_mutex_init(pmutex)
#define ast_mutex_destroy(a)
static void * resolution_thread(void *dns_query)
Thread that performs asynchronous resolution.
#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)
Structure for mutex and tracking information.
DNS Recurring Resolution API.
#define ast_mutex_unlock(a)