Skip to content

Commit 35c3832

Browse files
indutnyrvagg
authored andcommitted
deps: sync with upstream c-ares/c-ares@4ef6817
PR-URL: #5199 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 18b00de commit 35c3832

File tree

4 files changed

+67
-20
lines changed

4 files changed

+67
-20
lines changed

deps/cares/include/ares.h

+8
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
294294
int type,
295295
void *data);
296296

297+
typedef int (*ares_sock_config_callback)(ares_socket_t socket_fd,
298+
int type,
299+
void *data);
300+
297301
CARES_EXTERN int ares_library_init(int flags);
298302

299303
CARES_EXTERN int ares_library_init_mem(int flags,
@@ -344,6 +348,10 @@ CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
344348
ares_sock_create_callback callback,
345349
void *user_data);
346350

351+
CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel,
352+
ares_sock_config_callback callback,
353+
void *user_data);
354+
347355
CARES_EXTERN int ares_set_sortlist(ares_channel channel,
348356
const char *sortstr);
349357

deps/cares/src/ares_init.c

+34-20
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static void natural_mask(struct apattern *pat);
9090
!defined(ANDROID) && !defined(__ANDROID__) && !defined(CARES_USE_LIBRESOLV)
9191
static int config_domain(ares_channel channel, char *str);
9292
static int config_lookup(ares_channel channel, const char *str,
93-
const char *bindch, const char *filech);
93+
const char *bindch, const char *altbindch,
94+
const char *filech);
9495
static char *try_config(char *s, const char *opt, char scc);
9596
#endif
9697

@@ -164,6 +165,8 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
164165
channel->sock_state_cb_data = NULL;
165166
channel->sock_create_cb = NULL;
166167
channel->sock_create_cb_data = NULL;
168+
channel->sock_config_cb = NULL;
169+
channel->sock_config_cb_data = NULL;
167170

168171
channel->last_server = 0;
169172
channel->last_timeout_processed = (time_t)now.tv_sec;
@@ -291,6 +294,8 @@ int ares_dup(ares_channel *dest, ares_channel src)
291294
/* Now clone the options that ares_save_options() doesn't support. */
292295
(*dest)->sock_create_cb = src->sock_create_cb;
293296
(*dest)->sock_create_cb_data = src->sock_create_cb_data;
297+
(*dest)->sock_config_cb = src->sock_config_cb;
298+
(*dest)->sock_config_cb_data = src->sock_config_cb_data;
294299

295300
strncpy((*dest)->local_dev_name, src->local_dev_name,
296301
sizeof(src->local_dev_name));
@@ -1025,11 +1030,6 @@ static int get_DNS_AdaptersAddresses(char **outptr)
10251030
}
10261031
else if (namesrvr.sa->sa_family == AF_INET6)
10271032
{
1028-
/* Windows apparently always reports some IPv6 DNS servers that
1029-
* prefixed with fec0:0:0:ffff. These ususally do not point to
1030-
* working DNS servers, so we ignore them. */
1031-
if (strncmp(txtaddr, "fec0:0:0:ffff:", 14) == 0)
1032-
continue;
10331033
if (memcmp(&namesrvr.sa6->sin6_addr, &ares_in6addr_any,
10341034
sizeof(namesrvr.sa6->sin6_addr)) == 0)
10351035
continue;
@@ -1269,7 +1269,7 @@ static int init_by_resolv_conf(ares_channel channel)
12691269
if ((p = try_config(line, "domain", ';')) && update_domains)
12701270
status = config_domain(channel, p);
12711271
else if ((p = try_config(line, "lookup", ';')) && !channel->lookups)
1272-
status = config_lookup(channel, p, "bind", "file");
1272+
status = config_lookup(channel, p, "bind", NULL, "file");
12731273
else if ((p = try_config(line, "search", ';')) && update_domains)
12741274
status = set_search(channel, p);
12751275
else if ((p = try_config(line, "nameserver", ';')) &&
@@ -1310,8 +1310,7 @@ static int init_by_resolv_conf(ares_channel channel)
13101310
ARES_SUCCESS)
13111311
{
13121312
if ((p = try_config(line, "hosts:", '\0')) && !channel->lookups)
1313-
/* ignore errors */
1314-
(void)config_lookup(channel, p, "dns", "files");
1313+
(void)config_lookup(channel, p, "dns", "resolve", "files");
13151314
}
13161315
fclose(fp);
13171316
}
@@ -1320,15 +1319,16 @@ static int init_by_resolv_conf(ares_channel channel)
13201319
switch(error) {
13211320
case ENOENT:
13221321
case ESRCH:
1323-
status = ARES_EOF;
13241322
break;
13251323
default:
13261324
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
13271325
error, strerror(error)));
13281326
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
13291327
"/etc/nsswitch.conf"));
1330-
status = ARES_EFILE;
13311328
}
1329+
1330+
/* ignore error, maybe we will get luck in next if clause */
1331+
status = ARES_EOF;
13321332
}
13331333
}
13341334

@@ -1341,7 +1341,7 @@ static int init_by_resolv_conf(ares_channel channel)
13411341
{
13421342
if ((p = try_config(line, "order", '\0')) && !channel->lookups)
13431343
/* ignore errors */
1344-
(void)config_lookup(channel, p, "bind", "hosts");
1344+
(void)config_lookup(channel, p, "bind", NULL, "hosts");
13451345
}
13461346
fclose(fp);
13471347
}
@@ -1350,15 +1350,16 @@ static int init_by_resolv_conf(ares_channel channel)
13501350
switch(error) {
13511351
case ENOENT:
13521352
case ESRCH:
1353-
status = ARES_EOF;
13541353
break;
13551354
default:
13561355
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
13571356
error, strerror(error)));
13581357
DEBUGF(fprintf(stderr, "Error opening file: %s\n",
13591358
"/etc/host.conf"));
1360-
status = ARES_EFILE;
13611359
}
1360+
1361+
/* ignore error, maybe we will get luck in next if clause */
1362+
status = ARES_EOF;
13621363
}
13631364
}
13641365

@@ -1371,7 +1372,7 @@ static int init_by_resolv_conf(ares_channel channel)
13711372
{
13721373
if ((p = try_config(line, "hosts=", '\0')) && !channel->lookups)
13731374
/* ignore errors */
1374-
(void)config_lookup(channel, p, "bind", "local");
1375+
(void)config_lookup(channel, p, "bind", NULL, "local");
13751376
}
13761377
fclose(fp);
13771378
}
@@ -1380,14 +1381,15 @@ static int init_by_resolv_conf(ares_channel channel)
13801381
switch(error) {
13811382
case ENOENT:
13821383
case ESRCH:
1383-
status = ARES_EOF;
13841384
break;
13851385
default:
13861386
DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
13871387
error, strerror(error)));
13881388
DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf"));
1389-
status = ARES_EFILE;
13901389
}
1390+
1391+
/* ignore error, default value will be chosen for `channel->lookups` */
1392+
status = ARES_EOF;
13911393
}
13921394
}
13931395

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

15931595
static int config_lookup(ares_channel channel, const char *str,
1594-
const char *bindch, const char *filech)
1596+
const char *bindch, const char *altbindch,
1597+
const char *filech)
15951598
{
15961599
char lookups[3], *l;
15971600
const char *vqualifier p;
15981601

1602+
if (altbindch == NULL)
1603+
altbindch = bindch;
1604+
15991605
/* Set the lookup order. Only the first letter of each work
16001606
* is relevant, and it has to be "b" for DNS or "f" for the
16011607
* host file. Ignore everything else.
@@ -1604,8 +1610,8 @@ static int config_lookup(ares_channel channel, const char *str,
16041610
p = str;
16051611
while (*p)
16061612
{
1607-
if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
1608-
if (*p == *bindch) *l++ = 'b';
1613+
if ((*p == *bindch || *p == *altbindch || *p == *filech) && l < lookups + 2) {
1614+
if (*p == *bindch || *p == *altbindch) *l++ = 'b';
16091615
else *l++ = 'f';
16101616
}
16111617
while (*p && !ISSPACE(*p) && (*p != ','))
@@ -2090,6 +2096,14 @@ void ares_set_socket_callback(ares_channel channel,
20902096
channel->sock_create_cb_data = data;
20912097
}
20922098

2099+
void ares_set_socket_configure_callback(ares_channel channel,
2100+
ares_sock_config_callback cb,
2101+
void *data)
2102+
{
2103+
channel->sock_config_cb = cb;
2104+
channel->sock_config_cb_data = data;
2105+
}
2106+
20932107
int ares_set_sortlist(ares_channel channel, const char *sortstr)
20942108
{
20952109
int nsort = 0;

deps/cares/src/ares_private.h

+3
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ struct ares_channeldata {
311311

312312
ares_sock_create_callback sock_create_cb;
313313
void *sock_create_cb_data;
314+
315+
ares_sock_config_callback sock_config_cb;
316+
void *sock_config_cb_data;
314317
};
315318

316319
/* Memory management functions */

deps/cares/src/ares_process.c

+22
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,17 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
10311031
}
10321032
#endif
10331033

1034+
if (channel->sock_config_cb)
1035+
{
1036+
int err = channel->sock_config_cb(s, SOCK_STREAM,
1037+
channel->sock_config_cb_data);
1038+
if (err < 0)
1039+
{
1040+
sclose(s);
1041+
return err;
1042+
}
1043+
}
1044+
10341045
/* Connect to the server. */
10351046
if (connect(s, sa, salen) == -1)
10361047
{
@@ -1115,6 +1126,17 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
11151126
return -1;
11161127
}
11171128

1129+
if (channel->sock_config_cb)
1130+
{
1131+
int err = channel->sock_config_cb(s, SOCK_DGRAM,
1132+
channel->sock_config_cb_data);
1133+
if (err < 0)
1134+
{
1135+
sclose(s);
1136+
return err;
1137+
}
1138+
}
1139+
11181140
/* Connect to the server. */
11191141
if (connect(s, sa, salen) == -1)
11201142
{

0 commit comments

Comments
 (0)