The Asterisk DNS API is designed as a facade over resolver implementations. It provides a consistent view and also additional features. These additional features include a construct for doing queries in parallel and gathering the results, parsing some DNS types, and applying sorting/weight logic to some DNS types.
The API provides a guarantee that it is safe to initiate and cancel queries from any thread. It does NOT, however, provide a guarantee that the ordering of queries shall be preserved. In other words, if you execute multiple queries individually you will not necessarily receive callbacks in the order the queries were originally executed. This API only guarantees that an individual DNS result and records are safe to retrieve within the scope of the respective asynchronous callback.
The dns.h file is the public API into the DNS core. It provides mechanisms to perform individual DNS queries and access the results. All data structures are opaque and can not be accessed directly.
A query contains information about an in-process DNS query. It also contains information about the result of the query.
A result contains information about a completed DNS query. It also contains the resulting DNS records (if there are any).
A record is a DNS record.
The dns_query_set.h file is the public API into doing parallel queries. It provides mechanisms to group DNS queries together and receive notification when all have been completed. It mirrors the single query API in functionality.
The dns_naptr.h file is the public API into accessing NAPTR records. The DNS core will automatically parse and make this information available. It will also sort the records.
The dns_srv.h file is the public API into accessing SRV records. The DNS core will automatically parse and make this information available. It will also sort the records.
The dns_tlsa.h file is the public API into accessing TLSA records.
The dns_resolver.h file contains the interface as defined for resolver implementations.
The dns_internal.h file contains the internal data structures.
This example blocks the calling thread until resolution has completed. Once completed result information is returned.
This example does not block the calling thread when resolving. A callback is invoked upon query completion instead. The result information can then be retrieved from the query.
This example uses a query set to do two queries in an asynchronous manner. Each query is done on a different domain. Once both queries have completed the callback is invoked and each query result can be examined.
This example does a fall back from an AAAA record lookup to an A record lookup if no results were available for the AAAA record lookup. This also uses the asynchronous function and the same callback is used for both queries.
This example does a NAPTR lookup followed by SRV followed by AAAA and then A. The results of the NAPTR and SRV lookups are taken into account when deciding the next step to take.
The recurring example has the DNS core re-run the specified query according to the lowest TTL of the result records. It is up to the user to store the previous results and determine whether action should be taken or not.