Remove vestigial 'sortlist' code
These were the remnants of the 'sortlist' option in resolv.conf, which
Android never supported and is superseded by RFC 3484 sorting.
Removing it will improve our test coverage scores because this code was
actually unreachable :-)
Test: atest
Change-Id: I2134dccd55be8ec977fd4aa8c047b82fb74e3769
diff --git a/gethnamaddr.cpp b/gethnamaddr.cpp
index 66f3a8e..c9a6b2a 100644
--- a/gethnamaddr.cpp
+++ b/gethnamaddr.cpp
@@ -106,13 +106,10 @@
char ac;
} align;
-static struct hostent* getanswer(const querybuf*, int, const char*, int, res_state, struct hostent*,
- char*, size_t, int*);
static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
const std::function<void(struct hostent* hp)>& mapping_param,
const std::function<void(char* src, char* dst)>& mapping_addr);
static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep);
-static void addrsort(char**, int, res_state);
static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
const android_net_context* netcontext, getnamaddr* info,
@@ -145,8 +142,7 @@
} while (0)
static struct hostent* getanswer(const querybuf* answer, int anslen, const char* qname, int qtype,
- res_state res, struct hostent* hent, char* buf, size_t buflen,
- int* he) {
+ struct hostent* hent, char* buf, size_t buflen, int* he) {
const HEADER* hp;
const uint8_t* cp;
int n;
@@ -369,12 +365,6 @@
}
if (haveanswer) {
*hap = NULL;
- /*
- * Note: we sort even if host can take only one address
- * in its return structures - should give it the "best"
- * address in that case, not some random one
- */
- if (res->nsort && haveanswer > 1 && qtype == T_A) addrsort(addr_ptrs, haveanswer, res);
if (!hent->h_name) {
n = (int) strlen(qname) + 1; /* for the \0 */
if (n > ep - bp || n >= MAXHOSTNAMELEN) goto no_recovery;
@@ -691,44 +681,6 @@
});
}
-static void addrsort(char** ap, int num, res_state res) {
- int i, j;
- char** p;
- short aval[MAXADDRS];
- int needsort = 0;
-
- _DIAGASSERT(ap != NULL);
-
- p = ap;
- for (i = 0; i < num; i++, p++) {
- for (j = 0; (unsigned) j < res->nsort; j++)
- if (res->sort_list[j].addr.s_addr ==
- (((struct in_addr*) (void*) (*p))->s_addr & res->sort_list[j].mask))
- break;
- aval[i] = j;
- if (needsort == 0 && i > 0 && j < aval[i - 1]) needsort = i;
- }
- if (!needsort) return;
-
- while (needsort < num) {
- for (j = needsort - 1; j >= 0; j--) {
- if (aval[j] > aval[j + 1]) {
- char* hp;
-
- i = aval[j];
- aval[j] = aval[j + 1];
- aval[j + 1] = i;
-
- hp = ap[j];
- ap[j] = ap[j + 1];
- ap[j + 1] = hp;
- } else
- break;
- }
- needsort++;
- }
-}
-
static int dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
int n, type;
info->hp->h_addrtype = addr_type;
@@ -759,7 +711,7 @@
// See also herrnoToAiErrno().
return herrnoToAiErrno(he);
}
- hostent* hp = getanswer(buf.get(), n, name, type, res, info->hp, info->buf, info->buflen, &he);
+ hostent* hp = getanswer(buf.get(), n, name, type, info->hp, info->buf, info->buflen, &he);
if (hp == NULL) return herrnoToAiErrno(he);
return 0;
@@ -824,7 +776,7 @@
// See also herrnoToAiErrno().
return herrnoToAiErrno(he);
}
- hostent* hp = getanswer(buf.get(), n, qbuf, T_PTR, res, info->hp, info->buf, info->buflen, &he);
+ hostent* hp = getanswer(buf.get(), n, qbuf, T_PTR, info->hp, info->buf, info->buflen, &he);
if (hp == NULL) return herrnoToAiErrno(he);
char* bf = (char*) (hp->h_addr_list + 2);
diff --git a/res_init.cpp b/res_init.cpp
index c59e126..ecfb35d 100644
--- a/res_init.cpp
+++ b/res_init.cpp
@@ -120,10 +120,7 @@
if (statp->_u._ext.ext != NULL) {
memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext));
statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;
- strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");
- strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");
}
- statp->nsort = 0;
res_setservers(statp, u, nserv);
if (nserv > 0) {
diff --git a/res_state_ext.h b/res_state_ext.h
index 6ed3398..d0dbc1a 100644
--- a/res_state_ext.h
+++ b/res_state_ext.h
@@ -8,15 +8,6 @@
// TODO: consider inlining into res_state
struct res_state_ext {
sockaddr_union nsaddrs[MAXNS];
- struct sort_list {
- int af;
- union {
- struct in_addr ina;
- struct in6_addr in6a;
- } addr, mask;
- } sort_list[MAXRESOLVSORT];
- char nsuffix[64];
- char nsuffix2[64];
};
#endif // NETD_RES_STATE_EXT_H
diff --git a/resolv_private.h b/resolv_private.h
index b0bae72..8ab6939 100644
--- a/resolv_private.h
+++ b/resolv_private.h
@@ -79,7 +79,6 @@
* Global defines and variables for resolver stub.
*/
#define RES_TIMEOUT 5000 /* min. milliseconds between retries */
-#define MAXRESOLVSORT 10 /* number of net to sort on */
#define RES_MAXNDOTS 15 /* should reflect bit field size */
#define RES_DFLRETRY 2 /* Default #/tries. */
#define RES_MAXTIME 65535 /* Infinity, in milliseconds. */
@@ -95,19 +94,10 @@
uint16_t id; // current message id
std::vector<std::string> search_domains; // domains to search
unsigned ndots : 4; // threshold for initial abs. query
- unsigned nsort : 4; // number of elements in sort_list[]
- char unused[3];
- struct {
- struct in_addr addr;
- uint32_t mask;
- } sort_list[MAXRESOLVSORT];
unsigned _mark; /* If non-0 SET_MARK to _mark on all request sockets */
int _vcsock; /* PRIVATE: for res_send VC i/o */
uint32_t _flags; /* PRIVATE: see below */
- uint32_t _pad; /* make _u 64 bit aligned */
union {
- /* On an 32-bit arch this means 512b total. */
- char pad[72 - 4 * sizeof(int) - 2 * sizeof(void*)];
struct {
uint16_t nscount;
uint16_t nstimes[MAXNS]; /* ms. */