summaryrefslogtreecommitdiff
path: root/main/dns_core.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2015-04-13 10:47:01 -0300
committerJoshua Colp <jcolp@digium.com>2015-04-15 10:47:53 -0300
commita3cec44a0a415e803057a11ab11d80e4f93e10cf (patch)
tree550c4a127eae12504f06ae3c7a96927173b0bbb6 /main/dns_core.c
parent60d1911482c1dcf44d34e30f252857d75f5d5d77 (diff)
res_pjsip: Add external PJSIP resolver implementation using core DNS API.
This change adds the following: 1. A query set implementation. This is an API that allows queries to be executed in parallel and once all have completed a callback is invoked. 2. Unit tests for the query set implementation. 3. An external PJSIP resolver which uses the DNS core API to do NAPTR, SRV, AAAA, and A lookups. For the resolver it will do NAPTR, SRV, and AAAA/A lookups in parallel. If NAPTR or SRV are available it will then do more queries. And so on. Preference is NAPTR > SRV > AAAA/A, with IPv6 preferred over IPv4. For transport it will prefer TLS > TCP > UDP if no explicit transport has been provided. Configured transports on the system are taken into account to eliminate resolved addresses which have no hope of completing. ASTERISK-24947 #close Reported by: Joshua Colp Change-Id: I56cb03ce4f9d3d600776f36928e0b3e379b5d71e
Diffstat (limited to 'main/dns_core.c')
-rw-r--r--main/dns_core.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/main/dns_core.c b/main/dns_core.c
index e66c71d62..0b471db91 100644
--- a/main/dns_core.c
+++ b/main/dns_core.c
@@ -32,7 +32,6 @@
ASTERISK_REGISTER_FILE()
#include "asterisk/linkedlists.h"
-#include "asterisk/vector.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/sched.h"
@@ -163,6 +162,11 @@ const char *ast_dns_record_get_data(const struct ast_dns_record *record)
return record->data_ptr;
}
+size_t ast_dns_record_get_data_size(const struct ast_dns_record *record)
+{
+ return record->data_len;
+}
+
const struct ast_dns_record *ast_dns_record_get_next(const struct ast_dns_record *record)
{
return AST_LIST_NEXT(record, list);
@@ -186,9 +190,9 @@ static void dns_query_destroy(void *data)
ast_dns_result_free(query->result);
}
-struct ast_dns_query_active *ast_dns_resolve_async(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
+struct ast_dns_query *dns_query_alloc(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
{
- struct ast_dns_query_active *active;
+ struct ast_dns_query *query;
if (ast_strlen_zero(name)) {
ast_log(LOG_WARNING, "Could not perform asynchronous resolution, no name provided\n");
@@ -215,30 +219,42 @@ struct ast_dns_query_active *ast_dns_resolve_async(const char *name, int rr_type
return NULL;
}
- active = ao2_alloc_options(sizeof(*active), dns_query_active_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!active) {
- return NULL;
- }
-
- active->query = ao2_alloc_options(sizeof(*active->query) + strlen(name) + 1, dns_query_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!active->query) {
- ao2_ref(active, -1);
+ query = ao2_alloc_options(sizeof(*query) + strlen(name) + 1, dns_query_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!query) {
return NULL;
}
- active->query->callback = callback;
- active->query->user_data = ao2_bump(data);
- active->query->rr_type = rr_type;
- active->query->rr_class = rr_class;
- strcpy(active->query->name, name); /* SAFE */
+ query->callback = callback;
+ query->user_data = ao2_bump(data);
+ query->rr_type = rr_type;
+ query->rr_class = rr_class;
+ strcpy(query->name, name); /* SAFE */
AST_RWLIST_RDLOCK(&resolvers);
- active->query->resolver = AST_RWLIST_FIRST(&resolvers);
+ query->resolver = AST_RWLIST_FIRST(&resolvers);
AST_RWLIST_UNLOCK(&resolvers);
- if (!active->query->resolver) {
+ if (!query->resolver) {
ast_log(LOG_ERROR, "Attempted to do a DNS query for '%s' of class '%d' and type '%d' but no resolver is available\n",
name, rr_class, rr_type);
+ ao2_ref(query, -1);
+ return NULL;
+ }
+
+ return query;
+}
+
+struct ast_dns_query_active *ast_dns_resolve_async(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
+{
+ struct ast_dns_query_active *active;
+
+ active = ao2_alloc_options(sizeof(*active), dns_query_active_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!active) {
+ return NULL;
+ }
+
+ active->query = dns_query_alloc(name, rr_type, rr_class, callback, data);
+ if (!active->query) {
ao2_ref(active, -1);
return NULL;
}