Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade c-ares #1678

Merged
merged 3 commits into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions deps/cares/cares.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
'direct_dependent_settings': {
'include_dirs': [ 'include' ]
},
'defines': [ 'HAVE_CONFIG_H' ],
'sources': [
'common.gypi',
'include/ares.h',
Expand Down Expand Up @@ -96,7 +95,6 @@
'src/inet_ntop.c',
'src/ares_inet_net_pton.h',
'src/setup_once.h',
'src/windows_port.c'
],
'conditions': [
[ 'library=="static_library"', {
Expand All @@ -107,7 +105,7 @@
[ 'OS=="win"', {
'include_dirs': [ 'config/win32' ],
'sources': [
'config/win32/ares_config.h',
'src/config-win32.h',
'src/windows_port.c',
'src/ares_getenv.c',
'src/ares_iphlpapi.h',
Expand All @@ -126,6 +124,7 @@
'-Wextra',
'-Wno-unused-parameter'
],
'defines': [ 'HAVE_CONFIG_H' ],
}],
[ 'OS not in "win android"', {
'cflags': [
Expand Down
49 changes: 1 addition & 48 deletions deps/cares/include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,8 @@
# define WIN32
#endif

/*************************** libuv patch ***************/

/*
* We want to avoid autoconf altogether since there are a finite number of
* operating systems and simply build c-ares. Therefore we do not want the
* configurations provided by ares_build.h since we are always statically
* linking c-ares into libuv. Having a system dependent ares_build.h forces
* all users of ares.h to include the correct ares_build.h. We do not care
* about the linking checks provided by ares_rules.h. This would complicate
* the libuv build process.
*/


#if defined(WIN32)
/* Configure process defines this to 1 when it finds out that system */
/* header file ws2tcpip.h must be included by the external interface. */
/* #undef CARES_PULL_WS2TCPIP_H */
# include <winsock2.h>
# include <ws2tcpip.h>
# include <windows.h>

#else /* Not Windows */

# include <sys/time.h>
# include <sys/types.h>
# include <sys/socket.h>
#endif

#if 0
/* The size of `long', as computed by sizeof. */
#define CARES_SIZEOF_LONG 4
#endif

/* Integral data type used for ares_socklen_t. */
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t

#if 0
/* The size of `ares_socklen_t', as computed by sizeof. */
#define CARES_SIZEOF_ARES_SOCKLEN_T 4
#endif

/* Data type definition of ares_socklen_t. */
typedef int ares_socklen_t;

#if 0 /* libuv disabled */
#include "ares_rules.h" /* c-ares rules enforcement */
#endif

/*********************** end libuv patch ***************/
typedef unsigned ares_socklen_t;

#include <sys/types.h>

Expand Down
4 changes: 2 additions & 2 deletions deps/cares/include/ares_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

#define ARES_VERSION_MAJOR 1
#define ARES_VERSION_MINOR 10
#define ARES_VERSION_PATCH 0
#define ARES_VERSION_PATCH 1
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
(ARES_VERSION_MINOR<<8)|\
(ARES_VERSION_PATCH))
#define ARES_VERSION_STR "1.10.0-DEV"
#define ARES_VERSION_STR "1.10.1-DEV"

#if (ARES_VERSION >= 0x010700)
# define CARES_HAVE_ARES_LIBRARY_INIT 1
Expand Down
5 changes: 4 additions & 1 deletion deps/cares/src/ares__read_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
/* Allocate more space. */
newbuf = realloc(*buf, *bufsize * 2);
if (!newbuf)
return ARES_ENOMEM;
{
free(*buf);
return ARES_ENOMEM;
}
*buf = newbuf;
*bufsize *= 2;
}
Expand Down
5 changes: 3 additions & 2 deletions deps/cares/src/ares_gethostbyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ static void host_callback(void *arg, int status, int timeouts,
else if (hquery->sent_family == AF_INET6)
{
status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
if ((status == ARES_ENODATA || status == ARES_EBADRESP) &&
hquery->want_family == AF_UNSPEC) {
if ((status == ARES_ENODATA || status == ARES_EBADRESP ||
(status == ARES_SUCCESS && host && host->h_addr_list[0] == NULL)) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just recalling, are we going to switch io.js to use the proper error names instead of the made up one we have (ENOTFOUND)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no love for ENOTFOUND but renaming it may result in a lot of breakage. :-/

hquery->want_family == AF_UNSPEC) {
/* The query returned something but either there were no AAAA
records (e.g. just CNAME) or the response was malformed. Try
looking up A instead. */
Expand Down
20 changes: 14 additions & 6 deletions deps/cares/src/ares_getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ static char *lookup_service(unsigned short port, int flags,
struct servent se;
#endif
char tmpbuf[4096];
char *name;
size_t name_len;

if (port)
{
Expand Down Expand Up @@ -323,14 +325,20 @@ static char *lookup_service(unsigned short port, int flags,
#endif
}
if (sep && sep->s_name)
/* get service name */
strcpy(tmpbuf, sep->s_name);
{
/* get service name */
name = sep->s_name;
}
else
/* get port as a string */
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
if (strlen(tmpbuf) < buflen)
{
/* get port as a string */
sprintf(tmpbuf, "%u", (unsigned int)ntohs(port));
name = tmpbuf;
}
name_len = strlen(name);
if (name_len < buflen)
/* return it if buffer big enough */
strcpy(buf, tmpbuf);
memcpy(buf, name, name_len + 1);
else
/* avoid reusing previous one */
buf[0] = '\0';
Expand Down
8 changes: 3 additions & 5 deletions deps/cares/src/ares_getsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ int ares_getsock(ares_channel channel,
/* Are there any active queries? */
int active_queries = !ares__is_list_empty(&(channel->all_queries));

for (i = 0;
(i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
i++)
for (i = 0; i < channel->nservers; i++)
{
server = &channel->servers[i];
/* We only need to register interest in UDP sockets if we have
* outstanding queries.
*/
if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
{
if(sockindex >= numsocks)
if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
break;
socks[sockindex] = server->udp_socket;
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
Expand All @@ -52,7 +50,7 @@ int ares_getsock(ares_channel channel,
*/
if (server->tcp_socket != ARES_SOCKET_BAD)
{
if(sockindex >= numsocks)
if(sockindex >= numsocks || sockindex >= ARES_GETSOCK_MAXNUM)
break;
socks[sockindex] = server->tcp_socket;
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
Expand Down
13 changes: 10 additions & 3 deletions deps/cares/src/ares_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ int ares_dup(ares_channel *dest, ares_channel src)
which is most of them */
rc = ares_save_options(src, &opts, &optmask);
if(rc)
{
ares_destroy_options(&opts);
return rc;
}

/* Then create the new channel with those options */
rc = ares_init_options(dest, &opts, optmask);
Expand Down Expand Up @@ -1158,20 +1161,24 @@ static int init_by_resolv_conf(ares_channel channel)
FILE *fp;
size_t linesize;
int error;
int update_domains;

/* Don't read resolv.conf and friends if we don't have to */
if (ARES_CONFIG_CHECK(channel))
return ARES_SUCCESS;

/* Only update search domains if they're not already specified */
update_domains = (channel->ndomains == -1);

fp = fopen(PATH_RESOLV_CONF, "r");
if (fp) {
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
{
if ((p = try_config(line, "domain", ';')))
if ((p = try_config(line, "domain", ';')) && update_domains)
status = config_domain(channel, p);
else if ((p = try_config(line, "lookup", ';')) && !channel->lookups)
status = config_lookup(channel, p, "bind", "file");
else if ((p = try_config(line, "search", ';')))
else if ((p = try_config(line, "search", ';')) && update_domains)
status = set_search(channel, p);
else if ((p = try_config(line, "nameserver", ';')) &&
channel->nservers == -1)
Expand Down Expand Up @@ -1410,7 +1417,7 @@ static int init_by_defaults(ares_channel channel)
goto error;
}

} WHILE_FALSE;
} while (res != 0);

dot = strchr(hostname, '.');
if (dot) {
Expand Down
2 changes: 1 addition & 1 deletion deps/cares/src/ares_ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct addrinfo
#endif
#endif

/* Defined in ares_net_pton.c for no particular reason. */
/* Defined in inet_net_pton.c for no particular reason. */
extern const struct ares_in6_addr ares_in6addr_any; /* :: */


Expand Down
48 changes: 41 additions & 7 deletions deps/cares/src/ares_nowarn.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (C) 2010-2012 by Daniel Stenberg
/* Copyright (C) 2010-2013 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
Expand All @@ -21,6 +21,10 @@
# include <assert.h>
#endif

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#if defined(__INTEL_COMPILER) && defined(__unix__)

#ifdef HAVE_NETINET_IN_H
Expand All @@ -36,13 +40,43 @@

#include "ares_nowarn.h"

#define CARES_MASK_USHORT (~(unsigned short) 0)
#define CARES_MASK_UINT (~(unsigned int) 0)
#define CARES_MASK_ULONG (~(unsigned long) 0)
#if (SIZEOF_SHORT == 2)
# define CARES_MASK_SSHORT 0x7FFF
# define CARES_MASK_USHORT 0xFFFF
#elif (SIZEOF_SHORT == 4)
# define CARES_MASK_SSHORT 0x7FFFFFFF
# define CARES_MASK_USHORT 0xFFFFFFFF
#elif (SIZEOF_SHORT == 8)
# define CARES_MASK_SSHORT 0x7FFFFFFFFFFFFFFF
# define CARES_MASK_USHORT 0xFFFFFFFFFFFFFFFF
#else
# error "SIZEOF_SHORT not defined"
#endif

#define CARES_MASK_SSHORT (CARES_MASK_USHORT >> 1)
#define CARES_MASK_SINT (CARES_MASK_UINT >> 1)
#define CARES_MASK_SLONG (CARES_MASK_ULONG >> 1)
#if (SIZEOF_INT == 2)
# define CARES_MASK_SINT 0x7FFF
# define CARES_MASK_UINT 0xFFFF
#elif (SIZEOF_INT == 4)
# define CARES_MASK_SINT 0x7FFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFF
#elif (SIZEOF_INT == 8)
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFF
#elif (SIZEOF_INT == 16)
# define CARES_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
# define CARES_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
#else
# error "SIZEOF_INT not defined"
#endif

#ifndef HAVE_LIMITS_H
/* systems without <limits.h> we guess have 32 bit longs */
#define CARES_MASK_SLONG 0x7FFFFFFFL
#define CARES_MASK_ULONG 0xFFFFFFFFUL
#else
#define CARES_MASK_ULONG ULONG_MAX
#define CARES_MASK_SLONG LONG_MAX
#endif

/*
** unsigned size_t to signed long
Expand Down
3 changes: 3 additions & 0 deletions deps/cares/src/ares_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ int ares_set_servers_csv(ares_channel channel,
return ARES_SUCCESS; /* blank all servers */

csv = malloc(i + 2);
if (!csv)
return ARES_ENOMEM;

strcpy(csv, _csv);
if (csv[i-1] != ',') { /* make parsing easier by ensuring ending ',' */
csv[i] = ',';
Expand Down
5 changes: 4 additions & 1 deletion deps/cares/src/ares_parse_soa_reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ ares_parse_soa_reply(const unsigned char *abuf, int alen,
/* allocate result struct */
soa = ares_malloc_data(ARES_DATATYPE_SOA_REPLY);
if (!soa)
return ARES_ENOMEM;
{
status = ARES_ENOMEM;
goto failed_stat;
}

/* nsname */
status = ares__expand_name_for_response(aptr, abuf, alen, &soa->nsname, &len);
Expand Down
7 changes: 1 addition & 6 deletions deps/cares/src/ares_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,7 @@ struct ares_channeldata {
/* return true if now is exactly check time or later */
int ares__timedout(struct timeval *now,
struct timeval *check);
/* add the specific number of milliseconds to the time in the first argument */
int ares__timeadd(struct timeval *now,
int millisecs);
/* return time offset between now and (future) check, in milliseconds */
long ares__timeoffset(struct timeval *now,
struct timeval *check);

/* returns ARES_SUCCESS if library has been initialized */
int ares_library_initialized(void);
void ares__send_query(ares_channel channel, struct query *query,
Expand Down
17 changes: 2 additions & 15 deletions deps/cares/src/ares_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ int ares__timedout(struct timeval *now,
}

/* add the specific number of milliseconds to the time in the first argument */
int ares__timeadd(struct timeval *now,
int millisecs)
static void timeadd(struct timeval *now, int millisecs)
{
now->tv_sec += millisecs/1000;
now->tv_usec += (millisecs%1000)*1000;
Expand All @@ -112,19 +111,8 @@ int ares__timeadd(struct timeval *now,
++(now->tv_sec);
now->tv_usec -= 1000000;
}

return 0;
}

/* return time offset between now and (future) check, in milliseconds */
long ares__timeoffset(struct timeval *now,
struct timeval *check)
{
return (check->tv_sec - now->tv_sec)*1000 +
(check->tv_usec - now->tv_usec)/1000;
}


/*
* generic process function
*/
Expand Down Expand Up @@ -831,8 +819,7 @@ void ares__send_query(ares_channel channel, struct query *query,
timeplus = channel->timeout << (query->try_count / channel->nservers);
timeplus = (timeplus * (9 + (rand () & 7))) / 16;
query->timeout = *now;
ares__timeadd(&query->timeout,
timeplus);
timeadd(&query->timeout, timeplus);
/* Keep track of queries bucketed by timeout, so we can process
* timeout events quickly.
*/
Expand Down
Loading