network: obtain address instance from fd, bind-to-zero in ListenSocke…#645
Conversation
…tImpl. Refactor 33ece57 to assist with zero binding from integration tests.
7eb448a to
46be529
Compare
| socklen_t ss_len = sizeof ss; | ||
| const int rc = ::getsockname(fd, reinterpret_cast<sockaddr*>(&ss), &ss_len); | ||
| if (rc != 0) { | ||
| const int err = errno; |
| } | ||
| default: | ||
| throw EnvoyException(fmt::format("Unexpected family in getsockname result: {}", ss.ss_family)); | ||
| return nullptr; |
There was a problem hiding this comment.
nit: line can't be reached.
| const struct sockaddr_in* sin = reinterpret_cast<const struct sockaddr_in*>(&ss); | ||
| ASSERT(AF_INET == sin->sin_family); | ||
| return InstanceConstSharedPtr(new Address::Ipv4Instance(sin)); | ||
| break; |
There was a problem hiding this comment.
nit: line can't be reached.
| const struct sockaddr_in6* sin6 = reinterpret_cast<const struct sockaddr_in6*>(&ss); | ||
| ASSERT(AF_INET6 == sin6->sin6_family); | ||
| return InstanceConstSharedPtr(new Address::Ipv6Instance(*sin6)); | ||
| break; |
There was a problem hiding this comment.
nit: line can't be reached.
| throw EnvoyException(fmt::format("Unexpected family in getsockname result: {}", ss.ss_family)); | ||
| return nullptr; | ||
| } | ||
| return nullptr; |
There was a problem hiding this comment.
nit: Would just do NOT_REACHED here if compiler complains
| throw EnvoyException( | ||
| fmt::format("cannot bind '{}': {}", local_address_->asString(), strerror(errno))); | ||
| } | ||
| if (local_address_->ip()->port() == 0) { |
There was a problem hiding this comment.
doBind() is also called in UdsListenSocket case so I think this line will crash without checking if ip() is not null or type is IP
There was a problem hiding this comment.
Yeah, didn't run the full tests before pushing, will fix.
|
Fixed, tests pass (this is what happens when you write code while in the middle of a meting ;) ) |
| throw EnvoyException( | ||
| fmt::format("cannot bind '{}': {}", local_address_->asString(), strerror(errno))); | ||
| } | ||
| if (local_address_->type() == Address::Type::Ip && local_address_->ip() != nullptr && |
There was a problem hiding this comment.
nit: local_address_->ip() != nullptr is guaranteed if local_address_->type() == Address::Type::Ip
Description: update the envoy ref. This bump includes #9767 which will enable us to turn on process logs for Android devices in a subsequent PR. Risk Level: med, as always with a ref update. Testing: CI Signed-off-by: Jose Nino <jnino@lyft.com> Signed-off-by: JP Simard <jp@jpsim.com>
Description: update the envoy ref. This bump includes #9767 which will enable us to turn on process logs for Android devices in a subsequent PR. Risk Level: med, as always with a ref update. Testing: CI Signed-off-by: Jose Nino <jnino@lyft.com> Signed-off-by: JP Simard <jp@jpsim.com>
…tImpl.
Refactor 33ece57 to assist with zero binding from integration tests.