Skip to content
Closed
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
1 change: 1 addition & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ proto_library(
deps = [
"//contrib/envoy/extensions/filters/http/squash/v3:pkg",
"//contrib/envoy/extensions/filters/http/sxg/v3alpha:pkg",
"//contrib/envoy/extensions/filters/network/generic_proxy/v3alpha:pkg",
"//contrib/envoy/extensions/filters/network/kafka_broker/v3:pkg",
"//contrib/envoy/extensions/filters/network/kafka_mesh/v3alpha:pkg",
"//contrib/envoy/extensions/filters/network/mysql_proxy/v3:pkg",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/config/core/v3:pkg",
"//envoy/config/route/v3:pkg",
"//envoy/type/matcher/v3:pkg",
"@com_github_cncf_udpa//udpa/annotations:pkg",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
syntax = "proto3";

package envoy.extensions.filters.network.generic_proxy.v3alpha;

import "envoy/config/core/v3/base.proto";
import "envoy/config/core/v3/config_source.proto";
import "envoy/config/core/v3/extension.proto";
import "envoy/config/route/v3/route_components.proto";
import "envoy/type/matcher/v3/string.proto";

import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";

import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.network.generic_proxy.v3alpha";
option java_outer_classname = "GenericProxyProto";
option java_multiple_files = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Generic Proxy]
// [#extension: proxy.filters.network.generic_proxy]
// [#next-free-field: 8]
message GenericProxyConfig {
// The human readable prefix to use when emitting statistics.
string stat_prefix = 1 [(validate.rules).string = {min_len: 1}];

// Specific codec implementation for generic proxy. The codec will be used to decode/encode
// downstream request and upstream response.
config.core.v3.TypedExtensionConfig codec_specifier = 2
[(validate.rules).message = {required: true}];

oneof route_specifier {
// Static route table for generic proxy.
RouteConfiguration route_config = 6;

// the generic proxy's route table will be dynamically loaded via the RDS API.
GRDS grds = 7;
}

// A list of individual generic filters that make up the filter chain for requests made to the
// generic proxy. Order matters as the filters are processed sequentially.
repeated GenericFilter generic_filters = 5;
}

message GRDS {
// Configuration source specifier for RDS.
config.core.v3.ConfigSource config_source = 1 [(validate.rules).message = {required: true}];

// The name of the route configuration. This name will be passed to the RDS API. This allows
// an Envoy configuration with multiple Generic listeners ( and associated Generic filters)
// to use different route configurations.
string route_config_name = 2 [(validate.rules).string = {min_len: 1}];
}

// GenericFilter configures a generic filter.
message GenericFilter {
// The name of the filter to instantiate. The name must match a supported
// filter.
string name = 1 [(validate.rules).string = {min_len: 1}];

// Filter specific configuration which depends on the filter being instantiated. See the
// supported filters for further documentation.
google.protobuf.Any config = 2;
}

// [#next-free-field: 9]
message HeaderMatch {
// The name of header/metadata need to match.
string name = 1 [(validate.rules).string = {min_len: 1}];

// Specific match rule of header/metadata.
oneof match_specifier {
// If specified, header match will be performed based on the string match rule.
type.matcher.v3.StringMatcher string_match = 2;

// If specified, header match will be performed based on whether the header is in the
// request.
bool present_match = 3;
}

// If specified, the match result will be inverted before checking. Defaults to false.
//
// Examples:
//
// * The regex ``\d{3}`` does not match the value *1234*, so it will match when inverted.
// * The range [-10,0) will match the value -1, so it will not match when inverted.
bool invert_match = 8;
}

message Authority {
// A list of authority value. Used to match request authority of downstream request.
// If request authority does not match this rule, the entire request does not match the
// current route set.
repeated string authorities = 1 [(validate.rules).repeated = {min_items: 1}];

repeated Route routes = 2;
}

message RouteMatch {
// Used to match request path of downstream request. If request path does not match
// this rule, the entire request does not match the current route.
type.matcher.v3.StringMatcher path = 1;

// Used to match request method of downstream request. If request method does not match
// this rule, the entire request does not match the current route.
type.matcher.v3.StringMatcher method = 2;

// A list of header match rules that downstream request need to match. As long as one
// of the rules is not matched successfully, the entire request is not matched successfully.
repeated HeaderMatch headers = 3;
}

message RetryPolicy {
// When certain conditions are met, the upstream request is retried. Supports retry when a
// network error occurs or when the response status is a specific status.
string retry_on = 1;

// Maximum number of retries. For a downstream request, envoy may issue `1 + may_retry`
// upstream requests.
uint32 max_retry = 2;

// If not specified, then Route.timeout will be used.
google.protobuf.Duration per_try_timeout = 3;
}

message DirectReturn {
}

// [#next-free-field: 9]
message Route {
// Match rules of current route. Used to determine whether a request should be forwarded
// using the current routing rules.
RouteMatch match = 1;

oneof route_specifier {
option (validate.required) = true;

// Indicates the upstream cluster to which the request should be routed.
string cluster = 2 [(validate.rules).string = {min_len: 1}];

// Multiple upstream clusters can be specified for a given route. The request is routed
// to one of the upstream clusters based on weights assigned to each cluster. Currently
// ClusterWeight only supports the name and weight fields.
config.route.v3.WeightedCluster weighted_clusters = 3;

// Return a fixed response downstream.
DirectReturn direct = 4;
}

// Downstream request timeout.
google.protobuf.Duration timeout = 5;

// Retry policy used by current route.
RetryPolicy retry = 6;

// Route level config for L7 generic filters. The key should always be the generic filter name.
map<string, google.protobuf.Any> per_filter_config = 7;

// Route metadata.
config.core.v3.Metadata metadata = 8;
}

message RouteConfiguration {
// The name of route config.
string name = 1 [(validate.rules).string = {min_len: 1}];

// A list of route entry config.
repeated Authority config = 2;
}
1 change: 1 addition & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ proto_library(
deps = [
"//contrib/envoy/extensions/filters/http/squash/v3:pkg",
"//contrib/envoy/extensions/filters/http/sxg/v3alpha:pkg",
"//contrib/envoy/extensions/filters/network/generic_proxy/v3alpha:pkg",
"//contrib/envoy/extensions/filters/network/kafka_broker/v3:pkg",
"//contrib/envoy/extensions/filters/network/kafka_mesh/v3alpha:pkg",
"//contrib/envoy/extensions/filters/network/mysql_proxy/v3:pkg",
Expand Down
1 change: 1 addition & 0 deletions contrib/contrib_build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONTRIB_EXTENSIONS = {
"envoy.filters.network.mysql_proxy": "//contrib/mysql_proxy/filters/network/source:config",
"envoy.filters.network.postgres_proxy": "//contrib/postgres_proxy/filters/network/source:config",
"envoy.filters.network.rocketmq_proxy": "//contrib/rocketmq_proxy/filters/network/source:config",
"envoy.filters.network.generic_proxy": "//contrib/generic_proxy/filters/network/source:config",

#
# Sip proxy
Expand Down
5 changes: 5 additions & 0 deletions contrib/extensions_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ envoy.bootstrap.vcl:
- envoy.bootstrap
security_posture: requires_trusted_downstream_and_upstream
status: alpha
envoy.filters.network.generic_proxy:
categories:
- envoy.filters.network
security_posture: requires_trusted_downstream_and_upstream
status: alpha
68 changes: 68 additions & 0 deletions contrib/generic_proxy/filters/network/source/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_contrib_extension",
"envoy_cc_library",
"envoy_contrib_package",
)

licenses(["notice"]) # Apache 2

envoy_contrib_package()

envoy_cc_library(
name = "filter_lib",
srcs = [
"generic_proxy.cc",
],
hdrs = [
"generic_proxy.h",
],
deps = [
":route_lib",
"//contrib/generic_proxy/filters/network/source/interface:generic_codec_interface",
"//envoy/network:filter_interface",
"//envoy/server:factory_context_interface",
"//source/common/common:linked_object",
"//source/common/common:minimal_logger_lib",
"//source/common/stream_info:stream_info_lib",
"//source/extensions/filters/network/common:factory_base_lib",
"@envoy_api//contrib/envoy/extensions/filters/network/generic_proxy/v3alpha:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

envoy_cc_contrib_extension(
name = "config",
srcs = [
"config.cc",
],
hdrs = [
"config.h",
],
deps = [
":filter_lib",
"//contrib/generic_proxy/filters/network/source/filters/router:config",
"//envoy/server:filter_config_interface",
"@envoy_api//contrib/envoy/extensions/filters/network/generic_proxy/v3alpha:pkg_cc_proto",
],
)

envoy_cc_library(
name = "route_lib",
srcs = [
"route_impl.cc",
],
hdrs = [
"route_impl.h",
],
deps = [
"//contrib/generic_proxy/filters/network/source/interface:generic_config_interface",
"//contrib/generic_proxy/filters/network/source/interface:generic_route_interface",
"//envoy/server:factory_context_interface",
"//source/common/common:matchers_lib",
"//source/common/config:metadata_lib",
"//source/common/config:utility_lib",
"@envoy_api//contrib/envoy/extensions/filters/network/generic_proxy/v3alpha:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)
22 changes: 22 additions & 0 deletions contrib/generic_proxy/filters/network/source/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "contrib/generic_proxy/filters/network/source/config.h"

namespace Envoy {
namespace Proxy {
namespace NetworkFilters {
namespace GenericProxy {

Envoy::Network::FilterFactoryCb
Factory::createFilterFactoryFromProtoTyped(const GenericProxyConfig& proto_config,
Envoy::Server::Configuration::FactoryContext& context) {
auto config = std::make_shared<FilterConfig>(proto_config, context);
return [config, &context](Envoy::Network::FilterManager& filter_manager) -> void {
filter_manager.addReadFilter(std::make_shared<Filter>(config, context));
};
}

REGISTER_FACTORY(Factory, Envoy::Server::Configuration::NamedNetworkFilterConfigFactory);

} // namespace GenericProxy
} // namespace NetworkFilters
} // namespace Proxy
} // namespace Envoy
29 changes: 29 additions & 0 deletions contrib/generic_proxy/filters/network/source/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#pragma once

#include "envoy/registry/registry.h"

#include "source/extensions/filters/network/common/factory_base.h"

#include "contrib/envoy/extensions/filters/network/generic_proxy/v3alpha/generic_proxy.pb.h"
#include "contrib/envoy/extensions/filters/network/generic_proxy/v3alpha/generic_proxy.pb.validate.h"
#include "contrib/generic_proxy/filters/network/source/generic_proxy.h"

namespace Envoy {
namespace Proxy {
namespace NetworkFilters {
namespace GenericProxy {

class Factory : public Envoy::Extensions::NetworkFilters::Common::FactoryBase<GenericProxyConfig> {
public:
Factory() : FactoryBase(Filter::name()) {}

Envoy::Network::FilterFactoryCb
createFilterFactoryFromProtoTyped(const GenericProxyConfig& proto_config,
Envoy::Server::Configuration::FactoryContext& context) override;
};

} // namespace GenericProxy
} // namespace NetworkFilters
} // namespace Proxy
} // namespace Envoy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
licenses(["notice"]) # Apache 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_contrib_package",
)

licenses(["notice"]) # Apache 2

envoy_contrib_package()

envoy_cc_library(
name = "router_lib",
srcs = [
"router.cc",
],
hdrs = [
"router.h",
],
deps = [
"//contrib/generic_proxy/filters/network/source/interface:generic_codec_interface",
"//contrib/generic_proxy/filters/network/source/interface:generic_config_interface",
"//contrib/generic_proxy/filters/network/source/interface:generic_filter_interface",
"//source/common/buffer:buffer_lib",
"//source/common/common:linked_object",
"//source/common/common:minimal_logger_lib",
"//source/common/upstream:load_balancer_lib",
],
)

envoy_cc_library(
name = "config",
srcs = [
"config.cc",
],
hdrs = [
"config.h",
],
deps = [
":router_lib",
"//contrib/generic_proxy/filters/network/source/interface:generic_config_interface",
"//envoy/registry",
],
)
Loading