Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 0 additions & 3 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,6 @@ ConnectionManagerImpl::ActiveStream::ActiveStream(ConnectionManagerImpl& connect
max_stream_duration_timer_->enableTimer(connection_manager_.config_.maxStreamDuration().value(),
this);
}

filter_manager_.streamInfo().setRequestedServerName(
Comment thread
soulxu marked this conversation as resolved.
connection_manager_.read_callbacks_->connection().requestedServerName());
}

void ConnectionManagerImpl::ActiveStream::completeRequest() {
Expand Down
1 change: 0 additions & 1 deletion source/common/tcp_proxy/tcp_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ void Filter::onUpstreamConnection() {
read_callbacks_->upstreamHost()->outlierDetector().putResult(
Upstream::Outlier::Result::LocalOriginConnectSuccessFinal);

getStreamInfo().setRequestedServerName(read_callbacks_->connection().requestedServerName());
ENVOY_CONN_LOG(debug, "TCP:onUpstreamEvent(), requestedServerName: {}",
read_callbacks_->connection(), getStreamInfo().requestedServerName());

Expand Down
4 changes: 4 additions & 0 deletions source/server/active_tcp_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ void ActiveTcpListener::resumeListening() {

void ActiveTcpListener::newConnection(Network::ConnectionSocketPtr&& socket,
std::unique_ptr<StreamInfo::StreamInfo> stream_info) {
// populate the SNI into stream info, the network filters needn't do that again.
Comment thread
soulxu marked this conversation as resolved.
Outdated
if (!socket->requestedServerName().empty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done unconditionally? I would expect that calling setRequestedServerName() with an empty string would have no effect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has a constructor even for empty string https://github.com/envoyproxy/envoy/blob/main/source/common/stream_info/stream_info_impl.h#L237. Or we can move the check inside the setRequestedServerName(), but that will block the case when want to set the server name back to empty. Although I'm not sure we have any case to set the server name back to empty, but it still feels bad for an interface.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is functionally the same without this check; setting it to empty is the same as not setting it. Please remove the conditional to simplify the code. Same in unlink().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, let me remove it.

stream_info->setRequestedServerName(socket->requestedServerName());
}

// Find matching filter chain.
const auto filter_chain = config_->filterChainManager().findFilterChain(*socket);
Expand Down
29 changes: 29 additions & 0 deletions test/server/active_tcp_listener_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ class ActiveTcpListenerTest : public testing::Test, protected Logger::Loggable<L
std::shared_ptr<NiceMock<Network::MockListenerFilterMatcher>> listener_filter_matcher_;
};

TEST_F(ActiveTcpListenerTest, PopulateSNIWhenNoFilterChainMatched) {
auto listener = std::make_unique<Network::MockListener>();
EXPECT_CALL(*listener, onDestroy());

NiceMock<Network::MockConnectionBalancer> balancer1;
Network::Address::InstanceConstSharedPtr normal_address(
new Network::Address::Ipv4Instance("127.0.0.1", 10001));
EXPECT_CALL(*socket_factory_, localAddress()).WillRepeatedly(ReturnRef(normal_address));
EXPECT_CALL(listener_config_, connectionBalancer()).WillRepeatedly(ReturnRef(balancer1));
EXPECT_CALL(listener_config_, listenerScope).Times(testing::AnyNumber());
EXPECT_CALL(listener_config_, listenerFiltersTimeout());
EXPECT_CALL(listener_config_, continueOnListenerFiltersTimeout());
EXPECT_CALL(listener_config_, filterChainManager()).WillRepeatedly(ReturnRef(manager_));
EXPECT_CALL(listener_config_, openConnections()).WillRepeatedly(ReturnRef(resource_limit_));

auto active_listener1 =
std::make_unique<ActiveTcpListener>(conn_handler_, std::move(listener), listener_config_);

Network::MockConnectionSocket* accepted_socket1 = new NiceMock<Network::MockConnectionSocket>();
Comment thread
soulxu marked this conversation as resolved.
Outdated
EXPECT_CALL(*accepted_socket1, requestedServerName()).WillRepeatedly(Return("envoy.io"));

EXPECT_CALL(manager_, findFilterChain(_)).WillRepeatedly(Return(nullptr));
Comment thread
soulxu marked this conversation as resolved.
Outdated

std::unique_ptr<StreamInfo::StreamInfoImpl> stream_info(
new StreamInfo::StreamInfoImpl(dispatcher_.timeSource(), nullptr));
Comment thread
soulxu marked this conversation as resolved.
Outdated
active_listener1->newConnection(Network::ConnectionSocketPtr{accepted_socket1},
std::move(stream_info));
}

// Verify that the server connection with recovered address is rebalanced at redirected listener.
TEST_F(ActiveTcpListenerTest, RedirectedRebalancer) {
NiceMock<Network::MockListenerConfig> listener_config1;
Expand Down