Loading Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ cc_library { "res_mkquery.cpp", "res_query.cpp", "res_send.cpp", "res_state.cpp", "res_stats.cpp", "Dns64Configuration.cpp", "DnsProxyListener.cpp", Loading DnsProxyListener.cpp +22 −13 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ namespace { constexpr int MAX_QUERIES_PER_UID = 256; // Max packet size for answer, sync with getaddrinfo.c // TODO: switch to dynamically allocated buffers with std::vector constexpr int MAXPACKET = 8 * 1024; android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID); Loading Loading @@ -1033,7 +1034,8 @@ DnsProxyListener::GetHostByNameHandler::~GetHostByNameHandler() { free(mName); } void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, struct hostent** hpp, void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, hostent* hbuf, char* buf, size_t buflen, struct hostent** hpp, NetworkDnsEventReported* event) { // Don't have to consider family AF_UNSPEC case because gethostbyname{, 2} only supports // family AF_INET or AF_INET6. Loading @@ -1051,7 +1053,7 @@ void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, struc // If caller wants IPv6 answers but no data, try to query IPv4 answers for synthesis const uid_t uid = mClient->getUid(); if (queryLimiter.start(uid)) { *rv = android_gethostbynamefornetcontext(mName, AF_INET, &mNetContext, hpp, event); *rv = resolv_gethostbyname(mName, AF_INET, hbuf, buf, buflen, &mNetContext, hpp, event); queryLimiter.finish(uid); if (*rv) { *rv = EAI_NODATA; // return original error code Loading @@ -1074,11 +1076,14 @@ void DnsProxyListener::GetHostByNameHandler::run() { maybeFixupNetContext(&mNetContext); const uid_t uid = mClient->getUid(); hostent* hp = nullptr; hostent hbuf; char tmpbuf[MAXPACKET]; int32_t rv = 0; NetworkDnsEventReported event; initDnsEvent(&event); if (queryLimiter.start(uid)) { rv = android_gethostbynamefornetcontext(mName, mAf, &mNetContext, &hp, &event); rv = resolv_gethostbyname(mName, mAf, &hbuf, tmpbuf, sizeof tmpbuf, &mNetContext, &hp, &event); queryLimiter.finish(uid); } else { rv = EAI_MEMORY; Loading @@ -1086,12 +1091,12 @@ void DnsProxyListener::GetHostByNameHandler::run() { << ", max concurrent queries reached"; } doDns64Synthesis(&rv, &hp, &event); doDns64Synthesis(&rv, &hbuf, tmpbuf, sizeof tmpbuf, &hp, &event); const int32_t latencyUs = saturate_cast<int32_t>(s.timeTakenUs()); event.set_latency_micros(latencyUs); event.set_event_type(EVENT_GETHOSTBYNAME); LOG(DEBUG) << "GetHostByNameHandler::run: errno: " << (hp ? "success" : strerror(errno)); LOG(DEBUG) << "GetHostByNameHandler::run: result: " << gai_strerror(rv); bool success = true; if (hp) { Loading Loading @@ -1181,7 +1186,9 @@ DnsProxyListener::GetHostByAddrHandler::~GetHostByAddrHandler() { free(mAddress); } void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(struct hostent** hpp, void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(hostent* hbuf, char* buf, size_t buflen, struct hostent** hpp, NetworkDnsEventReported* event) { if (*hpp != nullptr || mAddressFamily != AF_INET6 || !mAddress) { return; Loading Loading @@ -1210,14 +1217,14 @@ void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(struct hostent if (queryLimiter.start(uid)) { // Remove NAT64 prefix and do reverse DNS query struct in_addr v4addr = {.s_addr = v6addr.s6_addr32[3]}; android_gethostbyaddrfornetcontext(&v4addr, sizeof(v4addr), AF_INET, &mNetContext, hpp, resolv_gethostbyaddr(&v4addr, sizeof(v4addr), AF_INET, hbuf, buf, buflen, &mNetContext, hpp, event); queryLimiter.finish(uid); if (*hpp) { // Replace IPv4 address with original queried IPv6 address in place. The space has // reserved by dns_gethtbyaddr() and netbsd_gethostent_r() in // system/netd/resolv/gethnamaddr.cpp. // Note that android_gethostbyaddrfornetcontext returns only one entry in result. // Note that resolv_gethostbyaddr() returns only one entry in result. memcpy((*hpp)->h_addr_list[0], &v6addr, sizeof(v6addr)); (*hpp)->h_addrtype = AF_INET6; (*hpp)->h_length = sizeof(struct in6_addr); Loading @@ -1232,12 +1239,14 @@ void DnsProxyListener::GetHostByAddrHandler::run() { maybeFixupNetContext(&mNetContext); const uid_t uid = mClient->getUid(); hostent* hp = nullptr; hostent hbuf; char tmpbuf[MAXPACKET]; int32_t rv = 0; NetworkDnsEventReported event; initDnsEvent(&event); if (queryLimiter.start(uid)) { rv = android_gethostbyaddrfornetcontext(mAddress, mAddressLen, mAddressFamily, &mNetContext, &hp, &event); rv = resolv_gethostbyaddr(mAddress, mAddressLen, mAddressFamily, &hbuf, tmpbuf, sizeof tmpbuf, &mNetContext, &hp, &event); queryLimiter.finish(uid); } else { rv = EAI_MEMORY; Loading @@ -1245,12 +1254,12 @@ void DnsProxyListener::GetHostByAddrHandler::run() { << ", max concurrent queries reached"; } doDns64ReverseLookup(&hp, &event); doDns64ReverseLookup(&hbuf, tmpbuf, sizeof tmpbuf, &hp, &event); const int32_t latencyUs = saturate_cast<int32_t>(s.timeTakenUs()); event.set_latency_micros(latencyUs); event.set_event_type(EVENT_GETHOSTBYADDR); LOG(DEBUG) << "GetHostByAddrHandler::run: result: " << (hp ? "success" : gai_strerror(rv)); LOG(DEBUG) << "GetHostByAddrHandler::run: result: " << gai_strerror(rv); bool success = true; if (hp) { Loading DnsProxyListener.h +4 −2 Original line number Diff line number Diff line Loading @@ -84,7 +84,8 @@ class DnsProxyListener : public FrameworkListener { std::string threadName(); private: void doDns64Synthesis(int32_t* rv, hostent** hpp, NetworkDnsEventReported* event); void doDns64Synthesis(int32_t* rv, hostent* hbuf, char* buf, size_t buflen, hostent** hpp, NetworkDnsEventReported* event); SocketClient* mClient; // ref counted char* mName; // owned. TODO: convert to std::string. Loading @@ -110,7 +111,8 @@ class DnsProxyListener : public FrameworkListener { std::string threadName(); private: void doDns64ReverseLookup(hostent** hpp, NetworkDnsEventReported* event); void doDns64ReverseLookup(hostent* hbuf, char* buf, size_t buflen, hostent** hpp, NetworkDnsEventReported* event); SocketClient* mClient; // ref counted void* mAddress; // address to lookup; owned Loading PREUPLOAD.cfg +1 −0 Original line number Diff line number Diff line [Builtin Hooks] clang_format = true commit_msg_test_field = false [Builtin Hooks Options] clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp getaddrinfo.cpp +6 −11 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ #include <android-base/logging.h> #include "netd_resolv/resolv.h" #include "res_init.h" #include "resolv_cache.h" #include "resolv_private.h" Loading Loading @@ -1445,18 +1446,11 @@ static int dns_getaddrinfo(const char* name, const addrinfo* pai, return EAI_FAMILY; } res_state res = res_get_state(); if (!res) return EAI_MEMORY; /* this just sets our netid val in the thread private data so we don't have to * modify the api's all the way down to res_send.c's res_nsend. We could * fully populate the thread private data here, but if we get down there * and have a cache hit that would be wasted, so we do the rest there on miss */ res_setnetcontext(res, netcontext, event); ResState res; res_init(&res, netcontext, event); int he; if (res_searchN(name, &q, res, &he) < 0) { if (res_searchN(name, &q, &res, &he) < 0) { // Return h_errno (he) to catch more detailed errors rather than EAI_NODATA. // Note that res_searchN() doesn't set the pair NETDB_INTERNAL and errno. // See also herrnoToAiErrno(). Loading Loading @@ -1612,7 +1606,8 @@ static int res_queryN(const char* name, res_target* target, res_state res, int* LOG(DEBUG) << __func__ << ": (" << cl << ", " << type << ")"; n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf)); n = res_nmkquery(QUERY, name, cl, type, /*data=*/nullptr, /*datalen=*/0, buf, sizeof(buf), res->netcontext_flags); if (n > 0 && (res->netcontext_flags & (NET_CONTEXT_FLAG_USE_DNS_OVER_TLS | NET_CONTEXT_FLAG_USE_EDNS)) && Loading Loading
Android.bp +0 −1 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ cc_library { "res_mkquery.cpp", "res_query.cpp", "res_send.cpp", "res_state.cpp", "res_stats.cpp", "Dns64Configuration.cpp", "DnsProxyListener.cpp", Loading
DnsProxyListener.cpp +22 −13 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ namespace { constexpr int MAX_QUERIES_PER_UID = 256; // Max packet size for answer, sync with getaddrinfo.c // TODO: switch to dynamically allocated buffers with std::vector constexpr int MAXPACKET = 8 * 1024; android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID); Loading Loading @@ -1033,7 +1034,8 @@ DnsProxyListener::GetHostByNameHandler::~GetHostByNameHandler() { free(mName); } void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, struct hostent** hpp, void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, hostent* hbuf, char* buf, size_t buflen, struct hostent** hpp, NetworkDnsEventReported* event) { // Don't have to consider family AF_UNSPEC case because gethostbyname{, 2} only supports // family AF_INET or AF_INET6. Loading @@ -1051,7 +1053,7 @@ void DnsProxyListener::GetHostByNameHandler::doDns64Synthesis(int32_t* rv, struc // If caller wants IPv6 answers but no data, try to query IPv4 answers for synthesis const uid_t uid = mClient->getUid(); if (queryLimiter.start(uid)) { *rv = android_gethostbynamefornetcontext(mName, AF_INET, &mNetContext, hpp, event); *rv = resolv_gethostbyname(mName, AF_INET, hbuf, buf, buflen, &mNetContext, hpp, event); queryLimiter.finish(uid); if (*rv) { *rv = EAI_NODATA; // return original error code Loading @@ -1074,11 +1076,14 @@ void DnsProxyListener::GetHostByNameHandler::run() { maybeFixupNetContext(&mNetContext); const uid_t uid = mClient->getUid(); hostent* hp = nullptr; hostent hbuf; char tmpbuf[MAXPACKET]; int32_t rv = 0; NetworkDnsEventReported event; initDnsEvent(&event); if (queryLimiter.start(uid)) { rv = android_gethostbynamefornetcontext(mName, mAf, &mNetContext, &hp, &event); rv = resolv_gethostbyname(mName, mAf, &hbuf, tmpbuf, sizeof tmpbuf, &mNetContext, &hp, &event); queryLimiter.finish(uid); } else { rv = EAI_MEMORY; Loading @@ -1086,12 +1091,12 @@ void DnsProxyListener::GetHostByNameHandler::run() { << ", max concurrent queries reached"; } doDns64Synthesis(&rv, &hp, &event); doDns64Synthesis(&rv, &hbuf, tmpbuf, sizeof tmpbuf, &hp, &event); const int32_t latencyUs = saturate_cast<int32_t>(s.timeTakenUs()); event.set_latency_micros(latencyUs); event.set_event_type(EVENT_GETHOSTBYNAME); LOG(DEBUG) << "GetHostByNameHandler::run: errno: " << (hp ? "success" : strerror(errno)); LOG(DEBUG) << "GetHostByNameHandler::run: result: " << gai_strerror(rv); bool success = true; if (hp) { Loading Loading @@ -1181,7 +1186,9 @@ DnsProxyListener::GetHostByAddrHandler::~GetHostByAddrHandler() { free(mAddress); } void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(struct hostent** hpp, void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(hostent* hbuf, char* buf, size_t buflen, struct hostent** hpp, NetworkDnsEventReported* event) { if (*hpp != nullptr || mAddressFamily != AF_INET6 || !mAddress) { return; Loading Loading @@ -1210,14 +1217,14 @@ void DnsProxyListener::GetHostByAddrHandler::doDns64ReverseLookup(struct hostent if (queryLimiter.start(uid)) { // Remove NAT64 prefix and do reverse DNS query struct in_addr v4addr = {.s_addr = v6addr.s6_addr32[3]}; android_gethostbyaddrfornetcontext(&v4addr, sizeof(v4addr), AF_INET, &mNetContext, hpp, resolv_gethostbyaddr(&v4addr, sizeof(v4addr), AF_INET, hbuf, buf, buflen, &mNetContext, hpp, event); queryLimiter.finish(uid); if (*hpp) { // Replace IPv4 address with original queried IPv6 address in place. The space has // reserved by dns_gethtbyaddr() and netbsd_gethostent_r() in // system/netd/resolv/gethnamaddr.cpp. // Note that android_gethostbyaddrfornetcontext returns only one entry in result. // Note that resolv_gethostbyaddr() returns only one entry in result. memcpy((*hpp)->h_addr_list[0], &v6addr, sizeof(v6addr)); (*hpp)->h_addrtype = AF_INET6; (*hpp)->h_length = sizeof(struct in6_addr); Loading @@ -1232,12 +1239,14 @@ void DnsProxyListener::GetHostByAddrHandler::run() { maybeFixupNetContext(&mNetContext); const uid_t uid = mClient->getUid(); hostent* hp = nullptr; hostent hbuf; char tmpbuf[MAXPACKET]; int32_t rv = 0; NetworkDnsEventReported event; initDnsEvent(&event); if (queryLimiter.start(uid)) { rv = android_gethostbyaddrfornetcontext(mAddress, mAddressLen, mAddressFamily, &mNetContext, &hp, &event); rv = resolv_gethostbyaddr(mAddress, mAddressLen, mAddressFamily, &hbuf, tmpbuf, sizeof tmpbuf, &mNetContext, &hp, &event); queryLimiter.finish(uid); } else { rv = EAI_MEMORY; Loading @@ -1245,12 +1254,12 @@ void DnsProxyListener::GetHostByAddrHandler::run() { << ", max concurrent queries reached"; } doDns64ReverseLookup(&hp, &event); doDns64ReverseLookup(&hbuf, tmpbuf, sizeof tmpbuf, &hp, &event); const int32_t latencyUs = saturate_cast<int32_t>(s.timeTakenUs()); event.set_latency_micros(latencyUs); event.set_event_type(EVENT_GETHOSTBYADDR); LOG(DEBUG) << "GetHostByAddrHandler::run: result: " << (hp ? "success" : gai_strerror(rv)); LOG(DEBUG) << "GetHostByAddrHandler::run: result: " << gai_strerror(rv); bool success = true; if (hp) { Loading
DnsProxyListener.h +4 −2 Original line number Diff line number Diff line Loading @@ -84,7 +84,8 @@ class DnsProxyListener : public FrameworkListener { std::string threadName(); private: void doDns64Synthesis(int32_t* rv, hostent** hpp, NetworkDnsEventReported* event); void doDns64Synthesis(int32_t* rv, hostent* hbuf, char* buf, size_t buflen, hostent** hpp, NetworkDnsEventReported* event); SocketClient* mClient; // ref counted char* mName; // owned. TODO: convert to std::string. Loading @@ -110,7 +111,8 @@ class DnsProxyListener : public FrameworkListener { std::string threadName(); private: void doDns64ReverseLookup(hostent** hpp, NetworkDnsEventReported* event); void doDns64ReverseLookup(hostent* hbuf, char* buf, size_t buflen, hostent** hpp, NetworkDnsEventReported* event); SocketClient* mClient; // ref counted void* mAddress; // address to lookup; owned Loading
PREUPLOAD.cfg +1 −0 Original line number Diff line number Diff line [Builtin Hooks] clang_format = true commit_msg_test_field = false [Builtin Hooks Options] clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
getaddrinfo.cpp +6 −11 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ #include <android-base/logging.h> #include "netd_resolv/resolv.h" #include "res_init.h" #include "resolv_cache.h" #include "resolv_private.h" Loading Loading @@ -1445,18 +1446,11 @@ static int dns_getaddrinfo(const char* name, const addrinfo* pai, return EAI_FAMILY; } res_state res = res_get_state(); if (!res) return EAI_MEMORY; /* this just sets our netid val in the thread private data so we don't have to * modify the api's all the way down to res_send.c's res_nsend. We could * fully populate the thread private data here, but if we get down there * and have a cache hit that would be wasted, so we do the rest there on miss */ res_setnetcontext(res, netcontext, event); ResState res; res_init(&res, netcontext, event); int he; if (res_searchN(name, &q, res, &he) < 0) { if (res_searchN(name, &q, &res, &he) < 0) { // Return h_errno (he) to catch more detailed errors rather than EAI_NODATA. // Note that res_searchN() doesn't set the pair NETDB_INTERNAL and errno. // See also herrnoToAiErrno(). Loading Loading @@ -1612,7 +1606,8 @@ static int res_queryN(const char* name, res_target* target, res_state res, int* LOG(DEBUG) << __func__ << ": (" << cl << ", " << type << ")"; n = res_nmkquery(res, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf)); n = res_nmkquery(QUERY, name, cl, type, /*data=*/nullptr, /*datalen=*/0, buf, sizeof(buf), res->netcontext_flags); if (n > 0 && (res->netcontext_flags & (NET_CONTEXT_FLAG_USE_DNS_OVER_TLS | NET_CONTEXT_FLAG_USE_EDNS)) && Loading