Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 13 additions & 1 deletion source/common/network/apple_dns_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,19 @@ DNSServiceErrorType AppleDnsResolverImpl::PendingResolution::dnsServiceGetAddrIn
break;
case DnsLookupFamily::Auto:
case DnsLookupFamily::V4Preferred:
protocol = kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6;
/* We want to make sure we don't get any address that is not routable. Passing 0
* to apple's `DNSServiceGetAddrInfo` will make a best attempt to filter out IPv6
* or IPv4 addresses depending on what's routable, per Apple's documentation:
*
* If neither flag is set, the system will apply an intelligent heuristic, which
* is (currently) that it will attempt to look up both, except:
* If "hostname" is a wide-area unicast DNS hostname (i.e. not a ".local." name) but
* this host has no routable IPv6 address, then the call will not try to look up IPv6
* addresses for "hostname", since any addresses it found would be unlikely to be of
* any use anyway. Similarly, if this host has no routable IPv4 address, the call will
* not try to look up IPv4 addresses for "hostname".
*/
protocol = 0;
break;
}

Expand Down
91 changes: 34 additions & 57 deletions test/common/network/apple_dns_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,25 @@ TEST_F(AppleDnsImplTest, LocalLookup) {
dispatcher_->run(Event::Dispatcher::RunType::Block);
}

TEST_F(AppleDnsImplTest, DnsIpAddressVersion) {
TEST_F(AppleDnsImplTest, DnsIpAddressVersionAuto) {
EXPECT_NE(nullptr, resolveWithExpectations("google.com", DnsLookupFamily::Auto,
DnsResolver::ResolutionStatus::Success, true));
dispatcher_->run(Event::Dispatcher::RunType::Block);
}

TEST_F(AppleDnsImplTest, DnsIpAddressVersionV4Preferred) {
EXPECT_NE(nullptr, resolveWithExpectations("google.com", DnsLookupFamily::V4Preferred,
DnsResolver::ResolutionStatus::Success, true));
dispatcher_->run(Event::Dispatcher::RunType::Block);
}

TEST_F(AppleDnsImplTest, DnsIpAddressVersionV4Only) {
EXPECT_NE(nullptr, resolveWithExpectations("google.com", DnsLookupFamily::V4Only,
DnsResolver::ResolutionStatus::Success, true));
dispatcher_->run(Event::Dispatcher::RunType::Block);
}

TEST_F(AppleDnsImplTest, DnsIpAddressVersionV6Only) {
EXPECT_NE(nullptr, resolveWithExpectations("google.com", DnsLookupFamily::V6Only,
DnsResolver::ResolutionStatus::Success, true));
dispatcher_->run(Event::Dispatcher::RunType::Block);
Expand Down Expand Up @@ -222,10 +228,7 @@ TEST_F(AppleDnsImplTest, CallbackExceptionLocalResolution) {
// Validate working of cancellation provided by ActiveDnsQuery return.
TEST_F(AppleDnsImplTest, Cancel) {
ActiveDnsQuery* query =
resolveWithUnreferencedParameters("some.domain", DnsLookupFamily::Auto, false);

EXPECT_NE(nullptr, resolveWithExpectations("google.com", DnsLookupFamily::Auto,
DnsResolver::ResolutionStatus::Success, true));
resolveWithUnreferencedParameters("google.com", DnsLookupFamily::Auto, false);

ASSERT_NE(nullptr, query);
query->cancel(Network::ActiveDnsQuery::CancelReason::QueryAbandoned);
Expand Down Expand Up @@ -305,10 +308,8 @@ class AppleDnsImplFakeApiTest : public testing::Test {
Network::Address::Ipv4Instance address(&addr4);
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(
// Have the API call synchronously call the provided callback.
WithArgs<5, 6>(Invoke([&](DNSServiceGetAddrInfoReply callback, void* context) -> void {
Expand Down Expand Up @@ -349,10 +350,8 @@ class AppleDnsImplFakeApiTest : public testing::Test {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -429,10 +428,8 @@ TEST_F(AppleDnsImplFakeApiTest, ErrorInSocketAccess) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(-1));
Expand Down Expand Up @@ -466,10 +463,8 @@ TEST_F(AppleDnsImplFakeApiTest, InvalidFileEvent) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -503,10 +498,8 @@ TEST_F(AppleDnsImplFakeApiTest, ErrorInProcessResult) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -558,10 +551,8 @@ TEST_F(AppleDnsImplFakeApiTest, QuerySynchronousCompletion) {
Network::Address::Ipv4Instance address(&addr4);
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(
// Have the API call synchronously call the provided callback.
WithArgs<5, 6>(Invoke([&](DNSServiceGetAddrInfoReply callback, void* context) -> void {
Expand Down Expand Up @@ -618,10 +609,8 @@ TEST_F(AppleDnsImplFakeApiTest, MultipleAddresses) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -684,10 +673,8 @@ TEST_F(AppleDnsImplFakeApiTest, MultipleAddressesSecondOneFails) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -734,10 +721,8 @@ TEST_F(AppleDnsImplFakeApiTest, MultipleQueries) {
absl::Notification dns_callback_executed2;

// Start first query.
EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -805,10 +790,8 @@ TEST_F(AppleDnsImplFakeApiTest, MultipleQueriesOneFails) {
absl::Notification dns_callback_executed2;

// Start first query.
EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -869,10 +852,8 @@ TEST_F(AppleDnsImplFakeApiTest, ResultWithOnlyNonAdditiveReplies) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -904,10 +885,8 @@ TEST_F(AppleDnsImplFakeApiTest, ResultWithNullAddress) {
Network::Address::Ipv4Instance address(&addr4);
DNSServiceGetAddrInfoReply reply_callback;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(SaveArg<5>(&reply_callback), Return(kDNSServiceErr_NoError)));

EXPECT_CALL(dns_service_, dnsServiceRefSockFD(_)).WillOnce(Return(0));
Expand Down Expand Up @@ -941,10 +920,8 @@ TEST_F(AppleDnsImplFakeApiTest, DeallocateOnDestruction) {
DNSServiceGetAddrInfoReply reply_callback;
absl::Notification dns_callback_executed;

EXPECT_CALL(dns_service_,
dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0,
kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6,
StrEq(hostname.c_str()), _, _))
EXPECT_CALL(dns_service_, dnsServiceGetAddrInfo(_, kDNSServiceFlagsTimeout, 0, 0,
StrEq(hostname.c_str()), _, _))
.WillOnce(DoAll(
SaveArg<5>(&reply_callback),
WithArgs<0>(Invoke([](DNSServiceRef* ref) -> void { *ref = new _DNSServiceRef_t{}; })),
Expand Down
1 change: 1 addition & 0 deletions tools/spelling/spelling_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1300,3 +1300,4 @@ crlf
ep
suri
transid
routable