From c7f622003d00b8f0640f4bcf206406b13659d113 Mon Sep 17 00:00:00 2001 From: AJ Heller Date: Thu, 20 May 2021 17:41:04 -0700 Subject: [PATCH] Remove fd dependencies from the local_security_connector (#26290) --- .../local/local_security_connector.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/lib/security/security_connector/local/local_security_connector.cc b/src/core/lib/security/security_connector/local/local_security_connector.cc index 1c1cfe9248f..aec493c8b4f 100644 --- a/src/core/lib/security/security_connector/local/local_security_connector.cc +++ b/src/core/lib/security/security_connector/local/local_security_connector.cc @@ -29,6 +29,7 @@ #include #include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/address_utils/sockaddr_utils.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -39,6 +40,7 @@ #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/security/credentials/local/local_credentials.h" #include "src/core/lib/security/transport/security_handshaker.h" +#include "src/core/lib/uri/uri_parser.h" #include "src/core/tsi/local_transport_security.h" #define GRPC_UDS_URI_PATTERN "unix:" @@ -70,13 +72,14 @@ void local_check_peer(tsi_peer peer, grpc_endpoint* ep, grpc_core::RefCountedPtr* auth_context, grpc_closure* on_peer_checked, grpc_local_connect_type type) { - int fd = grpc_endpoint_get_fd(ep); grpc_resolved_address resolved_addr; - memset(&resolved_addr, 0, sizeof(resolved_addr)); - resolved_addr.len = GRPC_MAX_SOCKADDR_SIZE; bool is_endpoint_local = false; - if (getsockname(fd, reinterpret_cast(resolved_addr.addr), - &resolved_addr.len) == 0) { + absl::string_view local_addr = grpc_endpoint_get_local_address(ep); + absl::StatusOr uri = grpc_core::URI::Parse(local_addr); + if (!uri.ok() || !grpc_parse_uri(*uri, &resolved_addr)) { + gpr_log(GPR_ERROR, "Could not parse endpoint address: %s", + std::string(local_addr.data(), local_addr.size()).c_str()); + } else { grpc_resolved_address addr_normalized; grpc_resolved_address* addr = grpc_sockaddr_is_v4mapped(&resolved_addr, &addr_normalized) @@ -103,7 +106,7 @@ void local_check_peer(tsi_peer peer, grpc_endpoint* ep, } } } - grpc_error_handle error = GRPC_ERROR_NONE; + grpc_error_handle error; if (!is_endpoint_local) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Endpoint is neither UDS or TCP loopback address.");