Asterisk - The Open Source Telephony Project GIT-master-2070bb5
Macros | Functions | Variables
dns_system_resolver.c File Reference

The default DNS resolver for Asterisk. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/astobj2.h"
#include "asterisk/dns.h"
#include "asterisk/dns_core.h"
#include "asterisk/dns_resolver.h"
#include "asterisk/linkedlists.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/utils.h"
Include dependency graph for dns_system_resolver.c:

Go to the source code of this file.

Macros

#define DNS_SYSTEM_RESOLVER_FAILURE   -1
 Resolver return code upon failure. More...
 
#define DNS_SYSTEM_RESOLVER_PRIORITY   INT_MAX
 The consideration priority for this resolver implementation. More...
 
#define DNS_SYSTEM_RESOLVER_SUCCESS   0
 Resolver return code upon success. More...
 

Functions

int ast_dns_system_resolver_init (void)
 Initializes the resolver. More...
 
static int dns_system_resolver_add_record (void *context, unsigned char *record, int record_len, int ttl)
 Callback to handle processing resource records. More...
 
static int dns_system_resolver_cancel (struct ast_dns_query *query)
 Cancels processing resolution for a given query. More...
 
static void dns_system_resolver_destroy (void)
 Destructor. More...
 
static int dns_system_resolver_process_query (void *data)
 Callback to handle processing the query from the ast_taskprocessor instance. More...
 
static int dns_system_resolver_resolve (struct ast_dns_query *query)
 Resolves a DNS query. More...
 
static int dns_system_resolver_set_response (void *context, unsigned char *dns_response, int dns_response_len, int rcode)
 Callback to handle initializing the results field. More...
 

Variables

struct ast_dns_resolver dns_system_resolver_base
 The base definition for the dns_system_resolver. More...
 
static struct ast_taskprocessordns_system_resolver_tp
 The task processor to use for making DNS searches asynchronous. More...
 

Detailed Description

The default DNS resolver for Asterisk.

Author
Ashley Sanders asand.nosp@m.ers@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file dns_system_resolver.c.

Macro Definition Documentation

◆ DNS_SYSTEM_RESOLVER_FAILURE

#define DNS_SYSTEM_RESOLVER_FAILURE   -1

Resolver return code upon failure.

Definition at line 46 of file dns_system_resolver.c.

◆ DNS_SYSTEM_RESOLVER_PRIORITY

#define DNS_SYSTEM_RESOLVER_PRIORITY   INT_MAX

The consideration priority for this resolver implementation.

Definition at line 40 of file dns_system_resolver.c.

◆ DNS_SYSTEM_RESOLVER_SUCCESS

#define DNS_SYSTEM_RESOLVER_SUCCESS   0

Resolver return code upon success.

Definition at line 43 of file dns_system_resolver.c.

Function Documentation

◆ ast_dns_system_resolver_init()

int ast_dns_system_resolver_init ( void  )

Initializes the resolver.

Return values
0on success
-1on failure

Definition at line 244 of file dns_system_resolver.c.

245{
246 /* Register the base resolver */
248
249 if (res) {
251 }
252
253 /* Instantiate the task processor */
254 dns_system_resolver_tp = ast_taskprocessor_get("dns_system_resolver_tp",
256
257 /* Return error if the task processor failed to instantiate */
260 }
261
262 /* Register the cleanup function */
264
266}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
int ast_dns_resolver_register(struct ast_dns_resolver *resolver)
Register a DNS resolver.
Definition: dns_core.c:630
static struct ast_taskprocessor * dns_system_resolver_tp
The task processor to use for making DNS searches asynchronous.
#define DNS_SYSTEM_RESOLVER_FAILURE
Resolver return code upon failure.
static void dns_system_resolver_destroy(void)
Destructor.
#define DNS_SYSTEM_RESOLVER_SUCCESS
Resolver return code upon success.
struct ast_dns_resolver dns_system_resolver_base
The base definition for the dns_system_resolver.
struct ast_taskprocessor * ast_taskprocessor_get(const char *name, enum ast_tps_options create)
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary.
@ TPS_REF_DEFAULT
return a reference to a taskprocessor, create one if it does not exist
Definition: taskprocessor.h:76

References ast_dns_resolver_register(), ast_register_cleanup(), ast_taskprocessor_get(), dns_system_resolver_base, dns_system_resolver_destroy(), DNS_SYSTEM_RESOLVER_FAILURE, DNS_SYSTEM_RESOLVER_SUCCESS, dns_system_resolver_tp, and TPS_REF_DEFAULT.

Referenced by asterisk_daemon().

◆ dns_system_resolver_add_record()

static int dns_system_resolver_add_record ( void *  context,
unsigned char *  record,
int  record_len,
int  ttl 
)
static

Callback to handle processing resource records.

Adds an individual resource record discovered with ast_search_dns_ex to the ast_dns_query currently being resolved.

Definition at line 84 of file dns_system_resolver.c.

85{
86 struct ast_dns_query *query = context;
87
88 /* Add the record to the query.*/
89 return ast_dns_resolver_add_record(query,
92 ttl,
93 (const char*) record,
94 record_len);
95}
int ast_dns_query_get_rr_type(const struct ast_dns_query *query)
Get the record resource type of a DNS query.
Definition: dns_core.c:62
int ast_dns_query_get_rr_class(const struct ast_dns_query *query)
Get the record resource class of a DNS query.
Definition: dns_core.c:67
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.
Definition: dns_core.c:535
A DNS query.
Definition: dns_internal.h:137

References ast_dns_query_get_rr_class(), ast_dns_query_get_rr_type(), ast_dns_resolver_add_record(), and voicemailpwcheck::context.

Referenced by dns_system_resolver_process_query().

◆ dns_system_resolver_cancel()

static int dns_system_resolver_cancel ( struct ast_dns_query query)
static

Cancels processing resolution for a given query.

Note
The system API calls block so there is no way to cancel them. Therefore, this function always returns failure when invoked.

Definition at line 110 of file dns_system_resolver.c.

111{
113}

References DNS_SYSTEM_RESOLVER_FAILURE.

◆ dns_system_resolver_destroy()

static void dns_system_resolver_destroy ( void  )
static

Destructor.

Definition at line 120 of file dns_system_resolver.c.

121{
122 /* Unreference the task processor */
124
125 /* Unregister the base resolver */
127}
void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver)
Unregister a DNS resolver.
Definition: dns_core.c:680
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.

References ast_dns_resolver_unregister(), ast_taskprocessor_unreference(), dns_system_resolver_base, and dns_system_resolver_tp.

Referenced by ast_dns_system_resolver_init().

◆ dns_system_resolver_process_query()

static int dns_system_resolver_process_query ( void *  data)
static

Callback to handle processing the query from the ast_taskprocessor instance.

Definition at line 140 of file dns_system_resolver.c.

141{
142 struct ast_dns_query *query = data;
143
144 /* Perform the DNS search */
151
152 /* Handle the possible return values from the DNS search */
153 if (res == AST_DNS_SEARCH_FAILURE) {
154 ast_debug(1, "DNS search failed for query: '%s'\n",
156 } else if (res == AST_DNS_SEARCH_NO_RECORDS) {
157 ast_debug(1, "DNS search failed to yield any results for query: '%s'\n",
159 }
160
161 /* Mark the query as complete */
163
164 /* Reduce the reference count on the query object */
165 ao2_ref(query, -1);
166
167 return res;
168}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
enum ast_dns_search_result ast_search_dns_ex(void *context, const char *dname, int rr_class, int rr_type, int(*response_handler)(void *context, unsigned char *dns_response, int dns_response_len, int rcode), int(*record_handler)(void *context, unsigned char *record, int record_len, int ttl))
Extended version of the DNS search function.
Definition: dns.c:536
ast_dns_search_result
DNS search return values.
Definition: dns.h:28
@ AST_DNS_SEARCH_FAILURE
Definition: dns.h:29
@ AST_DNS_SEARCH_NO_RECORDS
Definition: dns.h:30
const char * ast_dns_query_get_name(const struct ast_dns_query *query)
Get the name queried in a DNS query.
Definition: dns_core.c:57
void ast_dns_resolver_completed(struct ast_dns_query *query)
Mark a DNS query as having been completed.
Definition: dns_core.c:599
static int dns_system_resolver_add_record(void *context, unsigned char *record, int record_len, int ttl)
Callback to handle processing resource records.
static int dns_system_resolver_set_response(void *context, unsigned char *dns_response, int dns_response_len, int rcode)
Callback to handle initializing the results field.
#define ast_debug(level,...)
Log a DEBUG message.

References ao2_ref, ast_debug, ast_dns_query_get_name(), ast_dns_query_get_rr_class(), ast_dns_query_get_rr_type(), ast_dns_resolver_completed(), AST_DNS_SEARCH_FAILURE, AST_DNS_SEARCH_NO_RECORDS, ast_search_dns_ex(), dns_system_resolver_add_record(), and dns_system_resolver_set_response().

Referenced by dns_system_resolver_resolve().

◆ dns_system_resolver_resolve()

static int dns_system_resolver_resolve ( struct ast_dns_query query)
static

Resolves a DNS query.

Definition at line 180 of file dns_system_resolver.c.

181{
182 /* Add query processing handler to the task processor */
185 ao2_bump(query));
186
187 /* The query processing handler was not added to the task processor */
188 if (res < 0) {
189 ast_log(LOG_ERROR, "Failed to perform async DNS resolution of '%s'\n",
191 ao2_ref(query, -1);
192 }
193
194 /* Return the result of adding the query processing handler to the task processor */
195 return res;
196}
#define ast_log
Definition: astobj2.c:42
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
static int dns_system_resolver_process_query(void *data)
Callback to handle processing the query from the ast_taskprocessor instance.
#define LOG_ERROR
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int(*task_exe)(void *datap), void *datap) attribute_warn_unused_result
Push a task into the specified taskprocessor queue and signal the taskprocessor thread.

References ao2_bump, ao2_ref, ast_dns_query_get_name(), ast_log, ast_taskprocessor_push(), dns_system_resolver_process_query(), dns_system_resolver_tp, and LOG_ERROR.

◆ dns_system_resolver_set_response()

static int dns_system_resolver_set_response ( void *  context,
unsigned char *  dns_response,
int  dns_response_len,
int  rcode 
)
static

Callback to handle initializing the results field.

Definition at line 211 of file dns_system_resolver.c.

212{
213 struct ast_dns_query *query = context;
214 int res;
215
216 /* Instantiate the query's result field (if necessary). */
217 if (!ast_dns_query_get_result(query)) {
218 res = ast_dns_resolver_set_result(query,
219 0,
220 0,
221 rcode,
223 (const char*) dns_response,
224 dns_response_len);
225
226 if (res) {
227 /* There was a problem instantiating the results field. */
228 ast_log(LOG_ERROR, "Could not instantiate the results field for query: '%s'\n",
230 }
231 } else {
233 }
234
235 return res;
236}
struct ast_dns_result * ast_dns_query_get_result(const struct ast_dns_query *query)
Get the result information for a DNS query.
Definition: dns_core.c:77
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.
Definition: dns_core.c:456

References ast_dns_query_get_name(), ast_dns_query_get_result(), ast_dns_resolver_set_result(), ast_log, voicemailpwcheck::context, DNS_SYSTEM_RESOLVER_SUCCESS, and LOG_ERROR.

Referenced by dns_system_resolver_process_query().

Variable Documentation

◆ dns_system_resolver_base

struct ast_dns_resolver dns_system_resolver_base

The base definition for the dns_system_resolver.

Definition at line 61 of file dns_system_resolver.c.

Referenced by ast_dns_system_resolver_init(), and dns_system_resolver_destroy().

◆ dns_system_resolver_tp

struct ast_taskprocessor* dns_system_resolver_tp
static

The task processor to use for making DNS searches asynchronous.

Definition at line 58 of file dns_system_resolver.c.

Referenced by ast_dns_system_resolver_init(), dns_system_resolver_destroy(), and dns_system_resolver_resolve().