ares_private.h (27706B)
1 /* MIT License 2 * 3 * Copyright (c) 1998 Massachusetts Institute of Technology 4 * Copyright (c) 2010 Daniel Stenberg 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 * 25 * SPDX-License-Identifier: MIT 26 */ 27 #ifndef __ARES_PRIVATE_H 28 #define __ARES_PRIVATE_H 29 30 /* ============================================================================ 31 * NOTE: All c-ares source files should include ares_private.h as the first 32 * header. 33 * ============================================================================ 34 */ 35 36 #include "ares_setup.h" 37 #include "ares.h" 38 39 #ifdef HAVE_NETINET_IN_H 40 # include <netinet/in.h> 41 #endif 42 43 #include "ares_mem.h" 44 #include "ares_ipv6.h" 45 #include "util/ares_math.h" 46 #include "util/ares_time.h" 47 #include "util/ares_rand.h" 48 #include "ares_array.h" 49 #include "ares_llist.h" 50 #include "dsa/ares_slist.h" 51 #include "ares_htable_strvp.h" 52 #include "ares_htable_szvp.h" 53 #include "ares_htable_asvp.h" 54 #include "ares_htable_dict.h" 55 #include "ares_htable_vpvp.h" 56 #include "ares_htable_vpstr.h" 57 #include "record/ares_dns_multistring.h" 58 #include "ares_buf.h" 59 #include "record/ares_dns_private.h" 60 #include "util/ares_iface_ips.h" 61 #include "util/ares_threads.h" 62 #include "ares_socket.h" 63 #include "ares_conn.h" 64 #include "ares_str.h" 65 #include "str/ares_strsplit.h" 66 #include "util/ares_uri.h" 67 68 #ifndef HAVE_GETENV 69 # include "ares_getenv.h" 70 # define getenv(ptr) ares_getenv(ptr) 71 #endif 72 73 #define DEFAULT_TIMEOUT 2000 /* milliseconds */ 74 #define DEFAULT_TRIES 3 75 #ifndef INADDR_NONE 76 # define INADDR_NONE 0xffffffff 77 #endif 78 79 /* By using a double cast, we can get rid of the bogus warning of 80 * warning: cast from 'const struct sockaddr *' to 'const struct sockaddr_in6 *' 81 * increases required alignment from 1 to 4 [-Wcast-align] 82 */ 83 #define CARES_INADDR_CAST(type, var) ((type)((const void *)var)) 84 85 #if defined(USE_WINSOCK) 86 87 # define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP" 88 # define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters" 89 # define WIN_DNSCLIENT "Software\\Policies\\Microsoft\\System\\DNSClient" 90 # define WIN_NT_DNSCLIENT \ 91 "Software\\Policies\\Microsoft\\Windows NT\\DNSClient" 92 # define NAMESERVER "NameServer" 93 # define DHCPNAMESERVER "DhcpNameServer" 94 # define DATABASEPATH "DatabasePath" 95 # define WIN_PATH_HOSTS "\\hosts" 96 # define SEARCHLIST_KEY "SearchList" 97 # define PRIMARYDNSSUFFIX_KEY "PrimaryDNSSuffix" 98 # define INTERFACES_KEY "Interfaces" 99 # define DOMAIN_KEY "Domain" 100 # define DHCPDOMAIN_KEY "DhcpDomain" 101 # define PATH_RESOLV_CONF "" 102 #elif defined(WATT32) 103 104 # define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf" 105 W32_FUNC const char *_w32_GetHostsFile(void); 106 107 #elif defined(NETWARE) 108 109 # define PATH_RESOLV_CONF "sys:/etc/resolv.cfg" 110 # define PATH_HOSTS "sys:/etc/hosts" 111 112 #elif defined(__riscos__) 113 114 # define PATH_RESOLV_CONF "" 115 # define PATH_HOSTS "InetDBase:Hosts" 116 117 #elif defined(__HAIKU__) 118 119 # define PATH_RESOLV_CONF "/system/settings/network/resolv.conf" 120 # define PATH_HOSTS "/system/settings/network/hosts" 121 122 #else 123 124 # define PATH_RESOLV_CONF "/etc/resolv.conf" 125 # ifdef ETC_INET 126 # define PATH_HOSTS "/etc/inet/hosts" 127 # else 128 # define PATH_HOSTS "/etc/hosts" 129 # endif 130 131 #endif 132 133 /********* EDNS defines section ******/ 134 #define EDNSPACKETSZ \ 135 1232 /* Reasonable UDP payload size, as agreed by operators \ 136 https://www.dnsflagday.net/2020/#faq */ 137 #define MAXENDSSZ 4096 /* Maximum (local) limit for edns packet size */ 138 #define EDNSFIXEDSZ 11 /* Size of EDNS header */ 139 140 /********* EDNS defines section ******/ 141 142 /* Default values for server failover behavior. We retry failed servers with 143 * a 10% probability and a minimum delay of 5 seconds between retries. 144 */ 145 #define DEFAULT_SERVER_RETRY_CHANCE 10 146 #define DEFAULT_SERVER_RETRY_DELAY 5000 147 148 struct ares_query; 149 typedef struct ares_query ares_query_t; 150 151 /* State to represent a DNS query */ 152 struct ares_query { 153 /* Query ID from qbuf, for faster lookup, and current timeout */ 154 unsigned short qid; /* host byte order */ 155 ares_timeval_t ts; /*!< Timestamp query was sent */ 156 ares_timeval_t timeout; 157 ares_channel_t *channel; 158 159 /* 160 * Node object for each list entry the query belongs to in order to 161 * make removal operations O(1). 162 */ 163 ares_slist_node_t *node_queries_by_timeout; 164 ares_llist_node_t *node_queries_to_conn; 165 ares_llist_node_t *node_all_queries; 166 167 /* connection handle query is associated with */ 168 ares_conn_t *conn; 169 170 /* Query */ 171 ares_dns_record_t *query; 172 173 ares_callback_dnsrec callback; 174 void *arg; 175 176 /* Query status */ 177 size_t try_count; /* Number of times we tried this query already. */ 178 size_t cookie_try_count; /* Attempt count for cookie resends */ 179 ares_bool_t using_tcp; 180 ares_status_t error_status; 181 size_t timeouts; /* number of timeouts we saw for this request */ 182 ares_bool_t no_retries; /* do not perform any additional retries, this is 183 * set when a query is to be canceled */ 184 }; 185 186 struct apattern { 187 struct ares_addr addr; 188 unsigned char mask; 189 }; 190 191 struct ares_qcache; 192 typedef struct ares_qcache ares_qcache_t; 193 194 struct ares_hosts_file; 195 typedef struct ares_hosts_file ares_hosts_file_t; 196 197 struct ares_channeldata { 198 /* Configuration data */ 199 unsigned int flags; 200 size_t timeout; /* in milliseconds */ 201 size_t tries; 202 size_t ndots; 203 size_t maxtimeout; /* in milliseconds */ 204 ares_bool_t rotate; 205 unsigned short udp_port; /* stored in network order */ 206 unsigned short tcp_port; /* stored in network order */ 207 int socket_send_buffer_size; /* setsockopt takes int */ 208 int socket_receive_buffer_size; /* setsockopt takes int */ 209 char **domains; 210 size_t ndomains; 211 struct apattern *sortlist; 212 size_t nsort; 213 char *lookups; 214 size_t ednspsz; 215 unsigned int qcache_max_ttl; 216 ares_evsys_t evsys; 217 unsigned int optmask; 218 219 /* For binding to local devices and/or IP addresses. Leave 220 * them null/zero for no binding. 221 */ 222 char local_dev_name[32]; 223 unsigned int local_ip4; 224 unsigned char local_ip6[16]; 225 226 /* Thread safety lock */ 227 ares_thread_mutex_t *lock; 228 229 /* Conditional to wake waiters when queue is empty */ 230 ares_thread_cond_t *cond_empty; 231 232 /* Server addresses and communications state. Sorted by least consecutive 233 * failures, followed by the configuration order if failures are equal. */ 234 ares_slist_t *servers; 235 236 /* random state to use when generating new ids and generating retry penalties 237 */ 238 ares_rand_state *rand_state; 239 240 /* All active queries in a single list */ 241 ares_llist_t *all_queries; 242 /* Queries bucketed by qid, for quickly dispatching DNS responses: */ 243 ares_htable_szvp_t *queries_by_qid; 244 245 /* Queries bucketed by timeout, for quickly handling timeouts: */ 246 ares_slist_t *queries_by_timeout; 247 248 /* Map linked list node member for connection to file descriptor. We use 249 * the node instead of the connection object itself so we can quickly look 250 * up a connection and remove it if necessary (as otherwise we'd have to 251 * scan all connections) */ 252 ares_htable_asvp_t *connnode_by_socket; 253 254 ares_sock_state_cb sock_state_cb; 255 void *sock_state_cb_data; 256 257 ares_sock_create_callback sock_create_cb; 258 void *sock_create_cb_data; 259 260 ares_sock_config_callback sock_config_cb; 261 void *sock_config_cb_data; 262 263 struct ares_socket_functions_ex sock_funcs; 264 void *sock_func_cb_data; 265 const struct ares_socket_functions *legacy_sock_funcs; 266 void *legacy_sock_funcs_cb_data; 267 268 ares_pending_write_cb notify_pending_write_cb; 269 void *notify_pending_write_cb_data; 270 ares_bool_t notify_pending_write; 271 272 /* Path for resolv.conf file, configurable via ares_options */ 273 char *resolvconf_path; 274 275 /* Path for hosts file, configurable via ares_options */ 276 char *hosts_path; 277 278 /* Maximum UDP queries per connection allowed */ 279 size_t udp_max_queries; 280 281 /* Cache of local hosts file */ 282 ares_hosts_file_t *hf; 283 284 /* Query Cache */ 285 ares_qcache_t *qcache; 286 287 /* Fields controlling server failover behavior. 288 * The retry chance is the probability (1/N) by which we will retry a failed 289 * server instead of the best server when selecting a server to send queries 290 * to. 291 * The retry delay is the minimum time in milliseconds to wait between doing 292 * such retries (applied per-server). 293 */ 294 unsigned short server_retry_chance; 295 size_t server_retry_delay; 296 297 /* Callback triggered when a server has a successful or failed response */ 298 ares_server_state_callback server_state_cb; 299 void *server_state_cb_data; 300 301 /* TRUE if a reinit is pending. Reinit spawns a thread to read the system 302 * configuration and then apply the configuration since configuration 303 * reading may block. The thread handle is provided for waiting on thread 304 * exit. */ 305 ares_bool_t reinit_pending; 306 ares_thread_t *reinit_thread; 307 308 /* Whether the system is up or not. This is mainly to prevent deadlocks 309 * and access violations during the cleanup process. Some things like 310 * system config changes might get triggered and we need a flag to make 311 * sure we don't take action. */ 312 ares_bool_t sys_up; 313 }; 314 315 /* Does the domain end in ".onion" or ".onion."? Case-insensitive. */ 316 ares_bool_t ares_is_onion_domain(const char *name); 317 318 /* Returns one of the normal ares status codes like ARES_SUCCESS */ 319 ares_status_t ares_send_query(ares_server_t *requested_server /* Optional */, 320 ares_query_t *query, const ares_timeval_t *now); 321 ares_status_t ares_requeue_query(ares_query_t *query, const ares_timeval_t *now, 322 ares_status_t status, 323 ares_bool_t inc_try_count, 324 const ares_dns_record_t *dnsrec, 325 ares_array_t **requeue); 326 327 /*! Count the number of labels (dots+1) in a domain */ 328 size_t ares_name_label_cnt(const char *name); 329 330 /*! Retrieve a list of names to use for searching. The first successful 331 * query in the list wins. This function also uses the HOSTSALIASES file 332 * as well as uses channel configuration to determine the search order. 333 * 334 * \param[in] channel initialized ares channel 335 * \param[in] name initial name being searched 336 * \param[out] names array of names to attempt, use ares_strsplit_free() 337 * when no longer needed. 338 * \param[out] names_len number of names in array 339 * \return ARES_SUCCESS on success, otherwise one of the other error codes. 340 */ 341 ares_status_t ares_search_name_list(const ares_channel_t *channel, 342 const char *name, char ***names, 343 size_t *names_len); 344 345 /*! Function to create callback arg for converting from ares_callback_dnsrec 346 * to ares_calback */ 347 void *ares_dnsrec_convert_arg(ares_callback callback, void *arg); 348 349 /*! Callback function used to convert from the ares_callback_dnsrec prototype to 350 * the ares_callback prototype, by writing the result and passing that to 351 * the inner callback. 352 */ 353 void ares_dnsrec_convert_cb(void *arg, ares_status_t status, size_t timeouts, 354 const ares_dns_record_t *dnsrec); 355 356 void ares_free_query(ares_query_t *query); 357 358 unsigned short ares_generate_new_id(ares_rand_state *state); 359 ares_status_t ares_expand_name_validated(const unsigned char *encoded, 360 const unsigned char *abuf, size_t alen, 361 char **s, size_t *enclen, 362 ares_bool_t is_hostname); 363 ares_status_t ares_expand_string_ex(const unsigned char *encoded, 364 const unsigned char *abuf, size_t alen, 365 unsigned char **s, size_t *enclen); 366 ares_status_t ares_init_servers_state(ares_channel_t *channel); 367 ares_status_t ares_init_by_options(ares_channel_t *channel, 368 const struct ares_options *options, 369 int optmask); 370 ares_status_t ares_init_by_sysconfig(ares_channel_t *channel); 371 void ares_set_socket_functions_def(ares_channel_t *channel); 372 373 typedef struct { 374 ares_llist_t *sconfig; 375 struct apattern *sortlist; 376 size_t nsortlist; 377 char **domains; 378 size_t ndomains; 379 char *lookups; 380 size_t ndots; 381 size_t tries; 382 ares_bool_t rotate; 383 size_t timeout_ms; 384 ares_bool_t usevc; 385 } ares_sysconfig_t; 386 387 ares_status_t ares_sysconfig_set_options(ares_sysconfig_t *sysconfig, 388 const char *str); 389 390 ares_status_t ares_init_by_environment(ares_sysconfig_t *sysconfig); 391 392 393 typedef ares_status_t (*ares_sysconfig_line_cb_t)(const ares_channel_t *channel, 394 ares_sysconfig_t *sysconfig, 395 ares_buf_t *line); 396 397 ares_status_t ares_sysconfig_parse_resolv_line(const ares_channel_t *channel, 398 ares_sysconfig_t *sysconfig, 399 ares_buf_t *line); 400 401 ares_status_t ares_sysconfig_process_buf(const ares_channel_t *channel, 402 ares_sysconfig_t *sysconfig, 403 ares_buf_t *buf, 404 ares_sysconfig_line_cb_t cb); 405 406 ares_status_t ares_init_sysconfig_files(const ares_channel_t *channel, 407 ares_sysconfig_t *sysconfig, 408 ares_bool_t process_resolvconf); 409 #ifdef __APPLE__ 410 ares_status_t ares_init_sysconfig_macos(const ares_channel_t *channel, 411 ares_sysconfig_t *sysconfig); 412 #endif 413 #ifdef USE_WINSOCK 414 ares_status_t ares_init_sysconfig_windows(const ares_channel_t *channel, 415 ares_sysconfig_t *sysconfig); 416 #endif 417 418 ares_status_t ares_parse_sortlist(struct apattern **sortlist, size_t *nsort, 419 const char *str); 420 421 /* Returns ARES_SUCCESS if alias found, alias is set. Returns ARES_ENOTFOUND 422 * if not alias found. Returns other errors on critical failure like 423 * ARES_ENOMEM */ 424 ares_status_t ares_lookup_hostaliases(const ares_channel_t *channel, 425 const char *name, char **alias); 426 427 ares_status_t ares_cat_domain(const char *name, const char *domain, char **s); 428 ares_status_t ares_sortaddrinfo(ares_channel_t *channel, 429 struct ares_addrinfo_node *ai_node); 430 431 void ares_freeaddrinfo_nodes(struct ares_addrinfo_node *ai_node); 432 ares_bool_t ares_is_localhost(const char *name); 433 434 struct ares_addrinfo_node * 435 ares_append_addrinfo_node(struct ares_addrinfo_node **ai_node); 436 void ares_addrinfo_cat_nodes(struct ares_addrinfo_node **head, 437 struct ares_addrinfo_node *tail); 438 439 void ares_freeaddrinfo_cnames(struct ares_addrinfo_cname *ai_cname); 440 441 struct ares_addrinfo_cname * 442 ares_append_addrinfo_cname(struct ares_addrinfo_cname **ai_cname); 443 444 ares_status_t ares_append_ai_node(int aftype, unsigned short port, 445 unsigned int ttl, const void *adata, 446 struct ares_addrinfo_node **nodes); 447 448 void ares_addrinfo_cat_cnames(struct ares_addrinfo_cname **head, 449 struct ares_addrinfo_cname *tail); 450 451 ares_status_t ares_parse_into_addrinfo(const ares_dns_record_t *dnsrec, 452 ares_bool_t cname_only_is_enodata, 453 unsigned short port, 454 struct ares_addrinfo *ai); 455 ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec, 456 const void *addr, int addrlen, 457 int family, struct hostent **host); 458 459 /* host address must be valid or NULL as will create or append */ 460 ares_status_t ares_addrinfo2hostent(const struct ares_addrinfo *ai, int family, 461 struct hostent **host); 462 463 ares_status_t ares_addrinfo2addrttl(const struct ares_addrinfo *ai, int family, 464 size_t req_naddrttls, 465 struct ares_addrttl *addrttls, 466 struct ares_addr6ttl *addr6ttls, 467 size_t *naddrttls); 468 ares_status_t ares_addrinfo_localhost(const char *name, unsigned short port, 469 const struct ares_addrinfo_hints *hints, 470 struct ares_addrinfo *ai); 471 472 ares_status_t ares_servers_update(ares_channel_t *channel, 473 ares_llist_t *server_list, 474 ares_bool_t user_specified); 475 ares_status_t 476 ares_sconfig_append(const ares_channel_t *channel, ares_llist_t **sconfig, 477 const struct ares_addr *addr, unsigned short udp_port, 478 unsigned short tcp_port, const char *ll_iface); 479 ares_status_t ares_sconfig_append_fromstr(const ares_channel_t *channel, 480 ares_llist_t **sconfig, 481 const char *str, 482 ares_bool_t ignore_invalid); 483 ares_status_t ares_in_addr_to_sconfig_llist(const struct in_addr *servers, 484 size_t nservers, 485 ares_llist_t **llist); 486 ares_status_t ares_get_server_addr(const ares_server_t *server, 487 ares_buf_t *buf); 488 489 struct ares_hosts_entry; 490 typedef struct ares_hosts_entry ares_hosts_entry_t; 491 492 void ares_hosts_file_destroy(ares_hosts_file_t *hf); 493 ares_status_t ares_hosts_search_ipaddr(ares_channel_t *channel, 494 ares_bool_t use_env, const char *ipaddr, 495 const ares_hosts_entry_t **entry); 496 ares_status_t ares_hosts_search_host(ares_channel_t *channel, 497 ares_bool_t use_env, const char *host, 498 const ares_hosts_entry_t **entry); 499 ares_status_t ares_hosts_entry_to_hostent(const ares_hosts_entry_t *entry, 500 int family, struct hostent **hostent); 501 ares_status_t ares_hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry, 502 const char *name, int family, 503 unsigned short port, 504 ares_bool_t want_cnames, 505 struct ares_addrinfo *ai); 506 507 /* Same as ares_query_dnsrec() except does not take a channel lock. Use this 508 * if a channel lock is already held */ 509 ares_status_t ares_query_nolock(ares_channel_t *channel, const char *name, 510 ares_dns_class_t dnsclass, 511 ares_dns_rec_type_t type, 512 ares_callback_dnsrec callback, void *arg, 513 unsigned short *qid); 514 515 /*! Flags controlling behavior for ares_send_nolock() */ 516 typedef enum { 517 ARES_SEND_FLAG_NOCACHE = 1 << 0, /*!< Do not query the cache */ 518 ARES_SEND_FLAG_NORETRY = 1 << 1 /*!< Do not retry this query on error */ 519 } ares_send_flags_t; 520 521 /* Similar to ares_send_dnsrec() except does not take a channel lock, allows 522 * specifying a particular server to use, and also flags controlling behavior. 523 */ 524 ares_status_t ares_send_nolock(ares_channel_t *channel, ares_server_t *server, 525 ares_send_flags_t flags, 526 const ares_dns_record_t *dnsrec, 527 ares_callback_dnsrec callback, void *arg, 528 unsigned short *qid); 529 530 /* Same as ares_gethostbyaddr() except does not take a channel lock. Use this 531 * if a channel lock is already held */ 532 void ares_gethostbyaddr_nolock(ares_channel_t *channel, const void *addr, 533 int addrlen, int family, 534 ares_host_callback callback, void *arg); 535 536 /*! Parse a compressed DNS name as defined in RFC1035 starting at the current 537 * offset within the buffer. 538 * 539 * It is assumed that either a const buffer is being used, or before 540 * the message processing was started that ares_buf_reclaim() was called. 541 * 542 * \param[in] buf Initialized buffer object 543 * \param[out] name Pointer passed by reference to be filled in with 544 * allocated string of the parsed name that must be 545 * ares_free()'d by the caller. 546 * \param[in] is_hostname if ARES_TRUE, will validate the character set for 547 * a valid hostname or will return error. 548 * \return ARES_SUCCESS on success 549 */ 550 ares_status_t ares_dns_name_parse(ares_buf_t *buf, char **name, 551 ares_bool_t is_hostname); 552 553 /*! Write the DNS name to the buffer in the DNS domain-name syntax as a 554 * series of labels. The maximum domain name length is 255 characters with 555 * each label being a maximum of 63 characters. If the validate_hostname 556 * flag is set, it will strictly validate the character set. 557 * 558 * \param[in,out] buf Initialized buffer object to write name to 559 * \param[in,out] list Pointer passed by reference to maintain a list of 560 * domain name to indexes used for name compression. 561 * Pass NULL (not by reference) if name compression isn't 562 * desired. Otherwise the list will be automatically 563 * created upon first entry. 564 * \param[in] validate_hostname Validate the hostname character set. 565 * \param[in] name Name to write out, it may have escape 566 * sequences. 567 * \return ARES_SUCCESS on success, most likely ARES_EBADNAME if the name is 568 * bad. 569 */ 570 ares_status_t ares_dns_name_write(ares_buf_t *buf, ares_llist_t **list, 571 ares_bool_t validate_hostname, 572 const char *name); 573 574 /*! Check if the queue is empty, if so, wake any waiters. This is only 575 * effective if built with threading support. 576 * 577 * Must be holding a channel lock when calling this function. 578 * 579 * \param[in] channel Initialized ares channel object 580 */ 581 void ares_queue_notify_empty(ares_channel_t *channel); 582 583 #define ARES_CONFIG_CHECK(x) \ 584 (x && x->lookups && ares_slist_len(x->servers) > 0 && x->timeout > 0 && \ 585 x->tries > 0) 586 587 ares_bool_t ares_subnet_match(const struct ares_addr *addr, 588 const struct ares_addr *subnet, 589 unsigned char netmask); 590 ares_bool_t ares_addr_is_linklocal(const struct ares_addr *addr); 591 592 void ares_qcache_destroy(ares_qcache_t *cache); 593 ares_status_t ares_qcache_create(ares_rand_state *rand_state, 594 unsigned int max_ttl, 595 ares_qcache_t **cache_out); 596 void ares_qcache_flush(ares_qcache_t *cache); 597 ares_status_t ares_qcache_insert(ares_channel_t *channel, 598 const ares_timeval_t *now, 599 const ares_query_t *query, 600 ares_dns_record_t *dnsrec); 601 ares_status_t ares_qcache_fetch(ares_channel_t *channel, 602 const ares_timeval_t *now, 603 const ares_dns_record_t *dnsrec, 604 const ares_dns_record_t **dnsrec_resp); 605 606 void ares_metrics_record(const ares_query_t *query, ares_server_t *server, 607 ares_status_t status, const ares_dns_record_t *dnsrec); 608 size_t ares_metrics_server_timeout(const ares_server_t *server, 609 const ares_timeval_t *now); 610 611 ares_status_t ares_cookie_apply(ares_dns_record_t *dnsrec, ares_conn_t *conn, 612 const ares_timeval_t *now); 613 ares_status_t ares_cookie_validate(ares_query_t *query, 614 const ares_dns_record_t *dnsresp, 615 ares_conn_t *conn, 616 const ares_timeval_t *now, 617 ares_array_t **requeue); 618 619 ares_status_t ares_channel_threading_init(ares_channel_t *channel); 620 void ares_channel_threading_destroy(ares_channel_t *channel); 621 void ares_channel_lock(const ares_channel_t *channel); 622 void ares_channel_unlock(const ares_channel_t *channel); 623 624 struct ares_event_thread; 625 typedef struct ares_event_thread ares_event_thread_t; 626 627 void ares_event_thread_destroy(ares_channel_t *channel); 628 ares_status_t ares_event_thread_init(ares_channel_t *channel); 629 630 631 #ifdef _WIN32 632 # define HOSTENT_ADDRTYPE_TYPE short 633 # define HOSTENT_LENGTH_TYPE short 634 #else 635 # define HOSTENT_ADDRTYPE_TYPE int 636 # define HOSTENT_LENGTH_TYPE int 637 #endif 638 639 #endif /* __ARES_PRIVATE_H */