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

network: obtain address instance from fd, bind-to-zero in ListenSocke… #645

Merged
merged 3 commits into from
Mar 28, 2017

Conversation

htuch
Copy link
Member

@htuch htuch commented Mar 28, 2017

…tImpl.

Refactor 33ece57 to assist with zero binding from integration tests.

…tImpl.

Refactor 33ece57 to assist with zero binding from integration tests.
@htuch
Copy link
Member Author

htuch commented Mar 28, 2017

@jamessynge

socklen_t ss_len = sizeof ss;
const int rc = ::getsockname(fd, reinterpret_cast<sockaddr*>(&ss), &ss_len);
if (rc != 0) {
const int err = errno;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: local var not needed

}
default:
throw EnvoyException(fmt::format("Unexpected family in getsockname result: {}", ss.ss_family));
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: line can't be reached.

throw EnvoyException(fmt::format("Unexpected family in getsockname result: {}", ss.ss_family));
return nullptr;
}
return nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would just do NOT_REACHED here if compiler complains

@@ -15,6 +15,11 @@ void ListenSocketImpl::doBind() {
throw EnvoyException(
fmt::format("cannot bind '{}': {}", local_address_->asString(), strerror(errno)));
}
if (local_address_->ip()->port() == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, didn't run the full tests before pushing, will fix.

@htuch
Copy link
Member Author

htuch commented Mar 28, 2017

Fixed, tests pass (this is what happens when you write code while in the middle of a meting ;) )

@@ -15,6 +15,12 @@ void ListenSocketImpl::doBind() {
throw EnvoyException(
fmt::format("cannot bind '{}': {}", local_address_->asString(), strerror(errno)));
}
if (local_address_->type() == Address::Type::Ip && local_address_->ip() != nullptr &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: local_address_->ip() != nullptr is guaranteed if local_address_->type() == Address::Type::Ip

@mattklein123 mattklein123 merged commit 7c86fe3 into envoyproxy:master Mar 28, 2017
@htuch htuch deleted the refactor-addr-from-fd branch March 31, 2017 16:30
jpsim pushed a commit that referenced this pull request Nov 28, 2022
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 <[email protected]>
Signed-off-by: JP Simard <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
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 <[email protected]>
Signed-off-by: JP Simard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants