-
Notifications
You must be signed in to change notification settings - Fork 5.3k
DNS: officially (previously only unofficially) allowing null resolutions #19588
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0c2594
DNS: officially (previously only unofficially) allowing null resolutions
alyssawilk c60a27d
adding flag
alyssawilk 86b54b0
Merge branch 'main' into dns2
alyssawilk e6d7ef6
comment
alyssawilk 0a21c0c
update mocks
alyssawilk 9d32ce0
Merge branch 'main' into dns2
alyssawilk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,13 @@ void latchTime(Http::StreamDecoderFilterCallbacks* decoder_callbacks, absl::stri | |
| struct ResponseStringValues { | ||
| const std::string DnsCacheOverflow = "DNS cache overflow"; | ||
| const std::string PendingRequestOverflow = "Dynamic forward proxy pending request overflow"; | ||
| const std::string DnsResolutionFailure = "DNS resolution failure"; | ||
| }; | ||
|
|
||
| struct RcDetailsValues { | ||
| const std::string DnsCacheOverflow = "dns_cache_overflow"; | ||
| const std::string PendingRequestOverflow = "dynamic_forward_proxy_pending_request_overflow"; | ||
| const std::string DnsResolutionFailure = "dns_resolution_failure"; | ||
| }; | ||
|
|
||
| using CustomClusterType = envoy::config::cluster::v3::Cluster::CustomClusterType; | ||
|
|
@@ -143,11 +145,15 @@ Http::FilterHeadersStatus ProxyFilter::decodeHeaders(Http::RequestHeaderMap& hea | |
| ENVOY_STREAM_LOG(debug, "DNS cache entry already loaded, continuing", *decoder_callbacks_); | ||
|
|
||
| auto const& host = config_->cache().getHost(headers.Host()->value().getStringView()); | ||
| latchTime(decoder_callbacks_, DNS_END); | ||
| if (host.has_value()) { | ||
| if (!host.value()->address()) { | ||
| onDnsResolutionFail(); | ||
| return Http::FilterHeadersStatus::StopIteration; | ||
| } | ||
| addHostAddressToFilterState(host.value()->address()); | ||
| } | ||
|
|
||
| latchTime(decoder_callbacks_, DNS_END); | ||
| return Http::FilterHeadersStatus::Continue; | ||
| } | ||
| case LoadDnsCacheEntryStatus::Loading: | ||
|
|
@@ -167,20 +173,12 @@ Http::FilterHeadersStatus ProxyFilter::decodeHeaders(Http::RequestHeaderMap& hea | |
|
|
||
| void ProxyFilter::addHostAddressToFilterState( | ||
| const Network::Address::InstanceConstSharedPtr& address) { | ||
| ASSERT(address); // null pointer checks must be done before calling this function. | ||
|
|
||
| if (!config_->saveUpstreamAddress()) { | ||
| return; | ||
| } | ||
|
|
||
| // `onLoadDnsCacheComplete` is called by DNS cache on first resolution even if there was a | ||
| // resolution failure (null address). This check makes sure that we do not add null address to | ||
| // FilterState when this happens. | ||
| if (!address) { | ||
| ENVOY_STREAM_LOG(debug, "Cannot add address to filter state: invalid address", | ||
| *decoder_callbacks_); | ||
| return; | ||
| } | ||
|
|
||
| ENVOY_STREAM_LOG(trace, "Adding resolved host {} to filter state", *decoder_callbacks_, | ||
| address->asString()); | ||
|
|
||
|
|
@@ -195,6 +193,13 @@ void ProxyFilter::addHostAddressToFilterState( | |
| StreamInfo::FilterState::LifeSpan::Request); | ||
| } | ||
|
|
||
| void ProxyFilter::onDnsResolutionFail() { | ||
| decoder_callbacks_->streamInfo().setResponseFlag(StreamInfo::ResponseFlag::DnsResolutionFailed); | ||
| decoder_callbacks_->sendLocalReply(Http::Code::ServiceUnavailable, | ||
|
Member
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. @Augustyniak @buildbreaker @goaway @jpsim @Reflejo FYI, now we will have a more explicit error for DNS failures from the forward proxy filter. Rather than the |
||
| ResponseStrings::get().DnsResolutionFailure, nullptr, | ||
| absl::nullopt, RcDetails::get().DnsResolutionFailure); | ||
| } | ||
|
|
||
| void ProxyFilter::onLoadDnsCacheComplete( | ||
| const Common::DynamicForwardProxy::DnsHostInfoSharedPtr& host_info) { | ||
| ENVOY_STREAM_LOG(debug, "load DNS cache complete, continuing after adding resolved host: {}", | ||
|
|
@@ -203,6 +208,10 @@ void ProxyFilter::onLoadDnsCacheComplete( | |
| ASSERT(circuit_breaker_ != nullptr); | ||
| circuit_breaker_.reset(); | ||
|
|
||
| if (!host_info->address()) { | ||
| onDnsResolutionFail(); | ||
| return; | ||
| } | ||
| addHostAddressToFilterState(host_info->address()); | ||
|
|
||
| decoder_callbacks_->continueDecoding(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider calling
latchTime(decoder_callbacks_, DNS_END);before this line (or inonDnsResolutionFail().