forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
network: add socket interface factory and config option (envoyproxy#1…
…1630) Add bootstrap config option that allows startup injection of a custom SocketInterface. Risk Level: Low Testing: n/a Docs Changes: n/a Release Notes: n/a Signed-off-by: Florin Coras <[email protected]> Signed-off-by: scheler <[email protected]>
- Loading branch information
1 parent
6a4c9af
commit 7c745ae
Showing
22 changed files
with
276 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DO NOT EDIT. This file is generated by tools/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"], | ||
) |
17 changes: 17 additions & 0 deletions
17
api/envoy/extensions/network/socket_interface/v3/default_socket_interface.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.network.socket_interface.v3; | ||
|
||
import "udpa/annotations/status.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.network.socket_interface.v3"; | ||
option java_outer_classname = "DefaultSocketInterfaceProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Default Socket Interface configuration] | ||
|
||
// Configuration for default socket interface that relies on OS dependent syscall to create | ||
// sockets. | ||
message DefaultSocketInterface { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
generated_api_shadow/envoy/config/bootstrap/v3/bootstrap.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 5 additions & 1 deletion
6
generated_api_shadow/envoy/config/bootstrap/v4alpha/bootstrap.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
generated_api_shadow/envoy/extensions/network/socket_interface/v3/BUILD
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...ed_api_shadow/envoy/extensions/network/socket_interface/v3/default_socket_interface.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include "envoy/config/typed_config.h" | ||
#include "envoy/network/socket.h" | ||
#include "envoy/registry/registry.h" | ||
#include "envoy/server/bootstrap_extension_config.h" | ||
|
||
#include "common/singleton/threadsafe_singleton.h" | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
|
||
namespace Envoy { | ||
namespace Network { | ||
|
||
// Wrapper for SocketInterface instances returned by createBootstrapExtension() which must be | ||
// implemented by all factories that derive SocketInterfaceBase | ||
class SocketInterfaceExtension : public Server::BootstrapExtension { | ||
public: | ||
SocketInterfaceExtension(SocketInterface& sock_interface) : sock_interface_(sock_interface) {} | ||
SocketInterface& socketInterface() { return sock_interface_; } | ||
|
||
private: | ||
SocketInterface& sock_interface_; | ||
}; | ||
|
||
// Class to be derived by all SocketInterface implementations. | ||
// | ||
// It acts both as a SocketInterface and as a BootstrapExtensionFactory. The latter is used, on the | ||
// one hand, to configure and initialize the interface and, on the other, for SocketInterface lookup | ||
// by leveraging the FactoryRegistry. As required for all bootstrap extensions, all derived classes | ||
// should register via the REGISTER_FACTORY() macro as BootstrapExtensionFactory. | ||
// | ||
// SocketInterface instances can be retrieved using the factory name, i.e., string returned by | ||
// name() function implemented by all classes that derive SocketInterfaceBase, via | ||
// Network::socketInterface(). When instantiating addresses, address resolvers should | ||
// set the socket interface field to the name of the socket interface implementation that should | ||
// be used to create sockets for said addresses. | ||
class SocketInterfaceBase : public SocketInterface, | ||
public Server::Configuration::BootstrapExtensionFactory {}; | ||
|
||
/** | ||
* Lookup SocketInterface instance by name | ||
* @param name Name of the socket interface to be looked up | ||
* @return Pointer to @ref SocketInterface instance that registered using the name of nullptr | ||
*/ | ||
static inline const SocketInterface* socketInterface(std::string name) { | ||
auto factory = | ||
Registry::FactoryRegistry<Server::Configuration::BootstrapExtensionFactory>::getFactory(name); | ||
return dynamic_cast<SocketInterface*>(factory); | ||
} | ||
|
||
using SocketInterfaceSingleton = InjectableSingleton<SocketInterface>; | ||
using SocketInterfaceLoader = ScopedInjectableLoader<SocketInterface>; | ||
|
||
} // namespace Network | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.