-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
connection: Add TCP_FASTOPEN listener option #2793
Conversation
@dnoe This is related to the other socket-option work you're looking at. |
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
Per new release note policy please add a release note with any applicable feature docs to https://github.com/envoyproxy/data-plane-api/blob/master/docs/root/intro/version_history.rst. Thank you! |
@mattklein123 I've added a note in envoyproxy/data-plane-api#539 |
@bmetzdorf #2734 is in - are you up for pulling and merging? |
@alyssawilk yep! Will do in the next couple of days! |
@alyssawilk I think I need to wait for #2719 to be merged. |
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
@@ -32,8 +32,25 @@ bool SocketOptionImpl::setOption(Socket& socket, Socket::SocketState state) cons | |||
return false; | |||
} | |||
} | |||
} | |||
} else if (state == Socket::SocketState::Listening) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap the IP_TRANSPARENT
option setting above into if (state != Socket::SocketState::Listening) { ... }
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
|
||
// Add the options to the socket_ so that SocketState::Listening options can be | ||
// set in the worker after listen()/evconnlistener_new() is called. | ||
socket_->addOption(option); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does adding these options here break anything else?
I wrote a lot of this code, so removing myself as reviewer |
I've tested this latest commit macOS: Linux: |
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
@@ -31,7 +31,11 @@ class Socket { | |||
*/ | |||
virtual void close() PURE; | |||
|
|||
enum class SocketState { PreBind, PostBind }; | |||
enum class SocketState { | |||
PreBind, // after socket creation but before binding the socket to a port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest moving these to the line previous, e.g.
// Socket options are applied after socket creation but before...
Prebind,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, just a few more comments.
#ifdef TCP_FASTOPEN | ||
#define ENVOY_SOCKET_TCP_FASTOPEN Network::SocketOptionName(TCP_FASTOPEN) | ||
#else | ||
#define ENVOY_SOCKET_TCP_FASTOPEN Network::SocketOptionName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried manually forcing this option and seeing what happens to the tests? In my experience, this is a useful step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@htuch Do you mean just enforce TCP_FASTOPEN on all listeners by default and then run the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean as an experiment in your local client, change that #ifdef
line to #if 0
and see if bazel test //test/...
passes.
|
||
#include "server/configuration_impl.h" | ||
|
||
#ifdef TCP_FASTOPEN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can live in socket_option_impl.h
alongside the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
std::shared_ptr<MockSocketOption> option = std::make_shared<MockSocketOption>(); | ||
socket.addOption(option); | ||
EXPECT_CALL(*option, setOption(_, Socket::SocketState::Listening)).WillOnce(Return(false)); | ||
EXPECT_THROW(TestListenerImpl(dispatcher, socket, listener_callbacks, true, false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could make this EXPECT_THROW_WITH_MESSAGE
to get better precision on why we see the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm working on this one.
TEST_F(SocketOptionImplTest, SetOptionFreebindPostBind) { | ||
SocketOptionImpl socket_option{{}, true}; | ||
EXPECT_TRUE(socket_option.setOption(socket_, Socket::SocketState::PostBind)); | ||
testSetSocketOptionSuccess(socket_option, IPPROTO_IP, ENVOY_SOCKET_IP_FREEBIND, 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup!
Api::MockOsSysCalls os_sys_calls_; | ||
TestThreadsafeSingletonInjector<Api::OsSysCallsImpl> os_calls{&os_sys_calls_}; | ||
|
||
void testSetSocketOptionSuccess(ListenerSocketOptionImpl& socket_option, int socket_level, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this subclass SocketOptionImplTest
and inherit this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bmetzdorf can you give me a quick yes/no on the various feedback? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm working on this one.
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
Signed-off-by: Greg Greenway <ggreenway@apple.com>
#ifdef TCP_FASTOPEN | ||
#define ENVOY_SOCKET_TCP_FASTOPEN Network::SocketOptionName(TCP_FASTOPEN) | ||
#else | ||
#define ENVOY_SOCKET_TCP_FASTOPEN Network::SocketOptionName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@htuch Do you mean just enforce TCP_FASTOPEN on all listeners by default and then run the tests?
ENVOY_LOG(debug, "Successfully set socket option TCP_FASTOPEN to {}", tfo_value); | ||
} | ||
} else { | ||
ENVOY_LOG(warn, "Unsupported socket option TCP_FASTOPEN"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is missing coverage.
Signed-off-by: Bjoern Metzdorf <bmetzdorf@apple.com>
@htuch Please let me know if |
namespace Network { | ||
namespace { | ||
|
||
class SocketOptionTestHarness : public testing::Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this looks good. As a nit, I would probably call it SocketOptionTestBase
or SocketOptionTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bmetzdorf. Merging to unblock #3042, @bmetzdorf has signed up to address remaining minor feedback in a followup PR.
connection: Add TCP_FASTOPEN listener option
This allows accepting TCP_FASTOPEN based connections. Works on both Linux and OSX.
Feedback on this is very welcome. It was tested manually on Linux and OSX.
API Changes: envoyproxy/data-plane-api#539
Signed-off-by: Bjoern Metzdorf bmetzdorf@apple.com
Risk Level: Low