summaryrefslogtreecommitdiff
path: root/resolv/gethnamaddr.cpp
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-07-27 23:06:32 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-07-27 23:06:32 +0000
commitc8400101938fddb8789bc8de87c713b382f569e4 (patch)
treeb39647c8c88f09a0294f0f8173b91fa14a790bdb /resolv/gethnamaddr.cpp
parent5b1c32b39ed9157ea6eefadc141d866d9201ffce (diff)
parent72e88a79af497b294787c6ba7e232c3bd4f3c137 (diff)
Snap for 5761090 from 72e88a79af497b294787c6ba7e232c3bd4f3c137 to qt-c2f2-releaseq10.0-r9rebase
Change-Id: Ibea92fe8f60ff6049c82d9ada661b9b01129e6bd
Diffstat (limited to 'resolv/gethnamaddr.cpp')
-rw-r--r--resolv/gethnamaddr.cpp54
1 files changed, 35 insertions, 19 deletions
diff --git a/resolv/gethnamaddr.cpp b/resolv/gethnamaddr.cpp
index 1cf06943..a40a7b78 100644
--- a/resolv/gethnamaddr.cpp
+++ b/resolv/gethnamaddr.cpp
@@ -78,6 +78,9 @@
#include "netd_resolv/resolv.h"
#include "resolv_cache.h"
#include "resolv_private.h"
+#include "stats.pb.h"
+
+using android::net::NetworkDnsEventReported;
// NetBSD uses _DIAGASSERT to null-check arguments and the like,
// but it's clear from the number of mistakes in their assertions
@@ -116,19 +119,22 @@ 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);
+ const android_net_context* netcontext, getnamaddr* info,
+ NetworkDnsEventReported* event);
static int dns_gethtbyname(const char* name, int af, getnamaddr* info);
static int gethostbyname_internal(const char* name, int af, res_state res, hostent* hp, char* hbuf,
- size_t hbuflen, const android_net_context* netcontext);
+ size_t hbuflen, const android_net_context* netcontext,
+ NetworkDnsEventReported* event);
static int gethostbyname_internal_real(const char* name, int af, res_state res, hostent* hp,
char* buf, size_t buflen);
static int android_gethostbyaddrfornetcontext_proxy_internal(const void*, socklen_t, int,
struct hostent*, char*, size_t,
- const struct android_net_context*);
+ const struct android_net_context*,
+ NetworkDnsEventReported* event);
static int android_gethostbyaddrfornetcontext_proxy(const void* addr, socklen_t len, int af,
const struct android_net_context* netcontext,
- hostent** hp);
+ hostent** hp, NetworkDnsEventReported* event);
#define BOUNDED_INCR(x) \
do { \
@@ -494,14 +500,16 @@ fake:
// very similar in proxy-ness to android_getaddrinfo_proxy
static int gethostbyname_internal(const char* name, int af, res_state res, hostent* hp, char* hbuf,
- size_t hbuflen, const android_net_context* netcontext) {
- res_setnetcontext(res, netcontext);
+ size_t hbuflen, const android_net_context* netcontext,
+ NetworkDnsEventReported* event) {
+ res_setnetcontext(res, netcontext, event);
return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen);
}
static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t len, int af,
struct hostent* hp, char* buf, size_t buflen,
- const struct android_net_context* netcontext) {
+ const struct android_net_context* netcontext,
+ NetworkDnsEventReported* event) {
const u_char* uaddr = (const u_char*) addr;
socklen_t size;
struct getnamaddr info;
@@ -543,7 +551,7 @@ static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t l
info.buf = buf;
info.buflen = buflen;
if (_hf_gethtbyaddr(uaddr, len, af, &info)) {
- int error = dns_gethtbyaddr(uaddr, len, af, netcontext, &info);
+ int error = dns_gethtbyaddr(uaddr, len, af, netcontext, &info, event);
if (error != 0) return error;
}
return 0;
@@ -551,8 +559,9 @@ static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t l
static int android_gethostbyaddrfornetcontext_proxy_internal(
const void* addr, socklen_t len, int af, struct hostent* hp, char* hbuf, size_t hbuflen,
- const struct android_net_context* netcontext) {
- return android_gethostbyaddrfornetcontext_real(addr, len, af, hp, hbuf, hbuflen, netcontext);
+ const struct android_net_context* netcontext, NetworkDnsEventReported* event) {
+ return android_gethostbyaddrfornetcontext_real(addr, len, af, hp, hbuf, hbuflen, netcontext,
+ event);
}
// TODO: Consider leaving function without returning error code as _gethtent() does because
@@ -795,7 +804,8 @@ static int dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
}
static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
- const android_net_context* netcontext, getnamaddr* info) {
+ const android_net_context* netcontext, getnamaddr* info,
+ NetworkDnsEventReported* event) {
char qbuf[MAXDNAME + 1], *qp, *ep;
int n;
int advance;
@@ -842,7 +852,7 @@ static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
res_state res = res_get_state();
if (!res) return EAI_MEMORY;
- res_setnetcontext(res, netcontext);
+ res_setnetcontext(res, netcontext, event);
int he;
n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf), &he);
if (n < 0) {
@@ -886,13 +896,16 @@ nospc:
*/
int android_gethostbynamefornetcontext(const char* name, int af,
- const struct android_net_context* netcontext, hostent** hp) {
- int error;
+ const struct android_net_context* netcontext, hostent** hp,
+ NetworkDnsEventReported* event) {
+ assert(event != nullptr);
+
res_state res = res_get_state();
if (res == NULL) return EAI_MEMORY;
res_static* rs = res_get_static(); // For thread-safety.
+ int error;
error = gethostbyname_internal(name, af, res, &rs->host, rs->hostbuf, sizeof(rs->hostbuf),
- netcontext);
+ netcontext, event);
if (error == 0) {
*hp = &rs->host;
}
@@ -900,16 +913,19 @@ int android_gethostbynamefornetcontext(const char* name, int af,
}
int android_gethostbyaddrfornetcontext(const void* addr, socklen_t len, int af,
- const struct android_net_context* netcontext, hostent** hp) {
- return android_gethostbyaddrfornetcontext_proxy(addr, len, af, netcontext, hp);
+ const struct android_net_context* netcontext, hostent** hp,
+ NetworkDnsEventReported* event) {
+ return android_gethostbyaddrfornetcontext_proxy(addr, len, af, netcontext, hp, event);
}
static int android_gethostbyaddrfornetcontext_proxy(const void* addr, socklen_t len, int af,
const struct android_net_context* netcontext,
- hostent** hp) {
+ hostent** hp, NetworkDnsEventReported* event) {
+ assert(event != nullptr);
+
struct res_static* rs = res_get_static(); // For thread-safety.
int error = android_gethostbyaddrfornetcontext_proxy_internal(
- addr, len, af, &rs->host, rs->hostbuf, sizeof(rs->hostbuf), netcontext);
+ addr, len, af, &rs->host, rs->hostbuf, sizeof(rs->hostbuf), netcontext, event);
if (error == 0) *hp = &rs->host;
return error;
}