-
Notifications
You must be signed in to change notification settings - Fork 5.4k
address: IPv4/IPv6 dual bind. #2201
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
456bdbb
address: IPv4/IPv6 dual bind.
htuch 3e4a245
Merge remote-tracking branch 'upstream/master' into ipv46-bind
htuch 00852fb
addressFromFd() can infer IPv6-only from socket options.
htuch fb3503f
Drop v6only() on address instance interface.
htuch 2b1202b
Admin interface integration test.
htuch 91a6a2a
Merge remote-tracking branch 'upstream/master' into ipv46-bind
htuch 6dff12c
Merge remote-tracking branch 'upstream/master' into ipv46-bind
htuch e944e63
Review feedback.
htuch c8ac37a
Merge remote-tracking branch 'upstream/master' into ipv46-bind
htuch 25dbb15
RELEASE_ASSERT getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, ..).
htuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,8 @@ namespace Envoy { | |
| namespace Network { | ||
| namespace Address { | ||
|
|
||
| Address::InstanceConstSharedPtr addressFromSockAddr(const sockaddr_storage& ss, socklen_t ss_len) { | ||
| Address::InstanceConstSharedPtr addressFromSockAddr(const sockaddr_storage& ss, socklen_t ss_len, | ||
| bool v6only) { | ||
| RELEASE_ASSERT(ss_len == 0 || ss_len >= sizeof(sa_family_t)); | ||
| switch (ss.ss_family) { | ||
| case AF_INET: { | ||
|
|
@@ -33,7 +34,7 @@ Address::InstanceConstSharedPtr addressFromSockAddr(const sockaddr_storage& ss, | |
| RELEASE_ASSERT(ss_len == 0 || ss_len == sizeof(sockaddr_in6)); | ||
| const struct sockaddr_in6* sin6 = reinterpret_cast<const struct sockaddr_in6*>(&ss); | ||
| ASSERT(AF_INET6 == sin6->sin6_family); | ||
| return std::make_shared<Address::Ipv6Instance>(*sin6); | ||
| return std::make_shared<Address::Ipv6Instance>(*sin6, v6only); | ||
| } | ||
| case AF_UNIX: { | ||
| const struct sockaddr_un* sun = reinterpret_cast<const struct sockaddr_un*>(&ss); | ||
|
|
@@ -47,14 +48,14 @@ Address::InstanceConstSharedPtr addressFromSockAddr(const sockaddr_storage& ss, | |
| NOT_REACHED; | ||
| } | ||
|
|
||
| InstanceConstSharedPtr addressFromFd(int fd) { | ||
| InstanceConstSharedPtr addressFromFd(int fd, bool v6only) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, shouldn't we getsockopt to determine if it is set, instead of having this as a parameter?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this makes sense. |
||
| sockaddr_storage ss; | ||
| socklen_t ss_len = sizeof ss; | ||
| const int rc = ::getsockname(fd, reinterpret_cast<sockaddr*>(&ss), &ss_len); | ||
| if (rc != 0) { | ||
| throw EnvoyException(fmt::format("getsockname failed for '{}': {}", fd, strerror(errno))); | ||
| } | ||
| return addressFromSockAddr(ss, ss_len); | ||
| return addressFromSockAddr(ss, ss_len, v6only); | ||
| } | ||
|
|
||
| InstanceConstSharedPtr peerAddressFromFd(int fd) { | ||
|
|
@@ -179,9 +180,10 @@ std::string Ipv6Instance::Ipv6Helper::makeFriendlyAddress() const { | |
| return ptr; | ||
| } | ||
|
|
||
| Ipv6Instance::Ipv6Instance(const sockaddr_in6& address) : InstanceBase(Type::Ip) { | ||
| Ipv6Instance::Ipv6Instance(const sockaddr_in6& address, bool v6only) : InstanceBase(Type::Ip) { | ||
| ip_.ipv6_.address_ = address; | ||
| ip_.friendly_address_ = ip_.ipv6_.makeFriendlyAddress(); | ||
| ip_.v6only_ = v6only; | ||
| friendly_name_ = fmt::format("[{}]:{}", ip_.friendly_address_, ip_.port()); | ||
| } | ||
|
|
||
|
|
@@ -219,7 +221,7 @@ int Ipv6Instance::socket(SocketType type) const { | |
| const int fd = socketFromSocketType(type); | ||
|
|
||
| // Setting IPV6_V6ONLY resticts the IPv6 socket to IPv6 connections only. | ||
| const int v6only = 1; | ||
| const int v6only = ip_.v6only_; | ||
| RELEASE_ASSERT(::setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)) != -1); | ||
| return fd; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be on class Ipv6 instead of here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe? Need to do some dynamic casting to make use of where I needed it, but I agree it's cleaner at the interface level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you pivot off of ipv6() being not-null in the cases that you need?