diff --git a/source/common/listener_manager/listener_impl.cc b/source/common/listener_manager/listener_impl.cc index ed1585afe452..2affcdc55301 100644 --- a/source/common/listener_manager/listener_impl.cc +++ b/source/common/listener_manager/listener_impl.cc @@ -636,7 +636,7 @@ ListenerImpl::buildUdpListenerFactory(const envoy::config::listener::v3::Listene } udp_listener_config_->listener_factory_ = std::make_unique( config.udp_listener_config().quic_options(), concurrency, quic_stat_names_, - validation_visitor_, listener_factory_context_->serverFactoryContext()); + validation_visitor_, *listener_factory_context_); #if UDP_GSO_BATCH_WRITER_COMPILETIME_SUPPORT // TODO(mattklein123): We should be able to use GSO without QUICHE/QUIC. Right now this causes // non-QUIC integration tests to fail, which I haven't investigated yet. Additionally, from diff --git a/source/common/quic/BUILD b/source/common/quic/BUILD index 2186c5f6004e..380d5d7e453d 100644 --- a/source/common/quic/BUILD +++ b/source/common/quic/BUILD @@ -65,7 +65,7 @@ envoy_cc_library( "//envoy/common:optref_lib", "//envoy/common:pure_lib", "//envoy/config:typed_config_interface", - "//envoy/server:process_context_interface", + "//envoy/server:factory_context_interface", "//envoy/stream_info:stream_info_interface", "@com_github_google_quiche//:quic_core_connection_lib", "@com_github_google_quiche//:quic_core_session_lib", diff --git a/source/common/quic/active_quic_listener.cc b/source/common/quic/active_quic_listener.cc index 691c4a9c29d3..ae480de8b86f 100644 --- a/source/common/quic/active_quic_listener.cc +++ b/source/common/quic/active_quic_listener.cc @@ -97,7 +97,7 @@ ActiveQuicListener::ActiveQuicListener( crypto_config_.get(), quic_config, &version_manager_, std::move(connection_helper), std::move(alarm_factory), quic::kQuicDefaultConnectionIdLength, parent, *config_, stats_, per_worker_stats_, dispatcher, listen_socket_, quic_stat_names, crypto_server_stream_factory_, - *connection_id_generator_, std::move(debug_visitor_factory)); + *connection_id_generator_, debug_visitor_factory); // Create udp_packet_writer Network::UdpPacketWriterPtr udp_packet_writer = @@ -261,7 +261,7 @@ void ActiveQuicListener::closeConnectionsWithFilterChain(const Network::FilterCh ActiveQuicListenerFactory::ActiveQuicListenerFactory( const envoy::config::listener::v3::QuicProtocolOptions& config, uint32_t concurrency, QuicStatNames& quic_stat_names, ProtobufMessage::ValidationVisitor& validation_visitor, - Server::Configuration::ServerFactoryContext& context) + Server::Configuration::ListenerFactoryContext& context) : concurrency_(concurrency), enabled_(config.enabled()), quic_stat_names_(quic_stat_names), packets_to_read_to_connection_count_ratio_( PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, packets_to_read_to_connection_count_ratio, @@ -313,12 +313,13 @@ ActiveQuicListenerFactory::ActiveQuicListenerFactory( // Initialize connection debug visitor factory if one is configured. if (config.has_connection_debug_visitor_config()) { - connection_debug_visitor_factory_ = - Config::Utility::getAndCheckFactory( + auto& factory = + Config::Utility::getAndCheckFactory( config.connection_debug_visitor_config()); - if (connection_debug_visitor_factory_.has_value()) { - connection_debug_visitor_factory_->setContext(context_.processContext()); - } + ProtobufTypes::MessagePtr message = Config::Utility::translateAnyToFactoryConfig( + config.connection_debug_visitor_config().typed_config(), + context_.messageValidationVisitor(), factory); + connection_debug_visitor_factory_ = factory.createFactory(*message, context_); } // Initialize connection ID generator factory. @@ -349,7 +350,7 @@ ActiveQuicListenerFactory::ActiveQuicListenerFactory( *Config::Utility::translateToFactoryConfig(config.server_preferred_address_config(), validation_visitor, server_preferred_address_config_factory), - validation_visitor, context_); + validation_visitor, context_.serverFactoryContext()); } worker_selector_ = @@ -437,7 +438,7 @@ ActiveQuicListenerFactory::createActiveQuicListener( listener_config, quic_config, kernel_worker_routing, enabled, quic_stat_names, packets_to_read_to_connection_count_ratio, receive_ecn_, crypto_server_stream_factory, proof_source_factory, std::move(cid_generator), worker_selector_, - connection_debug_visitor_factory_, reject_new_connections_); + makeOptRefFromPtr(connection_debug_visitor_factory_.get()), reject_new_connections_); } } // namespace Quic diff --git a/source/common/quic/active_quic_listener.h b/source/common/quic/active_quic_listener.h index 0ec62ac7df3e..ddc6f107ff1c 100644 --- a/source/common/quic/active_quic_listener.h +++ b/source/common/quic/active_quic_listener.h @@ -113,7 +113,7 @@ class ActiveQuicListenerFactory : public Network::ActiveUdpListenerFactory, ActiveQuicListenerFactory(const envoy::config::listener::v3::QuicProtocolOptions& config, uint32_t concurrency, QuicStatNames& quic_stat_names, ProtobufMessage::ValidationVisitor& validation_visitor, - Server::Configuration::ServerFactoryContext& context); + Server::Configuration::ListenerFactoryContext& context); // Network::ActiveUdpListenerFactory. Network::ConnectionHandler::ActiveUdpListenerPtr @@ -147,7 +147,7 @@ class ActiveQuicListenerFactory : public Network::ActiveUdpListenerFactory, crypto_server_stream_factory_; absl::optional> proof_source_factory_; - EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef connection_debug_visitor_factory_; + EnvoyQuicConnectionDebugVisitorFactoryInterfacePtr connection_debug_visitor_factory_; EnvoyQuicConnectionIdGeneratorFactoryPtr quic_cid_generator_factory_; EnvoyQuicServerPreferredAddressConfigPtr server_preferred_address_config_; quic::QuicConfig quic_config_; @@ -159,7 +159,7 @@ class ActiveQuicListenerFactory : public Network::ActiveUdpListenerFactory, const Network::Socket::OptionsSharedPtr options_{std::make_shared()}; QuicConnectionIdWorkerSelector worker_selector_; bool kernel_worker_routing_{}; - Server::Configuration::ServerFactoryContext& context_; + Server::Configuration::ListenerFactoryContext& context_; bool reject_new_connections_{}; static bool disable_kernel_bpf_packet_routing_for_test_; diff --git a/source/common/quic/envoy_quic_connection_debug_visitor_factory_interface.h b/source/common/quic/envoy_quic_connection_debug_visitor_factory_interface.h index 53d32c44bf15..3406491d9dc2 100644 --- a/source/common/quic/envoy_quic_connection_debug_visitor_factory_interface.h +++ b/source/common/quic/envoy_quic_connection_debug_visitor_factory_interface.h @@ -3,10 +3,9 @@ #include #include -#include "envoy/common/optref.h" #include "envoy/common/pure.h" #include "envoy/config/typed_config.h" -#include "envoy/server/process_context.h" +#include "envoy/server/factory_context.h" #include "envoy/stream_info/stream_info.h" #include "quiche/quic/core/quic_connection.h" @@ -15,23 +14,29 @@ namespace Envoy { namespace Quic { -class EnvoyQuicConnectionDebugVisitorFactoryInterface : public Config::TypedFactory { +class EnvoyQuicConnectionDebugVisitorFactoryInterface { public: - std::string category() const override { return "envoy.quic.connection_debug_visitor"; } - - void setContext(Envoy::ProcessContextOptRef context) { context_ = context; } + virtual ~EnvoyQuicConnectionDebugVisitorFactoryInterface() = default; // Returns a debug visitor to be attached to a Quic Connection. virtual std::unique_ptr - createQuicConnectionDebugVisitor(quic::QuicSession* session, + createQuicConnectionDebugVisitor(Event::Dispatcher& dispatcher, quic::QuicSession* session, const StreamInfo::StreamInfo& stream_info) PURE; - -protected: - Envoy::ProcessContextOptRef context_; }; +using EnvoyQuicConnectionDebugVisitorFactoryInterfacePtr = + std::unique_ptr; using EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef = OptRef; +class EnvoyQuicConnectionDebugVisitorFactoryFactoryInterface : public Config::TypedFactory { +public: + std::string category() const override { return "envoy.quic.connection_debug_visitor"; } + + virtual EnvoyQuicConnectionDebugVisitorFactoryInterfacePtr + createFactory(const Protobuf::Message& config, + Server::Configuration::ListenerFactoryContext& listener_context) PURE; +}; + } // namespace Quic } // namespace Envoy diff --git a/source/common/quic/envoy_quic_dispatcher.cc b/source/common/quic/envoy_quic_dispatcher.cc index b7b5ac42ebde..80b85f384d75 100644 --- a/source/common/quic/envoy_quic_dispatcher.cc +++ b/source/common/quic/envoy_quic_dispatcher.cc @@ -53,7 +53,7 @@ EnvoyQuicDispatcher::EnvoyQuicDispatcher( Network::Socket& listen_socket, QuicStatNames& quic_stat_names, EnvoyQuicCryptoServerStreamFactoryInterface& crypto_server_stream_factory, quic::ConnectionIdGeneratorInterface& generator, - EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef&& debug_visitor_factory) + EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef debug_visitor_factory) : quic::QuicDispatcher(&quic_config, crypto_config, version_manager, std::move(helper), std::make_unique(), std::move(alarm_factory), expected_server_connection_id_length, @@ -65,7 +65,7 @@ EnvoyQuicDispatcher::EnvoyQuicDispatcher( quic_stats_(generateStats(listener_config.listenerScope())), connection_stats_({QUIC_CONNECTION_STATS( POOL_COUNTER_PREFIX(listener_config.listenerScope(), "quic.connection"))}), - debug_visitor_factory_(std::move(debug_visitor_factory)) {} + debug_visitor_factory_(debug_visitor_factory) {} void EnvoyQuicDispatcher::OnConnectionClosed(quic::QuicConnectionId connection_id, quic::QuicErrorCode error, diff --git a/source/common/quic/envoy_quic_dispatcher.h b/source/common/quic/envoy_quic_dispatcher.h index 1ee5c8349b6c..7ff14b35569e 100644 --- a/source/common/quic/envoy_quic_dispatcher.h +++ b/source/common/quic/envoy_quic_dispatcher.h @@ -65,7 +65,7 @@ class EnvoyQuicDispatcher : public quic::QuicDispatcher { Network::Socket& listen_socket, QuicStatNames& quic_stat_names, EnvoyQuicCryptoServerStreamFactoryInterface& crypto_server_stream_factory, quic::ConnectionIdGeneratorInterface& generator, - EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef&& debug_visitor_factory); + EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef debug_visitor_factory); // quic::QuicDispatcher void OnConnectionClosed(quic::QuicConnectionId connection_id, quic::QuicErrorCode error, diff --git a/source/common/quic/envoy_quic_server_session.cc b/source/common/quic/envoy_quic_server_session.cc index 6ff59b7c4825..937c8eb615ff 100644 --- a/source/common/quic/envoy_quic_server_session.cc +++ b/source/common/quic/envoy_quic_server_session.cc @@ -55,7 +55,8 @@ EnvoyQuicServerSession::EnvoyQuicServerSession( #endif // If a factory is available, create a debug visitor and attach it to the connection. if (debug_visitor_factory.has_value()) { - debug_visitor_ = debug_visitor_factory->createQuicConnectionDebugVisitor(this, streamInfo()); + debug_visitor_ = + debug_visitor_factory->createQuicConnectionDebugVisitor(dispatcher, this, streamInfo()); quic_connection_->set_debug_visitor(debug_visitor_.get()); } quic_connection_->set_context_listener( diff --git a/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.cc b/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.cc index 99d7a35ad755..e46f361e57a3 100644 --- a/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.cc +++ b/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.cc @@ -23,12 +23,12 @@ void EnvoyQuicConnectionDebugVisitorBasic::OnConnectionClosed( std::unique_ptr EnvoyQuicConnectionDebugVisitorFactoryBasic::createQuicConnectionDebugVisitor( - quic::QuicSession* session, const StreamInfo::StreamInfo& stream_info) { + Event::Dispatcher&, quic::QuicSession* session, const StreamInfo::StreamInfo& stream_info) { return std::make_unique(session, stream_info); } -REGISTER_FACTORY(EnvoyQuicConnectionDebugVisitorFactoryBasic, - EnvoyQuicConnectionDebugVisitorFactoryInterface); +REGISTER_FACTORY(EnvoyQuicConnectionDebugVisitorFactoryFactoryBasic, + EnvoyQuicConnectionDebugVisitorFactoryFactoryInterface); } // namespace Quic } // namespace Envoy diff --git a/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.h b/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.h index 79fed4e16972..0b4a25c0e8ed 100644 --- a/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.h +++ b/source/extensions/quic/connection_debug_visitor/basic/envoy_quic_connection_debug_visitor_basic.h @@ -41,6 +41,13 @@ class EnvoyQuicConnectionDebugVisitorBasic : public quic::QuicConnectionDebugVis class EnvoyQuicConnectionDebugVisitorFactoryBasic : public EnvoyQuicConnectionDebugVisitorFactoryInterface { + std::unique_ptr + createQuicConnectionDebugVisitor(Event::Dispatcher&, quic::QuicSession* session, + const StreamInfo::StreamInfo& stream_info) override; +}; + +class EnvoyQuicConnectionDebugVisitorFactoryFactoryBasic + : public EnvoyQuicConnectionDebugVisitorFactoryFactoryInterface { public: std::string name() const override { return "envoy.quic.connection_debug_visitor.basic"; } @@ -48,9 +55,10 @@ class EnvoyQuicConnectionDebugVisitorFactoryBasic return std::make_unique(); } - std::unique_ptr - createQuicConnectionDebugVisitor(quic::QuicSession* session, - const StreamInfo::StreamInfo& stream_info) override; + EnvoyQuicConnectionDebugVisitorFactoryInterfacePtr + createFactory(const Protobuf::Message&, Server::Configuration::ListenerFactoryContext&) override { + return std::make_unique(); + } }; DECLARE_FACTORY(EnvoyQuicConnectionDebugVisitorFactoryBasic); diff --git a/test/common/quic/BUILD b/test/common/quic/BUILD index ea52a3d483df..1688bafaf50b 100644 --- a/test/common/quic/BUILD +++ b/test/common/quic/BUILD @@ -244,6 +244,7 @@ envoy_cc_test( "//source/server:process_context_lib", "//test/mocks/network:network_mocks", "//test/mocks/server:instance_mocks", + "//test/mocks/server:listener_factory_context_mocks", "//test/test_common:network_utility_lib", "//test/test_common:simulated_time_system_lib", "//test/test_common:test_runtime_lib", diff --git a/test/common/quic/active_quic_listener_test.cc b/test/common/quic/active_quic_listener_test.cc index 7720f70b269d..c27fe9f013d2 100644 --- a/test/common/quic/active_quic_listener_test.cc +++ b/test/common/quic/active_quic_listener_test.cc @@ -25,7 +25,7 @@ #include "test/mocks/network/mocks.h" #include "test/mocks/runtime/mocks.h" #include "test/mocks/server/instance.h" -#include "test/mocks/server/server_factory_context.h" +#include "test/mocks/server/listener_factory_context.h" #include "test/mocks/ssl/mocks.h" #include "test/test_common/environment.h" #include "test/test_common/network_utility.h" @@ -118,7 +118,7 @@ class ActiveQuicListenerFactoryPeer { } static EnvoyQuicConnectionDebugVisitorFactoryInterfaceOptRef debugVisitorFactory(ActiveQuicListenerFactory* factory) { - return factory->connection_debug_visitor_factory_; + return makeOptRefFromPtr(factory->connection_debug_visitor_factory_.get()); } }; @@ -365,7 +365,7 @@ class ActiveQuicListenerTest : public testing::TestWithParam context_; + testing::NiceMock context_; TestScopedRuntime scoped_runtime_; Network::Address::IpVersion version_; Event::SimulatedTimeSystemHelper simulated_time_system_; @@ -727,13 +727,13 @@ class ActiveQuicListenerFactoryTest : public testing::Test { std::unique_ptr createQuicListenerFactory(envoy::config::listener::v3::QuicProtocolOptions options) { return std::make_unique(options, /*concurrency=*/1, quic_stat_names_, - validation_visitor_, server_context_); + validation_visitor_, listener_context_); } Stats::SymbolTable symbol_table_; QuicStatNames quic_stat_names_ = QuicStatNames(symbol_table_); NiceMock validation_visitor_; - testing::NiceMock server_context_; + testing::NiceMock listener_context_; }; TEST_F(ActiveQuicListenerFactoryTest, NoDebugVisitorConfigured) { @@ -743,10 +743,6 @@ TEST_F(ActiveQuicListenerFactoryTest, NoDebugVisitorConfigured) { } TEST_F(ActiveQuicListenerFactoryTest, DebugVisitorConfigured) { - TestProcessObject test_process_object; - ProcessContextImpl context(test_process_object); - EXPECT_CALL(server_context_, processContext()) - .WillRepeatedly(Return(ProcessContextOptRef(context))); envoy::config::listener::v3::QuicProtocolOptions quic_config; quic_config.mutable_connection_debug_visitor_config()->set_name( "envoy.quic.connection_debug_visitor.mock"); @@ -756,10 +752,6 @@ TEST_F(ActiveQuicListenerFactoryTest, DebugVisitorConfigured) { auto debug_visitor_factory = ActiveQuicListenerFactoryPeer::debugVisitorFactory(listener_factory.get()); EXPECT_TRUE(debug_visitor_factory.has_value()); - auto test_debug_visitor_factory = - dynamic_cast(debug_visitor_factory.ptr()); - EXPECT_TRUE(test_debug_visitor_factory->processContext().has_value()); - EXPECT_EQ(&test_debug_visitor_factory->processContext().value().get(), &context); } } // namespace Quic diff --git a/test/common/quic/test_utils.h b/test/common/quic/test_utils.h index 058f9d6d5c96..b635bba63c9e 100644 --- a/test/common/quic/test_utils.h +++ b/test/common/quic/test_utils.h @@ -345,28 +345,36 @@ class MockQuicConnectionDebugVisitor : public quic::QuicConnectionDebugVisitor { class TestEnvoyQuicConnectionDebugVisitorFactory : public EnvoyQuicConnectionDebugVisitorFactoryInterface { public: - std::string name() const override { return "envoy.quic.connection_debug_visitor.mock"; } - - Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override { - return std::make_unique<::test::common::config::DummyConfig>(); - } std::unique_ptr - createQuicConnectionDebugVisitor(quic::QuicSession* session, + createQuicConnectionDebugVisitor(Event::Dispatcher&, quic::QuicSession* session, const StreamInfo::StreamInfo& stream_info) override { auto debug_visitor = std::make_unique(session, stream_info); mock_debug_visitor_ = debug_visitor.get(); return debug_visitor; } - Envoy::ProcessContextOptRef processContext() const { return context_; } - MockQuicConnectionDebugVisitor* mock_debug_visitor_; }; -DECLARE_FACTORY(TestEnvoyQuicConnectionDebugVisitorFactory); +class TestEnvoyQuicConnectionDebugVisitorFactoryFactory + : public EnvoyQuicConnectionDebugVisitorFactoryFactoryInterface { +public: + std::string name() const override { return "envoy.quic.connection_debug_visitor.mock"; } + + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override { + return std::make_unique<::test::common::config::DummyConfig>(); + } + + EnvoyQuicConnectionDebugVisitorFactoryInterfacePtr + createFactory(const Protobuf::Message&, Server::Configuration::ListenerFactoryContext&) override { + return std::make_unique(); + } +}; + +DECLARE_FACTORY(TestEnvoyQuicConnectionDebugVisitorFactoryFactory); -REGISTER_FACTORY(TestEnvoyQuicConnectionDebugVisitorFactory, - Envoy::Quic::EnvoyQuicConnectionDebugVisitorFactoryInterface); +REGISTER_FACTORY(TestEnvoyQuicConnectionDebugVisitorFactoryFactory, + Envoy::Quic::EnvoyQuicConnectionDebugVisitorFactoryFactoryInterface); class TestNetworkObserverRegistry : public Quic::EnvoyQuicNetworkObserverRegistry { public: diff --git a/test/integration/BUILD b/test/integration/BUILD index 5ebea41e18cb..360044dfc248 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -1143,6 +1143,7 @@ envoy_cc_test_library( "//test/mocks/http:header_validator_mocks", "//test/mocks/protobuf:protobuf_mocks", "//test/mocks/runtime:runtime_mocks", + "//test/mocks/server:listener_factory_context_mocks", "//test/mocks/server:overload_manager_mocks", "//test/test_common:network_utility_lib", "//test/test_common:test_time_system_interface", diff --git a/test/integration/fake_upstream.h b/test/integration/fake_upstream.h index b8600382cb61..bef6733dc7c0 100644 --- a/test/integration/fake_upstream.h +++ b/test/integration/fake_upstream.h @@ -39,6 +39,7 @@ #include "test/mocks/http/header_validator.h" #include "test/mocks/protobuf/mocks.h" #include "test/mocks/server/instance.h" +#include "test/mocks/server/listener_factory_context.h" #if defined(ENVOY_ENABLE_QUIC) #include "source/common/quic/active_quic_listener.h" @@ -866,7 +867,7 @@ class FakeUpstream : Logger::Loggable, if (context_ == nullptr) { // Only initialize this when needed to avoid slowing down non-QUIC integration tests. context_ = std::make_unique< - testing::NiceMock>(); + testing::NiceMock>(); } udp_listener_config_.listener_factory_ = std::make_unique( parent_.quic_options_, 1, parent_.quic_stat_names_, parent_.validation_visitor_, @@ -931,7 +932,7 @@ class FakeUpstream : Logger::Loggable, const std::vector empty_access_logs_; std::unique_ptr init_manager_; const Network::ListenerInfoConstSharedPtr listener_info_; - std::unique_ptr context_; + std::unique_ptr context_; }; void threadRoutine();