Asterisk - The Open Source Telephony Project  21.4.1
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"

Go to the source code of this file.

Macros

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

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.
 
static int dns_system_resolver_process_query (void *data)
 Callback to handle processing the query from the ast_taskprocessor instance.
 
static int dns_system_resolver_resolve (struct ast_dns_query *query)
 Resolves a DNS query.
 
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.
 

Variables

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

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.

Function Documentation

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.

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

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 */
258  if (!dns_system_resolver_tp) {
260  }
261 
262  /* Register the cleanup function */
264 
266 }
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...
return a reference to a taskprocessor, create one if it does not exist
Definition: taskprocessor.h:76
#define DNS_SYSTEM_RESOLVER_SUCCESS
Resolver return code upon success.
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 void dns_system_resolver_destroy(void)
Destructor.
struct ast_dns_resolver dns_system_resolver_base
The base definition for the dns_system_resolver.
#define DNS_SYSTEM_RESOLVER_FAILURE
Resolver return code upon failure.
static struct ast_taskprocessor * dns_system_resolver_tp
The task processor to use for making DNS searches asynchronous.
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.

References ast_dns_query_get_rr_class(), ast_dns_query_get_rr_type(), and ast_dns_resolver_add_record().

Referenced by dns_system_resolver_process_query().

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_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
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
A DNS query.
Definition: dns_internal.h:137
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
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.

References DNS_SYSTEM_RESOLVER_FAILURE.

111 {
113 }
#define DNS_SYSTEM_RESOLVER_FAILURE
Resolver return code upon failure.