From de85ff2a125a2c23378bd463259fbea3e05442f9 Mon Sep 17 00:00:00 2001 From: Greg Greenway Date: Tue, 19 Sep 2023 14:18:20 -0700 Subject: [PATCH] Revert "udp_session_filters: add HTTP capsule filter (#29569)" (#29714) This reverts commit e95324541b0e1cbfa07b43cbf87490cff7383f27. This change broke the compile_time_options CI job. Signed-off-by: Greg Greenway --- api/BUILD | 1 - .../udp_proxy/session/http_capsule/v3/BUILD | 9 - .../http_capsule/v3/http_capsule.proto | 18 -- .../filters/udp/udp_proxy/v3/udp_proxy.proto | 1 - api/versioning/BUILD | 1 - changelogs/current.yaml | 4 - docs/root/api-v3/config/filter/filter.rst | 1 - .../root/api-v3/config/filter/udp/session.rst | 8 - .../session_filters/http_capsule.rst | 13 -- .../listeners/udp_filters/udp_proxy.rst | 7 - source/extensions/extensions_build_config.bzl | 6 - source/extensions/extensions_metadata.yaml | 7 - .../udp_proxy/session_filters/filter_config.h | 2 +- .../session_filters/http_capsule/BUILD | 36 --- .../session_filters/http_capsule/config.cc | 32 --- .../session_filters/http_capsule/config.h | 37 --- .../http_capsule/http_capsule.cc | 87 ------- .../http_capsule/http_capsule.h | 56 ----- .../session_filters/http_capsule/BUILD | 40 ---- .../http_capsule/http_capsule_filter_test.cc | 213 ------------------ .../http_capsule_integration_test.cc | 199 ---------------- tools/extensions/extensions_schema.yaml | 1 - 22 files changed, 1 insertion(+), 778 deletions(-) delete mode 100644 api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/BUILD delete mode 100644 api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.proto delete mode 100644 docs/root/api-v3/config/filter/udp/session.rst delete mode 100644 docs/root/configuration/listeners/udp_filters/session_filters/http_capsule.rst delete mode 100644 source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD delete mode 100644 source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.cc delete mode 100644 source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.h delete mode 100644 source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.cc delete mode 100644 source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h delete mode 100644 test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD delete mode 100644 test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_filter_test.cc delete mode 100644 test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_integration_test.cc diff --git a/api/BUILD b/api/BUILD index 846242a3d544..37d46fa349dd 100644 --- a/api/BUILD +++ b/api/BUILD @@ -236,7 +236,6 @@ proto_library( "//envoy/extensions/filters/network/wasm/v3:pkg", "//envoy/extensions/filters/network/zookeeper_proxy/v3:pkg", "//envoy/extensions/filters/udp/dns_filter/v3:pkg", - "//envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3:pkg", "//envoy/extensions/filters/udp/udp_proxy/v3:pkg", "//envoy/extensions/formatter/cel/v3:pkg", "//envoy/extensions/formatter/metadata/v3:pkg", diff --git a/api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/BUILD b/api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/BUILD deleted file mode 100644 index ee92fb652582..000000000000 --- a/api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -# 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 = ["@com_github_cncf_udpa//udpa/annotations:pkg"], -) diff --git a/api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.proto b/api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.proto deleted file mode 100644 index e3455462b67f..000000000000 --- a/api/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package envoy.extensions.filters.udp.udp_proxy.session.http_capsule.v3; - -import "udpa/annotations/status.proto"; - -option java_package = "io.envoyproxy.envoy.extensions.filters.udp.udp_proxy.session.http_capsule.v3"; -option java_outer_classname = "HttpCapsuleProto"; -option java_multiple_files = true; -option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3;http_capsulev3"; -option (udpa.annotations.file_status).package_version_status = ACTIVE; - -// [#protodoc-title: UDP HTTP Capsule filter] -// UDP to HTTP capsules :ref:`overview `. -// [#extension: envoy.filters.udp.session.http_capsule] - -message FilterConfig { -} diff --git a/api/envoy/extensions/filters/udp/udp_proxy/v3/udp_proxy.proto b/api/envoy/extensions/filters/udp/udp_proxy/v3/udp_proxy.proto index 9d14b582cc69..25560b5c8c08 100644 --- a/api/envoy/extensions/filters/udp/udp_proxy/v3/udp_proxy.proto +++ b/api/envoy/extensions/filters/udp/udp_proxy/v3/udp_proxy.proto @@ -127,6 +127,5 @@ message UdpProxyConfig { // Optional session filters that will run for each UDP session. // Only one of use_per_packet_load_balancing or session_filters can be used. - // [#extension-category: envoy.filters.udp.session] repeated SessionFilter session_filters = 11; } diff --git a/api/versioning/BUILD b/api/versioning/BUILD index 902e803f3e9a..9b4dc169b54a 100644 --- a/api/versioning/BUILD +++ b/api/versioning/BUILD @@ -174,7 +174,6 @@ proto_library( "//envoy/extensions/filters/network/wasm/v3:pkg", "//envoy/extensions/filters/network/zookeeper_proxy/v3:pkg", "//envoy/extensions/filters/udp/dns_filter/v3:pkg", - "//envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3:pkg", "//envoy/extensions/filters/udp/udp_proxy/v3:pkg", "//envoy/extensions/formatter/cel/v3:pkg", "//envoy/extensions/formatter/metadata/v3:pkg", diff --git a/changelogs/current.yaml b/changelogs/current.yaml index 594159b83d07..07963281100e 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -256,10 +256,6 @@ new_features: change: | added :ref:` stats prefix option` to OTLP stats sink that enables adding a static prefix to all stats flushed by this sink. -- area: udp_proxy - change: | - added :ref:`http_capsule ` UDP session filter - that can be used to encapsule or decapsulate UDP datagrams in HTTP, when used for UDP tunneling. - area: tap change: | added :ref:`record_headers_received_time ` diff --git a/docs/root/api-v3/config/filter/filter.rst b/docs/root/api-v3/config/filter/filter.rst index c12835d917df..c076e80f6c28 100644 --- a/docs/root/api-v3/config/filter/filter.rst +++ b/docs/root/api-v3/config/filter/filter.rst @@ -8,7 +8,6 @@ Filters listener/listener network/network udp/udp - udp/session http/http dubbo/dubbo thrift/thrift diff --git a/docs/root/api-v3/config/filter/udp/session.rst b/docs/root/api-v3/config/filter/udp/session.rst deleted file mode 100644 index d42591853d0d..000000000000 --- a/docs/root/api-v3/config/filter/udp/session.rst +++ /dev/null @@ -1,8 +0,0 @@ -UDP session filters -==================== - -.. toctree:: - :glob: - :maxdepth: 2 - - ../../../extensions/filters/udp/udp_proxy/session/*/v3/* diff --git a/docs/root/configuration/listeners/udp_filters/session_filters/http_capsule.rst b/docs/root/configuration/listeners/udp_filters/session_filters/http_capsule.rst deleted file mode 100644 index 17defd1d0f7d..000000000000 --- a/docs/root/configuration/listeners/udp_filters/session_filters/http_capsule.rst +++ /dev/null @@ -1,13 +0,0 @@ -.. _config_udp_session_filters_http_capsule: - -HTTP Capsule filter -================================== - -Tunneling UDP datagrams over HTTP (see `Proxying UDP in HTTP `_) requires an encapsulation mechanism to preserve the boundaries of the original datagram. -This filter applies the `HTTP Datagrams and the Capsule Protocol `_ to downstream and upstream datagrams, so they are compliant with the Capsule Protocol. - -.. note:: - This filter must be used last in the UDP session filter chain, and should only be used when tunneling UDP over HTTP streams. - -* This filter should be configured with the type URL ``type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.session.http_capsule.v3.FilterConfig``. -* :ref:`v3 API reference ` diff --git a/docs/root/configuration/listeners/udp_filters/udp_proxy.rst b/docs/root/configuration/listeners/udp_filters/udp_proxy.rst index 42d8b2179868..209db74c26a3 100644 --- a/docs/root/configuration/listeners/udp_filters/udp_proxy.rst +++ b/docs/root/configuration/listeners/udp_filters/udp_proxy.rst @@ -89,13 +89,6 @@ upstream, similar to network filters. Additionally, since :ref:`per packet load balancing ` require choosing the upstream host for each received datagram, session filters can't be used when this option is enabled. -Envoy has the following builtin UDP session filters. - -.. toctree:: - :maxdepth: 2 - - session_filters/http_capsule - Example configuration --------------------- diff --git a/source/extensions/extensions_build_config.bzl b/source/extensions/extensions_build_config.bzl index 2578c123b020..d6164dacef35 100644 --- a/source/extensions/extensions_build_config.bzl +++ b/source/extensions/extensions_build_config.bzl @@ -213,12 +213,6 @@ EXTENSIONS = { "envoy.filters.udp.dns_filter": "//source/extensions/filters/udp/dns_filter:config", "envoy.filters.udp_listener.udp_proxy": "//source/extensions/filters/udp/udp_proxy:config", - # - # UDP Session filters - # - - "envoy.filters.udp.session.http_capsule": "//source/extensions/filters/udp/udp_proxy/session_filters/http_capsule:config", - # # Resource monitors # diff --git a/source/extensions/extensions_metadata.yaml b/source/extensions/extensions_metadata.yaml index 368a714beceb..096095d664bd 100644 --- a/source/extensions/extensions_metadata.yaml +++ b/source/extensions/extensions_metadata.yaml @@ -749,13 +749,6 @@ envoy.filters.udp_listener.udp_proxy: status: stable type_urls: - envoy.extensions.filters.udp.udp_proxy.v3.UdpProxyConfig -envoy.filters.udp.session.http_capsule: - categories: - - envoy.filters.udp.session - security_posture: robust_to_untrusted_downstream - status: alpha - type_urls: - - envoy.extensions.filters.udp.udp_proxy.session.http_capsule.v3.FilterConfig envoy.formatter.cel: categories: - envoy.formatter diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/filter_config.h b/source/extensions/filters/udp/udp_proxy/session_filters/filter_config.h index 07b41415b554..e89be71de9ad 100644 --- a/source/extensions/filters/udp/udp_proxy/session_filters/filter_config.h +++ b/source/extensions/filters/udp/udp_proxy/session_filters/filter_config.h @@ -33,7 +33,7 @@ class NamedUdpSessionFilterConfigFactory : public Envoy::Config::TypedFactory { createFilterFactoryFromProto(const Protobuf::Message& config, Server::Configuration::FactoryContext& context) PURE; - std::string category() const override { return "envoy.filters.udp.session"; } + std::string category() const override { return "envoy.udp.session_filters"; } }; } // namespace SessionFilters diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD b/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD deleted file mode 100644 index ebcf8ddce81d..000000000000 --- a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD +++ /dev/null @@ -1,36 +0,0 @@ -load( - "//bazel:envoy_build_system.bzl", - "envoy_cc_extension", - "envoy_cc_library", - "envoy_extension_package", -) - -licenses(["notice"]) # Apache 2 - -envoy_extension_package() - -envoy_cc_library( - name = "http_capsule_filter_lib", - srcs = ["http_capsule.cc"], - hdrs = ["http_capsule.h"], - deps = [ - "//source/common/common:assert_lib", - "//source/common/common:hex_lib", - "//source/extensions/filters/udp/udp_proxy/session_filters:filter_interface", - "@com_github_google_quiche//:quic_core_http_spdy_session_lib", - "@com_github_google_quiche//:quic_core_types_lib", - "@com_github_google_quiche//:quiche_common_connect_udp_datagram_payload_lib", - "@envoy_api//envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3:pkg_cc_proto", - ], -) - -envoy_cc_extension( - name = "config", - srcs = ["config.cc"], - hdrs = ["config.h"], - deps = [ - ":http_capsule_filter_lib", - "//source/extensions/filters/udp/udp_proxy/session_filters:factory_base_lib", - "@envoy_api//envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3:pkg_cc_proto", - ], -) diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.cc b/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.cc deleted file mode 100644 index 524777452da9..000000000000 --- a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include "source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.h" - -#include "envoy/registry/registry.h" -#include "envoy/server/filter_config.h" - -#include "source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h" - -namespace Envoy { -namespace Extensions { -namespace UdpFilters { -namespace UdpProxy { -namespace SessionFilters { -namespace HttpCapsule { - -FilterFactoryCb HttpCapsuleFilterConfigFactory::createFilterFactoryFromProtoTyped( - const FilterConfig&, Server::Configuration::FactoryContext& context) { - return [&context](FilterChainFactoryCallbacks& callbacks) -> void { - callbacks.addFilter(std::make_shared(context.timeSource())); - }; -} - -/** - * Static registration for the http_capsule filter. @see RegisterFactory. - */ -REGISTER_FACTORY(HttpCapsuleFilterConfigFactory, NamedUdpSessionFilterConfigFactory); - -} // namespace HttpCapsule -} // namespace SessionFilters -} // namespace UdpProxy -} // namespace UdpFilters -} // namespace Extensions -} // namespace Envoy diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.h b/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.h deleted file mode 100644 index 3ac7f37a5911..000000000000 --- a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.pb.h" -#include "envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.pb.validate.h" - -#include "source/extensions/filters/udp/udp_proxy/session_filters/factory_base.h" - -namespace Envoy { -namespace Extensions { -namespace UdpFilters { -namespace UdpProxy { -namespace SessionFilters { -namespace HttpCapsule { - -using FilterConfig = - envoy::extensions::filters::udp::udp_proxy::session::http_capsule::v3::FilterConfig; - -/** - * Config registration for the http_capsule filter. @see - * NamedNetworkFilterConfigFactory. - */ -class HttpCapsuleFilterConfigFactory : public FactoryBase { -public: - HttpCapsuleFilterConfigFactory() : FactoryBase("envoy.filters.udp.session.http_capsule"){}; - -private: - FilterFactoryCb - createFilterFactoryFromProtoTyped(const FilterConfig& proto_config, - Server::Configuration::FactoryContext& context) override; -}; - -} // namespace HttpCapsule -} // namespace SessionFilters -} // namespace UdpProxy -} // namespace UdpFilters -} // namespace Extensions -} // namespace Envoy diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.cc b/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.cc deleted file mode 100644 index 4e7b0f67ec02..000000000000 --- a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.cc +++ /dev/null @@ -1,87 +0,0 @@ -#include "source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h" - -#include "source/common/common/hex.h" - -#include "absl/strings/escaping.h" -#include "quiche/common/masque/connect_udp_datagram_payload.h" -#include "quiche/common/simple_buffer_allocator.h" -#include "quiche/quic/core/http/quic_spdy_stream.h" - -namespace Envoy { -namespace Extensions { -namespace UdpFilters { -namespace UdpProxy { -namespace SessionFilters { -namespace HttpCapsule { - -ReadFilterStatus HttpCapsuleFilter::onData(Network::UdpRecvData& data) { - std::string buffer = data.buffer_->toString(); - quiche::ConnectUdpDatagramUdpPacketPayload payload(buffer); - quiche::QuicheBuffer serialized_capsule = - SerializeCapsule(quiche::Capsule::Datagram(payload.Serialize()), &capsule_buffer_allocator_); - - data.buffer_->drain(data.buffer_->length()); - data.buffer_->add(serialized_capsule.AsStringView()); - return ReadFilterStatus::Continue; -} - -WriteFilterStatus HttpCapsuleFilter::onWrite(Network::UdpRecvData& data) { - // TODO(ohadvano): add filter callbacks to get addresses instead of saving them. - local_address_ = data.addresses_.local_; - peer_address_ = data.addresses_.peer_; - - for (const Buffer::RawSlice& slice : data.buffer_->getRawSlices()) { - absl::string_view mem_slice(reinterpret_cast(slice.mem_), slice.len_); - if (!capsule_parser_.IngestCapsuleFragment(mem_slice)) { - ENVOY_LOG(error, "Capsule ingestion error occured: slice length = {}", slice.len_); - break; - } - } - - // We always stop here as OnCapsule() callback will be responsible to inject - // datagrams to the filter chain once they are ready. - data.buffer_->drain(data.buffer_->length()); - return WriteFilterStatus::StopIteration; -} - -bool HttpCapsuleFilter::OnCapsule(const quiche::Capsule& capsule) { - quiche::CapsuleType capsule_type = capsule.capsule_type(); - if (capsule_type != quiche::CapsuleType::DATAGRAM) { - // Silently drops capsules with an unknown type. - return true; - } - - std::unique_ptr connect_udp_datagram_payload = - quiche::ConnectUdpDatagramPayload::Parse(capsule.datagram_capsule().http_datagram_payload); - if (!connect_udp_datagram_payload) { - // Indicates parsing failure to reset the data stream. - ENVOY_LOG(debug, "capsule parsing error"); - return false; - } - - if (connect_udp_datagram_payload->GetType() != - quiche::ConnectUdpDatagramPayload::Type::kUdpPacket) { - // Silently drops Datagrams with an unknown Context ID. - return true; - } - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(connect_udp_datagram_payload->GetUdpProxyingPayload()); - datagram.receive_time_ = time_source_.monotonicTime(); - datagram.addresses_ = {local_address_, peer_address_}; - - write_callbacks_->injectDatagramToFilterChain(datagram); - return true; -} - -void HttpCapsuleFilter::OnCapsuleParseFailure(absl::string_view reason) { - ENVOY_LOG(debug, "capsule parse failure: {}", reason); -} - -} // namespace HttpCapsule -} // namespace SessionFilters -} // namespace UdpProxy -} // namespace UdpFilters -} // namespace Extensions -} // namespace Envoy diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h b/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h deleted file mode 100644 index 7cecae66bf7d..000000000000 --- a/source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include "envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.pb.h" - -#include "source/common/common/logger.h" -#include "source/extensions/filters/udp/udp_proxy/session_filters/filter.h" - -#include "quiche/common/simple_buffer_allocator.h" -#include "quiche/quic/core/http/quic_spdy_stream.h" - -namespace Envoy { -namespace Extensions { -namespace UdpFilters { -namespace UdpProxy { -namespace SessionFilters { -namespace HttpCapsule { - -class HttpCapsuleFilter : public Filter, - public quiche::CapsuleParser::Visitor, - Logger::Loggable { -public: - HttpCapsuleFilter(TimeSource& time_source) : time_source_(time_source) {} - - // ReadFilter - ReadFilterStatus onNewSession() override { return ReadFilterStatus::Continue; } - ReadFilterStatus onData(Network::UdpRecvData& data) override; - void initializeReadFilterCallbacks(ReadFilterCallbacks& callbacks) override { - read_callbacks_ = &callbacks; - } - - // WriteFilter - WriteFilterStatus onWrite(Network::UdpRecvData& data) override; - void initializeWriteFilterCallbacks(WriteFilterCallbacks& callbacks) override { - write_callbacks_ = &callbacks; - } - - // quiche::CapsuleParser::Visitor - bool OnCapsule(const quiche::Capsule& capsule) override; - void OnCapsuleParseFailure(absl::string_view error_message) override; - -private: - ReadFilterCallbacks* read_callbacks_{}; - WriteFilterCallbacks* write_callbacks_{}; - quiche::CapsuleParser capsule_parser_{this}; - quiche::SimpleBufferAllocator capsule_buffer_allocator_; - Network::Address::InstanceConstSharedPtr local_address_; - Network::Address::InstanceConstSharedPtr peer_address_; - TimeSource& time_source_; -}; - -} // namespace HttpCapsule -} // namespace SessionFilters -} // namespace UdpProxy -} // namespace UdpFilters -} // namespace Extensions -} // namespace Envoy diff --git a/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD b/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD deleted file mode 100644 index eebb7aeeb83c..000000000000 --- a/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/BUILD +++ /dev/null @@ -1,40 +0,0 @@ -load( - "//bazel:envoy_build_system.bzl", - "envoy_package", -) -load( - "//test/extensions:extensions_build_system.bzl", - "envoy_extension_cc_test", -) - -licenses(["notice"]) # Apache 2 - -envoy_package() - -envoy_extension_cc_test( - name = "http_capsule_filter_test", - srcs = ["http_capsule_filter_test.cc"], - extension_names = ["envoy.filters.udp.session.http_capsule"], - deps = [ - "//source/extensions/filters/udp/udp_proxy/session_filters/http_capsule:config", - "//test/extensions/filters/udp/udp_proxy:mocks", - "//test/mocks/server:factory_context_mocks", - "@envoy_api//envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3:pkg_cc_proto", - ], -) - -envoy_extension_cc_test( - name = "http_capsule_integration_test", - srcs = ["http_capsule_integration_test.cc"], - extension_names = ["envoy.filters.udp.session.http_capsule"], - deps = [ - "//envoy/network:filter_interface", - "//envoy/server:filter_config_interface", - "//source/extensions/filters/udp/udp_proxy:config", - "//source/extensions/filters/udp/udp_proxy/session_filters/http_capsule:config", - "//source/extensions/filters/udp/udp_proxy/session_filters/http_capsule:http_capsule_filter_lib", - "//test/integration:integration_lib", - "//test/test_common:registry_lib", - "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", - ], -) diff --git a/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_filter_test.cc b/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_filter_test.cc deleted file mode 100644 index 0171a998ae41..000000000000 --- a/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_filter_test.cc +++ /dev/null @@ -1,213 +0,0 @@ -#include "envoy/extensions/filters/udp/udp_proxy/session/http_capsule/v3/http_capsule.pb.h" - -#include "source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h" - -#include "test/extensions/filters/udp/udp_proxy/mocks.h" -#include "test/mocks/server/factory_context.h" - -using testing::Eq; -using testing::NiceMock; -using testing::Return; - -namespace Envoy { -namespace Extensions { -namespace UdpFilters { -namespace UdpProxy { -namespace SessionFilters { -namespace HttpCapsule { -namespace { - -class HttpCapsuleFilterTest : public testing::Test { -public: - void setup() { - filter_ = std::make_unique(server_context_.timeSource()); - filter_->initializeReadFilterCallbacks(read_callbacks_); - filter_->initializeWriteFilterCallbacks(write_callbacks_); - } - - NiceMock server_context_; - std::unique_ptr filter_; - NiceMock read_callbacks_; - NiceMock write_callbacks_; - NiceMock stream_info_; -}; - -TEST_F(HttpCapsuleFilterTest, ContinueOnNewSession) { - setup(); - EXPECT_EQ(ReadFilterStatus::Continue, filter_->onNewSession()); -} - -TEST_F(HttpCapsuleFilterTest, EncapsulateEmptyDatagram) { - setup(); - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - EXPECT_EQ(ReadFilterStatus::Continue, filter_->onData(datagram)); - - const std::string expected_data = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "01" // Capsule length - "00" // Context ID - ); - - EXPECT_EQ(expected_data, datagram.buffer_->toString()); -} - -TEST_F(HttpCapsuleFilterTest, EncapsulateDatagram) { - setup(); - - const std::string payload = "payload"; - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(payload); - EXPECT_EQ(ReadFilterStatus::Continue, filter_->onData(datagram)); - - const std::string expected_data = - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "08" // Capsule Length = length(payload) + 1 - "00" // Context ID - ) + - payload; - - EXPECT_EQ(expected_data, datagram.buffer_->toString()); -} - -TEST_F(HttpCapsuleFilterTest, InvalidCapsule) { - setup(); - - const std::string invalid_context_id_fragment = - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "01" // Capsule Length - "c0" // Context ID (Invalid VarInt62) - ); - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(invalid_context_id_fragment); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)).Times(0); - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(datagram)); - EXPECT_EQ(0, datagram.buffer_->length()); -} - -TEST_F(HttpCapsuleFilterTest, IncompatibleCapsule) { - setup(); - - const std::string unexpected_capsule_fragment = - absl::HexStringToBytes("17" // Capsule Type is not DATAGRAM - "01" // Capsule Length - "00" // Unknown capsule payload - ); - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(unexpected_capsule_fragment); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)).Times(0); - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(datagram)); - EXPECT_EQ(0, datagram.buffer_->length()); -} - -TEST_F(HttpCapsuleFilterTest, UnknownContextId) { - setup(); - - const std::string invalid_context_id_fragment = - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "01" // Capsule Length - "01" // Unknown Context ID - ); - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(invalid_context_id_fragment); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)).Times(0); - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(datagram)); - EXPECT_EQ(0, datagram.buffer_->length()); -} - -TEST_F(HttpCapsuleFilterTest, DecapsulateDatagram) { - setup(); - - const std::string payload = "payload"; - const std::string capsule = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "08" // Capsule Length = length(payload) + 1 - "00" // Context ID - ) + - payload; - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(capsule); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)) - .WillOnce(Invoke([payload](Network::UdpRecvData& data) -> void { - EXPECT_EQ(payload, data.buffer_->toString()); - })); - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(datagram)); - EXPECT_EQ(0, datagram.buffer_->length()); -} - -TEST_F(HttpCapsuleFilterTest, DecapsulateSplitPayload) { - setup(); - - const std::string payload = "payload"; - const std::string capsule = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "08" // Capsule Length = length(payload) + 1 - "00" // Context ID - ) + - payload; - - int pivot_index = 4; // Some arbitrary split index of the capsule. - - // Send first part of the capsule and verify that a datagram was not injected. - Network::UdpRecvData payload1; - payload1.buffer_ = std::make_unique(); - payload1.buffer_->add(capsule.substr(0, pivot_index)); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)).Times(0); - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(payload1)); - EXPECT_EQ(0, payload1.buffer_->length()); - - // Send second part of the capsule and verify that a datagram was generated. - Network::UdpRecvData payload2; - payload2.buffer_ = std::make_unique(); - payload2.buffer_->add(capsule.substr(pivot_index)); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)) - .WillOnce(Invoke([payload](Network::UdpRecvData& data) -> void { - EXPECT_EQ(payload, data.buffer_->toString()); - })); - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(payload2)); - EXPECT_EQ(0, payload2.buffer_->length()); -} - -TEST_F(HttpCapsuleFilterTest, DecapsulateMultipleDatagrams) { - setup(); - - const std::string capsule = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "09" // Capsule Length = length(payload1) + 1 - "00" // Context ID - ) + - "payload1" + - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "09" // Capsule Length = length(payload2) + 1 - "00" // Context ID - ) + - "payload2"; - - Network::UdpRecvData datagram; - datagram.buffer_ = std::make_unique(); - datagram.buffer_->add(capsule); - EXPECT_CALL(write_callbacks_, injectDatagramToFilterChain(_)) - .WillOnce(Invoke([](Network::UdpRecvData& data) -> void { - EXPECT_EQ("payload1", data.buffer_->toString()); - })) - .WillOnce(Invoke([](Network::UdpRecvData& data) -> void { - EXPECT_EQ("payload2", data.buffer_->toString()); - })); - - EXPECT_EQ(WriteFilterStatus::StopIteration, filter_->onWrite(datagram)); - EXPECT_EQ(0, datagram.buffer_->length()); -} - -} // namespace -} // namespace HttpCapsule -} // namespace SessionFilters -} // namespace UdpProxy -} // namespace UdpFilters -} // namespace Extensions -} // namespace Envoy diff --git a/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_integration_test.cc b/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_integration_test.cc deleted file mode 100644 index 9976e03f76cf..000000000000 --- a/test/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule_integration_test.cc +++ /dev/null @@ -1,199 +0,0 @@ -#include "envoy/config/bootstrap/v3/bootstrap.pb.h" -#include "envoy/network/filter.h" -#include "envoy/server/filter_config.h" - -#include "source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/config.h" -#include "source/extensions/filters/udp/udp_proxy/session_filters/http_capsule/http_capsule.h" - -#include "test/integration/integration.h" -#include "test/test_common/network_utility.h" -#include "test/test_common/registry.h" - -namespace Envoy { -namespace Extensions { -namespace UdpFilters { -namespace UdpProxy { -namespace SessionFilters { -namespace HttpCapsule { -namespace { - -class HttpCapsuleIntegrationTest : public testing::TestWithParam, - public BaseIntegrationTest { -public: - HttpCapsuleIntegrationTest() - : BaseIntegrationTest(GetParam(), ConfigHelper::baseUdpListenerConfig()) {} - - void setup() { - setUdpFakeUpstream(FakeUpstreamConfig::UdpConfig()); - - config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) { - std::string filter_config = fmt::format(R"EOF( -name: udp_proxy -typed_config: - '@type': type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.v3.UdpProxyConfig - stat_prefix: foo - matcher: - on_no_match: - action: - name: route - typed_config: - '@type': type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.v3.Route - cluster: cluster_0 - session_filters: - - name: http_capsule - typed_config: - '@type': type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.session.http_capsule.v3.FilterConfig -)EOF"); - - auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0); - auto* filter = listener->add_listener_filters(); - TestUtility::loadFromYaml(filter_config, *filter); - }); - - BaseIntegrationTest::initialize(); - } -}; - -INSTANTIATE_TEST_SUITE_P(IpVersions, HttpCapsuleIntegrationTest, - testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), - TestUtility::ipTestParamsToString); - -TEST_P(HttpCapsuleIntegrationTest, BasicFlow) { - setup(); - - const uint32_t port = lookupPort("listener_0"); - const auto listener_address = Network::Utility::resolveUrl( - fmt::format("tcp://{}:{}", Network::Test::getLoopbackAddressUrlString(version_), port)); - - const std::string request = "hello"; - const std::string expected_request = - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "06" // Capsule Length = length(hello) + 1 - "00" // Context ID - ) + - request; - - const std::string expected_response = "world"; - const std::string response = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "06" // Capsule Length = length(world) + 1 - "00" // Context ID - ) + - expected_response; - - // Send datagram to be encapsulated. - Network::Test::UdpSyncPeer client(version_, Network::DEFAULT_UDP_MAX_DATAGRAM_SIZE); - client.write(request, *listener_address); - - // Wait for the upstream datagram. - Network::UdpRecvData request_datagram; - ASSERT_TRUE(fake_upstreams_[0]->waitForUdpDatagram(request_datagram)); - EXPECT_EQ(expected_request, request_datagram.buffer_->toString()); - - // Respond from the upstream. - fake_upstreams_[0]->sendUdpDatagram(response, request_datagram.addresses_.peer_); - Network::UdpRecvData response_datagram; - client.recv(response_datagram); - EXPECT_EQ(expected_response, response_datagram.buffer_->toString()); -} - -TEST_P(HttpCapsuleIntegrationTest, SendSplitCapsule) { - setup(); - - const uint32_t port = lookupPort("listener_0"); - const auto listener_address = Network::Utility::resolveUrl( - fmt::format("tcp://{}:{}", Network::Test::getLoopbackAddressUrlString(version_), port)); - - const std::string request = "hello"; - const std::string expected_request = - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "06" // Capsule Length = length(hello) + 1 - "00" // Context ID - ) + - request; - - const std::string expected_response = "world"; - const std::string response = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "06" // Capsule Length = length(world) + 1 - "00" // Context ID - ) + - expected_response; - - // Send datagram to be encapsulated. - Network::Test::UdpSyncPeer client(version_, Network::DEFAULT_UDP_MAX_DATAGRAM_SIZE); - client.write(request, *listener_address); - - // Wait for the upstream datagram. - Network::UdpRecvData request_datagram; - ASSERT_TRUE(fake_upstreams_[0]->waitForUdpDatagram(request_datagram)); - EXPECT_EQ(expected_request, request_datagram.buffer_->toString()); - - // Respond from the upstream. - int pivot_index = 4; - fake_upstreams_[0]->sendUdpDatagram(response.substr(0, pivot_index), - request_datagram.addresses_.peer_); - // Make sure that only one payload received, but none sent downstream because it's not a complete - // capsule. - test_server_->waitForCounterEq("cluster.cluster_0.udp.sess_rx_datagrams", 1); - EXPECT_EQ(0, test_server_->counter("udp.foo.downstream_sess_tx_datagrams")->value()); - - // Sending the rest of the capsule, so we expect a datagram flushed downstream. - fake_upstreams_[0]->sendUdpDatagram(response.substr(pivot_index), - request_datagram.addresses_.peer_); - Network::UdpRecvData response_datagram; - client.recv(response_datagram); - EXPECT_EQ(expected_response, response_datagram.buffer_->toString()); - test_server_->waitForCounterEq("cluster.cluster_0.udp.sess_rx_datagrams", 2); - test_server_->waitForCounterEq("udp.foo.downstream_sess_tx_datagrams", 1); -} - -TEST_P(HttpCapsuleIntegrationTest, SendMultipleCapsules) { - setup(); - - const uint32_t port = lookupPort("listener_0"); - const auto listener_address = Network::Utility::resolveUrl( - fmt::format("tcp://{}:{}", Network::Test::getLoopbackAddressUrlString(version_), port)); - - const std::string request = "hello"; - const std::string expected_request = - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "06" // Capsule Length = length(hello) + 1 - "00" // Context ID - ) + - request; - - std::string response = absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "0A" // Capsule Length = length(response1) + 1 - "00" // Context ID - ) + - "response1" + - absl::HexStringToBytes("00" // DATAGRAM Capsule Type - "0A" // Capsule Length = length(response2) + 1 - "00" // Context ID - ) + - "response2"; - - // Send datagram to be encapsulated. - Network::Test::UdpSyncPeer client(version_, Network::DEFAULT_UDP_MAX_DATAGRAM_SIZE); - client.write(request, *listener_address); - - // Wait for the upstream datagram. - Network::UdpRecvData request_datagram; - ASSERT_TRUE(fake_upstreams_[0]->waitForUdpDatagram(request_datagram)); - EXPECT_EQ(expected_request, request_datagram.buffer_->toString()); - - // // Respond from the upstream. - fake_upstreams_[0]->sendUdpDatagram(response, request_datagram.addresses_.peer_); - Network::UdpRecvData response_datagram; - client.recv(response_datagram); - EXPECT_EQ("response1", response_datagram.buffer_->toString()); - test_server_->waitForCounterEq("cluster.cluster_0.udp.sess_rx_datagrams", 1); - test_server_->waitForCounterEq("udp.foo.downstream_sess_tx_datagrams", 2); -} - -} // namespace -} // namespace HttpCapsule -} // namespace SessionFilters -} // namespace UdpProxy -} // namespace UdpFilters -} // namespace Extensions -} // namespace Envoy diff --git a/tools/extensions/extensions_schema.yaml b/tools/extensions/extensions_schema.yaml index 36181fb61786..9de574f19311 100644 --- a/tools/extensions/extensions_schema.yaml +++ b/tools/extensions/extensions_schema.yaml @@ -73,7 +73,6 @@ categories: - envoy.filters.listener - envoy.filters.network - envoy.filters.udp_listener -- envoy.filters.udp.session - envoy.filters.quic_listener - envoy.formatter - envoy.geoip_providers