Skip to content

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Apr 22, 2021

Avoid calling getnameinfo when formatting IPv6 addresses in CNetAddr::ToStringIP.

Fixes #21466.
Fixes #21967.

The IPv4 case was fixed in #21564.

@DrahtBot DrahtBot added the P2P label Apr 22, 2021
@laanwj
Copy link
Member

laanwj commented Apr 22, 2021

Concept ACK

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 54548ba

@shobitb
Copy link

shobitb commented May 17, 2021

ACK c10f27f

I've reviewed the code and it looks good. Also ran unit tests and make check completes successfully.

@practicalswift
Copy link
Contributor Author

@shobitb Thanks a lot for reviewing! I think you might have gotten the commit id wrong when ACK:ing. The last commit id in the sequence of commits is the one used when ACK:ing a PR assuming one ACK:s the entire PR and not just a subset of it :)

@laanwj
Copy link
Member

laanwj commented May 17, 2021

Code review ACK 54548ba
It at first surprised me that there are no tests for IPv6ToString. However there are for the higher-level functions. As this passes the CNetAddr ToString tests, I think this is covered sufficiently.

@laanwj laanwj merged commit 7b87fca into bitcoin:master May 17, 2021
socklen_t socklen = sizeof(sockaddr);
if (serv.GetSockAddr((struct sockaddr*)&sockaddr, &socklen)) {
char name[1025] = "";
if (!getnameinfo((const struct sockaddr*)&sockaddr, socklen, name,
Copy link
Member

Choose a reason for hiding this comment

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

Was removing link-local scoped id functionality an intended consequence of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If we want to restore that functionality we could pass m_scope_id to IPv6ToString and append it if non-zero.

@jonatack
Copy link
Member

According to #21982 (comment), no longer returning scoped ids was an intentional part of this PR. Maybe that wasn't obvious to reviewers. After test coverage was removed by #21689, no other tests signalled the change.

It would be good to be more explicit in the PR description regarding why make the change, and straightforward about what support was being dropped.

@vasild
Copy link
Contributor

vasild commented May 18, 2021

There seems to be two "functionalities" being discussed together, it took me some time to figure it out:

  1. The functionality of IPv6 scope id, introduced in Net: Add IPv6 Link-Local Address Support #7570. That is still working, has not been removed.
  2. The printout of such IPv6 addresses - before we used the system getnameinfo() which included %zoneid (on all or most platforms). Now we roll our own which does not include %zoneid.

For reference, here is the FreeBSD implementation of getnameinfo() (which is under... eh... the BSD license):

https://github.com/freebsd/freebsd-src/blob/c232fd4b4191a722f8c3193ef1e7c6efd8385182/lib/libc/net/getnameinfo.c#L43-L46

https://github.com/freebsd/freebsd-src/blob/c232fd4b4191a722f8c3193ef1e7c6efd8385182/lib/libc/net/getnameinfo.c#L358-L375

https://github.com/freebsd/freebsd-src/blob/c232fd4b4191a722f8c3193ef1e7c6efd8385182/sys/netinet6/in6.h#L296-L297

@practicalswift
Copy link
Contributor Author

practicalswift commented May 18, 2021

@vasild

Exactly. Thanks for bringing some sense to this.

What this entire discussion boils down to is if the expectation is that CNetAddr::ToStringIP() should print the IPv6 address or the IPv6 socket address:

  • IPv6 address (std::net::Ipv6Addr): "IPv6 addresses are defined as 128-bit integers in IETF RFC 4291. They are usually represented as eight 16-bit segments."
  • IPv6 socket address (std::net::SocketAddrV6): "IPv6 socket addresses consist of an IPv6 address, a 16-bit port number, as well as fields containing the traffic class, the flow label, and a scope identifier (see IETF RFC 2553, Section 3.3 for more details)."

@jonatack
Copy link
Member

Indeed. What does not make sense to me is why this PR was not upfront about this, nor the reasons that were given to have the only test coverage removed willy-nilly allowing this to be changed without tests warning about it, nor why we should break user space to follow the rustlang version without discussion. If those questions do not make sense, then I apologize.

@jonatack
Copy link
Member

The comment I referred to above in #21982 (comment):

If you by "functionality" mean not appending an unwanted %zone_index string to CNetAddr::ToString(), then yes that non-appending of an unwanted string is obviously intentional. The new implementation of IPv6ToString (which is called from CNetAddr::ToString) follows Rust's std::net::Ipv6Addr which does not append %zone_index. FWIW that is how the previous implementation of CNetAddr::ToString worked under macOS.

Yes, as the removed test and as #21690 showed, macOS returns a different getnameinfo format for scoped ids, without the zone id, from all the other platforms that do provide support for it. Why should we align with the macOS exception without discussing it? Does it not make sense to call attention to this change?

@vasild
Copy link
Contributor

vasild commented May 18, 2021

It should be easy to append %zoneid like @laanwj suggests?

@jonatack
Copy link
Member

It should be easy to append %zoneid like @laanwj suggests?

#21985

gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
7 participants