27 #include <arpa/nameser.h> 56 memcpy(ptr, &priority,
sizeof(priority));
61 memcpy(ptr, &weight,
sizeof(weight));
66 memcpy(ptr, &port,
sizeof(port));
126 int *srv_record_order,
int num_records)
172 if (i != num_records) {
191 { 10, 10, 5060,
"goose.down" },
194 int srv_record_order[] = { 0, };
198 info->name =
"srv_resolve_single_record";
199 info->category =
"/main/dns/srv/";
200 info->summary =
"Test an SRV lookup which returns a single record";
201 info->description =
"This test defines a single SRV record and performs a\n" 202 "resolution of the domain to which they belong. The test ensures that all\n" 203 "fields of the SRV record are parsed correctly";
215 { 20, 10, 5060,
"tacos" },
216 { 10, 10, 5060,
"goose.down" },
218 int srv_record_order[] = { 1, 0};
222 info->name =
"srv_resolve_sort_priority";
223 info->category =
"/main/dns/srv/";
224 info->summary =
"Test an SRV lookup which returns two records with differing priorities";
225 info->description =
"This test defines two SRV records with differing priorities and\n" 226 "performs a resolution of the domain to which they belong. The test ensures that\n" 227 "the two records are sorted according to priority and that all fields of the SRV\n" 228 "records are parsed correctly";
240 { 10, 0, 5060,
"tacos" },
241 { 10, 10, 5060,
"goose.down" },
243 int srv_record_order[] = { 1, 0};
247 info->name =
"srv_resolve_same_priority_zero_weight";
248 info->category =
"/main/dns/srv/";
249 info->summary =
"Test an SRV lookup which returns two records with same priority but different weights";
250 info->description =
"This test defines two SRV records with same priority but different weights and\n" 251 "performs a resolution of the domain to which they belong. The test ensures that\n" 252 "the record with zero weight comes last and that all fields of the SRV\n" 253 "records are parsed correctly";
265 { 10, 10, 5060,
"tacos" },
266 { 10, 20, 5060,
"goose.down" },
269 int srv_record_occurence[2] = { 0, };
275 info->name =
"srv_resolve_same_priority_different_weights";
276 info->category =
"/main/dns/srv/";
277 info->summary =
"Test an SRV lookup which returns two records with same priority but different weights";
278 info->description =
"This test defines two SRV records with same priority but different weights and\n" 279 "performs a resolution of the domain to which they belong. The test ensures that\n" 280 "the record with higher weight occurs more often than the one of lesser weight";
291 for (count = 0; count < 100; count++) {
311 for (i = 0; i <
ARRAY_LEN(records); i++) {
325 srv_record_occurence[i]++;
332 if (srv_record_occurence[0] > srv_record_occurence[1]) {
351 { 10, 10, 5060,
"tacos" },
352 { 10, 20, 5060,
"goose.down" },
353 { 5, 80, 5060,
"moo" },
354 { 5, 10, 5060,
"Canada" },
357 int srv_record_priority[4] = { 5, 5, 10, 10 };
358 int srv_record_occurence[4] = { 0, };
364 info->name =
"srv_resolve_different_priorities_different_weights";
365 info->category =
"/main/dns/srv/";
366 info->summary =
"Test an SRV lookup which returns four records with different priority and different weights";
367 info->description =
"This test defines four SRV records, two with one priority and two with another priority,\n" 368 "and different weights and performs a resolution of the domain to which they belong.\n" 369 "The test ensures that the priorities are sorted properly and that the records with higher weight\n" 370 "occur more often than the ones of less weight.";
381 for (count = 0; count < 100; count++) {
410 for (i = 0; i <
ARRAY_LEN(records); i++) {
424 srv_record_occurence[i]++;
431 if (srv_record_occurence[0] > srv_record_occurence[1]) {
436 if (srv_record_occurence[3] > srv_record_occurence[2]) {
497 { 10, 10, 5060,
"tacos.com", 0, 1, 1, 1 },
502 info->name =
"srv_resolve_record_missing_weight_port_host";
503 info->category =
"/main/dns/srv/";
504 info->summary =
"Test an SRV lookup which returns a single invalid record";
505 info->description =
"This test defines a single SRV record and performs a\n" 506 "resolution of the domain to which they belong. The test ensures that the\n" 507 "record is determined to be corrupt as it contains only a priority";
519 { 10, 10, 5060,
"tacos.com", 0, 0, 1, 1 },
524 info->name =
"srv_resolve_record_missing_port_host";
525 info->category =
"/main/dns/srv/";
526 info->summary =
"Test an SRV lookup which returns a single invalid record";
527 info->description =
"This test defines a single SRV record and performs a\n" 528 "resolution of the domain to which they belong. The test ensures that the\n" 529 "record is determined to be corrupt as it contains only a priority and weight";
541 { 10, 10, 5060,
"tacos.com", 0, 0, 0, 1 },
546 info->name =
"srv_resolve_record_missing_host";
547 info->category =
"/main/dns/srv/";
548 info->summary =
"Test an SRV lookup which returns a single invalid record";
549 info->description =
"This test defines a single SRV record and performs a\n" 550 "resolution of the domain to which they belong. The test ensures that the\n" 551 "record is determined to be corrupt as it contains only a priority, weight,\n" static int generate_srv_record(void *dns_record, char *buf)
unsigned short ast_dns_srv_get_priority(const struct ast_dns_record *record)
Get the priority from an SRV record.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
const struct ast_dns_record * ast_dns_record_get_next(const struct ast_dns_record *record)
Get the next DNS record.
Asterisk main include file. File version handling, generic pbx functions.
int ast_dns_resolve(const char *name, int rr_type, int rr_class, struct ast_dns_result **result)
Synchronously resolve a DNS query.
void ast_dns_result_free(struct ast_dns_result *result)
Free the DNS result information.
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.
#define ast_pthread_create_detached(a, b, c, d)
void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver)
Unregister a DNS resolver.
int ast_dns_test_generate_result(struct ast_dns_query *query, void *records, size_t num_records, size_t record_size, record_fn generate, char *buffer)
Generate a full DNS response for the given DNS records.
static struct ast_dns_resolver srv_resolver
AST_TEST_DEFINE(srv_resolve_single_record)
unsigned int ignore_priority
A DNS record to be used during a test.
#define AST_TEST_REGISTER(cb)
static int srv_cancel(struct ast_dns_query *query)
static int num_test_records
const char * name
The name of the resolver implementation.
static enum ast_test_result_state invalid_record_test(struct ast_test *test, struct srv_record *records, int num_records)
unsigned short ast_dns_srv_get_port(const struct ast_dns_record *record)
Get the port from an SRV record.
const char * ast_dns_srv_get_host(const struct ast_dns_record *record)
Get the hostname from an SRV record.
unsigned short ast_dns_srv_get_weight(const struct ast_dns_record *record)
Get the weight from an SRV record.
static int unload_module(void)
#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...)
int ast_dns_resolver_register(struct ast_dns_resolver *resolver)
Register a DNS resolver.
#define ao2_ref(o, delta)
static int load_module(void)
The result of a DNS query.
void ast_dns_resolver_completed(struct ast_dns_query *query)
Mark a DNS query as having been completed.
int ast_dns_test_write_domain(const char *string, char *buf)
Write a DNS domain to a buffer.
#define AST_TEST_UNREGISTER(cb)
static void * srv_thread(void *dns_query)
DNS resolver implementation.
const struct ast_dns_record * ast_dns_result_get_records(const struct ast_dns_result *result)
Get the first record of a DNS Result.
static void * cleanup(void *unused)
static enum ast_test_result_state nominal_test(struct ast_test *test, struct srv_record *records, int *srv_record_order, int num_records)
static struct srv_record * test_records
unsigned int ignore_weight
static char ans_buffer[1024]
DNS SRV Record Parsing API.
#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.
static int srv_resolve(struct ast_dns_query *query)