-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c-ares: add option for udp_max_queries #33551
Changes from 9 commits
ae8bd25
79ef702
2e40135
b97ad5a
16a1761
35d6a19
5f0625a
3a117a9
bc4470c
973c8ae
b59d5dc
5da6454
f97933a
392cc7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#include "source/extensions/network/dns_resolver/cares/dns_impl.h" | ||
|
||
#include <ares.h> | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <list> | ||
|
@@ -92,6 +94,11 @@ DnsResolverImpl::AresOptions DnsResolverImpl::defaultAresOptions() { | |
options.options_.flags |= ARES_FLAG_NOSEARCH; | ||
} | ||
|
||
if (dns_resolver_options_.has_udp_max_queries()) { | ||
options.optmask_ |= ARES_OPT_UDP_MAX_QUERIES; | ||
options.options_.udp_max_queries = dns_resolver_options_.udp_max_queries().value(); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
|
@@ -194,7 +201,7 @@ void DnsResolverImpl::AddrInfoPendingResolution::onAresGetAddrInfoCallback( | |
// | ||
// The channel cannot be destroyed and reinitialized here because that leads to a c-ares | ||
// segfault. | ||
if (status == ARES_ECONNREFUSED) { | ||
if (status == ARES_ECONNREFUSED || status == ARES_EREFUSED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This change is for updating c-ares library to 1.20, but have nothing to do with the udp_max_queries option support. Does it make sense to separate it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you split into two PRs? It will make it easier to review the dependency updates vs. the UDP query specific change proposed. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure I can split it. Let me send out a PR for library update. |
||
parent_.dirty_channel_ = true; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2089,5 +2089,36 @@ TEST_P(DnsImplCustomResolverTest, CustomResolverValidAfterChannelDestruction) { | |
EXPECT_FALSE(peer_->isChannelDirty()); | ||
} | ||
|
||
class DnsImplAresFlagsForMaxUdpQueriesinTest : public DnsImplTest { | ||
protected: | ||
bool tcpOnly() const override { return false; } | ||
void updateDnsResolverOptions() override { | ||
auto udp_max_queries = std::make_unique<ProtobufWkt::UInt32Value>(); | ||
udp_max_queries->set_value(100); | ||
dns_resolver_options_.set_allocated_udp_max_queries( | ||
dynamic_cast<ProtobufWkt::UInt32Value*>(udp_max_queries.release())); | ||
} | ||
}; | ||
|
||
// Parameterize the DNS test server socket address. | ||
INSTANTIATE_TEST_SUITE_P(IpVersions, DnsImplAresFlagsForMaxUdpQueriesinTest, | ||
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), | ||
TestUtility::ipTestParamsToString); | ||
|
||
// Validate that c_ares flag `ARES_OPT_UDP_MAX_QUERIES` is set when UInt32 property | ||
// `udp_max_queries` is set. | ||
TEST_P(DnsImplAresFlagsForMaxUdpQueriesinTest, UdpMaxQueriesIsSet) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yanjunxiang-google - do you mean by checking opts.udp_max_queries or something more involved ? I tried poking in that area but couldn't find anything obvious - if you have suggestions - happy to look into it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was pushing c'ares team for this change : c-ares/c-ares#444 I believe you can test like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change should be ok as is, since we rely on c-ares to test the behavior of the ARES_OPT_UDP_MAX_QUERIES flag. I do not think it is important to validate that this flag is working in c-ares. |
||
server_->addCName("root.cname.domain", "result.cname.domain"); | ||
server_->addHosts("result.cname.domain", {"201.134.56.7"}, RecordType::A); | ||
ares_options opts{}; | ||
int optmask = 0; | ||
EXPECT_EQ(ARES_SUCCESS, ares_save_options(peer_->channel(), &opts, &optmask)); | ||
EXPECT_TRUE((optmask & ARES_OPT_UDP_MAX_QUERIES) == ARES_OPT_UDP_MAX_QUERIES); | ||
EXPECT_TRUE(opts.udp_max_queries == 100); | ||
EXPECT_NE(nullptr, | ||
resolveWithUnreferencedParameters("root.cname.domain", DnsLookupFamily::Auto, true)); | ||
ares_destroy_options(&opts); | ||
} | ||
|
||
} // namespace Network | ||
} // namespace Envoy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to move this option in c-ares specific configuration: https://github.com/envoyproxy/envoy/blob/main/api/envoy/extensions/network/dns_resolver/cares/v3/cares_dns_resolver.proto ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was in two minds thinking that if tomorrow there was an option for apple dns resolver, it could be leveraged. But happy to move this to c-ares if that makes more sense.