Skip to content
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

listener: add envoy internal listener #12838

Closed
wants to merge 115 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
fb1db47
core: add envoy internal address
lambdai Aug 27, 2020
6fceaf2
listener: add internal listener api
lambdai Aug 27, 2020
df05bba
rename Network::ListenerImpl and Network::ListenerCallbacks
lambdai Aug 27, 2020
d7cac74
rename file
lambdai Aug 27, 2020
be6f09d
scaffold of internal listener impl
lambdai Aug 27, 2020
d305855
add missing file
lambdai Aug 27, 2020
b6d9da5
remove client address and add tests
lambdai Aug 27, 2020
c413df9
Merge remote-tracking branch 'origin/master' into eiaddr
lambdai Aug 27, 2020
48e0640
remove unimplement to fix docs
lambdai Aug 28, 2020
e81a41e
guard internal address
lambdai Sep 3, 2020
72cd41d
Merge remote-tracking branch 'me/eiaddr' into eiaddr
lambdai Sep 3, 2020
a337bde
add integration test for NullIoSocketHandleImpl
lambdai Sep 3, 2020
dc87455
add integration test for NullIoSocketHandleImpl
lambdai Sep 3, 2020
3be784d
Merge branch 'eiaddr' of github.com:lambdai/envoy-dai into eiaddr
lambdai Sep 3, 2020
51914a9
fix spelling
lambdai Sep 4, 2020
f12c3d2
Merge remote-tracking branch 'origin/master' into eiaddr
lambdai Sep 4, 2020
219e0da
Merge branch 'eiaddr' into eilistener
lambdai Sep 4, 2020
f8816b0
incomplete impl of internal listener
lambdai Sep 9, 2020
bc57e78
adding active internal listener
lambdai Sep 9, 2020
4c2d693
add listener manager test
lambdai Sep 11, 2020
cfca895
refactor ConnectionSocketImpl: has SocketImpl instead of inherit
lambdai Sep 11, 2020
07c1ecb
rename listener to stream_listener in tcpsocket
lambdai Sep 14, 2020
171b1d9
extract generic listener filter
lambdai Sep 14, 2020
c99aa54
active internal socket
lambdai Sep 14, 2020
b25f28d
adding BufferedIoSocketHandleImpl, start with recv
lambdai Sep 17, 2020
73c5074
format
lambdai Sep 17, 2020
8439a67
add buffered_io_socket_handle_test
lambdai Sep 21, 2020
d7cff5c
add flow control test
lambdai Sep 21, 2020
808ea05
add EventScheduleBasic test
lambdai Sep 23, 2020
50479ca
add more event test
lambdai Sep 23, 2020
5fdec41
add test close
lambdai Sep 24, 2020
b55e03e
add shutdown test
lambdai Sep 24, 2020
4a7970c
fixing test: working on TestReadFlowAfterShutdownWrite
lambdai Sep 25, 2020
5ffedb4
close buffered_io_socket_handle_impl_test
lambdai Sep 25, 2020
7a972a5
Merge branch 'master' into eilistener
lambdai Sep 25, 2020
81d4c2e
add basic closing client connection test
lambdai Sep 26, 2020
32eca3f
add connection callback and active close test in CLosingClientImpl
lambdai Sep 27, 2020
80a9d2c
dispatcher: create internal connection to nowhere
lambdai Sep 28, 2020
a5572cb
fixing create connection
lambdai Sep 28, 2020
254daa4
basic internal client connection test
lambdai Sep 29, 2020
568e42b
fix connect probe and add client write test
lambdai Sep 29, 2020
953326b
various fixes: client id on dispatcher, StreamListener for active Int…
lambdai Sep 30, 2020
cd30f84
adding back chain tcp proxy integration test
lambdai Oct 1, 2020
95b5a54
fix all internal listener integration test
lambdai Oct 1, 2020
abbffa5
fix test
lambdai Oct 1, 2020
c1e6f4c
small fixes and comments
lambdai Oct 5, 2020
f860594
format
lambdai Oct 6, 2020
d90cbea
amend
lambdai Oct 6, 2020
80a9178
Merge remote-tracking branch 'origin/master' into bsock
lambdai Oct 6, 2020
622ab92
clean up and add impl ::read()
lambdai Oct 7, 2020
420e498
clang tidy
lambdai Oct 8, 2020
d9ef28f
Merge remote-tracking branch 'origin/master' into bsock
lambdai Oct 8, 2020
4c53d54
impl BufferedIoSocketHandleImpl:write
lambdai Oct 8, 2020
812a288
comment
lambdai Oct 8, 2020
06cbbac
Merge branch 'bsock' into eilistener
lambdai Oct 8, 2020
273447d
remove posix header file
lambdai Oct 8, 2020
1c82dad
fix
lambdai Oct 9, 2020
8aaeee6
fix error code on read EOS
lambdai Oct 9, 2020
9f810f2
fix error code on read EOS
lambdai Oct 9, 2020
6422a4f
address comments
lambdai Oct 13, 2020
a978ced
fix TestShutdown and close
lambdai Oct 13, 2020
0cf62b4
fix
lambdai Oct 13, 2020
09c1adf
fix log and comments
lambdai Oct 14, 2020
b73ced3
addressing comment
lambdai Oct 14, 2020
49bd8d6
remove event counter
lambdai Oct 14, 2020
55b9acc
more test and event counter fix
lambdai Oct 14, 2020
a1e0b2b
Merge branch 'bsock' of github.com:lambdai/envoy-dai into bsock
lambdai Oct 14, 2020
fb32d30
format
lambdai Oct 14, 2020
9361c49
add missing
lambdai Oct 15, 2020
baf755a
ASSERT_DEBUG_DEATH
lambdai Oct 15, 2020
a6686b4
coverage
lambdai Oct 15, 2020
2d93b61
coverage, cont
lambdai Oct 15, 2020
992c377
coverage, cont
lambdai Oct 15, 2020
d1a695d
more
lambdai Oct 15, 2020
683ad7f
split userspacefileeventimpl
lambdai Oct 21, 2020
673bca0
add missing files forgot to add to git
lambdai Oct 21, 2020
e59fa57
add scaffold of user space event test
lambdai Oct 22, 2020
b65e540
various fix: file event test not ready yet
lambdai Oct 22, 2020
9291161
Merge branch 'master' into bsock
lambdai Oct 22, 2020
437eb9b
complete user space file event test
lambdai Oct 22, 2020
9299130
fix destroy order in test
lambdai Oct 22, 2020
1b4a204
address comment: no schedule next, typo
lambdai Oct 27, 2020
e3d2839
Merge branch 'master' into bsock
lambdai Oct 28, 2020
58971d9
file event owned by io handle
lambdai Oct 28, 2020
119a9cb
fix format
lambdai Oct 28, 2020
f18fb59
address comment: also add fails_on_windows to track
lambdai Oct 28, 2020
b3e1264
fix cc format
lambdai Oct 28, 2020
7fb8f79
declare UserSpaceFileEventImpl final
lambdai Oct 28, 2020
1af2888
remove onEvents
lambdai Oct 29, 2020
9cdfd1b
fix user space event test
lambdai Oct 29, 2020
6ca32cf
fix buffer io socket handle test
lambdai Oct 29, 2020
fd7e7ea
clang tidy
lambdai Oct 29, 2020
bd745ab
clang tidy and test coverage
lambdai Oct 29, 2020
2e80156
ct
lambdai Oct 30, 2020
089526f
address comments
lambdai Oct 30, 2020
f203b6e
simplify test on new dtor
lambdai Oct 30, 2020
34b18ed
erase triggered events
lambdai Oct 30, 2020
83bd452
final and remove EventListener interface
lambdai Nov 2, 2020
c98c4f9
move to test extensions
lambdai Nov 2, 2020
8d87a54
ns Extensions::IoSocket::BufferedIoSocket
lambdai Nov 2, 2020
a876244
test: ns Extensions::IoSocket::BufferedIoSocket
lambdai Nov 2, 2020
f780926
codeformat and owners
lambdai Nov 2, 2020
aefff6a
moving peer buffer to extension
lambdai Nov 2, 2020
47cf2a8
save file
lambdai Nov 2, 2020
c4a336e
Merge remote-tracking branch 'origin/master' into bsock
lambdai Nov 2, 2020
6244c65
clangtidy wellknown names
lambdai Nov 3, 2020
a58a712
dup counter
lambdai Nov 3, 2020
1269e1e
extension and LT
lambdai Nov 5, 2020
c7ffacc
add staging
lambdai Nov 5, 2020
f2633f4
revert
lambdai Nov 5, 2020
2c7820a
Merge remote-tracking branch 'origin/master' into bsock
lambdai Nov 5, 2020
7c81f18
revert cont
lambdai Nov 5, 2020
e0b7fe5
add internal related factory
lambdai Nov 6, 2020
bef9b0d
Merge branch 'bsock' into eilistener
lambdai Nov 11, 2020
c1d3655
merge and fix all build issue
lambdai Nov 11, 2020
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: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ extensions/filters/http/oauth2 @rgs1 @derekargueta @snowp
# HTTP Local Rate Limit
/*/extensions/filters/http/local_ratelimit @rgs1 @mattklein123
/*/extensions/filters/common/local_ratelimit @mattklein123 @rgs1
# user space socket pair and event
/*/extensions/io_socket/buffered_io_socket @lambdai @antoniovicente
20 changes: 20 additions & 0 deletions api/envoy/config/listener/v3/internal_listener.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package envoy.config.listener.v3;

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

option java_package = "io.envoyproxy.envoy.config.listener.v3";
option java_outer_classname = "InternalListenerProto";
option java_multiple_files = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#not-implemented-hide:]
// [#protodoc-title: internal listener]
// Describes a type of internal listener which expects to serve the cluster in
// the same envoy process.
message InternalListener {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.listener.v2.InternalListener";
}
9 changes: 8 additions & 1 deletion api/envoy/config/listener/v3/listener.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "envoy/config/core/v3/base.proto";
import "envoy/config/core/v3/extension.proto";
import "envoy/config/core/v3/socket_option.proto";
import "envoy/config/listener/v3/api_listener.proto";
import "envoy/config/listener/v3/internal_listener.proto";
import "envoy/config/listener/v3/listener_components.proto";
import "envoy/config/listener/v3/udp_listener_config.proto";

Expand Down Expand Up @@ -36,7 +37,7 @@ message ListenerCollection {
repeated udpa.core.v1.CollectionEntry entries = 1;
}

// [#next-free-field: 26]
// [#next-free-field: 27]
message Listener {
option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.Listener";

Expand Down Expand Up @@ -267,4 +268,10 @@ message Listener {
// The maximum length a tcp listener's pending connections queue can grow to. If no value is
// provided net.core.somaxconn will be used on Linux and 128 otherwise.
google.protobuf.UInt32Value tcp_backlog_size = 24;

// Used to represent an internal listener, which accepts connection from the cluster in the same envoy process.
// When this field is set, the address field must be :ref:`envoy internal address
// <envoy_api_field_config.core.v3.EnvoyInternalAddress>`.
// [#not-implemented-hide:]
InternalListener internal_listener = 26;
}
20 changes: 20 additions & 0 deletions api/envoy/config/listener/v4alpha/internal_listener.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion api/envoy/config/listener/v4alpha/listener.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion generated_api_shadow/envoy/config/listener/v3/listener.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions include/envoy/event/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ class Dispatcher {
Network::TransportSocketPtr&& transport_socket,
const Network::ConnectionSocket::OptionsSharedPtr& options) PURE;

/**
* Creates an client internal connection. Does NOT initiate the connection;
* the caller must then call connect() on the returned Network::ClientConnection.
* @param internal_address supplies the internal address to connect to.
* @param local_address supplies an address to bind to or nullptr. If nullptr is provided, an
* internal local_address is automatically generated. This address is accessible by the server
* connection as source address.
* @return Network::ClientConnectionPtr a client connection that is owned by the caller.
*/
virtual Network::ClientConnectionPtr
createInternalConnection(Network::Address::InstanceConstSharedPtr internal_address,
Network::Address::InstanceConstSharedPtr local_address) PURE;
/**
* Creates an async DNS resolver. The resolver should only be used on the thread that runs this
* dispatcher.
Expand Down
4 changes: 4 additions & 0 deletions include/envoy/network/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class EnvoyInternalAddress {

enum class Type { Ip, Pipe, EnvoyInternal };

constexpr absl::string_view IpName = "Ip";
constexpr absl::string_view PipeName = "Pipe";
constexpr absl::string_view EnvoyInternalName = "EnvoyInternal";

/**
* Interface for all network addresses.
*/
Expand Down
20 changes: 20 additions & 0 deletions include/envoy/network/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ class ListenerConfig {
*/
virtual UdpPacketWriterFactoryOptRef udpPacketWriterFactory() PURE;

/**
* @return true if this listener is internal listener.
*/
virtual bool isInternalListener() PURE;

/**
* @return the ``UdpListenerWorkerRouter`` for this listener. This will
* be non-empty iff this is a UDP listener.
Expand Down Expand Up @@ -207,6 +212,21 @@ class TcpListenerCallbacks {
virtual void onReject(RejectCause cause) PURE;
};

/**
* Callbacks invoked by a internal listener.
*/
class InternalListenerCallbacks {
public:
virtual ~InternalListenerCallbacks() = default;

/**
* Called when a new internal connection is created.
* @param socket supplies the socket. Note that the underlying IoHandle has no file descriptor
* although the interface provides fd.
*/
virtual void onNewSocket(Network::ConnectionSocketPtr socket) PURE;
};

/**
* Utility struct that encapsulates the information from a udp socket's recvmmsg call.
*/
Expand Down
3 changes: 2 additions & 1 deletion source/common/event/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ envoy_cc_library(
"//source/common/common:assert_lib",
"//source/common/common:thread_lib",
"//source/common/filesystem:watcher_lib",
"//source/common/network:dns_lib",
"//source/extensions/io_socket/buffered_io_socket:buffered_io_socket_handle_lib",
"//source/common/network:connection_lib",
"//source/common/network:dns_lib",
"//source/common/network:listener_lib",
"//source/common/runtime:runtime_features_lib",
] + select({
Expand Down
70 changes: 70 additions & 0 deletions source/common/event/dispatcher_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <chrono>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>

Expand All @@ -18,8 +19,11 @@
#include "common/event/signal_impl.h"
#include "common/event/timer_impl.h"
#include "common/filesystem/watcher_impl.h"
#include "common/network/address_impl.h"
#include "extensions/io_socket/buffered_io_socket/buffered_io_socket_handle_impl.h"
#include "common/network/connection_impl.h"
#include "common/network/dns_impl.h"
#include "common/network/raw_buffer_socket.h"
#include "common/network/tcp_listener_impl.h"
#include "common/network/udp_listener_impl.h"
#include "common/runtime/runtime_features.h"
Expand Down Expand Up @@ -129,6 +133,72 @@ DispatcherImpl::createClientConnection(Network::Address::InstanceConstSharedPtr
std::move(transport_socket), options);
}

namespace {
Network::Address::InstanceConstSharedPtr
nextClientAddress(const Network::Address::InstanceConstSharedPtr& server_address) {
static uint64_t id = 0;
return std::make_shared<Network::Address::EnvoyInternalInstance>(
absl::StrCat(server_address->asStringView(), "_", ++id));
}
} // namespace

Network::ClientConnectionPtr
DispatcherImpl::createInternalConnection(Network::Address::InstanceConstSharedPtr internal_address,
Network::Address::InstanceConstSharedPtr local_address) {
ASSERT(isThreadSafe());
if (internal_address == nullptr) {
return nullptr;
}
if (local_address == nullptr) {
local_address = nextClientAddress(internal_address);
}
// Find the internal listener callback. The listener will set up the server connection.
auto iter = internal_listeners_.find(internal_address->asString());
for (const auto& [name, _] : internal_listeners_) {
ENVOY_LOG_MISC(debug, "lambdai: p listener {}", name);
}
if (iter == internal_listeners_.end()) {
ENVOY_LOG_MISC(debug, "lambdai: no valid listener registered for envoy internal address {}",
internal_address->asString());
return std::make_unique<Network::ClosingClientConnectionImpl>(*this, internal_address,
local_address);
}

auto client_io_handle_ = std::make_unique<Extensions::IoSocket::BufferedIoSocket::BufferedIoSocketHandleImpl>();
auto server_io_handle_ = std::make_unique<Extensions::IoSocket::BufferedIoSocket::BufferedIoSocketHandleImpl>();
client_io_handle_->setWritablePeer(server_io_handle_.get());
server_io_handle_->setWritablePeer(client_io_handle_.get());

Network::RawBufferSocketFactory client_transport_socket_factory;
// ConnectionSocket conn_socket
auto client_conn_socket = std::make_unique<Network::InternalConnectionSocketImpl>(
std::move(client_io_handle_), local_address, internal_address);
auto server_conn_socket = std::make_unique<Network::InternalConnectionSocketImpl>(
std::move(server_io_handle_), internal_address, local_address);
ENVOY_LOG_MISC(debug, "lambdai: internal address {}", internal_address->asString());
ENVOY_LOG_MISC(debug, "lambdai: client address {}", local_address->asString());

auto client_conn = std::make_unique<Network::ClientConnectionImpl>(
*this, internal_address, local_address,
client_transport_socket_factory.createTransportSocket(nullptr), nullptr,
std::move(client_conn_socket));

(iter->second)(internal_address, std::move(server_conn_socket));
return client_conn;
}

void DispatcherImpl::registerInternalListener(
const std::string& internal_listener_id,
DispatcherImpl::InternalConnectionCallback internal_conn_callback) {
if (internal_conn_callback == nullptr) {
ENVOY_LOG_MISC(debug, "lambdai: unregister pipe factory on address {}", internal_listener_id);
internal_listeners_.erase(internal_listener_id);
} else {
ENVOY_LOG_MISC(debug, "lambdai: register pipe factory on address {}", internal_listener_id);
internal_listeners_[internal_listener_id] = internal_conn_callback;
}
}

Network::DnsResolverSharedPtr DispatcherImpl::createDnsResolver(
const std::vector<Network::Address::InstanceConstSharedPtr>& resolvers,
const bool use_tcp_for_dns_lookups) {
Expand Down
Loading