-
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
Provide ability to override socket API #11618
Comments
I intend to start a separate discussion of how to avoid pulling the rug from under the vendors that may depend on "internal" Envoy interfaces. This one is to focus on the socket API specifically. |
cc @florincoras |
@yanavlasov just some quick thoughts Practically, Now as to how to do that and current limitations:
Does this make sense or did I miss something? |
@florincoras I'm unsure I'm following you. Can't we already override default I suppose your second suggestion would solve our immediate issue. The changes have evolved so quickly that I did not notice that However it is still seems to me that |
It's pretty much the same thing. The idea with the factory was that you could add a shim in Envoy that, when built, links to your custom socket layer implementation. Then, switching between implementations is just a startup config change.
I guess that's possible. Personally, I'd be tempted to extend
Agreed. The only issue is the fact that we rely a lot on constructors when instantiating specialized |
@yanavlasov Are you needing separate route domains, so that for example you could have 10.0.0.1 go to different places in two different contexts, perhaps a "customer" context and an "admin" context? If that's what you're needing I think it would make sense to allow arbitrary tagging of addresses, so that the creator of an |
@ggreenway something like that. I think whether it is some sort of extensible tagging or something else is not particularly relevant. It all sort of acts as poor man's RTTI. |
@yanavlasov, I can start working on something once we're all in sync (cc @htuch). Still, if this ends up taking too long and you already have something that fixes the problem on your end, feel free to push it and I'll manage. |
Posting the link to the socket interface issues and next steps doc here as well for more visibility. |
@yanavlasov can we consider the issue solved after #12189? |
Could we make this change before calling it done? #12189 (comment) |
Replying here although it might be better to move the conversation back to #12189. I just took a very quick look at what would be needed to keep Assuming |
I think that Address::Instance can forward declare SocketInterface and accept a plain pointer to SocketInterface. SocketInterface can continue including the full definition of the address interface defined at include/envoy/network/address.h |
@antoniovicente apologies for the delay! That works for me, what do you think @mattklein123 @yanavlasov ? |
Sure SGTM. |
@antoniovicente would #12550 work? |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions. |
Recent changes to the socket related API no longer allow overriding methods such as
bind
orconnect
. This is both a bug report and proposal for how to bring this functionality back.The "socket API" here and below refers to a collection of methods for creating communication endpoints in use by Envoy which mirrors Posix sockets API.
Background:
Envoy provide ability to extend name resolution mechanism by registering a custom address "resolver" factory identified by a string ID. Custom resolver by specifying its ID in the
envoy.config.core.v3.SocketAddress
configuration proto. A resolver returnsEnvoy::Network::Address::Instance
interface to an IP address object.Previously socket API was part of the
Envoy::Network::Address::Instance
which while admittedly unorthodox allowed vendors to override default behavior of the API based on the type of resolver that created given IP address object.Recent redesign spread socket API between several interfaces:
Envoy::Network::SocketInterface
for creating descriptor objects. This interface is implemented by an object which is a singleton in Envoy process and can be customized through a factory.Envoy::Network::IoHandle
for return values fromSocketInterface
methods.Envoy::Network::Socket
. Objects of this interface are created from the Envoy::Network::IoHandle` to provide specializations for posix socket API.The objects that implement
Envoy::Network::Socket
are created internally by Envoy and their types can not be modified by vendors. Since this interface defines methods likebind
,listen
andconnect
the behavior of these methods can be overridden no longer.However some of our use cases require completely custom implementation of binding or connecting to some IP addresses (i.e. Cloud IPs). The customization is not just limited to providing additional socket options, but requires making calls to proprietary subsystems.
This proposal outlines new class hierarchy that would allow complete control over implementation of the socket API.
Stream socket descriptors can be placed into one of the 3 categories based on the use.
As such class hierarchy can be designed as follows:
Socket
interface with various methods common to all socket types (i.e.get/setsockopt
)DataSocket : Socket
for sending and receiving data.ListeningSocket : Socket
with methods specific to listening sockets. A callback that accepts new connections providesDataSocket
to communicate with the peer.ConnectingSocket : Socket
with methods specific to connecting sockets. A callback is invoked with theDataSocket
when new connection is established.SocketInterface
has methods added for creatingListeningSocket
andConnectingSocket
.NB: We could make
ConnectingSocket
derive fromDataSocket
to reduce the number of changes in the code.The
SocketInterface
implementation may need to distinguish between different types of IP addresses that are provided to it at the time of socket creation so it can instantiate different implementations of the socket interfaces. Use of RTTI is not desirable as it may require pulling in type definitions for IP address classes. However providing the string ID of the resolver that created the address is enough to cover existing use cases. As such theEnvoy::Network::Address::Instance
is proposed to be extended with theresolverId()
method returning the unique ID of the resolver.Datagram sockets have the superset of the
DataSocket
API with the additionalbind
andconnect
methods (if we useconnect
on UDP sockets).To support datagram sockets the following changes are proposed:DatagramSocket : DataSocket
with addedbind
method.SocketInterface
extended with the addition of the method for creating datagram sockets.This class hierarchy would allow vendors to provide custom implementations for all classes involved in establishing a connection:
SocketInterface
that can instantiate different implementations of theSocket
interface family that would allow all its methods to be overridden.The text was updated successfully, but these errors were encountered: