Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2fa0949
add ForwardRequestedServerName FilterState Object
vadimeisenbergibm Nov 6, 2018
9701ce6
add functionality to override requested server name in the upstream c…
vadimeisenbergibm Nov 6, 2018
ab66f42
replace override_server_name with TransportSocketOptions
vadimeisenbergibm Nov 7, 2018
5fe6e3e
fix compilation errors in tests
vadimeisenbergibm Nov 8, 2018
b6f32d7
fix format
vadimeisenbergibm Nov 8, 2018
6aff2ea
fix compilation errors
vadimeisenbergibm Nov 8, 2018
0b2a296
make overrideServerName() return const&
vadimeisenbergibm Nov 8, 2018
6c9128d
make the parameter of newSSL() const&
vadimeisenbergibm Nov 8, 2018
dedd511
fix a compilation error
vadimeisenbergibm Nov 8, 2018
27557de
fixed missed refactoring
vadimeisenbergibm Nov 8, 2018
b019a99
"refactor" a comment
vadimeisenbergibm Nov 8, 2018
09af682
fix a typo
vadimeisenbergibm Nov 8, 2018
8ff3b25
move stream_info/forward_requested_server_name to source/common/netwo…
vadimeisenbergibm Nov 8, 2018
cfbb753
StreamInfo::ForwardRequestedServerName -> Network::UpstreamServerName
vadimeisenbergibm Nov 8, 2018
566570f
append missing StreamInfo namespace
vadimeisenbergibm Nov 8, 2018
173849b
remove a leftover from the PR this PR was extracted from
vadimeisenbergibm Nov 8, 2018
41cf2c7
fix format
vadimeisenbergibm Nov 8, 2018
995d15e
remove names of the unused parameters
vadimeisenbergibm Nov 8, 2018
c8afa18
add comments
vadimeisenbergibm Nov 9, 2018
c9ed4a7
overrideServerName -> serverNameOverride
vadimeisenbergibm Nov 15, 2018
bdce6bb
make TransportSocketOptionsImpl::override_server_name_ const
vadimeisenbergibm Nov 16, 2018
895dafb
std::string -> absl::string_view
vadimeisenbergibm Nov 16, 2018
088f2d8
fix the hashKey() method
vadimeisenbergibm Nov 16, 2018
88b3d31
update the comments - explanation about serverNameOverride
vadimeisenbergibm Nov 17, 2018
e9c0a87
use sizeof of a variable instead of hardcoded size value
vadimeisenbergibm Nov 20, 2018
0fa1bd3
refactor scalar to byte vector conversion into pushScalarToByteVector()
vadimeisenbergibm Nov 20, 2018
7109894
uint -> unsigned int
vadimeisenbergibm Nov 20, 2018
b8f0d3c
add missing includes
vadimeisenbergibm Nov 20, 2018
dddd8e3
fix static initialization problem
vadimeisenbergibm Nov 20, 2018
2532513
fix format
vadimeisenbergibm Nov 20, 2018
588fa98
PerConnectionCluster::Key -> PerConnectionCluster::key() in tests
vadimeisenbergibm Nov 20, 2018
2f23141
add TODO replace long parameter lists with options objects
vadimeisenbergibm Nov 20, 2018
b31e6f6
use CONSTRUCT_ON_FIRST_USE macro
vadimeisenbergibm Nov 20, 2018
d84b467
combine pointer dereferencing and increment into one line
vadimeisenbergibm Nov 20, 2018
d6583b9
unsigned int -> uint32_t
vadimeisenbergibm Nov 20, 2018
505cce2
Revert "make the parameter of newSSL() const&"
vadimeisenbergibm Nov 20, 2018
58efa36
Merge branch 'master' into override_server_name
vadimeisenbergibm Nov 20, 2018
7080014
replace v1 json with v2 yaml in DynamicHostRemoveWithTls test
vadimeisenbergibm Nov 21, 2018
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
18 changes: 17 additions & 1 deletion include/envoy/network/transport_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "envoy/common/pure.h"
#include "envoy/ssl/connection.h"

#include "absl/types/optional.h"

namespace Envoy {
namespace Network {

Expand Down Expand Up @@ -136,6 +138,18 @@ class TransportSocket {

typedef std::unique_ptr<TransportSocket> TransportSocketPtr;

/**
* Options for creating transport sockets.
*/
class TransportSocketOptions {
public:
virtual ~TransportSocketOptions() {}
virtual const absl::optional<std::string>& overrideServerName() const PURE;

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.

comment for each method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

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.

Rename to serverNameOverride or just simply serverName; otherwise, it sounds like a mutating method vs. an option.

virtual void hashKey(std::vector<uint8_t>& key) const PURE;
Comment thread
lizan marked this conversation as resolved.
};

typedef std::shared_ptr<TransportSocketOptions> TransportSocketOptionsSharedPtr;

/**
* A factory for creating transport socket. It will be associated to filter chains and clusters.
*/
Expand All @@ -149,9 +163,11 @@ class TransportSocketFactory {
virtual bool implementsSecureTransport() const PURE;

/**
* @param options for creating the transport socket
* @return Network::TransportSocketPtr a transport socket to be passed to connection.
*/
virtual TransportSocketPtr createTransportSocket() const PURE;
virtual TransportSocketPtr
createTransportSocket(TransportSocketOptionsSharedPtr options) const PURE;
};

typedef std::unique_ptr<TransportSocketFactory> TransportSocketFactoryPtr;
Expand Down
15 changes: 9 additions & 6 deletions include/envoy/upstream/cluster_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ class ClusterManager {
* Can return nullptr if there is no host available in the cluster or if the cluster does not
* exist.
*/
virtual Tcp::ConnectionPool::Instance* tcpConnPoolForCluster(const std::string& cluster,
ResourcePriority priority,
LoadBalancerContext* context) PURE;
virtual Tcp::ConnectionPool::Instance*
tcpConnPoolForCluster(const std::string& cluster, ResourcePriority priority,
LoadBalancerContext* context,
Network::TransportSocketOptionsSharedPtr transport_socket_options) PURE;

/**
* Allocate a load balanced TCP connection for a cluster. The created connection is already
Expand All @@ -143,8 +144,9 @@ class ClusterManager {
* Returns both a connection and the host that backs the connection. Both can be nullptr if there
* is no host available in the cluster.
*/
virtual Host::CreateConnectionData tcpConnForCluster(const std::string& cluster,
LoadBalancerContext* context) PURE;
virtual Host::CreateConnectionData
tcpConnForCluster(const std::string& cluster, LoadBalancerContext* context,
Network::TransportSocketOptionsSharedPtr transport_socket_options) PURE;

/**
* Returns a client that can be used to make async HTTP calls against the given cluster. The
Expand Down Expand Up @@ -271,7 +273,8 @@ class ClusterManagerFactory {
virtual Tcp::ConnectionPool::InstancePtr
allocateTcpConnPool(Event::Dispatcher& dispatcher, HostConstSharedPtr host,
ResourcePriority priority,
const Network::ConnectionSocket::OptionsSharedPtr& options) PURE;
const Network::ConnectionSocket::OptionsSharedPtr& options,
Network::TransportSocketOptionsSharedPtr transport_socket_options) PURE;

/**
* Allocate a cluster from configuration proto.
Expand Down
3 changes: 2 additions & 1 deletion include/envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class Host : virtual public HostDescription {
*/
virtual CreateConnectionData
createConnection(Event::Dispatcher& dispatcher,
const Network::ConnectionSocket::OptionsSharedPtr& options) const PURE;
const Network::ConnectionSocket::OptionsSharedPtr& options,
Network::TransportSocketOptionsSharedPtr transport_socket_options) const PURE;

/**
* Create a health check connection for this host.
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http1/conn_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ ConnPoolImpl::ActiveClient::ActiveClient(ConnPoolImpl& parent)
parent_.conn_connect_ms_ = std::make_unique<Stats::Timespan>(
parent_.host_->cluster().stats().upstream_cx_connect_ms_, parent_.dispatcher_.timeSystem());
Upstream::Host::CreateConnectionData data =
parent_.host_->createConnection(parent_.dispatcher_, parent_.socket_options_);
parent_.host_->createConnection(parent_.dispatcher_, parent_.socket_options_, nullptr);
real_host_description_ = data.host_description_;
codec_client_ = parent_.createCodecClient(data);
codec_client_->addConnectionCallbacks(*this);
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http2/conn_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ConnPoolImpl::ActiveClient::ActiveClient(ConnPoolImpl& parent)
parent_.conn_connect_ms_ = std::make_unique<Stats::Timespan>(
parent_.host_->cluster().stats().upstream_cx_connect_ms_, parent_.dispatcher_.timeSystem());
Upstream::Host::CreateConnectionData data =
parent_.host_->createConnection(parent_.dispatcher_, parent_.socket_options_);
parent_.host_->createConnection(parent_.dispatcher_, parent_.socket_options_, nullptr);
real_host_description_ = data.host_description_;
client_ = parent_.createCodecClient(data);
client_->addConnectionCallbacks(*this);
Expand Down
9 changes: 9 additions & 0 deletions source/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,12 @@ envoy_cc_library(
"@envoy_api//envoy/api/v2/core:base_cc",
],
)

envoy_cc_library(
name = "transport_socket_options_lib",
srcs = ["transport_socket_options_impl.cc"],
hdrs = ["transport_socket_options_impl.h"],
deps = [
"//include/envoy/network:transport_socket_interface",
],
)
3 changes: 2 additions & 1 deletion source/common/network/raw_buffer_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ std::string RawBufferSocket::protocol() const { return EMPTY_STRING; }

void RawBufferSocket::onConnected() { callbacks_->raiseEvent(ConnectionEvent::Connected); }

TransportSocketPtr RawBufferSocketFactory::createTransportSocket() const {
TransportSocketPtr
RawBufferSocketFactory::createTransportSocket(TransportSocketOptionsSharedPtr) const {
return std::make_unique<RawBufferSocket>();
}

Expand Down
2 changes: 1 addition & 1 deletion source/common/network/raw_buffer_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RawBufferSocket : public TransportSocket, protected Logger::Loggable<Logge
class RawBufferSocketFactory : public TransportSocketFactory {
public:
// Network::TransportSocketFactory
TransportSocketPtr createTransportSocket() const override;
TransportSocketPtr createTransportSocket(TransportSocketOptionsSharedPtr options) const override;
bool implementsSecureTransport() const override;
};

Expand Down
20 changes: 20 additions & 0 deletions source/common/network/transport_socket_options_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "common/network/transport_socket_options_impl.h"

namespace Envoy {
namespace Network {
TransportSocketOptionsImpl::TransportSocketOptionsImpl(std::string override_server_name) {
if (!override_server_name.empty()) {
override_server_name_ = override_server_name;
}
}

void TransportSocketOptionsImpl::hashKey(std::vector<uint8_t>& key) const {
if (!override_server_name_.has_value()) {
return;
}

std::hash<std::string> hash_function;
key.push_back(hash_function(override_server_name_.value()));

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 don't think this does what is expected. The hash function will return a size_t, which will be truncated to a uint8_t here, rather than turned into a sequence of bytes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@htuch Addressed in 088f2d8. Could you please review this part?

}
} // namespace Network
} // namespace Envoy
21 changes: 21 additions & 0 deletions source/common/network/transport_socket_options_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "envoy/network/transport_socket.h"

namespace Envoy {
namespace Network {

class TransportSocketOptionsImpl : public TransportSocketOptions {
public:
TransportSocketOptionsImpl(std::string override_server_name = "");

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.

absl::string_view?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 895dafb.

const absl::optional<std::string>& overrideServerName() const override {
return override_server_name_;
}
void hashKey(std::vector<uint8_t>& key) const override;

private:
absl::optional<std::string> override_server_name_;

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.

Make this const and put it in the constructor initializer list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in bdce6bb.

};

} // namespace Network
} // namespace Envoy
14 changes: 9 additions & 5 deletions source/common/ssl/context_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ std::vector<uint8_t> ContextImpl::parseAlpnProtocols(const std::string& alpn_pro
return out;
}

bssl::UniquePtr<SSL> ContextImpl::newSsl() const {
bssl::UniquePtr<SSL> ContextImpl::newSsl(const absl::optional<std::string>&) const {
return bssl::UniquePtr<SSL>(SSL_new(ctx_.get()));
}

Expand Down Expand Up @@ -498,11 +498,15 @@ ClientContextImpl::ClientContextImpl(Stats::Scope& scope, const ClientContextCon
}
}

bssl::UniquePtr<SSL> ClientContextImpl::newSsl() const {
bssl::UniquePtr<SSL> ssl_con(ContextImpl::newSsl());
bssl::UniquePtr<SSL>
ClientContextImpl::newSsl(const absl::optional<std::string>& override_server_name) const {
bssl::UniquePtr<SSL> ssl_con(ContextImpl::newSsl(absl::nullopt));

if (!server_name_indication_.empty()) {
int rc = SSL_set_tlsext_host_name(ssl_con.get(), server_name_indication_.c_str());
std::string server_name_indication =
override_server_name.has_value() ? override_server_name.value() : server_name_indication_;

if (!server_name_indication.empty()) {
int rc = SSL_set_tlsext_host_name(ssl_con.get(), server_name_indication.c_str());
RELEASE_ASSERT(rc, "");
}

Expand Down
7 changes: 5 additions & 2 deletions source/common/ssl/context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "common/ssl/context_manager_impl.h"

#include "absl/types/optional.h"
#include "openssl/ssl.h"

namespace Envoy {
Expand Down Expand Up @@ -41,7 +42,8 @@ struct SslStats {

class ContextImpl : public virtual Context {
public:
virtual bssl::UniquePtr<SSL> newSsl() const;
virtual bssl::UniquePtr<SSL>
newSsl(const absl::optional<std::string>& override_server_name) const;

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.

Nit: making this argument an absl::optional<absl::string_view> (without reference) might be strictly more flexible.

@vadimeisenbergibm vadimeisenbergibm Nov 21, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 505cce2


/**
* Logs successful TLS handshake and updates stats.
Expand Down Expand Up @@ -142,7 +144,8 @@ class ClientContextImpl : public ContextImpl, public ClientContext {
ClientContextImpl(Stats::Scope& scope, const ClientContextConfig& config,
TimeSource& time_source);

bssl::UniquePtr<SSL> newSsl() const override;
bssl::UniquePtr<SSL>
newSsl(const absl::optional<std::string>& override_server_name) const override;

private:
const std::string server_name_indication_;
Expand Down
19 changes: 13 additions & 6 deletions source/common/ssl/ssl_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ class NotReadySslSocket : public Network::TransportSocket {
};
} // namespace

SslSocket::SslSocket(ContextSharedPtr ctx, InitialState state)
: ctx_(std::dynamic_pointer_cast<ContextImpl>(ctx)), ssl_(ctx_->newSsl()) {
SslSocket::SslSocket(ContextSharedPtr ctx, InitialState state,
Network::TransportSocketOptionsSharedPtr transport_socket_options)
: ctx_(std::dynamic_pointer_cast<ContextImpl>(ctx)),
ssl_(ctx_->newSsl(transport_socket_options != nullptr
? transport_socket_options->overrideServerName()
: absl::nullopt)) {
if (state == InitialState::Client) {
SSL_set_connect_state(ssl_.get());
} else {
Expand Down Expand Up @@ -370,7 +374,8 @@ ClientSslSocketFactory::ClientSslSocketFactory(ClientContextConfigPtr config,
config_->setSecretUpdateCallback([this]() { onAddOrUpdateSecret(); });
}

Network::TransportSocketPtr ClientSslSocketFactory::createTransportSocket() const {
Network::TransportSocketPtr ClientSslSocketFactory::createTransportSocket(
Network::TransportSocketOptionsSharedPtr transport_socket_options) const {
// onAddOrUpdateSecret() could be invoked in the middle of checking the existence of ssl_ctx and
// creating SslSocket using ssl_ctx. Capture ssl_ctx_ into a local variable so that we check and
// use the same ssl_ctx to create SslSocket.
Expand All @@ -380,7 +385,8 @@ Network::TransportSocketPtr ClientSslSocketFactory::createTransportSocket() cons
ssl_ctx = ssl_ctx_;
}
if (ssl_ctx) {
return std::make_unique<Ssl::SslSocket>(std::move(ssl_ctx), Ssl::InitialState::Client);
return std::make_unique<Ssl::SslSocket>(std::move(ssl_ctx), Ssl::InitialState::Client,
transport_socket_options);
} else {
ENVOY_LOG(debug, "Create NotReadySslSocket");
stats_.upstream_context_secrets_not_ready_.inc();
Expand Down Expand Up @@ -409,7 +415,8 @@ ServerSslSocketFactory::ServerSslSocketFactory(ServerContextConfigPtr config,
config_->setSecretUpdateCallback([this]() { onAddOrUpdateSecret(); });
}

Network::TransportSocketPtr ServerSslSocketFactory::createTransportSocket() const {
Network::TransportSocketPtr
ServerSslSocketFactory::createTransportSocket(Network::TransportSocketOptionsSharedPtr) const {
// onAddOrUpdateSecret() could be invoked in the middle of checking the existence of ssl_ctx and
// creating SslSocket using ssl_ctx. Capture ssl_ctx_ into a local variable so that we check and
// use the same ssl_ctx to create SslSocket.
Expand All @@ -419,7 +426,7 @@ Network::TransportSocketPtr ServerSslSocketFactory::createTransportSocket() cons
ssl_ctx = ssl_ctx_;
}
if (ssl_ctx) {
return std::make_unique<Ssl::SslSocket>(std::move(ssl_ctx), Ssl::InitialState::Server);
return std::make_unique<Ssl::SslSocket>(std::move(ssl_ctx), Ssl::InitialState::Server, nullptr);
} else {
ENVOY_LOG(debug, "Create NotReadySslSocket");
stats_.downstream_context_secrets_not_ready_.inc();
Expand Down
9 changes: 6 additions & 3 deletions source/common/ssl/ssl_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class SslSocket : public Network::TransportSocket,
public Connection,
protected Logger::Loggable<Logger::Id::connection> {
public:
SslSocket(ContextSharedPtr ctx, InitialState state);
SslSocket(ContextSharedPtr ctx, InitialState state,
Network::TransportSocketOptionsSharedPtr transport_socket_options);

// Ssl::Connection
bool peerCertificatePresented() const override;
Expand Down Expand Up @@ -87,7 +88,8 @@ class ClientSslSocketFactory : public Network::TransportSocketFactory,
ClientSslSocketFactory(ClientContextConfigPtr config, Ssl::ContextManager& manager,
Stats::Scope& stats_scope);

Network::TransportSocketPtr createTransportSocket() const override;
Network::TransportSocketPtr
createTransportSocket(Network::TransportSocketOptionsSharedPtr options) const override;
bool implementsSecureTransport() const override;

// Secret::SecretCallbacks
Expand All @@ -109,7 +111,8 @@ class ServerSslSocketFactory : public Network::TransportSocketFactory,
ServerSslSocketFactory(ServerContextConfigPtr config, Ssl::ContextManager& manager,
Stats::Scope& stats_scope, const std::vector<std::string>& server_names);

Network::TransportSocketPtr createTransportSocket() const override;
Network::TransportSocketPtr
createTransportSocket(Network::TransportSocketOptionsSharedPtr options) const override;
bool implementsSecureTransport() const override;

// Secret::SecretCallbacks
Expand Down
9 changes: 9 additions & 0 deletions source/common/stream_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "forward_requested_server_name_lib",
srcs = ["forward_requested_server_name.cc"],
hdrs = ["forward_requested_server_name.h"],
deps = [
"//include/envoy/stream_info:filter_state_interface",
],
)

envoy_cc_library(
name = "utility_lib",
srcs = ["utility.cc"],
Expand Down
10 changes: 10 additions & 0 deletions source/common/stream_info/forward_requested_server_name.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "common/stream_info/forward_requested_server_name.h"

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.

(cont from #4334 (comment))

I don't think this should be here and named like this. Name it "upstream_server_name" or "upstream_transport_socket_options" (if you put the class here).

The filter is not related directly to the TCP proxy. The filter specifies the intention that the SNI must be forwarded. Other filters, such as TCP proxy, can extract that information and forward the SNI.

The consumer of this is tcp_proxy, or you should make this into network namespace, as stream_info is for both L4/L7, while this is specific to transport socket / connection.

So there are three different names here:

  1. Forward Requested Server Name in the Stream Info, means that there is some requested server name, not necessarrily SNI, maybe requested server name from some other protocol, that must be forwarded to the upstream, not necessarily by tcp_proxy.

"forward" (i.e. propagating downstream server name to upstream) is decided by the filter setting this, this filter state doesn't imply that. Another filter can set this to arbitrary value.

The filter is not related directly to the TCP proxy. The filter specifies the intention that the SNI must be forwarded. Other filters, such as TCP proxy, can extract that information and forward the SNI.

  1. Override Server Name in tcp_proxy, cluster manager etc. it means that the server name of the upstream cluster must be overridden by that value. It does not specify that it is SNI and does not specify where this server name comes from.

Yes, this is right, now it is a struct named TransportSocketOptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@lizan So, making that struct into the network namespace, and calling it upstream_server_name will be OK?

Should I make this upstream_transport_socket_options to hold TransportSocketOptions? My intention was to decouple Filter state objects from TransportSocketOptions. We can have different Filter State objects holding basic types as strings and different filters like tcp_proxy can compose TransportSocketOptions differently, according to their logic.

I am OK with both solutions.

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.

Yeah I think upstream_server_name should be OK, then we can keep every filter state small.


namespace Envoy {
namespace StreamInfo {

const std::string ForwardRequestedServerName::Key =
"envoy.stream_info.forward_requested_server_name";

} // namespace StreamInfo
} // namespace Envoy
24 changes: 24 additions & 0 deletions source/common/stream_info/forward_requested_server_name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "envoy/stream_info/filter_state.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace StreamInfo {

/**
* Original Requested Server Name
*/
class ForwardRequestedServerName : public FilterState::Object {
public:
ForwardRequestedServerName(absl::string_view server_name) : server_name_(server_name) {}
const std::string& value() const { return server_name_; }
static const std::string Key;

private:
const std::string server_name_;
};

} // namespace StreamInfo
} // namespace Envoy
8 changes: 5 additions & 3 deletions source/common/tcp/conn_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ namespace Tcp {

ConnPoolImpl::ConnPoolImpl(Event::Dispatcher& dispatcher, Upstream::HostConstSharedPtr host,
Upstream::ResourcePriority priority,
const Network::ConnectionSocket::OptionsSharedPtr& options)
const Network::ConnectionSocket::OptionsSharedPtr& options,
Network::TransportSocketOptionsSharedPtr transport_socket_options)
: dispatcher_(dispatcher), host_(host), priority_(priority), socket_options_(options),
transport_socket_options_(transport_socket_options),
upstream_ready_timer_(dispatcher_.createTimer([this]() { onUpstreamReady(); })) {}

ConnPoolImpl::~ConnPoolImpl() {
Expand Down Expand Up @@ -356,8 +358,8 @@ ConnPoolImpl::ActiveConn::ActiveConn(ConnPoolImpl& parent)
parent_.conn_connect_ms_ = std::make_unique<Stats::Timespan>(
parent_.host_->cluster().stats().upstream_cx_connect_ms_, parent_.dispatcher_.timeSystem());

Upstream::Host::CreateConnectionData data =
parent_.host_->createConnection(parent_.dispatcher_, parent_.socket_options_);
Upstream::Host::CreateConnectionData data = parent_.host_->createConnection(
parent_.dispatcher_, parent_.socket_options_, parent_.transport_socket_options_);
real_host_description_ = data.host_description_;

conn_ = std::move(data.connection_);
Expand Down
Loading