-
Notifications
You must be signed in to change notification settings - Fork 5.5k
udp: add router for UDP proxy #18791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 46 commits
4cfa9c5
9891c45
367db00
3bd3085
4c1b126
3f762f7
95e1094
b592612
804aedd
37def08
77fb547
9c71fe4
b4cbd8d
4a201e7
b5086f2
42ce9c3
0b14da0
744d74b
cf61bb7
cc24008
f5fd481
f613a87
4a2f3f8
115b532
db04638
e9f56d7
786386b
f615fd5
854176a
7cff9bf
b0fb7d6
8cfdf65
cfee9b0
063cf40
35b0f5e
7303e6f
8184199
8f3e8e0
ecddff7
fae4e72
69376a9
0fc55bf
e779a36
fb2731e
68dc8fb
8de2770
e9cf799
03005e5
e162cae
d62539e
e49181a
b04a059
87d1361
bd7b917
b00cf9e
45165c6
5173760
0e19161
8b30f25
d3db96e
b501e34
bc33bd0
2b9fe8d
9d1abd2
628855d
cb3d52c
d6911cc
29e86f8
4478d77
c1dc8b1
086ea89
cf77be6
4830ec7
5ff8de5
43a1b80
2be0b73
03b55aa
549a487
a08f1e1
d368ef3
9b46d46
79d1748
f959f11
b9ac01e
96d1ca1
f0eead0
a5fc56d
00a84ef
eede13d
0617a91
4eeea14
dc59d27
3f9c62c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.filters.udp.udp_proxy.v3; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.filters.udp.udp_proxy.v3"; | ||
| option java_outer_classname = "RouteProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: UDP proxy route configuration] | ||
| // UDP proxy :ref:`configuration overview <config_udp_listener_filters_udp_proxy>`. | ||
|
|
||
| message Route { | ||
| // Indicates the upstream cluster to which the request should be routed. | ||
| string cluster = 1 [(validate.rules).string = {min_len: 1}]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.type.matcher.v3; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.type.matcher.v3"; | ||
| option java_outer_classname = "NetworkInputsProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Common Network Inputs] | ||
|
|
||
| // Match input indicates that matching should be done on a specific source IP. | ||
| // [#comment:TODO(snowp): Link to unified matching docs.] | ||
| message SourceIpMatchInput { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ New Features | |
| * thrift_proxy: support subset lb when using request or route metadata. | ||
| * transport_socket: added :ref:`envoy.transport_sockets.tcp_stats <envoy_v3_api_msg_extensions.transport_sockets.tcp_stats.v3.Config>` which generates additional statistics gathered from the OS TCP stack. | ||
| * udp: add support for multiple listener filters. | ||
| * udp_proxy: added :ref:`matcher <envoy_v3_api_field_extensions.filters.udp.udp_proxy.v3.UdpProxyConfig.matcher>` to support matching and routing to different clusters. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a note in deprecated below for the deprecated field.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, added. |
||
| * upstream: added the ability to :ref:`configure max connection duration <envoy_v3_api_field_config.core.v3.HttpProtocolOptions.max_connection_duration>` for upstream clusters. | ||
| * vcl_socket_interface: added VCL socket interface extension for fd.io VPP integration to :ref:`contrib images <install_contrib>`. This can be enabled via :ref:`VCL <envoy_v3_api_msg_extensions.vcl.v3alpha.VclSocketInterface>` configuration. | ||
| * xds: re-introduced unified delta and sotw xDS multiplexers that share most of the implementation. Added a new runtime config ``envoy.reloadable_features.unified_mux`` (disabled by default) that when enabled, switches xDS to use unified multiplexers. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| #include <memory> | ||
|
|
||
| #include "envoy/buffer/buffer.h" | ||
| #include "envoy/network/address.h" | ||
| #include "envoy/network/listen_socket.h" | ||
| #include "envoy/network/transport_socket.h" | ||
| #include "envoy/stream_info/stream_info.h" | ||
|
|
@@ -209,6 +210,15 @@ using ReadFilterSharedPtr = std::shared_ptr<ReadFilter>; | |
| class Filter : public WriteFilter, public ReadFilter {}; | ||
| using FilterSharedPtr = std::shared_ptr<Filter>; | ||
|
|
||
| class NetworkMatchingData { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: A short class comment would be nice (as would a commend on the sourceIp method, though the name is already quite readable)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
| public: | ||
| static absl::string_view name() { return "network"; } | ||
|
|
||
| virtual ~NetworkMatchingData() = default; | ||
|
|
||
| virtual OptRef<const Address::Ip> sourceIp() const PURE; | ||
| }; | ||
|
|
||
| /** | ||
| * Interface for adding individual network filters to a manager. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "data_impl_lib", | ||
| hdrs = ["data_impl.h"], | ||
| deps = [ | ||
| "//envoy/network:filter_interface", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "inputs_lib", | ||
| srcs = ["inputs.cc"], | ||
| hdrs = ["inputs.h"], | ||
| deps = [ | ||
| ":data_impl_lib", | ||
| "//envoy/matcher:matcher_interface", | ||
| "//envoy/server:factory_context_interface", | ||
| "@envoy_api//envoy/type/matcher/v3:pkg_cc_proto", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/network/filter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Matching { | ||
| /** | ||
| * Implementation of NetworkMatchingData, providing network specific data to | ||
| * the match tree. | ||
| */ | ||
| class NetworkMatchingDataImpl : public NetworkMatchingData { | ||
| public: | ||
| static absl::string_view name() { return "network"; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious about this static name() method. It both this class and the parent it returns the same value. Of course since it's static, it's not called polymorphically. How is it used?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, this method refers to the HttpMatchingDataImpl.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this method used, though? Where is it called?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how is the |
||
|
|
||
| NetworkMatchingDataImpl(const Address::Ip* source) : source_(source) {} | ||
|
|
||
| OptRef<const Address::Ip> sourceIp() const override { return makeOptRefFromPtr(source_); } | ||
|
|
||
| private: | ||
| const Address::Ip* const source_{}; | ||
| }; | ||
| } // namespace Matching | ||
| } // namespace Network | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include "source/common/network/matching/inputs.h" | ||
|
|
||
| #include "envoy/registry/registry.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Matching { | ||
| REGISTER_FACTORY(SourceIpDataInputFactory, Matcher::DataInputFactory<NetworkMatchingData>); | ||
| } // namespace Matching | ||
| } // namespace Network | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "envoy/matcher/matcher.h" | ||
| #include "envoy/network/filter.h" | ||
| #include "envoy/server/factory_context.h" | ||
| #include "envoy/type/matcher/v3/network_inputs.pb.h" | ||
| #include "envoy/type/matcher/v3/network_inputs.pb.validate.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
| namespace Matching { | ||
| /** | ||
| * Common base class for all the IP DataInputs. | ||
| */ | ||
| class IpDataInputBase : public Matcher::DataInput<NetworkMatchingData> { | ||
| public: | ||
| explicit IpDataInputBase() = default; | ||
|
|
||
| virtual OptRef<const Address::Ip> select(const NetworkMatchingData& data) const PURE; | ||
|
|
||
| Matcher::DataInputGetResult get(const NetworkMatchingData& data) const override { | ||
| const auto ip = select(data); | ||
|
|
||
| if (!ip.has_value()) { | ||
| return {Matcher::DataInputGetResult::DataAvailability::NotAvailable, absl::nullopt}; | ||
| } | ||
|
|
||
| return {Matcher::DataInputGetResult::DataAvailability::AllDataAvailable, ip->addressAsString()}; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Common base class for all the IP DataInputsFactory. | ||
| */ | ||
| template <class DataInputType, class ProtoType> | ||
| class IpDataInputFactoryBase : public Matcher::DataInputFactory<NetworkMatchingData> { | ||
| public: | ||
| explicit IpDataInputFactoryBase(const std::string& name) : name_(name) {} | ||
|
|
||
| std::string name() const override { return name_; } | ||
|
|
||
| Matcher::DataInputFactoryCb<NetworkMatchingData> | ||
| createDataInputFactoryCb(const Protobuf::Message&, ProtobufMessage::ValidationVisitor&) override { | ||
| return [] { return std::make_unique<DataInputType>(); }; | ||
| } | ||
| ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
| return std::make_unique<ProtoType>(); | ||
| } | ||
|
|
||
| private: | ||
| const std::string name_; | ||
| }; | ||
|
|
||
| class SourceIpDataInput : public IpDataInputBase { | ||
| public: | ||
| explicit SourceIpDataInput() = default; | ||
|
|
||
| OptRef<const Address::Ip> select(const NetworkMatchingData& data) const override { | ||
| return data.sourceIp(); | ||
| } | ||
| }; | ||
|
|
||
| class SourceIpDataInputFactory | ||
| : public IpDataInputFactoryBase<SourceIpDataInput, | ||
| envoy::type::matcher::v3::SourceIpMatchInput> { | ||
| public: | ||
| SourceIpDataInputFactory() : IpDataInputFactoryBase("source-ip") {} | ||
| }; | ||
|
|
||
| } // namespace Matching | ||
| } // namespace Network | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "router_interface", | ||
| hdrs = ["router.h"], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "router_lib", | ||
| srcs = ["router_impl.cc"], | ||
| hdrs = ["router_impl.h"], | ||
| deps = [ | ||
| ":router_interface", | ||
| "//source/common/common:empty_string", | ||
| "//source/common/matcher:matcher_lib", | ||
| "//source/common/matcher:validation_visitor_lib", | ||
| "//source/common/network/matching:inputs_lib", | ||
| "@envoy_api//envoy/extensions/filters/udp/udp_proxy/v3:pkg_cc_proto", | ||
| "@envoy_api//envoy/type/matcher/v3:pkg_cc_proto", | ||
| ], | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.