DNS: Create a system-level DNS resolver

Prior to this patch, the DNS core present in master had no default system-level
resolver implementation. Therefore, it was not possible for the DNS core to
perform resolutions unless the libunbound library was installed and the
res_resolver_unbound module was loaded.

This patch introduces a system-level DNS resolver implementation that will
register itself with the lowest consideration priority available (to ensure
that it is to be used only as a last resort). The resolver relies on low-level
DNS search functions to perform a rudimentary DNS search based on a provided
query and then supplies the search results to the DNS core.

ASTERISK-25146 #close
Reported By: Joshua Colp

Change-Id: I3b36ea17b889a98df4f8d80d50bb7ee175afa077
This commit is contained in:
Ashley Sanders
2015-07-07 15:03:34 -05:00
parent c12ace3ab3
commit 3cdfd39af7
5 changed files with 628 additions and 23 deletions

View File

@@ -29,6 +29,7 @@ int ast_cli_perms_init(int reload); /*!< Provided by cli.c */
int dnsmgr_init(void); /*!< Provided by dnsmgr.c */
void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */
int dnsmgr_reload(void); /*!< Provided by dnsmgr.c */
int ast_dns_system_resolver_init(void); /*!< Provided by dns_system_resolver.c */
void threadstorage_init(void); /*!< Provided by threadstorage.c */
int ast_device_state_engine_init(void); /*!< Provided by devicestate.c */
int astobj2_init(void); /*!< Provided by astobj2.c */

View File

@@ -24,17 +24,63 @@
#ifndef _ASTERISK_DNS_H
#define _ASTERISK_DNS_H
/*! \brief Perform DNS lookup (used by DNS, enum and SRV lookups)
\param context
\param dname Domain name to lookup (host, SRV domain, TXT record name)
\param class Record Class (see "man res_search")
\param type Record type (see "man res_search")
\param callback Callback function for handling DNS result
\note Asterisk DNS is synchronus at this time. This means that if your DNS
services does not work, Asterisk may lock while waiting for response.
*/
/*! \brief DNS search return values */
enum ast_dns_search_result {
AST_DNS_SEARCH_FAILURE = -1, /*!< DNS search resulted in failure */
AST_DNS_SEARCH_NO_RECORDS = 0, /*!< DNS search yielded no results */
AST_DNS_SEARCH_SUCCESS = 1 /*!< DNS search yielded at least one discovered record */
};
/*!
* \brief Perform DNS lookup (used by DNS, enum and SRV lookups)
*
* \param context Void pointer containing data to use in the callback function.
* \param dname Domain name to lookup (host, SRV domain, TXT record name).
* \param class Record Class (see "man res_search").
* \param type Record type (see "man res_search").
* \param answer The full DNS response.
* \param len The length of the full DNS response.
* \param callback Callback function for handling the discovered resource records from
* the DNS search.
*
* \retval -1 on search failure
* \retval 0 on no records found
* \retval 1 on success
*
* \note Asterisk DNS is synchronus at this time. This means that if your DNS
* service does not work, Asterisk may lock while waiting for a response.
*/
int ast_search_dns(void *context, const char *dname, int class, int type,
int (*callback)(void *context, unsigned char *answer, int len, unsigned char *fullanswer));
int (*callback)(void *context, unsigned char *answer, int len, unsigned char *fullanswer));
/*!
* \brief Extended version of the DNS search function.
*
* \details Performs a DNS lookup, (used by DNS, enum and SRV lookups), parses the
* results and notifies the observer with the response and discovered records
* via invoking the provided callbacks (used by ast_dns_system_resolver).
*
* \param context Void pointer containing data to use in the handler functions.
* \param dname Domain name to lookup (host, SRV domain, TXT record name).
* \param rr_class Record Class (see "man res_search").
* \param rr_type Record type (see "man res_search").
* \param response_handler Callback function for handling the DNS response. Invoked upon
* completion of the DNS search.
* \param record_handler Callback function for handling the discovered resource
* records from the DNS search. Invoked n times, where n is the
* number of records discovered while parsing the DNS
* response.
*
* \retval AST_DNS_SEARCH_FAILURE on search failure
* \retval AST_DNS_SEARCH_NO_RECORDS on no records found
* \retval AST_DNS_SEARCH_SUCCESS on success
*
* \note Asterisk DNS is synchronus at this time. This means that if your DNS
* service does not work, Asterisk may lock while waiting for a response.
*/
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));
/*! \brief Retrieve the configured nameservers of the system */
struct ao2_container *ast_dns_get_nameservers(void);