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
7 changes: 7 additions & 0 deletions include/envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,13 @@ class ClusterInfo {
virtual const absl::optional<envoy::config::cluster::v3::Cluster::OriginalDstLbConfig>&
lbOriginalDstConfig() const PURE;

/**
* @return const absl::optional<envoy::config::core::v3::TypedExtensionConfig>& the configuration
* for the upstream, if a custom upstream is configured.
*/
virtual const absl::optional<envoy::config::core::v3::TypedExtensionConfig>&
upstreamConfig() const PURE;

/**
* @return Whether the cluster is currently in maintenance mode and should not be routed to.
* Different filters may handle this situation in different ways. The implementation
Expand Down
22 changes: 10 additions & 12 deletions source/common/router/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,20 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,
}

std::unique_ptr<GenericConnPool> Filter::createConnPool() {
GenericConnPoolFactory* factory = nullptr;
if (cluster_->upstreamConfig().has_value()) {
factory = &Envoy::Config::Utility::getAndCheckFactory<GenericConnPoolFactory>(
cluster_->upstreamConfig().value());
} else {
factory = &Envoy::Config::Utility::getAndCheckFactoryByName<GenericConnPoolFactory>(
"envoy.filters.connection_pools.http.generic");
}
const bool should_tcp_proxy =
route_entry_->connectConfig().has_value() &&
downstream_headers_->getMethodValue() == Http::Headers::get().MethodValues.Connect;
Http::Protocol protocol = cluster_->upstreamHttpProtocol(callbacks_->streamInfo().protocol());
if (should_tcp_proxy) {
auto pool = std::make_unique<TcpConnPool>(config_.cm_, *route_entry_, protocol, this);
if (pool->valid()) {
return pool;
}
} else {
auto pool = std::make_unique<HttpConnPool>(config_.cm_, *route_entry_, protocol, this);
if (pool->valid()) {
return pool;
}
}
return nullptr;
return factory->createGenericConnPool(config_.cm_, should_tcp_proxy, *route_entry_, protocol,
this);
}

void Filter::sendNoHealthyUpstreamResponse() {
Expand Down
7 changes: 6 additions & 1 deletion source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,12 @@ ClusterInfoImpl::ClusterInfoImpl(
source_address_(getSourceAddress(config, bind_config)),
lb_least_request_config_(config.least_request_lb_config()),
lb_ring_hash_config_(config.ring_hash_lb_config()),
lb_original_dst_config_(config.original_dst_lb_config()), added_via_api_(added_via_api),
lb_original_dst_config_(config.original_dst_lb_config()),
upstream_config_(config.has_upstream_config()
? absl::make_optional<envoy::config::core::v3::TypedExtensionConfig>(
config.upstream_config())
: absl::nullopt),
added_via_api_(added_via_api),
lb_subset_(LoadBalancerSubsetInfoImpl(config.lb_subset_config())),
metadata_(config.metadata()), typed_metadata_(config.metadata()),
common_lb_config_(config.common_lb_config()),
Expand Down
5 changes: 5 additions & 0 deletions source/common/upstream/upstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ class ClusterInfoImpl : public ClusterInfo, protected Logger::Loggable<Logger::I
lbOriginalDstConfig() const override {
return lb_original_dst_config_;
}
const absl::optional<envoy::config::core::v3::TypedExtensionConfig>&
upstreamConfig() const override {
return upstream_config_;
}
bool maintenanceMode() const override;
uint64_t maxRequestsPerConnection() const override { return max_requests_per_connection_; }
uint32_t maxResponseHeadersCount() const override { return max_response_headers_count_; }
Expand Down Expand Up @@ -645,6 +649,7 @@ class ClusterInfoImpl : public ClusterInfo, protected Logger::Loggable<Logger::I
lb_least_request_config_;
absl::optional<envoy::config::cluster::v3::Cluster::RingHashLbConfig> lb_ring_hash_config_;
absl::optional<envoy::config::cluster::v3::Cluster::OriginalDstLbConfig> lb_original_dst_config_;
absl::optional<envoy::config::core::v3::TypedExtensionConfig> upstream_config_;
const bool added_via_api_;
LoadBalancerSubsetInfoImpl lb_subset_;
const envoy::config::core::v3::Metadata metadata_;
Expand Down
9 changes: 7 additions & 2 deletions source/extensions/upstreams/http/generic/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# placeholder build files for security_posture
# Will be filled in as #11327 lands.
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
Expand All @@ -13,8 +11,15 @@ envoy_package()
envoy_cc_extension(
name = "config",
srcs = [
"config.cc",
],
hdrs = [
"config.h",
],
security_posture = "robust_to_untrusted_downstream",
visibility = ["//visibility:public"],
deps = [
"//source/common/router:router_lib",
"@envoy_api//envoy/extensions/upstreams/http/generic/v3:pkg_cc_proto",
],
)
28 changes: 28 additions & 0 deletions source/extensions/upstreams/http/generic/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "extensions/upstreams/http/generic/config.h"

#include "common/router/upstream_request.h"

namespace Envoy {
namespace Extensions {
namespace Upstreams {
namespace Http {
namespace Generic {

Router::GenericConnPoolPtr GenericGenericConnPoolFactory::createGenericConnPool(
Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry,
Envoy::Http::Protocol protocol, Upstream::LoadBalancerContext* ctx) const {
if (is_connect) {
auto ret = std::make_unique<Router::TcpConnPool>(cm, route_entry, protocol, ctx);
return (ret->valid() ? std::move(ret) : nullptr);
}
auto ret = std::make_unique<Router::HttpConnPool>(cm, route_entry, protocol, ctx);
return (ret->valid() ? std::move(ret) : nullptr);
}

REGISTER_FACTORY(GenericGenericConnPoolFactory, Router::GenericConnPoolFactory);

} // namespace Generic
} // namespace Http
} // namespace Upstreams
} // namespace Extensions
} // namespace Envoy
37 changes: 37 additions & 0 deletions source/extensions/upstreams/http/generic/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "envoy/extensions/upstreams/http/generic/v3/generic_connection_pool.pb.h"
#include "envoy/registry/registry.h"
#include "envoy/router/router.h"

namespace Envoy {
namespace Extensions {
namespace Upstreams {
namespace Http {
namespace Generic {

/**
* Config registration for the GenericConnPool. * @see Router::GenericConnPoolFactory
*/
class GenericGenericConnPoolFactory : public Router::GenericConnPoolFactory {
public:
std::string name() const override { return "envoy.filters.connection_pools.http.generic"; }
std::string category() const override { return "envoy.upstreams"; }
Router::GenericConnPoolPtr
createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect,
const Router::RouteEntry& route_entry, Envoy::Http::Protocol protocol,
Upstream::LoadBalancerContext* ctx) const override;

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return std::make_unique<
envoy::extensions::upstreams::http::generic::v3::GenericConnectionPoolProto>();
}
};

DECLARE_FACTORY(GenericGenericConnPoolFactory);

} // namespace Generic
} // namespace Http
} // namespace Upstreams
} // namespace Extensions
} // namespace Envoy
9 changes: 7 additions & 2 deletions source/extensions/upstreams/http/http/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# placeholder build files for security_posture
# Will be filled in as #11327 lands.
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
Expand All @@ -13,8 +11,15 @@ envoy_package()
envoy_cc_extension(
name = "config",
srcs = [
"config.cc",
],
hdrs = [
"config.h",
],
security_posture = "robust_to_untrusted_downstream",
visibility = ["//visibility:public"],
deps = [
"//source/common/router:router_lib",
"@envoy_api//envoy/extensions/upstreams/http/http/v3:pkg_cc_proto",
],
)
24 changes: 24 additions & 0 deletions source/extensions/upstreams/http/http/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "extensions/upstreams/http/http/config.h"

#include "common/router/upstream_request.h"

namespace Envoy {
namespace Extensions {
namespace Upstreams {
namespace Http {
namespace Http {

Router::GenericConnPoolPtr HttpGenericConnPoolFactory::createGenericConnPool(
Upstream::ClusterManager& cm, bool, const Router::RouteEntry& route_entry,
Envoy::Http::Protocol protocol, Upstream::LoadBalancerContext* ctx) const {
auto ret = std::make_unique<Router::HttpConnPool>(cm, route_entry, protocol, ctx);
return (ret->valid() ? std::move(ret) : nullptr);
}

REGISTER_FACTORY(HttpGenericConnPoolFactory, Router::GenericConnPoolFactory);

} // namespace Http
} // namespace Http
} // namespace Upstreams
} // namespace Extensions
} // namespace Envoy
37 changes: 37 additions & 0 deletions source/extensions/upstreams/http/http/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "envoy/extensions/upstreams/http/http/v3/http_connection_pool.pb.h"
#include "envoy/registry/registry.h"
#include "envoy/router/router.h"

namespace Envoy {
namespace Extensions {
namespace Upstreams {
namespace Http {
namespace Http {

/**
* Config registration for the HttpConnPool. @see Router::GenericConnPoolFactory
*/
class HttpGenericConnPoolFactory : public Router::GenericConnPoolFactory {
public:
std::string name() const override { return "envoy.filters.connection_pools.http.http"; }
std::string category() const override { return "envoy.upstreams"; }
Router::GenericConnPoolPtr
createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect,
const Router::RouteEntry& route_entry, Envoy::Http::Protocol protocol,
Upstream::LoadBalancerContext* ctx) const override;

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return std::make_unique<
envoy::extensions::upstreams::http::http::v3::HttpConnectionPoolProto>();
}
};

DECLARE_FACTORY(HttpGenericConnPoolFactory);

} // namespace Http
} // namespace Http
} // namespace Upstreams
} // namespace Extensions
} // namespace Envoy
9 changes: 7 additions & 2 deletions source/extensions/upstreams/http/tcp/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# placeholder build files for security_posture
# Will be filled in as #11327 lands.
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
Expand All @@ -13,8 +11,15 @@ envoy_package()
envoy_cc_extension(
name = "config",
srcs = [
"config.cc",
],
hdrs = [
"config.h",
],
security_posture = "robust_to_untrusted_downstream",
visibility = ["//visibility:public"],
deps = [
"//source/common/router:router_lib",
"@envoy_api//envoy/extensions/upstreams/http/tcp/v3:pkg_cc_proto",
],
)
24 changes: 24 additions & 0 deletions source/extensions/upstreams/http/tcp/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "extensions/upstreams/http/tcp/config.h"

#include "common/router/upstream_request.h"

namespace Envoy {
namespace Extensions {
namespace Upstreams {
namespace Http {
namespace Tcp {

Router::GenericConnPoolPtr TcpGenericConnPoolFactory::createGenericConnPool(
Upstream::ClusterManager& cm, bool, const Router::RouteEntry& route_entry,
Envoy::Http::Protocol protocol, Upstream::LoadBalancerContext* ctx) const {
auto ret = std::make_unique<Router::TcpConnPool>(cm, route_entry, protocol, ctx);
return (ret->valid() ? std::move(ret) : nullptr);
}

REGISTER_FACTORY(TcpGenericConnPoolFactory, Router::GenericConnPoolFactory);

} // namespace Tcp
} // namespace Http
} // namespace Upstreams
} // namespace Extensions
} // namespace Envoy
35 changes: 35 additions & 0 deletions source/extensions/upstreams/http/tcp/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "envoy/extensions/upstreams/http/tcp/v3/tcp_connection_pool.pb.h"
#include "envoy/registry/registry.h"
#include "envoy/router/router.h"

namespace Envoy {
namespace Extensions {
namespace Upstreams {
namespace Http {
namespace Tcp {

/**
* Config registration for the TcpConnPool. @see Router::GenericConnPoolFactory
*/
class TcpGenericConnPoolFactory : public Router::GenericConnPoolFactory {
public:
std::string name() const override { return "envoy.filters.connection_pools.http.tcp"; }
std::string category() const override { return "envoy.upstreams"; }
Router::GenericConnPoolPtr
createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect,
const Router::RouteEntry& route_entry, Envoy::Http::Protocol protocol,
Upstream::LoadBalancerContext* ctx) const override;
ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return std::make_unique<envoy::extensions::upstreams::http::tcp::v3::TcpConnectionPoolProto>();
}
};

DECLARE_FACTORY(TcpGenericConnPoolFactory);

} // namespace Tcp
} // namespace Http
} // namespace Upstreams
} // namespace Extensions
} // namespace Envoy
3 changes: 3 additions & 0 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ envoy_cc_library(
"//source/common/stats:timespan_lib",
"//source/common/stream_info:stream_info_lib",
"//source/extensions/transport_sockets:well_known_names",
"//source/extensions/upstreams/http/generic:config",
"//source/extensions/upstreams/http/http:config",
"//source/extensions/upstreams/http/tcp:config",
],
)

Expand Down
1 change: 1 addition & 0 deletions test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ envoy_cc_test(
"//source/common/http:context_lib",
"//source/common/http:headers_lib",
"//source/common/http:utility_lib",
"//source/extensions/upstreams/http/generic:config",
"//test/mocks:common_lib",
"//test/mocks/buffer:buffer_mocks",
"//test/mocks/http:http_mocks",
Expand Down
6 changes: 6 additions & 0 deletions test/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ envoy_cc_test(
"//source/common/stream_info:uint32_accessor_lib",
"//source/common/upstream:upstream_includes",
"//source/common/upstream:upstream_lib",
"//source/extensions/upstreams/http/generic:config",
"//source/extensions/upstreams/http/http:config",
"//source/extensions/upstreams/http/tcp:config",
"//test/common/http:common_lib",
"//test/mocks/http:http_mocks",
"//test/mocks/local_info:local_info_mocks",
Expand All @@ -276,6 +279,8 @@ envoy_cc_test(
"//test/test_common:utility_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/transport_sockets/tls/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/upstreams/http/http/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/upstreams/http/tcp/v3:pkg_cc_proto",
"@envoy_api//envoy/type/v3:pkg_cc_proto",
],
)
Expand All @@ -292,6 +297,7 @@ envoy_cc_test(
"//source/common/upstream:upstream_includes",
"//source/common/upstream:upstream_lib",
"//source/extensions/access_loggers/file:config",
"//source/extensions/upstreams/http/generic:config",
"//test/common/http:common_lib",
"//test/mocks/access_log:access_log_mocks",
"//test/mocks/filesystem:filesystem_mocks",
Expand Down
Loading