Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ REPOSITORY_LOCATIONS = dict(
urls = ["https://files.pythonhosted.org/packages/c6/b4/510617906f8e0c5660e7d96fbc5585113f83ad547a3989b80297ac72a74c/thrift-0.11.0.tar.gz"],
),
com_github_c_ares_c_ares = dict(
sha256 = "7deb7872cbd876c29036d5f37e30c4cbc3cc068d59d8b749ef85bb0736649f04",
strip_prefix = "c-ares-cares-1_15_0",
urls = ["https://github.com/c-ares/c-ares/archive/cares-1_15_0.tar.gz"],
sha256 = "96edccdb19d79f6bc48c2c0e5916346c8f0507efa72e76bd146a1b9d05f93c2a",
strip_prefix = "c-ares-5dd3629bc93449840c36dd635ea6cce606b8c366",
# 2019-06-19
# 21 new commits from release-1.15.0. Upgrade for commit 7d3591ee8a1a63e7748e68e6d880bd1763a32885 "getaddrinfo enhancements"
# Use getaddrinfo to query DNS record and TTL.
# TODO(crazyxy): Update to release-1.16.0 when it is released.
urls = ["https://github.com/c-ares/c-ares/archive/5dd3629bc93449840c36dd635ea6cce606b8c366.tar.gz"],
),
com_github_circonus_labs_libcircllhist = dict(
sha256 = "8165aa25e529d7d4b9ae849d3bf30371255a99d6db0421516abcff23214cdc2c",
Expand Down
1 change: 1 addition & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Version history
* build: releases are built with Clang and linked with LLD.
* control-plane: management servers can respond with HTTP 304 to indicate that config is up to date for Envoy proxies polling a :ref:`REST API Config Type <envoy_api_field_core.ApiConfigSource.api_type>`
* csrf: added support for whitelisting additional source origins.
* dns: upgrade c-ares. Switch from ares_gethostbyname to ares_getaddrinfo.
Comment thread
yxue marked this conversation as resolved.
Outdated
* dubbo_proxy: support the :ref:`Dubbo proxy filter <config_network_filters_dubbo_proxy>`.
* eds: added support to specify max time for which endpoints can be used :ref:`gRPC filter <envoy_api_msg_ClusterLoadAssignment.Policy>`.
* event: added :ref:`loop duration and poll delay statistics <operations_performance>`.
Expand Down
73 changes: 41 additions & 32 deletions source/common/network/dns_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void DnsResolverImpl::initializeChannel(ares_options* options, int optmask) {
ares_init_options(&channel_, options, optmask | ARES_OPT_SOCK_STATE_CB);
}

void DnsResolverImpl::PendingResolution::onAresHostCallback(int status, int timeouts,
hostent* hostent) {
void DnsResolverImpl::PendingResolution::onAresGetAddrInfoCallback(int status, int timeouts,
ares_addrinfo* addrinfo) {
// We receive ARES_EDESTRUCTION when destructing with pending queries.
if (status == ARES_EDESTRUCTION) {
ASSERT(owned_);
Expand All @@ -81,32 +81,37 @@ void DnsResolverImpl::PendingResolution::onAresHostCallback(int status, int time

std::list<Address::InstanceConstSharedPtr> address_list;
if (status == ARES_SUCCESS) {
if (hostent->h_addrtype == AF_INET) {
for (int i = 0; hostent->h_addr_list[i] != nullptr; ++i) {
ASSERT(hostent->h_length == sizeof(in_addr));
sockaddr_in address;
memset(&address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_port = 0;
address.sin_addr = *reinterpret_cast<in_addr*>(hostent->h_addr_list[i]);
address_list.emplace_back(new Address::Ipv4Instance(&address));
if (addrinfo != nullptr && addrinfo->nodes != nullptr) {
if (addrinfo->nodes->ai_family == AF_INET) {
for (const ares_addrinfo_node* ai = addrinfo->nodes; ai != nullptr; ai = ai->ai_next) {
sockaddr_in address;
memset(&address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_port = 0;
address.sin_addr = reinterpret_cast<sockaddr_in*>(ai->ai_addr)->sin_addr;
address_list.emplace_back(new Address::Ipv4Instance(&address));
}
} else if (addrinfo->nodes->ai_family == AF_INET6) {
for (const ares_addrinfo_node* ai = addrinfo->nodes; ai != nullptr; ai = ai->ai_next) {
sockaddr_in6 address;
memset(&address, 0, sizeof(address));
address.sin6_family = AF_INET6;
address.sin6_port = 0;
address.sin6_addr = reinterpret_cast<sockaddr_in6*>(ai->ai_addr)->sin6_addr;
address_list.emplace_back(new Address::Ipv6Instance(address));
}
}
} else if (hostent->h_addrtype == AF_INET6) {
for (int i = 0; hostent->h_addr_list[i] != nullptr; ++i) {
ASSERT(hostent->h_length == sizeof(in6_addr));
sockaddr_in6 address;
memset(&address, 0, sizeof(address));
address.sin6_family = AF_INET6;
address.sin6_port = 0;
address.sin6_addr = *reinterpret_cast<in6_addr*>(hostent->h_addr_list[i]);
address_list.emplace_back(new Address::Ipv6Instance(address));
}
}
if (!address_list.empty()) {
completed_ = true;
}
}

if (!address_list.empty()) {
Comment thread
yxue marked this conversation as resolved.
Outdated
completed_ = true;
}

if (addrinfo) {
Comment thread
yxue marked this conversation as resolved.
Outdated
ares_freeaddrinfo(addrinfo);
}

if (timeouts > 0) {
ENVOY_LOG(debug, "DNS request timed out {} times", timeouts);
}
Expand Down Expand Up @@ -134,7 +139,7 @@ void DnsResolverImpl::PendingResolution::onAresHostCallback(int status, int time

if (!completed_ && fallback_if_failed_) {
fallback_if_failed_ = false;
getHostByName(AF_INET);
getAddrInfo(AF_INET);
// Note: Nothing can follow this call to getHostByName due to deletion of this
// object upon synchronous resolution.
return;
Expand Down Expand Up @@ -195,9 +200,9 @@ ActiveDnsQuery* DnsResolverImpl::resolve(const std::string& dns_name,
}

if (dns_lookup_family == DnsLookupFamily::V4Only) {
pending_resolution->getHostByName(AF_INET);
pending_resolution->getAddrInfo(AF_INET);
} else {
pending_resolution->getHostByName(AF_INET6);
pending_resolution->getAddrInfo(AF_INET6);
}

if (pending_resolution->completed_) {
Expand All @@ -215,11 +220,15 @@ ActiveDnsQuery* DnsResolverImpl::resolve(const std::string& dns_name,
}
}

void DnsResolverImpl::PendingResolution::getHostByName(int family) {
ares_gethostbyname(
channel_, dns_name_.c_str(), family,
[](void* arg, int status, int timeouts, hostent* hostent) {
static_cast<PendingResolution*>(arg)->onAresHostCallback(status, timeouts, hostent);
void DnsResolverImpl::PendingResolution::getAddrInfo(int family) {
struct ares_addrinfo_hints hints = {};
hints.ai_family = family;
hints.ai_flags = ARES_AI_CANONNAME | ARES_AI_ENVHOSTS | ARES_AI_NOSORT;
Comment thread
yxue marked this conversation as resolved.
Outdated

ares_getaddrinfo(
channel_, dns_name_.c_str(), /* service */ nullptr, &hints,
[](void* arg, int status, int timeouts, ares_addrinfo* addrinfo) {
static_cast<PendingResolution*>(arg)->onAresGetAddrInfoCallback(status, timeouts, addrinfo);
},
this);
}
Expand Down
12 changes: 6 additions & 6 deletions source/common/network/dns_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ class DnsResolverImpl : public DnsResolver, protected Logger::Loggable<Logger::I
}

/**
* c-ares ares_gethostbyname() query callback.
* @param status return status of call to ares_gethostbyname.
* ares_getaddrinfo query callback.
* @param status return status of call to ares_getaddrinfo.
* @param timeouts the number of times the request timed out.
* @param hostent structure that stores information about a given host.
* @param addrinfo structure to store address info.
*/
void onAresHostCallback(int status, int timeouts, hostent* hostent);
void onAresGetAddrInfoCallback(int status, int timeouts, ares_addrinfo* addrinfo);
/**
* wrapper function of call to ares_gethostbyname.
* wrapper function of call to ares_getaddrinfo.
* @param family currently AF_INET and AF_INET6 are supported.
*/
void getHostByName(int family);
void getAddrInfo(int family);

// Caller supplied callback to invoke on query completion or error.
const ResolveCb callback_;
Expand Down
1 change: 1 addition & 0 deletions tools/spelling_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ WS
Welford's
Werror
XDS
getaddrinfo
sendto
vip
xDSes
Expand Down