#pragma once #include "envoy/network/proxy_protocol.h" #include "envoy/network/transport_socket.h" #include "envoy/stream_info/filter_state.h" namespace Envoy { namespace Network { // A wrapper around another TransportSocketOptions that overrides the ALPN fallback. class AlpnDecoratingTransportSocketOptions : public TransportSocketOptions { public: AlpnDecoratingTransportSocketOptions(std::vector&& alpn, TransportSocketOptionsSharedPtr inner_options) : alpn_fallback_(std::move(alpn)), inner_options_(std::move(inner_options)) {} // Network::TransportSocketOptions const absl::optional& serverNameOverride() const override { return inner_options_->serverNameOverride(); } const std::vector& verifySubjectAltNameListOverride() const override { return inner_options_->verifySubjectAltNameListOverride(); } const std::vector& applicationProtocolListOverride() const override { return inner_options_->applicationProtocolListOverride(); } const std::vector& applicationProtocolFallback() const override { return alpn_fallback_; } absl::optional proxyProtocolOptions() const override { return inner_options_->proxyProtocolOptions(); } void hashKey(std::vector& key, const Network::TransportSocketFactory& factory) const override; private: const std::vector alpn_fallback_; const TransportSocketOptionsSharedPtr inner_options_; }; class TransportSocketOptionsImpl : public TransportSocketOptions { public: TransportSocketOptionsImpl( absl::string_view override_server_name = "", std::vector&& override_verify_san_list = {}, std::vector&& override_alpn = {}, std::vector&& fallback_alpn = {}, absl::optional proxy_proto_options = absl::nullopt) : override_server_name_(override_server_name.empty() ? absl::nullopt : absl::optional(override_server_name)), override_verify_san_list_{std::move(override_verify_san_list)}, override_alpn_list_{std::move(override_alpn)}, alpn_fallback_{std::move(fallback_alpn)}, proxy_protocol_options_(proxy_proto_options) {} // Network::TransportSocketOptions const absl::optional& serverNameOverride() const override { return override_server_name_; } const std::vector& verifySubjectAltNameListOverride() const override { return override_verify_san_list_; } const std::vector& applicationProtocolListOverride() const override { return override_alpn_list_; } const std::vector& applicationProtocolFallback() const override { return alpn_fallback_; } absl::optional proxyProtocolOptions() const override { return proxy_protocol_options_; } void hashKey(std::vector& key, const Network::TransportSocketFactory& factory) const override; private: const absl::optional override_server_name_; const std::vector override_verify_san_list_; const std::vector override_alpn_list_; const std::vector alpn_fallback_; const absl::optional proxy_protocol_options_; }; class TransportSocketOptionsUtility { public: /** * Construct TransportSocketOptions from StreamInfo::FilterState, using UpstreamServerName * and ApplicationProtocols key in the filter state. * @returns TransportSocketOptionsSharedPtr a shared pointer to the transport socket options, * nullptr if nothing is in the filter state. */ static TransportSocketOptionsSharedPtr fromFilterState(const StreamInfo::FilterState& stream_info); }; } // namespace Network } // namespace Envoy