am b989c9ce: (-s ours) Revert "DO NOT MERGE Revert "Add the libcutils localtime_tz and mktime_t extensions to bionic.""
* commit 'b989c9ceda71f6f75112645b5c45af341275cbab':
Revert "DO NOT MERGE Revert "Add the libcutils localtime_tz and mktime_t extensions to bionic.""
diff --git a/libc/Android.mk b/libc/Android.mk
index c98d2ff..4bf996b 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -805,6 +805,9 @@
LOCAL_WHOLE_STATIC_LIBRARIES := libbionic_ssp libc_bionic libc_netbsd
LOCAL_SYSTEM_SHARED_LIBRARIES :=
+# TODO: split out the asflags.
+LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
+
include $(BUILD_STATIC_LIBRARY)
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c
index 838e084..afc9a36 100644
--- a/libc/netbsd/resolv/res_cache.c
+++ b/libc/netbsd/resolv/res_cache.c
@@ -572,8 +572,6 @@
static int
_dnsPacket_checkQR( DnsPacket* packet )
{
- int len;
-
if (!_dnsPacket_checkQName(packet))
return 0;
@@ -832,8 +830,6 @@
static unsigned
_dnsPacket_hashQR( DnsPacket* packet, unsigned hash )
{
- int len;
-
hash = _dnsPacket_hashQName(packet, hash);
hash = _dnsPacket_hashBytes(packet, 4, hash); /* TYPE and CLASS */
return hash;
@@ -1020,8 +1016,58 @@
} Entry;
/**
- * Parse the answer records and find the smallest
- * TTL among the answer records.
+ * Find the TTL for a negative DNS result. This is defined as the minimum
+ * of the SOA records TTL and the MINIMUM-TTL field (RFC-2308).
+ *
+ * Return 0 if not found.
+ */
+static u_long
+answer_getNegativeTTL(ns_msg handle) {
+ int n, nscount;
+ u_long result = 0;
+ ns_rr rr;
+
+ nscount = ns_msg_count(handle, ns_s_ns);
+ for (n = 0; n < nscount; n++) {
+ if ((ns_parserr(&handle, ns_s_ns, n, &rr) == 0) && (ns_rr_type(rr) == ns_t_soa)) {
+ const u_char *rdata = ns_rr_rdata(rr); // find the data
+ const u_char *edata = rdata + ns_rr_rdlen(rr); // add the len to find the end
+ int len;
+ u_long ttl, rec_result = ns_rr_ttl(rr);
+
+ // find the MINIMUM-TTL field from the blob of binary data for this record
+ // skip the server name
+ len = dn_skipname(rdata, edata);
+ if (len == -1) continue; // error skipping
+ rdata += len;
+
+ // skip the admin name
+ len = dn_skipname(rdata, edata);
+ if (len == -1) continue; // error skipping
+ rdata += len;
+
+ if (edata - rdata != 5*NS_INT32SZ) continue;
+ // skip: serial number + refresh interval + retry interval + expiry
+ rdata += NS_INT32SZ * 4;
+ // finally read the MINIMUM TTL
+ ttl = ns_get32(rdata);
+ if (ttl < rec_result) {
+ rec_result = ttl;
+ }
+ // Now that the record is read successfully, apply the new min TTL
+ if (n == 0 || rec_result < result) {
+ result = rec_result;
+ }
+ }
+ }
+ return result;
+}
+
+/**
+ * Parse the answer records and find the appropriate
+ * smallest TTL among the records. This might be from
+ * the answer records if found or from the SOA record
+ * if it's a negative result.
*
* The returned TTL is the number of seconds to
* keep the answer in the cache.
@@ -1041,14 +1087,20 @@
if (ns_initparse(answer, answerlen, &handle) >= 0) {
// get number of answer records
ancount = ns_msg_count(handle, ns_s_an);
- for (n = 0; n < ancount; n++) {
- if (ns_parserr(&handle, ns_s_an, n, &rr) == 0) {
- ttl = ns_rr_ttl(rr);
- if (n == 0 || ttl < result) {
- result = ttl;
+
+ if (ancount == 0) {
+ // a response with no answers? Cache this negative result.
+ result = answer_getNegativeTTL(handle);
+ } else {
+ for (n = 0; n < ancount; n++) {
+ if (ns_parserr(&handle, ns_s_an, n, &rr) == 0) {
+ ttl = ns_rr_ttl(rr);
+ if (n == 0 || ttl < result) {
+ result = ttl;
+ }
+ } else {
+ XLOG("ns_parserr failed ancount no = %d. errno = %s\n", n, strerror(errno));
}
- } else {
- XLOG("ns_parserr failed ancount no = %d. errno = %s\n", n, strerror(errno));
}
}
} else {
@@ -1197,6 +1249,7 @@
struct resolv_cache_info* next;
char* nameservers[MAXNS +1];
struct addrinfo* nsaddrinfo[MAXNS + 1];
+ char* domains;
} CacheInfo;
#define HTABLE_VALID(x) ((x) != NULL && (x) != HTABLE_DELETED)
@@ -1252,7 +1305,7 @@
} else {
struct timespec ts = {0,0};
ts.tv_sec = _time_now() + PENDING_REQUEST_TIMEOUT;
- int rv = pthread_cond_timedwait(&ri->cond, &cache->lock, &ts);
+ pthread_cond_timedwait(&ri->cond, &cache->lock, &ts);
}
}
@@ -1306,7 +1359,6 @@
_cache_flush_locked( Cache* cache )
{
int nn;
- time_t now = _time_now();
for (nn = 0; nn < cache->max_entries; nn++)
{
@@ -1442,6 +1494,7 @@
remove("/data/reslog.txt");
}
else {
+ errno = 0; // else debug is introducing error signals
XLOG("_dump_answer: can't open file\n");
}
}
@@ -1577,9 +1630,7 @@
int answersize,
int *answerlen )
{
- DnsPacket pack[1];
Entry key[1];
- int index;
Entry** lookup;
Entry* e;
time_t now;
@@ -1752,8 +1803,6 @@
static struct resolv_cache* _find_named_cache_locked(const char* ifname);
/* gets a resolv_cache_info associated with an interface name, or NULL if not found */
static struct resolv_cache_info* _find_cache_info_locked(const char* ifname);
-/* free dns name server list of a resolv_cache_info structure */
-static void _free_nameservers(struct resolv_cache_info* cache_info);
/* look up the named cache, and creates one if needed */
static struct resolv_cache* _get_res_cache_for_iface_locked(const char* ifname);
/* empty the named cache */
@@ -1989,7 +2038,8 @@
}
void
-_resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers)
+_resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers,
+ const char *domains)
{
int i, rt, index;
struct addrinfo hints;
@@ -2023,6 +2073,7 @@
cache_info->nsaddrinfo[index] = NULL;
}
}
+ cache_info->domains = strdup(domains);
}
pthread_mutex_unlock(&_res_cache_list_lock);
}
diff --git a/libc/private/resolv_iface.h b/libc/private/resolv_iface.h
index f562687..3fe586e 100644
--- a/libc/private/resolv_iface.h
+++ b/libc/private/resolv_iface.h
@@ -48,7 +48,8 @@
extern void _resolv_set_default_iface(const char* ifname);
/* set name servers for an interface */
-extern void _resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers);
+extern void _resolv_set_nameservers_for_iface(const char* ifname, char** servers, int numservers,
+ const char *domains);
/* tell resolver of the address of an interface */
extern void _resolv_set_addr_of_iface(const char* ifname, struct in_addr* addr);
diff --git a/linker/Android.mk b/linker/Android.mk
index 5fccf9b..7c197f1 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -67,6 +67,9 @@
# just for this module
LOCAL_NO_CRT := true
+# TODO: split out the asflags.
+LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
+
include $(BUILD_SYSTEM)/dynamic_binary.mk
# See build/core/executable.mk