aboutsummaryrefslogtreecommitdiff
path: root/resolv/res_init.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2015-02-19 15:52:08 +0100
committerAndreas Schwab <schwab@suse.de>2015-05-21 15:16:37 +0200
commit2212c1420c92a33b0e0bd9a34938c9814a56c0f7 (patch)
tree47aebf7bf280857cf2c0279cdaf6493b453c3dfd /resolv/res_init.c
parentf58573781c3541d6a666036a6a815ea052242065 (diff)
downloadglibc-2212c1420c92a33b0e0bd9a34938c9814a56c0f7.tar
glibc-2212c1420c92a33b0e0bd9a34938c9814a56c0f7.tar.gz
glibc-2212c1420c92a33b0e0bd9a34938c9814a56c0f7.tar.bz2
glibc-2212c1420c92a33b0e0bd9a34938c9814a56c0f7.zip
Simplify handling of nameserver configuration in resolver
Remove use of ext.nsmap member of struct __res_state and always use an identity mapping betwen the nsaddr_list array and the ext.nsaddrs array. The fact that a nameserver has an IPv6 address is signalled by setting nsaddr_list[].sin_family to zero.
Diffstat (limited to 'resolv/res_init.c')
-rw-r--r--resolv/res_init.c47
1 files changed, 14 insertions, 33 deletions
diff --git a/resolv/res_init.c b/resolv/res_init.c
index 553ba12a5a..66561ffac2 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -153,10 +153,8 @@ __res_vinit(res_state statp, int preinit) {
char *cp, **pp;
int n;
char buf[BUFSIZ];
- int nserv = 0; /* number of IPv4 nameservers read from file */
-#ifdef _LIBC
- int nservall = 0; /* number of (IPv4 + IPV6) nameservers read from file */
-#endif
+ int nserv = 0; /* number of nameservers read from file */
+ int have_serv6 = 0;
int haveenv = 0;
int havesearch = 0;
#ifdef RESOLVSORT
@@ -184,15 +182,9 @@ __res_vinit(res_state statp, int preinit) {
statp->_flags = 0;
statp->qhook = NULL;
statp->rhook = NULL;
- statp->_u._ext.nsinit = 0;
statp->_u._ext.nscount = 0;
-#ifdef _LIBC
- statp->_u._ext.nscount6 = 0;
- for (n = 0; n < MAXNS; n++) {
- statp->_u._ext.nsaddrs[n] = NULL;
- statp->_u._ext.nsmap[n] = MAXNS;
- }
-#endif
+ for (n = 0; n < MAXNS; n++)
+ statp->_u._ext.nsaddrs[n] = NULL;
/* Allow user to override the local domain definition */
if ((cp = getenv("LOCALDOMAIN")) != NULL) {
@@ -296,11 +288,7 @@ __res_vinit(res_state statp, int preinit) {
continue;
}
/* read nameservers to query */
-#ifdef _LIBC
- if (MATCH(buf, "nameserver") && nservall < MAXNS) {
-#else
if (MATCH(buf, "nameserver") && nserv < MAXNS) {
-#endif
struct in_addr a;
cp = buf + sizeof("nameserver") - 1;
@@ -308,13 +296,12 @@ __res_vinit(res_state statp, int preinit) {
cp++;
if ((*cp != '\0') && (*cp != '\n')
&& __inet_aton(cp, &a)) {
- statp->nsaddr_list[nservall].sin_addr = a;
- statp->nsaddr_list[nservall].sin_family = AF_INET;
- statp->nsaddr_list[nservall].sin_port =
+ statp->nsaddr_list[nserv].sin_addr = a;
+ statp->nsaddr_list[nserv].sin_family = AF_INET;
+ statp->nsaddr_list[nserv].sin_port =
htons(NAMESERVER_PORT);
nserv++;
#ifdef _LIBC
- nservall++;
} else {
struct in6_addr a6;
char *el;
@@ -356,10 +343,11 @@ __res_vinit(res_state statp, int preinit) {
}
}
- statp->_u._ext.nsaddrs[nservall] = sa6;
- statp->_u._ext.nssocks[nservall] = -1;
- statp->_u._ext.nsmap[nservall] = MAXNS + 1;
- nservall++;
+ statp->nsaddr_list[nserv].sin_family = 0;
+ statp->_u._ext.nsaddrs[nserv] = sa6;
+ statp->_u._ext.nssocks[nserv] = -1;
+ have_serv6 = 1;
+ nserv++;
}
}
#endif
@@ -414,10 +402,9 @@ __res_vinit(res_state statp, int preinit) {
continue;
}
}
- statp->nscount = nservall;
+ statp->nscount = nserv;
#ifdef _LIBC
- if (nservall - nserv > 0) {
- statp->_u._ext.nscount6 = nservall - nserv;
+ if (have_serv6) {
/* We try IPv6 servers again. */
statp->ipv6_unavail = false;
}
@@ -606,11 +593,7 @@ __res_iclose(res_state statp, bool free_addr) {
statp->_vcsock = -1;
statp->_flags &= ~(RES_F_VC | RES_F_CONN);
}
-#ifdef _LIBC
- for (ns = 0; ns < MAXNS; ns++)
-#else
for (ns = 0; ns < statp->_u._ext.nscount; ns++)
-#endif
if (statp->_u._ext.nsaddrs[ns]) {
if (statp->_u._ext.nssocks[ns] != -1) {
close_not_cancel_no_status(statp->_u._ext.nssocks[ns]);
@@ -621,8 +604,6 @@ __res_iclose(res_state statp, bool free_addr) {
statp->_u._ext.nsaddrs[ns] = NULL;
}
}
- if (free_addr)
- statp->_u._ext.nsinit = 0;
}
libc_hidden_def (__res_iclose)