mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-18 15:49:56 +00:00
dns: Add core DNS API + unit tests and res_resolver_unbound module + unit tests.
This change adds an abstracted core DNS API which resembles the API described here[1]. The API provides a pluggable mechanism for resolvers and also a consistent view for records. Both synchronous and asynchronous queries are supported. This change also adds a res_resolver_unbound module which uses the libunbound library to provide resolution. Unit tests have also been written for all of the above to confirm the API and functionality. ASTERISK-24834 #close Reported by: Matt Jordan ASTERISK-24836 #close Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/4474/ Review: https://reviewboard.asterisk.org/r/4512/ [1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+DNS+API git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433370 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1065,6 +1065,9 @@
|
||||
/* Define to 1 if you have the `truncl' function. */
|
||||
#undef HAVE_TRUNCL
|
||||
|
||||
/* Define to 1 if you have the unbound library. */
|
||||
#undef HAVE_UNBOUND
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
|
||||
267
include/asterisk/dns_core.h
Normal file
267
include/asterisk/dns_core.h
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief Core DNS API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_CORE_H
|
||||
#define _ASTERISK_DNS_CORE_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! \brief Opaque structure for an active DNS query */
|
||||
struct ast_dns_query_active;
|
||||
|
||||
/*! \brief Opaque structure for a DNS query */
|
||||
struct ast_dns_query;
|
||||
|
||||
/*!
|
||||
* \brief Get the name queried in a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
*
|
||||
* \return the name queried
|
||||
*/
|
||||
const char *ast_dns_query_get_name(const struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Get the record resource type of a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
*
|
||||
* \return the record resource type
|
||||
*/
|
||||
int ast_dns_query_get_rr_type(const struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Get the record resource class of a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
*
|
||||
* \return the record resource class
|
||||
*/
|
||||
int ast_dns_query_get_rr_class(const struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Get the user specific data of a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
*
|
||||
* \return the user specific data
|
||||
*
|
||||
* \note The reference count of the data is NOT incremented on return
|
||||
*/
|
||||
void *ast_dns_query_get_data(const struct ast_dns_query *query);
|
||||
|
||||
/*! \brief Opaque structure for a DNS query result, guaranteed to be immutable */
|
||||
struct ast_dns_result;
|
||||
|
||||
/*!
|
||||
* \brief Get the result information for a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
*
|
||||
* \return the DNS result information
|
||||
*
|
||||
* \note The result is NOT ao2 allocated
|
||||
*/
|
||||
struct ast_dns_result *ast_dns_query_get_result(const struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Get whether the result is secure or not
|
||||
*
|
||||
* \param result The DNS result
|
||||
*
|
||||
* \return whether the result is secure or not
|
||||
*/
|
||||
unsigned int ast_dns_result_get_secure(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Get whether the result is bogus or not
|
||||
*
|
||||
* \param result The DNS result
|
||||
*
|
||||
* \return whether the result is bogus or not
|
||||
*/
|
||||
unsigned int ast_dns_result_get_bogus(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Get the error rcode of a DN result
|
||||
*
|
||||
* \param query The DNS result
|
||||
*
|
||||
* \return the DNS rcode
|
||||
*/
|
||||
unsigned int ast_dns_result_get_rcode(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Get the canonical name of the result
|
||||
*
|
||||
* \param result The DNS result
|
||||
*
|
||||
* \return the canonical name
|
||||
*/
|
||||
const char *ast_dns_result_get_canonical(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Get the first record of a DNS Result
|
||||
*
|
||||
* \param result The DNS result
|
||||
*
|
||||
* \return first DNS record
|
||||
*/
|
||||
const struct ast_dns_record *ast_dns_result_get_records(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Get the raw DNS answer from a DNS result
|
||||
*
|
||||
* \param result The DNS result
|
||||
*
|
||||
* \return The DNS result
|
||||
*/
|
||||
const char *ast_dns_result_get_answer(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the lowest TTL from a result
|
||||
*
|
||||
* \param result The DNS result
|
||||
*
|
||||
* \return the lowest TTL
|
||||
*
|
||||
* \note If no records exist this function will return a TTL of 0
|
||||
*/
|
||||
int ast_dns_result_get_lowest_ttl(const struct ast_dns_result *result);
|
||||
|
||||
/*!
|
||||
* \brief Free the DNS result information
|
||||
*
|
||||
* \param result The DNS result
|
||||
*/
|
||||
void ast_dns_result_free(struct ast_dns_result *result);
|
||||
|
||||
/*! \brief Opaque structure for a DNS record */
|
||||
struct ast_dns_record;
|
||||
|
||||
/*!
|
||||
* \brief Callback invoked when a query completes
|
||||
*
|
||||
* \param query The DNS query that was invoked
|
||||
*/
|
||||
typedef void (*ast_dns_resolve_callback)(const struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Get the resource record type of a DNS record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the resource record type
|
||||
*/
|
||||
int ast_dns_record_get_rr_type(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the resource record class of a DNS record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the resource record class
|
||||
*/
|
||||
int ast_dns_record_get_rr_class(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the TTL of a DNS record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the TTL
|
||||
*/
|
||||
int ast_dns_record_get_ttl(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the raw DNS record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the raw DNS record
|
||||
*/
|
||||
const char *ast_dns_record_get_data(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the next DNS record
|
||||
*
|
||||
* \param record The current DNS record
|
||||
*
|
||||
* \return the next DNS record
|
||||
*/
|
||||
const struct ast_dns_record *ast_dns_record_get_next(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Asynchronously resolve a DNS query
|
||||
*
|
||||
* \param name The name of what to resolve
|
||||
* \param rr_type Resource record type
|
||||
* \param rr_class Resource record class
|
||||
* \param callback The callback to invoke upon completion
|
||||
* \param data User data to make available on the query
|
||||
*
|
||||
* \retval non-NULL success - query has been sent for resolution
|
||||
* \retval NULL failure
|
||||
*
|
||||
* \note The result passed to the callback does not need to be freed
|
||||
*
|
||||
* \note The user data MUST be an ao2 object
|
||||
*
|
||||
* \note This function increments the reference count of the user data, it does NOT steal
|
||||
*
|
||||
* \note The active query must be released upon completion or cancellation using ao2_ref
|
||||
*/
|
||||
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);
|
||||
|
||||
/*!
|
||||
* \brief Cancel an asynchronous DNS resolution
|
||||
*
|
||||
* \param active The active DNS query returned from ast_dns_resolve_async
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*
|
||||
* \note If successfully cancelled the callback will not be invoked
|
||||
*/
|
||||
int ast_dns_resolve_cancel(struct ast_dns_query_active *active);
|
||||
|
||||
/*!
|
||||
* \brief Synchronously resolve a DNS query
|
||||
*
|
||||
* \param name The name of what to resolve
|
||||
* \param rr_type Resource record type
|
||||
* \param rr_class Resource record class
|
||||
* \param result A pointer to hold the DNS result
|
||||
*
|
||||
* \retval 0 success - query was completed and result is available
|
||||
* \retval -1 failure
|
||||
*/
|
||||
int ast_dns_resolve(const char *name, int rr_type, int rr_class, struct ast_dns_result **result);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_CORE_H */
|
||||
145
include/asterisk/dns_internal.h
Normal file
145
include/asterisk/dns_internal.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* \brief Internal DNS structure definitions
|
||||
*
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
/*! \brief Generic DNS record information */
|
||||
struct ast_dns_record {
|
||||
/*! \brief Resource record type */
|
||||
int rr_type;
|
||||
/*! \brief Resource record class */
|
||||
int rr_class;
|
||||
/*! \brief Time-to-live of the record */
|
||||
int ttl;
|
||||
/*! \brief The size of the raw DNS record */
|
||||
size_t data_len;
|
||||
/*! \brief Linked list information */
|
||||
AST_LIST_ENTRY(ast_dns_record) list;
|
||||
/*! \brief The raw DNS record */
|
||||
char data[0];
|
||||
};
|
||||
|
||||
/*! \brief An SRV record */
|
||||
struct ast_dns_srv_record {
|
||||
/*! \brief Generic DNS record information */
|
||||
struct ast_dns_record generic;
|
||||
/*! \brief The hostname in the SRV record */
|
||||
const char *host;
|
||||
/*! \brief The priority of the SRV record */
|
||||
unsigned short priority;
|
||||
/*! \brief The weight of the SRV record */
|
||||
unsigned short weight;
|
||||
/*! \brief The port in the SRV record */
|
||||
unsigned short port;
|
||||
};
|
||||
|
||||
/*! \brief A NAPTR record */
|
||||
struct ast_dns_naptr_record {
|
||||
/*! \brief Generic DNS record information */
|
||||
struct ast_dns_record generic;
|
||||
/*! \brief The flags from the NAPTR record */
|
||||
const char *flags;
|
||||
/*! \brief The service from the NAPTR record */
|
||||
const char *service;
|
||||
/*! \brief The regular expression from the NAPTR record */
|
||||
const char *regexp;
|
||||
/*! \brief The replacement from the NAPTR record */
|
||||
const char *replacement;
|
||||
/*! \brief The order for the NAPTR record */
|
||||
unsigned short order;
|
||||
/*! \brief The preference of the NAPTR record */
|
||||
unsigned short preference;
|
||||
};
|
||||
|
||||
/*! \brief The result of a DNS query */
|
||||
struct ast_dns_result {
|
||||
/*! \brief Whether the result is secure */
|
||||
unsigned int secure;
|
||||
/*! \brief Whether the result is bogus */
|
||||
unsigned int bogus;
|
||||
/*! \brief Optional rcode, set if an error occurred */
|
||||
unsigned int rcode;
|
||||
/*! \brief Records returned */
|
||||
AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
|
||||
/*! \brief The canonical name */
|
||||
const char *canonical;
|
||||
/*! \brief The raw DNS answer */
|
||||
const char *answer;
|
||||
/*! \brief Buffer for dynamic data */
|
||||
char buf[0];
|
||||
};
|
||||
|
||||
/*! \brief A DNS query */
|
||||
struct ast_dns_query {
|
||||
/*! \brief Callback to invoke upon completion */
|
||||
ast_dns_resolve_callback callback;
|
||||
/*! \brief User-specific data */
|
||||
void *user_data;
|
||||
/*! \brief The resolver in use for this query */
|
||||
struct ast_dns_resolver *resolver;
|
||||
/*! \brief Resolver-specific data */
|
||||
void *resolver_data;
|
||||
/*! \brief Result of the DNS query */
|
||||
struct ast_dns_result *result;
|
||||
/*! \brief Resource record type */
|
||||
int rr_type;
|
||||
/*! \brief Resource record class */
|
||||
int rr_class;
|
||||
/*! \brief The name of what is being resolved */
|
||||
char name[0];
|
||||
};
|
||||
|
||||
/*! \brief A recurring DNS query */
|
||||
struct ast_dns_query_recurring {
|
||||
/*! \brief Callback to invoke upon completion */
|
||||
ast_dns_resolve_callback callback;
|
||||
/*! \brief User-specific data */
|
||||
void *user_data;
|
||||
/*! \brief Current active query */
|
||||
struct ast_dns_query_active *active;
|
||||
/*! \brief The recurring query has been cancelled */
|
||||
unsigned int cancelled;
|
||||
/*! \brief Scheduled timer for next resolution */
|
||||
int timer;
|
||||
/*! \brief Resource record type */
|
||||
int rr_type;
|
||||
/*! \brief Resource record class */
|
||||
int rr_class;
|
||||
/*! \brief The name of what is being resolved */
|
||||
char name[0];
|
||||
};
|
||||
|
||||
/*! \brief An active DNS query */
|
||||
struct ast_dns_query_active {
|
||||
/*! \brief The underlying DNS query */
|
||||
struct ast_dns_query *query;
|
||||
};
|
||||
|
||||
struct ast_sched_context;
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the DNS scheduler context
|
||||
*
|
||||
* \return scheduler context
|
||||
*/
|
||||
struct ast_sched_context *ast_dns_get_sched(void);
|
||||
89
include/asterisk/dns_naptr.h
Normal file
89
include/asterisk/dns_naptr.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief DNS NAPTR Record Parsing API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_NAPTR_H
|
||||
#define _ASTERISK_DNS_NAPTR_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Get the flags from a NAPTR record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the flags
|
||||
*/
|
||||
const char *ast_dns_naptr_get_flags(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the service from a NAPTR record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the service
|
||||
*/
|
||||
const char *ast_dns_naptr_get_service(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the regular expression from a NAPTR record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the regular expression
|
||||
*/
|
||||
const char *ast_dns_naptr_get_regexp(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the replacement value from a NAPTR record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the replacement value
|
||||
*/
|
||||
const char *ast_dns_naptr_get_replacement(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the order from a NAPTR record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the order
|
||||
*/
|
||||
unsigned short ast_dns_naptr_get_order(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the preference from a NAPTR record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the preference
|
||||
*/
|
||||
unsigned short ast_dns_naptr_get_preference(const struct ast_dns_record *record);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_NAPTR_H */
|
||||
136
include/asterisk/dns_query_set.h
Normal file
136
include/asterisk/dns_query_set.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief DNS Query Set API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_QUERY_SET_H
|
||||
#define _ASTERISK_DNS_QUERY_SET_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! \brief Opaque structure for a set of DNS queries */
|
||||
struct ast_dns_query_set;
|
||||
|
||||
/*!
|
||||
* \brief Callback invoked when a query set completes
|
||||
*
|
||||
* \param query_set The DNS query set that was invoked
|
||||
*/
|
||||
typedef void (*ast_dns_query_set_callback)(const struct ast_dns_query_set *query_set);
|
||||
|
||||
/*!
|
||||
* \brief Create a query set to hold queries
|
||||
*
|
||||
* \retval non-NULL success
|
||||
* \retval NULL failure
|
||||
*/
|
||||
struct ast_dns_query_set *ast_dns_query_set_create(void);
|
||||
|
||||
/*!
|
||||
* \brief Add a query to a query set
|
||||
*
|
||||
* \param query_set A DNS query set
|
||||
* \param name The name of what to resolve
|
||||
* \param rr_type Resource record type
|
||||
* \param rr_class Resource record class
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*/
|
||||
int ast_dns_query_set_add(struct ast_dns_query_set *query_set, const char *name, int rr_type, int rr_class);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the number of queries in a query set
|
||||
*
|
||||
* \param query_set A DNS query set
|
||||
*
|
||||
* \return the number of queries
|
||||
*/
|
||||
size_t ast_dns_query_set_num_queries(const struct ast_dns_query_set *query_set);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a query from a query set
|
||||
*
|
||||
* \param query_set A DNS query set
|
||||
* \param index The index of the query to retrieve
|
||||
*
|
||||
* \retval non-NULL success
|
||||
* \retval NULL failure
|
||||
*/
|
||||
struct ast_dns_query *ast_dns_query_set_get(const struct ast_dns_query_set *query_set, unsigned int index);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve user specific data from a query set
|
||||
*
|
||||
* \param query_set A DNS query set
|
||||
*
|
||||
* \return user specific data
|
||||
*/
|
||||
void *ast_dns_query_set_get_data(const struct ast_dns_query_set *query_set);
|
||||
|
||||
/*!
|
||||
* \brief Asynchronously resolve queries in a query set
|
||||
*
|
||||
* \param query_set The query set
|
||||
* \param callback The callback to invoke upon completion
|
||||
* \param data User data to make available on the query set
|
||||
*
|
||||
* \note The callback will be invoked when all queries have completed
|
||||
*
|
||||
* \note The user data passed in to this function must be ao2 allocated
|
||||
*/
|
||||
void ast_dns_query_set_resolve_async(struct ast_dns_query_set *query_set, ast_dns_query_set_callback callback, void *data);
|
||||
|
||||
/*!
|
||||
* \brief Synchronously resolve queries in a query set
|
||||
*
|
||||
* \param query_set The query set
|
||||
*
|
||||
* \note This function will return when all queries have been completed
|
||||
*/
|
||||
void ast_query_set_resolve(struct ast_dns_query_set *query_set);
|
||||
|
||||
/*!
|
||||
* \brief Cancel an asynchronous DNS query set resolution
|
||||
*
|
||||
* \param query_set The DNS query set
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*
|
||||
* \note If successfully cancelled the callback will not be invoked
|
||||
*/
|
||||
int ast_dns_query_set_resolve_cancel(struct ast_dns_query_set *query_set);
|
||||
|
||||
/*!
|
||||
* \brief Free a query set
|
||||
*
|
||||
* \param query_set A DNS query set
|
||||
*/
|
||||
void ast_dns_query_set_free(struct ast_dns_query_set *query_set);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_QUERY_SET_H */
|
||||
78
include/asterisk/dns_recurring.h
Normal file
78
include/asterisk/dns_recurring.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief DNS Recurring Resolution API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_RECURRING_H
|
||||
#define _ASTERISK_DNS_RECURRING_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! \brief Opaque structure for a recurring DNS query */
|
||||
struct ast_dns_query_recurring;
|
||||
|
||||
/*!
|
||||
* \brief Asynchronously resolve a DNS query, and continue resolving it according to the lowest TTL available
|
||||
*
|
||||
* \param name The name of what to resolve
|
||||
* \param rr_type Resource record type
|
||||
* \param rr_class Resource record class
|
||||
* \param callback The callback to invoke upon completion
|
||||
* \param data User data to make available on the query
|
||||
*
|
||||
* \retval non-NULL success - query has been sent for resolution
|
||||
* \retval NULL failure
|
||||
*
|
||||
* \note The user data passed in to this function must be ao2 allocated
|
||||
*
|
||||
* \note This query will continue to happen according to the lowest TTL unless cancelled using ast_dns_resolve_recurring_cancel
|
||||
*
|
||||
* \note It is NOT possible for the callback to be invoked concurrently for the query multiple times
|
||||
*
|
||||
* \note The query will occur when the TTL expires, not before. This means that there is a period of time where the previous
|
||||
* information can be considered stale.
|
||||
*
|
||||
* \note If the TTL is determined to be 0 (the record specifies 0, or no records exist) this will cease doing a recurring query.
|
||||
* It is the responsibility of the caller to resume querying at an interval they determine.
|
||||
*/
|
||||
struct ast_dns_query_recurring *ast_dns_resolve_recurring(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data);
|
||||
|
||||
/*!
|
||||
* \brief Cancel an asynchronous recurring DNS resolution
|
||||
*
|
||||
* \param query The DNS query returned from ast_dns_resolve_recurring
|
||||
*
|
||||
* \retval 0 success - any active query has been cancelled and the query will no longer occur
|
||||
* \retval -1 failure - an active query was in progress and could not be cancelled
|
||||
*
|
||||
* \note If successfully cancelled the callback will not be invoked
|
||||
*
|
||||
* \note This function does NOT drop your reference to the recurring query, this should be dropped using ao2_ref
|
||||
*/
|
||||
int ast_dns_resolve_recurring_cancel(struct ast_dns_query_recurring *recurring);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_RECURRING_H */
|
||||
142
include/asterisk/dns_resolver.h
Normal file
142
include/asterisk/dns_resolver.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief DNS Resolver API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_RESOLVER_H
|
||||
#define _ASTERISK_DNS_RESOLVER_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! \brief DNS resolver implementation */
|
||||
struct ast_dns_resolver {
|
||||
/*! \brief The name of the resolver implementation */
|
||||
const char *name;
|
||||
|
||||
/*! \brief Priority for this resolver if multiple exist, lower being higher priority */
|
||||
unsigned int priority;
|
||||
|
||||
/*!
|
||||
* \brief Perform resolution of a DNS query
|
||||
*
|
||||
* \note The reference count of the query should be increased and released
|
||||
* upon the query completing or being successfully cancelled
|
||||
*/
|
||||
int (*resolve)(struct ast_dns_query *query);
|
||||
|
||||
/*! \brief Cancel resolution of a DNS query */
|
||||
int (*cancel)(struct ast_dns_query *query);
|
||||
|
||||
/*! \brief Linked list information */
|
||||
AST_RWLIST_ENTRY(ast_dns_resolver) next;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Set resolver specific data on a query
|
||||
*
|
||||
* \param query The DNS query
|
||||
* \param data The resolver specific data
|
||||
*
|
||||
* \note The resolver data MUST be an ao2 object
|
||||
*
|
||||
* \note This function increments the reference count of the resolver data, it does NOT steal
|
||||
*
|
||||
* \note Once resolver specific data has been set it can not be changed
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure, resolver data is already set
|
||||
*/
|
||||
int ast_dns_resolver_set_data(struct ast_dns_query *query, void *data);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve resolver specific data
|
||||
*
|
||||
* \param query The DNS query
|
||||
*
|
||||
* \return the resolver specific data
|
||||
*
|
||||
* \note The reference count of the resolver data is NOT incremented on return
|
||||
*/
|
||||
void *ast_dns_resolver_get_data(const struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Set result information for a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
* \param result Whether the result is secured or not
|
||||
* \param bogus Whether the result is bogus or not
|
||||
* \param rcode Optional response code
|
||||
* \param canonical The canonical name
|
||||
* \param answer The raw DNS answer
|
||||
* \param answer_size The size of the raw DNS answer
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*/
|
||||
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);
|
||||
|
||||
/*!
|
||||
* \brief Add a DNS record to the result of a DNS query
|
||||
*
|
||||
* \param query The DNS query
|
||||
* \param rr_type Resource record type
|
||||
* \param rr_class Resource record class
|
||||
* \param ttl TTL of the record
|
||||
* \param data The raw DNS record
|
||||
* \param size The size of the raw DNS record
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*/
|
||||
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);
|
||||
|
||||
/*!
|
||||
* \brief Mark a DNS query as having been completed
|
||||
*
|
||||
* \param query The DNS query
|
||||
*/
|
||||
void ast_dns_resolver_completed(struct ast_dns_query *query);
|
||||
|
||||
/*!
|
||||
* \brief Register a DNS resolver
|
||||
*
|
||||
* \param resolver A DNS resolver implementation
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*/
|
||||
int ast_dns_resolver_register(struct ast_dns_resolver *resolver);
|
||||
|
||||
/*!
|
||||
* \brief Unregister a DNS resolver
|
||||
*
|
||||
* \param resolver A DNS resolver implementation
|
||||
*/
|
||||
void ast_dns_resolver_unregister(struct ast_dns_resolver *resolver);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_RESOLVER_H */
|
||||
71
include/asterisk/dns_srv.h
Normal file
71
include/asterisk/dns_srv.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief DNS SRV Record Parsing API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_SRV_H
|
||||
#define _ASTERISK_DNS_SRV_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Get the hostname from an SRV record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the hostname
|
||||
*/
|
||||
const char *ast_dns_srv_get_host(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the priority from an SRV record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the priority
|
||||
*/
|
||||
unsigned short ast_dns_srv_get_priority(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the weight from an SRV record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the weight
|
||||
*/
|
||||
unsigned short ast_dns_srv_get_weight(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the port from an SRV record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the port
|
||||
*/
|
||||
unsigned short ast_dns_srv_get_port(const struct ast_dns_record *record);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_SRV_H */
|
||||
72
include/asterisk/dns_tlsa.h
Normal file
72
include/asterisk/dns_tlsa.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2015, Digium, Inc.
|
||||
*
|
||||
* Joshua Colp <jcolp@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief DNS TLSA Record Parsing API
|
||||
* \author Joshua Colp <jcolp@digium.com>
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_DNS_TLSA_H
|
||||
#define _ASTERISK_DNS_TLSA_H
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Get the certificate usage field from a TLSA record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the certificate usage field
|
||||
*/
|
||||
|
||||
unsigned int ast_dns_tlsa_get_usage(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the selector field from a TLSA record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the selector field
|
||||
*/
|
||||
unsigned int ast_dns_tlsa_get_selector(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the matching type field from a TLSA record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the matching type field
|
||||
*/
|
||||
unsigned int ast_dns_tlsa_get_matching_type(const struct ast_dns_record *record);
|
||||
|
||||
/*!
|
||||
* \brief Get the certificate association data from a TLSA record
|
||||
*
|
||||
* \param record The DNS record
|
||||
*
|
||||
* \return the certificate association data
|
||||
*/
|
||||
const char *ast_dns_tlsa_get_association_data(const struct ast_dns_record *record);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASTERISK_DNS_TLSA_H */
|
||||
Reference in New Issue
Block a user