Skip to content

Commit

Permalink
deps: sync with upstream c-ares/c-ares@4ef6817
Browse files Browse the repository at this point in the history
PR-URL: #5199
Reviewed-By: Myles Borins <[email protected]>
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
indutny authored and rvagg committed Feb 15, 2016
1 parent 18b00de commit 35c3832
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
8 changes: 8 additions & 0 deletions deps/cares/include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
int type,
void *data);

typedef int (*ares_sock_config_callback)(ares_socket_t socket_fd,
int type,
void *data);

CARES_EXTERN int ares_library_init(int flags);

CARES_EXTERN int ares_library_init_mem(int flags,
Expand Down Expand Up @@ -344,6 +348,10 @@ CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
ares_sock_create_callback callback,
void *user_data);

CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel,
ares_sock_config_callback callback,
void *user_data);

CARES_EXTERN int ares_set_sortlist(ares_channel channel,
const char *sortstr);

Expand Down
54 changes: 34 additions & 20 deletions deps/cares/src/ares_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ static void natural_mask(struct apattern *pat);
!defined(ANDROID) && !defined(__ANDROID__) && !defined(CARES_USE_LIBRESOLV)
static int config_domain(ares_channel channel, char *str);
static int config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *filech);
const char *bindch, const char *altbindch,
const char *filech);
static char *try_config(char *s, const char *opt, char scc);
#endif

Expand Down Expand Up @@ -164,6 +165,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
channel->sock_state_cb_data = NULL;
channel->sock_create_cb = NULL;
channel->sock_create_cb_data = NULL;
channel->sock_config_cb = NULL;
channel->sock_config_cb_data = NULL;

channel->last_server = 0;
channel->last_timeout_processed = (time_t)now.tv_sec;
Expand Down Expand Up @@ -291,6 +294,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
/* Now clone the options that ares_save_options() doesn't support. */
(*dest)->sock_create_cb = src->sock_create_cb;
(*dest)->sock_create_cb_data = src->sock_create_cb_data;
(*dest)->sock_config_cb = src->sock_config_cb;
(*dest)->sock_config_cb_data = src->sock_config_cb_data;

strncpy((*dest)->local_dev_name, src->local_dev_name,
sizeof(src->local_dev_name));
Expand Down Expand Up @@ -1025,11 +1030,6 @@ static int get_DNS_AdaptersAddresses(char **outptr)
}
else if (namesrvr.sa->sa_family == AF_INET6)
{
/* Windows apparently always reports some IPv6 DNS servers that
* prefixed with fec0:0:0:ffff. These ususally do not point to
* working DNS servers, so we ignore them. */
if (strncmp(txtaddr, "fec0:0:0:ffff:", 14) == 0)
continue;
if (memcmp(&namesrvr.sa6->sin6_addr, &ares_in6addr_any,
sizeof(namesrvr.sa6->sin6_addr)) == 0)
continue;
Expand Down Expand Up @@ -1269,7 +1269,7 @@ static int init_by_resolv_conf(ares_channel channel)
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");
status = config_lookup(channel, p, "bind", NULL, "file");
else if ((p = try_config(line, "search", ';')) && update_domains)
status = set_search(channel, p);
else if ((p = try_config(line, "nameserver", ';')) &&
Expand Down Expand Up @@ -1310,8 +1310,7 @@ static int init_by_resolv_conf(ares_channel channel)
ARES_SUCCESS)
{
if ((p = try_config(line, "hosts:", '\0')) && !channel->lookups)
/* ignore errors */
(void)config_lookup(channel, p, "dns", "files");
(void)config_lookup(channel, p, "dns", "resolve", "files");
}
fclose(fp);
}
Expand All @@ -1320,15 +1319,16 @@ static int init_by_resolv_conf(ares_channel channel)
switch(error) {
case ENOENT:
case ESRCH:
status = ARES_EOF;
break;
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
error, strerror(error)));
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
"/etc/nsswitch.conf"));
status = ARES_EFILE;
}

/* ignore error, maybe we will get luck in next if clause */
status = ARES_EOF;
}
}

Expand All @@ -1341,7 +1341,7 @@ static int init_by_resolv_conf(ares_channel channel)
{
if ((p = try_config(line, "order", '\0')) && !channel->lookups)
/* ignore errors */
(void)config_lookup(channel, p, "bind", "hosts");
(void)config_lookup(channel, p, "bind", NULL, "hosts");
}
fclose(fp);
}
Expand All @@ -1350,15 +1350,16 @@ static int init_by_resolv_conf(ares_channel channel)
switch(error) {
case ENOENT:
case ESRCH:
status = ARES_EOF;
break;
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
error, strerror(error)));
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
"/etc/host.conf"));
status = ARES_EFILE;
}

/* ignore error, maybe we will get luck in next if clause */
status = ARES_EOF;
}
}

Expand All @@ -1371,7 +1372,7 @@ static int init_by_resolv_conf(ares_channel channel)
{
if ((p = try_config(line, "hosts=", '\0')) && !channel->lookups)
/* ignore errors */
(void)config_lookup(channel, p, "bind", "local");
(void)config_lookup(channel, p, "bind", NULL, "local");
}
fclose(fp);
}
Expand All @@ -1380,14 +1381,15 @@ static int init_by_resolv_conf(ares_channel channel)
switch(error) {
case ENOENT:
case ESRCH:
status = ARES_EOF;
break;
default:
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
error, strerror(error)));
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf"));
status = ARES_EFILE;
}

/* ignore error, default value will be chosen for `channel->lookups` */
status = ARES_EOF;
}
}

Expand Down Expand Up @@ -1591,11 +1593,15 @@ static int config_domain(ares_channel channel, char *str)
#endif

static int config_lookup(ares_channel channel, const char *str,
const char *bindch, const char *filech)
const char *bindch, const char *altbindch,
const char *filech)
{
char lookups[3], *l;
const char *vqualifier p;

if (altbindch == NULL)
altbindch = bindch;

/* Set the lookup order. Only the first letter of each work
* is relevant, and it has to be "b" for DNS or "f" for the
* host file. Ignore everything else.
Expand All @@ -1604,8 +1610,8 @@ static int config_lookup(ares_channel channel, const char *str,
p = str;
while (*p)
{
if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
if (*p == *bindch) *l++ = 'b';
if ((*p == *bindch || *p == *altbindch || *p == *filech) && l < lookups + 2) {
if (*p == *bindch || *p == *altbindch) *l++ = 'b';
else *l++ = 'f';
}
while (*p && !ISSPACE(*p) && (*p != ','))
Expand Down Expand Up @@ -2090,6 +2096,14 @@ void ares_set_socket_callback(ares_channel channel,
channel->sock_create_cb_data = data;
}

void ares_set_socket_configure_callback(ares_channel channel,
ares_sock_config_callback cb,
void *data)
{
channel->sock_config_cb = cb;
channel->sock_config_cb_data = data;
}

int ares_set_sortlist(ares_channel channel, const char *sortstr)
{
int nsort = 0;
Expand Down
3 changes: 3 additions & 0 deletions deps/cares/src/ares_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ struct ares_channeldata {

ares_sock_create_callback sock_create_cb;
void *sock_create_cb_data;

ares_sock_config_callback sock_config_cb;
void *sock_config_cb_data;
};

/* Memory management functions */
Expand Down
22 changes: 22 additions & 0 deletions deps/cares/src/ares_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,17 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
}
#endif

if (channel->sock_config_cb)
{
int err = channel->sock_config_cb(s, SOCK_STREAM,
channel->sock_config_cb_data);
if (err < 0)
{
sclose(s);
return err;
}
}

/* Connect to the server. */
if (connect(s, sa, salen) == -1)
{
Expand Down Expand Up @@ -1115,6 +1126,17 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
return -1;
}

if (channel->sock_config_cb)
{
int err = channel->sock_config_cb(s, SOCK_DGRAM,
channel->sock_config_cb_data);
if (err < 0)
{
sclose(s);
return err;
}
}

/* Connect to the server. */
if (connect(s, sa, salen) == -1)
{
Expand Down

0 comments on commit 35c3832

Please sign in to comment.