-
Notifications
You must be signed in to change notification settings - Fork 5.3k
transport sockets: expose proxy protocol socket #12762
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
Changes from all commits
fc67cf5
2323504
f813691
0ee7c45
71ba92d
1291529
6c91f31
4825f05
473cbbe
00775ba
bf270c5
07a1022
7ebf550
bd93847
f89950a
1df7242
1fd4212
e658e90
a655265
ffbfef5
12ec394
0b73ee1
3542aaa
df53fe7
defb718
55d11b3
4d9f748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| #include "common/common/utility.h" | ||
| #include "common/config/well_known_names.h" | ||
| #include "common/network/application_protocol.h" | ||
| #include "common/network/proxy_protocol_filter_state.h" | ||
| #include "common/network/transport_socket_options_impl.h" | ||
| #include "common/network/upstream_server_name.h" | ||
| #include "common/router/metadatamatchcriteria_impl.h" | ||
|
|
@@ -414,6 +415,18 @@ Network::FilterStatus Filter::initializeUpstreamConnection() { | |
| } | ||
|
|
||
| if (downstreamConnection()) { | ||
| if (!read_callbacks_->connection() | ||
| .streamInfo() | ||
| .filterState() | ||
| ->hasData<Network::ProxyProtocolFilterState>( | ||
| Network::ProxyProtocolFilterState::key())) { | ||
| read_callbacks_->connection().streamInfo().filterState()->setData( | ||
| Network::ProxyProtocolFilterState::key(), | ||
| std::make_unique<Network::ProxyProtocolFilterState>(Network::ProxyProtocolData{ | ||
| downstreamConnection()->remoteAddress(), downstreamConnection()->localAddress()}), | ||
| StreamInfo::FilterState::StateType::ReadOnly, | ||
| StreamInfo::FilterState::LifeSpan::Connection); | ||
| } | ||
|
Comment on lines
+418
to
+429
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. It seems odd to me that we jam this data into filter state only to read it back in the next function call. What is the use case for nested states here? Could we just pass the addresses directly into the
Contributor
Author
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. It was like this at one point and changed from feedback #11584 (comment). I'm fine either way
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. If this has already been discussed it's fine with me. We can revisit later if needed. |
||
| transport_socket_options_ = Network::TransportSocketOptionsUtility::fromFilterState( | ||
| downstreamConnection()->streamInfo().filterState()); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #include "extensions/transport_sockets/proxy_protocol/config.h" | ||
|
|
||
| #include "envoy/extensions/transport_sockets/proxy_protocol/v3/upstream_proxy_protocol.pb.h" | ||
| #include "envoy/extensions/transport_sockets/proxy_protocol/v3/upstream_proxy_protocol.pb.validate.h" | ||
| #include "envoy/registry/registry.h" | ||
|
|
||
| #include "common/config/utility.h" | ||
|
|
||
| #include "extensions/transport_sockets/proxy_protocol/proxy_protocol.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace TransportSockets { | ||
| namespace ProxyProtocol { | ||
|
|
||
| Network::TransportSocketFactoryPtr | ||
| UpstreamProxyProtocolSocketConfigFactory::createTransportSocketFactory( | ||
| const Protobuf::Message& message, | ||
| Server::Configuration::TransportSocketFactoryContext& context) { | ||
| const auto& outer_config = | ||
| MessageUtil::downcastAndValidate<const envoy::extensions::transport_sockets::proxy_protocol:: | ||
| v3::ProxyProtocolUpstreamTransport&>( | ||
| message, context.messageValidationVisitor()); | ||
| auto& inner_config_factory = Config::Utility::getAndCheckFactory< | ||
| Server::Configuration::UpstreamTransportSocketConfigFactory>(outer_config.transport_socket()); | ||
| ProtobufTypes::MessagePtr inner_factory_config = Config::Utility::translateToFactoryConfig( | ||
| outer_config.transport_socket(), context.messageValidationVisitor(), inner_config_factory); | ||
| auto inner_transport_factory = | ||
| inner_config_factory.createTransportSocketFactory(*inner_factory_config, context); | ||
alyssawilk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return std::make_unique<UpstreamProxyProtocolSocketFactory>(std::move(inner_transport_factory), | ||
| outer_config.config()); | ||
| } | ||
|
|
||
| ProtobufTypes::MessagePtr UpstreamProxyProtocolSocketConfigFactory::createEmptyConfigProto() { | ||
| return std::make_unique< | ||
| envoy::extensions::transport_sockets::proxy_protocol::v3::ProxyProtocolUpstreamTransport>(); | ||
| ; | ||
| } | ||
|
|
||
| REGISTER_FACTORY(UpstreamProxyProtocolSocketConfigFactory, | ||
| Server::Configuration::UpstreamTransportSocketConfigFactory); | ||
|
|
||
| } // namespace ProxyProtocol | ||
| } // namespace TransportSockets | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/server/transport_socket_config.h" | ||
|
|
||
| #include "extensions/transport_sockets/well_known_names.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace TransportSockets { | ||
| namespace ProxyProtocol { | ||
|
|
||
| /** | ||
| * Config registration for the proxy protocol wrapper for transport socket factory. | ||
| * @see TransportSocketConfigFactory. | ||
| */ | ||
| class UpstreamProxyProtocolSocketConfigFactory | ||
| : public Server::Configuration::UpstreamTransportSocketConfigFactory { | ||
| public: | ||
| std::string name() const override { return TransportSocketNames::get().UpstreamProxyProtocol; } | ||
| ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
| Network::TransportSocketFactoryPtr createTransportSocketFactory( | ||
| const Protobuf::Message& config, | ||
| Server::Configuration::TransportSocketFactoryContext& context) override; | ||
| }; | ||
|
|
||
| } // namespace ProxyProtocol | ||
| } // namespace TransportSockets | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
Uh oh!
There was an error while loading. Please reload this page.