Skip to content

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

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
htuch:refactor-addr-from-fd
Mar 28, 2017
Merged

network: obtain address instance from fd, bind-to-zero in ListenSocke…#645
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
htuch:refactor-addr-from-fd

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 htuch force-pushed the refactor-addr-from-fd branch from 7eb448a to 46be529 Compare March 28, 2017 20:19
@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

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 ;) )

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 <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
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 <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
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