Do not expand unusable v4 addresses in event engine.

PiperOrigin-RevId: 605689655
pull/35877/head
gRPC Team Bot 10 months ago committed by Copybara-Service
parent 67a15395d2
commit 4cbe274f4b
  1. 10
      src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc

@ -249,6 +249,13 @@ absl::StatusOr<int> ListenerContainerAddAllLocalAddresses(
return absl::FailedPreconditionError(
absl::StrCat("getifaddrs: ", std::strerror(errno)));
}
static const bool is_ipv4_available = [] {
const int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd >= 0) close(fd);
return fd >= 0;
}();
for (ifa_it = ifa; ifa_it != nullptr; ifa_it = ifa_it->ifa_next) {
ResolvedAddress addr;
socklen_t len;
@ -256,6 +263,9 @@ absl::StatusOr<int> ListenerContainerAddAllLocalAddresses(
if (ifa_it->ifa_addr == nullptr) {
continue;
} else if (ifa_it->ifa_addr->sa_family == AF_INET) {
if (!is_ipv4_available) {
continue;
}
len = static_cast<socklen_t>(sizeof(sockaddr_in));
} else if (ifa_it->ifa_addr->sa_family == AF_INET6) {
len = static_cast<socklen_t>(sizeof(sockaddr_in6));

Loading…
Cancel
Save