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

extension: User space io socket #14917

Merged
merged 23 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 source/extensions/io_socket/user_space/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ envoy_cc_library(
":file_event_lib",
":io_handle_lib",
"//source/common/event:dispatcher_includes",
"//source/common/network:address_lib",
"//source/common/network:default_socket_interface_lib",
],
)
13 changes: 9 additions & 4 deletions source/extensions/io_socket/user_space/io_handle_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ uint64_t move(Buffer::Instance& dst, Buffer::Instance& src, uint64_t max_length)
}
} // namespace

const Network::Address::InstanceConstSharedPtr& IoHandleImpl::getCommonInternalAddress() {
CONSTRUCT_ON_FIRST_USE(Network::Address::InstanceConstSharedPtr,
// std::static_pointer_cast<Network::Address::InstanceSharedPtr>(
lambdai marked this conversation as resolved.
Show resolved Hide resolved
std::make_shared<const Network::Address::EnvoyInternalInstance>(
"internal_address_for_user_space_io_handle"));
}

IoHandleImpl::IoHandleImpl()
: pending_received_data_([&]() -> void { this->onBelowLowWatermark(); },
[&]() -> void { this->onAboveHighWatermark(); }, []() -> void {}) {}
Expand Down Expand Up @@ -286,13 +293,11 @@ Api::SysCallIntResult IoHandleImpl::setBlocking(bool) { return makeInvalidSyscal
absl::optional<int> IoHandleImpl::domain() { return absl::nullopt; }

Network::Address::InstanceConstSharedPtr IoHandleImpl::localAddress() {
// TODO(lambdai): Rewrite when caller accept error as the return value.
throw EnvoyException(fmt::format("getsockname failed for IoHandleImpl"));
return IoHandleImpl::getCommonInternalAddress();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd. All internal handles have the same address, no way to log which is which.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how can this address be used....
This address doesn't provide the ability to connect to or listen. The connection socket could use AddressProvider to set the view of local address and remote address anyway

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address may be useful in logs to tell what is connected to what.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it to the next phase when we do pass a reasonable address to IoHandleImpl

}

Network::Address::InstanceConstSharedPtr IoHandleImpl::peerAddress() {
// TODO(lambdai): Rewrite when caller accept error as the return value.
throw EnvoyException(fmt::format("getsockname failed for IoHandleImpl"));
return IoHandleImpl::getCommonInternalAddress();
}

void IoHandleImpl::initializeFileEvent(Event::Dispatcher& dispatcher, Event::FileReadyCb cb,
Expand Down
3 changes: 3 additions & 0 deletions source/extensions/io_socket/user_space/io_handle_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "envoy/api/os_sys_calls.h"
#include "envoy/common/platform.h"
#include "envoy/event/dispatcher.h"
#include "envoy/network/address.h"
#include "envoy/network/io_handle.h"

#include "common/buffer/watermark_buffer.h"
Expand Down Expand Up @@ -37,6 +38,8 @@ class IoHandleImpl final : public Network::IoHandle,
protected Logger::Loggable<Logger::Id::io>,
NonCopyable {
public:
static const Network::Address::InstanceConstSharedPtr& getCommonInternalAddress();
lambdai marked this conversation as resolved.
Show resolved Hide resolved

~IoHandleImpl() override;

// Network::IoHandle
Expand Down
18 changes: 13 additions & 5 deletions test/extensions/io_socket/user_space/io_handle_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,19 @@ TEST_F(IoHandleImplTest, NotifyWritableAfterShutdownWrite) {
io_handle_peer_->close();
}

TEST_F(IoHandleImplTest, ReturnValidInternalAddress) {
const auto& local_address = io_handle_->peerAddress();
ASSERT_NE(nullptr, local_address);
ASSERT_EQ(nullptr, local_address->ip());
ASSERT_EQ(nullptr, local_address->pipe());
ASSERT_NE(nullptr, local_address->envoyInternalAddress());
const auto& remote_address = io_handle_->peerAddress();
ASSERT_NE(nullptr, remote_address);
ASSERT_EQ(nullptr, remote_address->ip());
ASSERT_EQ(nullptr, remote_address->pipe());
ASSERT_NE(nullptr, remote_address->envoyInternalAddress());
}

TEST_F(IoHandleImplTest, NotSupportingMmsg) { EXPECT_FALSE(io_handle_->supportsMmsg()); }

TEST_F(IoHandleImplTest, NotSupportsUdpGro) { EXPECT_FALSE(io_handle_->supportsUdpGro()); }
Expand Down Expand Up @@ -1074,11 +1087,6 @@ TEST_F(IoHandleImplNotImplementedTest, ErrorOnListen) {
EXPECT_THAT(io_handle_->listen(back_log_is_ignored), IsNotSupportedResult());
}

TEST_F(IoHandleImplNotImplementedTest, ErrorOnAddress) {
ASSERT_THROW(io_handle_->peerAddress(), EnvoyException);
ASSERT_THROW(io_handle_->localAddress(), EnvoyException);
}

TEST_F(IoHandleImplNotImplementedTest, ErrorOnSetOption) {
EXPECT_THAT(io_handle_->setOption(0, 0, nullptr, 0), IsNotSupportedResult());
}
Expand Down