dns_internal.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2015, Digium, Inc.
00005  *
00006  * Joshua Colp <jcolp@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Internal DNS structure definitions
00022  *
00023  * \author Joshua Colp <jcolp@digium.com>
00024  */
00025 
00026 /*! \brief Generic DNS record information */
00027 struct ast_dns_record {
00028    /*! \brief Resource record type */
00029    int rr_type;
00030    /*! \brief Resource record class */
00031    int rr_class;
00032    /*! \brief Time-to-live of the record */
00033    int ttl;
00034    /*! \brief The size of the raw DNS record */
00035    size_t data_len;
00036    /*! \brief Linked list information */
00037    AST_LIST_ENTRY(ast_dns_record) list;
00038    /*! \brief pointer to record-specific data.
00039     *
00040     * For certain "subclasses" of DNS records, the
00041     * location of the raw DNS data will differ from
00042     * the generic case. This pointer will reliably
00043     * be set to point to the raw DNS data, no matter
00044     * where in the structure it may lie.
00045     */
00046    char *data_ptr;
00047    /*! \brief The raw DNS record */
00048    char data[0];
00049 };
00050 
00051 /*! \brief An SRV record */
00052 struct ast_dns_srv_record {
00053    /*! \brief Generic DNS record information */
00054    struct ast_dns_record generic;
00055    /*! \brief The hostname in the SRV record */
00056    const char *host;
00057    /*! \brief The priority of the SRV record */
00058    unsigned short priority;
00059    /*! \brief The weight of the SRV record */
00060    unsigned short weight;
00061    /*! \brief The port in the SRV record */
00062    unsigned short port;
00063    /*! \brief The running weight sum */
00064    unsigned int weight_sum;
00065    /*! \brief Additional data */
00066    char data[0];
00067 };
00068 
00069 /*! \brief A NAPTR record */
00070 struct ast_dns_naptr_record {
00071    /*! \brief Generic DNS record information */
00072    struct ast_dns_record generic;
00073    /*! \brief The flags from the NAPTR record */
00074    const char *flags;
00075    /*! \brief The service from the NAPTR record */
00076    const char *service;
00077    /*! \brief The regular expression from the NAPTR record */
00078    const char *regexp;
00079    /*! \brief The replacement from the NAPTR record */
00080    const char *replacement;
00081    /*! \brief The order for the NAPTR record */
00082    unsigned short order;
00083    /*! \brief The preference of the NAPTR record */
00084    unsigned short preference;
00085    /*! \brief Buffer for NAPTR-specific data
00086     *
00087     * This includes the raw NAPTR record, as well as
00088     * the area where the flags, service, regexp, and
00089     * replacement strings are stored.
00090     */
00091    char data[0];
00092 };
00093 
00094 /*! \brief The result of a DNS query */
00095 struct ast_dns_result {
00096    /*! \brief Whether the result is secure */
00097    unsigned int secure;
00098    /*! \brief Whether the result is bogus */
00099    unsigned int bogus;
00100    /*! \brief Optional rcode, set if an error occurred */
00101    unsigned int rcode;
00102    /*! \brief Records returned */
00103    AST_LIST_HEAD_NOLOCK(dns_records, ast_dns_record) records;
00104    /*! \brief The canonical name */
00105    const char *canonical;
00106    /*! \brief The raw DNS answer */
00107    const char *answer;
00108    /*! \brief The size of the raw DNS answer */
00109    size_t answer_size;
00110    /*! \brief Buffer for dynamic data */
00111    char buf[0];
00112 };
00113 
00114 /*! \brief A DNS query */
00115 struct ast_dns_query {
00116    /*! \brief Callback to invoke upon completion */
00117    ast_dns_resolve_callback callback;
00118    /*! \brief User-specific data */
00119    void *user_data;
00120    /*! \brief The resolver in use for this query */
00121    struct ast_dns_resolver *resolver;
00122    /*! \brief Resolver-specific data */
00123    void *resolver_data;
00124    /*! \brief Result of the DNS query */
00125    struct ast_dns_result *result;
00126    /*! \brief Resource record type */
00127    int rr_type;
00128    /*! \brief Resource record class */
00129    int rr_class;
00130    /*! \brief The name of what is being resolved */
00131    char name[0];
00132 };
00133 
00134 /*! \brief A recurring DNS query */
00135 struct ast_dns_query_recurring {
00136    /*! \brief Callback to invoke upon completion */
00137    ast_dns_resolve_callback callback;
00138    /*! \brief User-specific data */
00139    void *user_data;
00140    /*! \brief Current active query */
00141    struct ast_dns_query_active *active;
00142    /*! \brief The recurring query has been cancelled */
00143    unsigned int cancelled;
00144    /*! \brief Scheduled timer for next resolution */
00145    int timer;
00146    /*! \brief Resource record type */
00147    int rr_type;
00148    /*! \brief Resource record class */
00149    int rr_class;
00150    /*! \brief The name of what is being resolved */
00151    char name[0];
00152 };
00153 
00154 /*! \brief An active DNS query */
00155 struct ast_dns_query_active {
00156    /*! \brief The underlying DNS query */
00157    struct ast_dns_query *query;
00158 };
00159 
00160 struct ast_sched_context;
00161 
00162 /*!
00163  * \brief Retrieve the DNS scheduler context
00164  *
00165  * \return scheduler context
00166  */
00167 struct ast_sched_context *ast_dns_get_sched(void);
00168 
00169 /*!
00170  * \brief Allocate and parse a DNS NAPTR record
00171  *
00172  * \param query The DNS query
00173  * \param data This specific NAPTR record
00174  * \param size The size of the NAPTR record
00175  *
00176  * \retval non-NULL success
00177  * \retval NULL failure
00178  */
00179 struct ast_dns_record *dns_naptr_alloc(struct ast_dns_query *query, const char *data, const size_t size);
00180 
00181 /*!
00182  * \brief Sort the NAPTR records on a result
00183  *
00184  * \param result The DNS result
00185  */
00186 void dns_naptr_sort(struct ast_dns_result *result);
00187 
00188 /*!
00189  * \brief Allocate and parse a DNS SRV record
00190  *
00191  * \param query The DNS query
00192  * \param data This specific SRV record
00193  * \param size The size of the SRV record
00194  *
00195  * \retval non-NULL success
00196  * \retval NULL failure
00197  */
00198 struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size);
00199 
00200 /*!
00201  * \brief Sort the SRV records on a result
00202  *
00203  * \param result The DNS result
00204  */
00205 void dns_srv_sort(struct ast_dns_result *result);
00206 
00207 /*!
00208  * \brief Find the location of a DNS record within the entire DNS answer
00209  *
00210  * The DNS record that has been returned by the resolver may be a copy of the record that was
00211  * found in the complete DNS response. If so, then some DNS record types (specifically those that
00212  * parse domains) will need to locate the DNS record within the complete DNS response. This is so
00213  * that if the domain contains pointers to other sections of the DNS response, then the referenced
00214  * domains may be located.
00215  *
00216  * \param record The DNS record returned by a resolver implementation
00217  * \param record_size The size of the DNS record in bytes
00218  * \param response The complete DNS answer
00219  * \param response_size The size of the complete DNS response
00220  */
00221 char *dns_find_record(const char *record, size_t record_size, const char *response, size_t response_size);
00222 
00223 /*!
00224  * \brief Parse a 16-bit unsigned value from a DNS record
00225  *
00226  * \param cur Pointer to the location of the 16-bit value in the DNS record
00227  * \param[out] val The parsed 16-bit unsigned integer
00228  * \return The number of bytes consumed while parsing
00229  */
00230 int dns_parse_short(unsigned char *cur, uint16_t *val);
00231 
00232 /*!
00233  * \brief Parse a DNS string from a DNS record
00234  *
00235  * A DNS string consists of an 8-bit size, followed by the
00236  * string value (not NULL-terminated).
00237  *
00238  * \param cur Pointer to the location of the DNS string
00239  * \param[out] size The parsed size of the DNS string
00240  * \param[out] val The contained string (not NULL-terminated)
00241  * \return The number of bytes consumed while parsing
00242  */
00243 int dns_parse_string(char *cur, uint8_t *size, char **val);

Generated on Thu Apr 16 06:27:33 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6