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

[core] Add support for vsock transport #32847

Merged
merged 24 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ grpc_cc_library(
"//src/core:lib/iomgr/tcp_windows.cc",
"//src/core:lib/iomgr/unix_sockets_posix.cc",
"//src/core:lib/iomgr/unix_sockets_posix_noop.cc",
"//src/core:lib/iomgr/vsock.cc",
"//src/core:lib/iomgr/wakeup_fd_eventfd.cc",
"//src/core:lib/iomgr/wakeup_fd_nospecial.cc",
"//src/core:lib/iomgr/wakeup_fd_pipe.cc",
Expand Down Expand Up @@ -1386,6 +1387,7 @@ grpc_cc_library(
"//src/core:lib/iomgr/tcp_server_utils_posix.h",
"//src/core:lib/iomgr/tcp_windows.h",
"//src/core:lib/iomgr/unix_sockets_posix.h",
"//src/core:lib/iomgr/vsock.h",
"//src/core:lib/iomgr/wakeup_fd_pipe.h",
"//src/core:lib/iomgr/wakeup_fd_posix.h",
"//src/core:lib/resource_quota/api.h",
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt

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

2 changes: 2 additions & 0 deletions Makefile

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

8 changes: 8 additions & 0 deletions build_autogenerated.yaml

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

1 change: 1 addition & 0 deletions config.m4

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

1 change: 1 addition & 0 deletions config.w32

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

6 changes: 6 additions & 0 deletions doc/naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Most gRPC implementations support the following URI schemes:
as the first character; the implementation will prepend this null. Do not include
the null in `abstract_path`.

- `vsock:cid:port` -- VSOCK (Linux systems only)
- `cid` is 32-bit Context Identifier (CID). It indicates the source or
destination, which is either a virtual machine or the host.
- `port` is a 32-bit port number. It differentiates between multiple
services running on a single machine.

The following schemes are supported by the gRPC C-core implementation,
but may not be supported in other languages:

Expand Down
2 changes: 2 additions & 0 deletions gRPC-C++.podspec

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

3 changes: 3 additions & 0 deletions gRPC-Core.podspec

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

2 changes: 2 additions & 0 deletions grpc.gemspec

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

3 changes: 3 additions & 0 deletions grpc.gyp

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

2 changes: 2 additions & 0 deletions package.xml

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

5 changes: 5 additions & 0 deletions src/core/ext/filters/client_channel/http_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ absl::optional<std::string> HttpProxyMapper::MapName(
std::string(server_uri).c_str());
return absl::nullopt;
}
if (uri->scheme() == "vsock") {
gpr_log(GPR_INFO, "not using proxy for VSock '%s'",
std::string(server_uri).c_str());
return absl::nullopt;
}
// Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set.
auto no_proxy_str = GetEnv("no_grpc_proxy");
if (!no_proxy_str.has_value()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Support for resolving ipv4:, ipv6:, unix: schemes
Support for resolving ipv4:, ipv6:, unix:, vsock: schemes
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@ class UnixAbstractResolverFactory : public ResolverFactory {
};
#endif // GRPC_HAVE_UNIX_SOCKET

#ifdef GRPC_HAVE_VSOCK
class VSockResolverFactory : public ResolverFactory {
public:
bool IsValidUri(const URI& uri) const override {
return ParseUri(uri, grpc_parse_vsock, nullptr);
}

OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
return CreateSockaddrResolver(std::move(args), grpc_parse_vsock);
}

std::string GetDefaultAuthority(const URI& /*uri*/) const override {
return "localhost";
}

absl::string_view scheme() const override { return "vsock"; }
};

#endif // GRPC_HAVE_VSOCK

} // namespace

void RegisterSockaddrResolver(CoreConfiguration::Builder* builder) {
Expand All @@ -185,6 +205,10 @@ void RegisterSockaddrResolver(CoreConfiguration::Builder* builder) {
builder->resolver_registry()->RegisterResolverFactory(
std::make_unique<UnixAbstractResolverFactory>());
#endif
#ifdef GRPC_HAVE_VSOCK
builder->resolver_registry()->RegisterResolverFactory(
std::make_unique<VSockResolverFactory>());
#endif
}

} // namespace grpc_core
4 changes: 4 additions & 0 deletions src/core/ext/transport/chttp2/server/chttp2_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "src/core/lib/iomgr/resolved_address.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "src/core/lib/iomgr/unix_sockets_posix.h"
#include "src/core/lib/iomgr/vsock.h"
#include "src/core/lib/resource_quota/memory_quota.h"
#include "src/core/lib/resource_quota/resource_quota.h"
#include "src/core/lib/security/credentials/credentials.h"
Expand Down Expand Up @@ -98,6 +99,7 @@ using ::grpc_event_engine::experimental::EventEngine;

const char kUnixUriPrefix[] = "unix:";
const char kUnixAbstractUriPrefix[] = "unix-abstract:";
const char kVSockUriPrefix[] = "vsock:";

class Chttp2ServerListener : public Server::ListenerInterface {
public:
Expand Down Expand Up @@ -941,6 +943,8 @@ grpc_error_handle Chttp2ServerAddPort(Server* server, const char* addr,
kUnixAbstractUriPrefix)) {
resolved_or =
grpc_resolve_unix_abstract_domain_address(parsed_addr_unprefixed);
} else if (absl::ConsumePrefix(&parsed_addr_unprefixed, kVSockUriPrefix)) {
resolved_or = grpc_resolve_vsock_address(parsed_addr_unprefixed);
} else {
resolved_or =
GetDNSResolver()->LookupHostnameBlocking(parsed_addr, "https");
Expand Down