Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion library/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ envoy_cc_library(
"//library/common/event:provisional_dispatcher_lib",
"//library/common/http:client_lib",
"//library/common/http:header_utility_lib",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/stats:utility_lib",
"//library/common/types:c_types_lib",
"@envoy//envoy/server:lifecycle_notifier_interface",
Expand Down
16 changes: 8 additions & 8 deletions library/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ envoy_status_t Engine::main(const std::string config, const std::string log_leve
Envoy::Server::ServerLifecycleNotifier::Stage::PostInit, [this]() -> void {
ASSERT(Thread::MainThread::isMainOrTestThread());

network_configurator_ =
Network::ConfiguratorFactory{server_->serverFactoryContext()}.get();
connectivity_manager_ =
Network::ConnectivityManagerFactory{server_->serverFactoryContext()}.get();
Envoy::Network::Android::Utility::setAlternateGetifaddrs();
auto v4_interfaces = network_configurator_->enumerateV4Interfaces();
auto v6_interfaces = network_configurator_->enumerateV6Interfaces();
auto v4_interfaces = connectivity_manager_->enumerateV4Interfaces();
auto v6_interfaces = connectivity_manager_->enumerateV6Interfaces();
logInterfaces("netconf_get_v4_interfaces", v4_interfaces);
logInterfaces("netconf_get_v6_interfaces", v6_interfaces);
client_scope_ = server_->serverFactoryContext().scope().createScope("pulse.");
Expand All @@ -140,7 +140,7 @@ envoy_status_t Engine::main(const std::string config, const std::string log_leve

// Ensure destructors run on Envoy's main thread.
postinit_callback_handler_.reset(nullptr);
network_configurator_.reset();
connectivity_manager_.reset();
client_scope_.reset();
stat_name_set_.reset();
log_delegate_ptr_.reset(nullptr);
Expand Down Expand Up @@ -295,10 +295,10 @@ Http::Client& Engine::httpClient() {
return *http_client_;
}

Network::Configurator& Engine::networkConfigurator() {
Network::ConnectivityManager& Engine::networkConnectivityManager() {
RELEASE_ASSERT(dispatcher_->isThreadSafe(),
"networkConfigurator must be accessed from dispatcher's context");
return *network_configurator_;
"networkConnectivityManager must be accessed from dispatcher's context");
return *connectivity_manager_;
}

void Engine::flushStats() {
Expand Down
8 changes: 4 additions & 4 deletions library/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "library/common/common/lambda_logger_delegate.h"
#include "library/common/engine_common.h"
#include "library/common/http/client.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"
#include "library/common/types/c_types.h"

namespace Envoy {
Expand Down Expand Up @@ -58,9 +58,9 @@ class Engine : public Logger::Loggable<Logger::Id::main> {

/**
* Accessor for the network configuraator. Must be called from the dispatcher's context.
* @return Network::Configurator&, the network configurator.
* @return Network::ConnectivityManager&, the network connectivity_manager.
*/
Network::Configurator& networkConfigurator();
Network::ConnectivityManager& networkConnectivityManager();

/**
* Increment a counter with a given string of elements and by the given count.
Expand Down Expand Up @@ -145,7 +145,7 @@ class Engine : public Logger::Loggable<Logger::Id::main> {
Thread::MutexBasicLockable mutex_;
Thread::CondVar cv_;
Http::ClientPtr http_client_;
Network::ConfiguratorSharedPtr network_configurator_;
Network::ConnectivityManagerSharedPtr connectivity_manager_;
Event::ProvisionalDispatcherPtr dispatcher_;
// Used by the cerr logger to ensure logs don't overwrite each other.
absl::Mutex log_mutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ envoy_cc_extension(
deps = [
":filter_cc_proto",
"//library/common/http:internal_headers_lib",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/stream_info:extra_stream_info_lib",
"//library/common/types:c_types_lib",
"@envoy//envoy/http:codes_interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Http::FilterFactoryCb NetworkConfigurationFilterFactory::createFilterFactoryFrom
proto_config,
const std::string&, Server::Configuration::FactoryContext& context) {

auto network_configurator = Network::ConfiguratorFactory{context}.get();
auto connectivity_manager = Network::ConnectivityManagerFactory{context}.get();
bool enable_drain_post_dns_refresh = proto_config.enable_drain_post_dns_refresh();
bool enable_interface_binding = proto_config.enable_interface_binding();

return [network_configurator, enable_drain_post_dns_refresh,
return [connectivity_manager, enable_drain_post_dns_refresh,
enable_interface_binding](Http::FilterChainFactoryCallbacks& callbacks) -> void {
callbacks.addStreamFilter(std::make_shared<NetworkConfigurationFilter>(
network_configurator, enable_drain_post_dns_refresh, enable_interface_binding));
connectivity_manager, enable_drain_post_dns_refresh, enable_interface_binding));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ void NetworkConfigurationFilter::setDecoderFilterCallbacks(
StreamInfo::FilterState::StateType::Mutable, StreamInfo::FilterState::LifeSpan::Request);

auto options = std::make_shared<Network::Socket::Options>();
network_configurator_->setInterfaceBindingEnabled(enable_interface_binding_);
network_configurator_->setDrainPostDnsRefreshEnabled(enable_drain_post_dns_refresh_);
extra_stream_info_->configuration_key_ = network_configurator_->addUpstreamSocketOptions(options);
connectivity_manager_->setInterfaceBindingEnabled(enable_interface_binding_);
connectivity_manager_->setDrainPostDnsRefreshEnabled(enable_drain_post_dns_refresh_);
extra_stream_info_->configuration_key_ = connectivity_manager_->addUpstreamSocketOptions(options);
decoder_callbacks_->addUpstreamSocketOptions(options);
}

Http::FilterHeadersStatus NetworkConfigurationFilter::encodeHeaders(Http::ResponseHeaderMap&,
bool) {
ENVOY_LOG(debug, "NetworkConfigurationFilter::encodeHeaders");
// Report request status to network configurator, so that socket configuration may be adapted
// to current network conditions. Receiving headers from upstream always means some level of
// network transmission was successful, so we unconditionally set network_fault to false.
network_configurator_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
// Report request status to network connectivity_manager, so that socket configuration may be
// adapted to current network conditions. Receiving headers from upstream always means some level
// of network transmission was successful, so we unconditionally set network_fault to false.
connectivity_manager_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
false /* network_fault */);

return Http::FilterHeadersStatus::Continue;
Expand All @@ -45,16 +45,16 @@ Http::LocalErrorStatus NetworkConfigurationFilter::onLocalReply(const LocalReply
// Envoy uses local replies to report various local errors, including networking failures (which
// Envoy Mobile later surfaces as errors). As a proxy for the many different types of network
// errors, this code interprets any local error where a stream received no bytes from the upstream
// as a network fault. This status is passed to the configurator below when we report network
// usage, where it may be factored into future socket configuration.
// as a network fault. This status is passed to the connectivity_manager below when we report
// network usage, where it may be factored into future socket configuration.
bool network_fault = !success_status && (!decoder_callbacks_->streamInfo().upstreamInfo() ||
!decoder_callbacks_->streamInfo()
.upstreamInfo()
->upstreamTiming()
.first_upstream_rx_byte_received_.has_value());
// Report request status to network configurator, so that socket configuration may be adapted
// to current network conditions.
network_configurator_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
// Report request status to network connectivity_manager, so that socket configuration may be
// adapted to current network conditions.
connectivity_manager_->reportNetworkUsage(extra_stream_info_->configuration_key_.value(),
network_fault);

return Http::LocalErrorStatus::ContinueAndResetStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "source/extensions/filters/http/common/pass_through_filter.h"

#include "library/common/extensions/filters/http/network_configuration/filter.pb.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"
#include "library/common/stream_info/extra_stream_info.h"
#include "library/common/types/c_types.h"

Expand All @@ -21,9 +21,9 @@ namespace NetworkConfiguration {
class NetworkConfigurationFilter final : public Http::PassThroughFilter,
public Logger::Loggable<Logger::Id::filter> {
public:
NetworkConfigurationFilter(Network::ConfiguratorSharedPtr network_configurator,
NetworkConfigurationFilter(Network::ConnectivityManagerSharedPtr connectivity_manager,
bool enable_drain_post_dns_refresh, bool enable_interface_binding)
: network_configurator_(network_configurator),
: connectivity_manager_(connectivity_manager),
extra_stream_info_(nullptr), // always set in setDecoderFilterCallbacks
enable_drain_post_dns_refresh_(enable_drain_post_dns_refresh),
enable_interface_binding_(enable_interface_binding) {}
Expand All @@ -36,7 +36,7 @@ class NetworkConfigurationFilter final : public Http::PassThroughFilter,
Http::LocalErrorStatus onLocalReply(const LocalReplyData&) override;

private:
Network::ConfiguratorSharedPtr network_configurator_;
Network::ConnectivityManagerSharedPtr connectivity_manager_;
StreamInfo::ExtraStreamInfo* extra_stream_info_;
bool enable_drain_post_dns_refresh_;
bool enable_interface_binding_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ syntax = "proto3";
package envoymobile.extensions.filters.http.network_configuration;

message NetworkConfiguration {
// If set to true, the filter will permit the NetworkConfigurator to provide upstream
// If set to true, the filter will permit the NetworkConnectivityManager to provide upstream
// socket option that MAY bind a connection to a specific network interface.
bool enable_interface_binding = 1;

// If set to true, the filter will permit the NetworkConfigurator to drain connections
// If set to true, the filter will permit the NetworkConnectivityManager to drain connections
// when a DNS refresh is externally triggered.
bool enable_drain_post_dns_refresh = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ envoy_cc_extension(
repository = "@envoy",
deps = [
":predicate_cc_proto",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/stream_info:extra_stream_info_lib",
"@envoy//envoy/upstream:retry_interface",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ NetworkConfigurationRetryOptionsPredicate::NetworkConfigurationRetryOptionsPredi
const envoymobile::extensions::retry::options::network_configuration::
NetworkConfigurationOptionsPredicate&,
Upstream::RetryExtensionFactoryContext& context) {
network_configurator_ = Network::ConfiguratorHandle{context.singletonManager()}.get();
RELEASE_ASSERT(network_configurator_ != nullptr, "unexpected nullptr network configurator");
connectivity_manager_ = Network::ConnectivityManagerHandle{context.singletonManager()}.get();
RELEASE_ASSERT(connectivity_manager_ != nullptr,
"unexpected nullptr network connectivity_manager");
}

Upstream::RetryOptionsPredicate::UpdateOptionsReturn
Expand Down Expand Up @@ -53,25 +54,26 @@ NetworkConfigurationRetryOptionsPredicate::updateOptions(

// As a proxy for the many different types of network errors, this code interprets any failure
// where a stream received no bytes from the upstream as a network fault. This status is passed to
// the configurator below when we report network usage, where it may be factored into future
// socket configuration.
// the connectivity_manager below when we report network usage, where it may be factored into
// future socket configuration.
bool network_fault =
!stream_info.upstreamInfo() ||
!stream_info.upstreamInfo()->upstreamTiming().first_upstream_rx_byte_received_.has_value();

// Report request status to network configurator, so that socket configuration may be adapted
// to current network conditions.
network_configurator_->reportNetworkUsage(extra_stream_info->configuration_key_.value(),
// Report request status to network connectivity_manager, so that socket configuration may be
// adapted to current network conditions.
connectivity_manager_->reportNetworkUsage(extra_stream_info->configuration_key_.value(),
network_fault);

// Update socket configuration for next retry attempt.
extra_stream_info->configuration_key_ = network_configurator_->addUpstreamSocketOptions(options);
extra_stream_info->configuration_key_ = connectivity_manager_->addUpstreamSocketOptions(options);

// The options returned here replace any existing socket options used for a prior attempt. At
// present, all socket options set in Envoy Mobile are provided by the NetworkConfigurator, so
// it's safe to simply replace them.
// present, all socket options set in Envoy Mobile are provided by the NetworkConnectivityManager,
// so it's safe to simply replace them.
// TODO(goaway): If additional socket options are ever provided by a source other than the
// NetworkConfigurator, we need to account for the potential presence of those options here.
// NetworkConnectivityManager, we need to account for the potential presence of those options
// here.
return Upstream::RetryOptionsPredicate::UpdateOptionsReturn{options};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "library/common/extensions/retry/options/network_configuration/predicate.pb.h"
#include "library/common/extensions/retry/options/network_configuration/predicate.pb.validate.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"

namespace Envoy {
namespace Extensions {
Expand All @@ -25,7 +25,7 @@ class NetworkConfigurationRetryOptionsPredicate : public Upstream::RetryOptionsP
updateOptions(const Upstream::RetryOptionsPredicate::UpdateOptionsParameters&) const override;

private:
Network::ConfiguratorSharedPtr network_configurator_;
Network::ConnectivityManagerSharedPtr connectivity_manager_;
};

} // namespace Options
Expand Down
2 changes: 1 addition & 1 deletion library/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ envoy_cc_library(
"//library/common/extensions/filters/http/network_configuration:network_configuration_filter_lib",
"//library/common/http:header_utility_lib",
"//library/common/jni:android_jni_utility_lib",
"//library/common/network:configurator_lib",
"//library/common/network:connectivity_manager_lib",
"//library/common/network:synthetic_address_lib",
"//library/common/stream_info:extra_stream_info_lib",
"//library/common/types:c_types_lib",
Expand Down
2 changes: 1 addition & 1 deletion library/common/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "library/common/http/header_utility.h"
#include "library/common/http/headers.h"
#include "library/common/jni/android_jni_utility.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"
#include "library/common/stream_info/extra_stream_info.h"

namespace Envoy {
Expand Down
9 changes: 5 additions & 4 deletions library/common/main_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "library/common/engine_handle.h"
#include "library/common/extensions/filters/http/platform_bridge/c_types.h"
#include "library/common/http/client.h"
#include "library/common/network/configurator.h"
#include "library/common/network/connectivity_manager.h"

// NOLINT(namespace-envoy)

Expand Down Expand Up @@ -66,9 +66,10 @@ envoy_status_t reset_stream(envoy_engine_t engine, envoy_stream_t stream) {
}

envoy_status_t set_preferred_network(envoy_engine_t engine, envoy_network_t network) {
envoy_netconf_t configuration_key = Envoy::Network::Configurator::setPreferredNetwork(network);
envoy_netconf_t configuration_key =
Envoy::Network::ConnectivityManager::setPreferredNetwork(network);
Envoy::EngineHandle::runOnEngineDispatcher(engine, [configuration_key](auto& engine) -> void {
engine.networkConfigurator().refreshDns(configuration_key, true);
engine.networkConnectivityManager().refreshDns(configuration_key, true);
});
// TODO(snowp): Should this return failure ever?
return ENVOY_SUCCESS;
Expand Down Expand Up @@ -191,5 +192,5 @@ void terminate_engine(envoy_engine_t engine) { Envoy::EngineHandle::terminateEng

envoy_status_t reset_connectivity_state(envoy_engine_t e) {
return Envoy::EngineHandle::runOnEngineDispatcher(
e, [](auto& engine) { engine.networkConfigurator().resetConnectivityState(); });
e, [](auto& engine) { engine.networkConnectivityManager().resetConnectivityState(); });
}
6 changes: 3 additions & 3 deletions library/common/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ licenses(["notice"]) # Apache 2
envoy_package()

envoy_cc_library(
name = "configurator_lib",
name = "connectivity_manager_lib",
srcs = [
"configurator.cc",
"connectivity_manager.cc",
"android.cc",
] + select({
"//bazel:include_ifaddrs": [
Expand All @@ -19,7 +19,7 @@ envoy_cc_library(
}),
hdrs = [
"android.h",
"configurator.h",
"connectivity_manager.h",
],
copts = select({
"//bazel:include_ifaddrs": ["-DINCLUDE_IFADDRS"],
Expand Down
Loading