2006-07-26 12:54:08 +02:00
|
|
|
#ifndef __ARES_PRIVATE_H
|
|
|
|
#define __ARES_PRIVATE_H
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of M.I.T. not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the
|
|
|
|
* software without specific, written prior permission.
|
|
|
|
* M.I.T. makes no representations about the suitability of
|
|
|
|
* this software for any purpose. It is provided "as is"
|
|
|
|
* without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2004-08-20 15:45:26 +02:00
|
|
|
#if !defined(WIN32) || defined(WATT32)
|
2003-10-07 23:54:04 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
/* We define closesocket() here so that we can use this function all over
|
|
|
|
the source code for closing sockets. */
|
|
|
|
#define closesocket(x) close(x)
|
|
|
|
#endif
|
|
|
|
|
2004-07-01 08:58:47 +02:00
|
|
|
#ifdef WATT32
|
|
|
|
#include <tcp.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#undef closesocket
|
|
|
|
#define closesocket(s) close_s(s)
|
|
|
|
#define writev(s,v,c) writev_s(s,v,c)
|
|
|
|
#endif
|
|
|
|
|
2005-08-10 19:03:53 +02:00
|
|
|
#ifdef NETWARE
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
2004-10-06 09:50:18 +02:00
|
|
|
#define DEFAULT_TIMEOUT 5
|
|
|
|
#define DEFAULT_TRIES 4
|
2003-10-07 23:54:04 +02:00
|
|
|
#ifndef INADDR_NONE
|
2004-10-06 09:50:18 +02:00
|
|
|
#define INADDR_NONE 0xffffffff
|
2003-10-07 23:54:04 +02:00
|
|
|
#endif
|
|
|
|
|
2004-08-20 15:45:26 +02:00
|
|
|
#if defined(WIN32) && !defined(WATT32)
|
2003-10-07 23:54:04 +02:00
|
|
|
|
2004-11-10 15:30:25 +01:00
|
|
|
#define IS_NT() ((int)GetVersion() > 0)
|
2003-10-07 23:54:04 +02:00
|
|
|
#define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP"
|
|
|
|
#define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"
|
|
|
|
#define NAMESERVER "NameServer"
|
|
|
|
#define DHCPNAMESERVER "DhcpNameServer"
|
2004-09-26 20:20:58 +02:00
|
|
|
#define DATABASEPATH "DatabasePath"
|
|
|
|
#define WIN_PATH_HOSTS "\\hosts"
|
2004-07-01 15:55:13 +02:00
|
|
|
|
|
|
|
#elif defined(WATT32)
|
|
|
|
|
|
|
|
#define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf"
|
|
|
|
|
2004-07-04 23:36:32 +02:00
|
|
|
#elif defined(NETWARE)
|
|
|
|
|
|
|
|
#define PATH_RESOLV_CONF "sys:/etc/resolv.cfg"
|
2004-10-06 09:50:18 +02:00
|
|
|
#define PATH_HOSTS "sys:/etc/hosts"
|
2004-07-04 23:36:32 +02:00
|
|
|
|
2006-01-05 08:57:32 +01:00
|
|
|
#elif defined(__riscos__)
|
|
|
|
|
|
|
|
#define PATH_HOSTS "InetDBase:Hosts"
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
#else
|
|
|
|
|
2004-10-06 09:50:18 +02:00
|
|
|
#define PATH_RESOLV_CONF "/etc/resolv.conf"
|
2003-10-07 23:54:04 +02:00
|
|
|
#ifdef ETC_INET
|
2004-10-06 09:50:18 +02:00
|
|
|
#define PATH_HOSTS "/etc/inet/hosts"
|
2003-10-07 23:54:04 +02:00
|
|
|
#else
|
2004-10-06 09:50:18 +02:00
|
|
|
#define PATH_HOSTS "/etc/hosts"
|
2003-10-07 23:54:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-05-30 23:11:10 +02:00
|
|
|
#define ARES_ID_KEY_LEN 31
|
|
|
|
|
2005-04-15 17:25:16 +02:00
|
|
|
#include "ares_ipv6.h"
|
2007-10-02 04:18:01 +02:00
|
|
|
#include "ares_llist.h"
|
2005-04-15 17:25:16 +02:00
|
|
|
|
2007-09-29 20:18:47 +02:00
|
|
|
struct query;
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
struct send_request {
|
|
|
|
/* Remaining data to send */
|
2004-02-04 08:52:13 +01:00
|
|
|
const unsigned char *data;
|
2004-02-27 14:21:47 +01:00
|
|
|
size_t len;
|
2003-10-07 23:54:04 +02:00
|
|
|
|
2007-09-28 16:28:14 +02:00
|
|
|
/* The query for which we're sending this data */
|
|
|
|
struct query* owner_query;
|
|
|
|
/* The buffer we're using, if we have our own copy of the packet */
|
|
|
|
unsigned char *data_storage;
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
/* Next request in queue */
|
|
|
|
struct send_request *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct server_state {
|
|
|
|
struct in_addr addr;
|
2004-07-23 00:18:45 +02:00
|
|
|
ares_socket_t udp_socket;
|
|
|
|
ares_socket_t tcp_socket;
|
2003-10-07 23:54:04 +02:00
|
|
|
|
|
|
|
/* Mini-buffer for reading the length word */
|
|
|
|
unsigned char tcp_lenbuf[2];
|
|
|
|
int tcp_lenbuf_pos;
|
|
|
|
int tcp_length;
|
|
|
|
|
|
|
|
/* Buffer for reading actual TCP data */
|
|
|
|
unsigned char *tcp_buffer;
|
|
|
|
int tcp_buffer_pos;
|
|
|
|
|
|
|
|
/* TCP output queue */
|
|
|
|
struct send_request *qhead;
|
|
|
|
struct send_request *qtail;
|
2007-09-28 16:28:14 +02:00
|
|
|
|
|
|
|
/* Which incarnation of this connection is this? We don't want to
|
|
|
|
* retransmit requests into the very same socket, but if the server
|
|
|
|
* closes on us and we re-open the connection, then we do want to
|
|
|
|
* re-send. */
|
|
|
|
int tcp_connection_generation;
|
|
|
|
|
2007-09-29 20:18:47 +02:00
|
|
|
/* Circular, doubly-linked list of outstanding queries to this server */
|
|
|
|
struct list_node queries_to_server;
|
|
|
|
|
|
|
|
/* Link back to owning channel */
|
|
|
|
ares_channel channel;
|
|
|
|
|
2007-09-28 16:28:14 +02:00
|
|
|
/* Is this server broken? We mark connections as broken when a
|
|
|
|
* request that is queued for sending times out.
|
|
|
|
*/
|
|
|
|
int is_broken;
|
2003-10-07 23:54:04 +02:00
|
|
|
};
|
|
|
|
|
2007-09-29 20:18:47 +02:00
|
|
|
/* State to represent a DNS query */
|
2003-10-07 23:54:04 +02:00
|
|
|
struct query {
|
|
|
|
/* Query ID from qbuf, for faster lookup, and current timeout */
|
|
|
|
unsigned short qid;
|
|
|
|
time_t timeout;
|
|
|
|
|
2007-09-29 20:18:47 +02:00
|
|
|
/*
|
|
|
|
* Links for the doubly-linked lists in which we insert a query.
|
|
|
|
* These circular, doubly-linked lists that are hash-bucketed based
|
|
|
|
* the attributes we care about, help making most important
|
|
|
|
* operations O(1).
|
|
|
|
*/
|
|
|
|
struct list_node queries_by_qid; /* hopefully in same cache line as qid */
|
|
|
|
struct list_node queries_by_timeout;
|
|
|
|
struct list_node queries_to_server;
|
|
|
|
struct list_node all_queries;
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
/* Query buf with length at beginning, for TCP transmission */
|
2004-02-04 08:52:13 +01:00
|
|
|
unsigned char *tcpbuf;
|
2003-10-07 23:54:04 +02:00
|
|
|
int tcplen;
|
|
|
|
|
|
|
|
/* Arguments passed to ares_send() (qbuf points into tcpbuf) */
|
2004-02-04 08:52:13 +01:00
|
|
|
const unsigned char *qbuf;
|
2003-10-07 23:54:04 +02:00
|
|
|
int qlen;
|
|
|
|
ares_callback callback;
|
|
|
|
void *arg;
|
|
|
|
|
|
|
|
/* Query status */
|
|
|
|
int try;
|
|
|
|
int server;
|
2007-09-28 16:28:14 +02:00
|
|
|
struct query_server_info *server_info; /* per-server state */
|
2003-10-07 23:54:04 +02:00
|
|
|
int using_tcp;
|
|
|
|
int error_status;
|
2007-09-28 16:46:51 +02:00
|
|
|
int timeouts; /* number of timeouts we saw for this request */
|
2003-10-07 23:54:04 +02:00
|
|
|
};
|
|
|
|
|
2007-09-28 16:28:14 +02:00
|
|
|
/* Per-server state for a query */
|
|
|
|
struct query_server_info {
|
|
|
|
int skip_server; /* should we skip server, due to errors, etc? */
|
|
|
|
int tcp_connection_generation; /* into which TCP connection did we send? */
|
|
|
|
};
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
/* An IP address pattern; matches an IP address X if X & mask == addr */
|
2005-04-09 18:49:47 +02:00
|
|
|
#define PATTERN_MASK 0x1
|
|
|
|
#define PATTERN_CIDR 0x2
|
|
|
|
|
2005-04-09 21:59:59 +02:00
|
|
|
union ares_addr {
|
|
|
|
struct in_addr addr4;
|
|
|
|
struct in6_addr addr6;
|
|
|
|
};
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
struct apattern {
|
2005-04-09 21:59:59 +02:00
|
|
|
union ares_addr addr;
|
2005-04-09 18:49:47 +02:00
|
|
|
union
|
|
|
|
{
|
2005-04-09 21:59:59 +02:00
|
|
|
union ares_addr addr;
|
2005-04-09 18:49:47 +02:00
|
|
|
unsigned short bits;
|
|
|
|
} mask;
|
2005-04-09 21:59:59 +02:00
|
|
|
int family;
|
2005-04-09 18:49:47 +02:00
|
|
|
unsigned short type;
|
2003-10-07 23:54:04 +02:00
|
|
|
};
|
|
|
|
|
2007-05-30 23:11:10 +02:00
|
|
|
typedef struct rc4_key
|
|
|
|
{
|
|
|
|
unsigned char state[256];
|
|
|
|
unsigned char x;
|
|
|
|
unsigned char y;
|
|
|
|
} rc4_key;
|
|
|
|
|
2003-10-07 23:54:04 +02:00
|
|
|
struct ares_channeldata {
|
|
|
|
/* Configuration data */
|
|
|
|
int flags;
|
|
|
|
int timeout;
|
|
|
|
int tries;
|
|
|
|
int ndots;
|
|
|
|
int udp_port;
|
|
|
|
int tcp_port;
|
2007-09-28 16:46:51 +02:00
|
|
|
int socket_send_buffer_size;
|
|
|
|
int socket_receive_buffer_size;
|
2003-10-07 23:54:04 +02:00
|
|
|
char **domains;
|
|
|
|
int ndomains;
|
|
|
|
struct apattern *sortlist;
|
|
|
|
int nsort;
|
|
|
|
char *lookups;
|
|
|
|
|
|
|
|
/* Server addresses and communications state */
|
|
|
|
struct server_state *servers;
|
|
|
|
int nservers;
|
|
|
|
|
|
|
|
/* ID to use for next query */
|
|
|
|
unsigned short next_id;
|
2007-05-30 23:11:10 +02:00
|
|
|
/* key to use when generating new ids */
|
|
|
|
rc4_key id_key;
|
2003-10-07 23:54:04 +02:00
|
|
|
|
2007-09-28 16:28:14 +02:00
|
|
|
/* Generation number to use for the next TCP socket open/close */
|
|
|
|
int tcp_connection_generation;
|
|
|
|
|
2007-09-29 20:18:47 +02:00
|
|
|
/* The time at which we last called process_timeouts() */
|
|
|
|
time_t last_timeout_processed;
|
|
|
|
|
|
|
|
/* Circular, doubly-linked list of queries, bucketed various ways.... */
|
|
|
|
/* All active queries in a single list: */
|
|
|
|
struct list_node all_queries;
|
|
|
|
/* Queries bucketed by qid, for quickly dispatching DNS responses: */
|
|
|
|
#define ARES_QID_TABLE_SIZE 2048
|
|
|
|
struct list_node queries_by_qid[ARES_QID_TABLE_SIZE];
|
|
|
|
/* Queries bucketed by timeout, for quickly handling timeouts: */
|
|
|
|
#define ARES_TIMEOUT_TABLE_SIZE 1024
|
|
|
|
struct list_node queries_by_timeout[ARES_TIMEOUT_TABLE_SIZE];
|
2006-05-03 08:11:44 +02:00
|
|
|
|
|
|
|
ares_sock_state_cb sock_state_cb;
|
|
|
|
void *sock_state_cb_data;
|
2003-10-07 23:54:04 +02:00
|
|
|
};
|
|
|
|
|
2007-05-30 23:11:10 +02:00
|
|
|
void ares__rc4(rc4_key* key,unsigned char *buffer_ptr, int buffer_len);
|
2003-10-07 23:54:04 +02:00
|
|
|
void ares__send_query(ares_channel channel, struct query *query, time_t now);
|
2006-05-03 08:11:44 +02:00
|
|
|
void ares__close_sockets(ares_channel channel, struct server_state *server);
|
2005-04-08 17:41:31 +02:00
|
|
|
int ares__get_hostent(FILE *fp, int family, struct hostent **host);
|
2003-10-07 23:54:04 +02:00
|
|
|
int ares__read_line(FILE *fp, char **buf, int *bufsize);
|
2007-09-29 20:18:47 +02:00
|
|
|
void ares__free_query(struct query *query);
|
2007-05-30 23:11:10 +02:00
|
|
|
short ares__generate_new_id(rc4_key* key);
|
|
|
|
|
|
|
|
#define ARES_SWAP_BYTE(a,b) \
|
|
|
|
{ unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; }
|
2004-02-17 08:40:02 +01:00
|
|
|
|
2006-05-03 08:11:44 +02:00
|
|
|
#define SOCK_STATE_CALLBACK(c, s, r, w) \
|
|
|
|
do { \
|
|
|
|
if ((c)->sock_state_cb) \
|
|
|
|
(c)->sock_state_cb((c)->sock_state_cb_data, (s), (r), (w)); \
|
|
|
|
} while (0)
|
|
|
|
|
2004-02-17 08:40:02 +01:00
|
|
|
#ifdef CURLDEBUG
|
|
|
|
/* This is low-level hard-hacking memory leak tracking and similar. Using the
|
|
|
|
libcurl lowlevel code from within library is ugly and only works when
|
|
|
|
c-ares is built and linked with a similarly debug-build libcurl, but we do
|
|
|
|
this anyway for convenience. */
|
|
|
|
#include "../lib/memdebug.h"
|
|
|
|
#endif
|
2006-07-26 12:54:08 +02:00
|
|
|
|
|
|
|
#endif /* __ARES_PRIVATE_H */
|