-
Notifications
You must be signed in to change notification settings - Fork 37.7k
build: target Windows 7 when building libevent and fix ipv6 usage #19375
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
Conversation
libevent uses getaddrinfo when available, and falls back to gethostbyname Windows has both, but gethostbyname only supports IPv4 libevent fails to detect Windows's getaddrinfo due to not including the right headers This patches libevent's configure script to check it correctly
@@ -14,6 +16,7 @@ define $(package)_set_vars | |||
$(package)_config_opts_release=--disable-debug-mode | |||
$(package)_config_opts_linux=--with-pic | |||
$(package)_config_opts_android=--with-pic | |||
$(package)_cppflags_mingw32=-D_WIN32_WINNT=0x0601 |
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.
I don't see how this can work... evutil.c #undef _WIN32_WINNT
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.
It's only undef'd after the inclusion of ws2tcpip.h
which is where the AI_*
definitions are.
In the ws2tcpip.h
header on my machine I've got:
#define AI_PASSIVE 0x00000001
#define AI_CANONNAME 0x00000002
#define AI_NUMERICHOST 0x00000004
#if (_WIN32_WINNT >= 0x0600)
#define AI_NUMERICSERV 0x00000008
#define AI_ALL 0x00000100
#define AI_ADDRCONFIG 0x00000400
#define AI_V4MAPPED 0x00000800
#define AI_NON_AUTHORITATIVE 0x00004000
#define AI_SECURE 0x00008000
#define AI_RETURN_PREFERRED_NAMES 0x00010000
#endif
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.
Oh, weird. That seems like it's probably a bug, but not our problem.
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.
You might want to add a comment here in the makefile about why this is defined, and why it works.
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.
@laanwj I've added a comment here. These kinds of details probably deserve a separate document in depends (we could also add some of the macOS stuff there as well). I can follow up by writing up some more extensive docs.
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.
utACK
tACK b440aca. Adjusted test commands:
Relevant parts of bitcoind console messages:
|
Just a clarification to "how" this is working, and follow up to the comments above. By default, the mingw32 compiler, (on my machine, So the fix here isn't just that we are overriding libevents internal The seconds point is header include order. Because the #define AI_PASSIVE 0x00000001
#define AI_CANONNAME 0x00000002
#define AI_NUMERICHOST 0x00000004
#if (_WIN32_WINNT >= 0x0600)
#define AI_NUMERICSERV 0x00000008
#define AI_ALL 0x00000100
#define AI_ADDRCONFIG 0x00000400
#define AI_V4MAPPED 0x00000800
#define AI_NON_AUTHORITATIVE 0x00004000
#define AI_SECURE 0x00008000
#define AI_RETURN_PREFERRED_NAMES 0x00010000
#endif is included before libevent #undefs |
Gitian builds
|
This enables of the use of AI_* definitions in the Windows headers, specifically AI_ADDRCONFIG, which fixes an issue with libevent and ipv6 on Windows. It also aligns with what we define in configure when building Core.
b440aca
to
eb6b735
Compare
ACK eb6b735 |
Post-merge ACK eb6b735 . |
This enables of the use of AI_* definitions in the Windows headers, specifically AI_ADDRCONFIG, which fixes an issue with libevent and ipv6 on Windows. It also aligns with what we define in configure when building Core. Github-Pull: bitcoin#19375 Rebased-From: eb6b735
Summary: Fix for ipv6 on Windows. Backport of core [[bitcoin/bitcoin#19375 | PR19375]]. Depends on D7742. Test Plan: make build-win64 cmake -GNinja .. \ -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/Win64.cmake \ -DBUILD_BITCOIN_SEEDER=OFF ninja Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D7743
TLDR: This poaches a commit from #18287 and adds one more to adjust the Windows version targeted when building libevent. These changes combined should fully fix ipv6 usage with the RPC server on Windows.
Binding the RPC server to a ipv6 address does not currently work on Windows.
We currently try and bind to
127.0.0.1
and::1
by default.On Windows you'll see lines like this in debug.log:
This issue was bought up in, and supposedly fixed by #18287, however the two people that tested it, both said that it didn't fix the problem. I think I now understand why that change alone is incomplete.
Our call into libevent starts with evhttp_bind_socket_with_handle():
The problem is falling into "#ifndef AI_ADDRCONFIG":
When this occurs, hints end up being adjusted, and it seems that ipv6 addresses end up being mis-identified as ipv4?
However this shouldn't happen, as these
AI_
definitions are available on Windows.The issue is that in evutil.c,
_WIN32_WINNT
is set to0x501
(XP).This obviously predates Vista (
0x0600
), which is when theAI_ADDRCONFIG
definition (and others) became available.The change here will override libevents internal D_WIN32_WINNT defines. This should be ok, because it's only making "more" of the Windows API available. It's also aligned with what we do in our own configure, we pass
D_WIN32_WINNT=0x0601
. We also now use linker flags to restrict our binary from running on a Windows version earlier than Windows 7.The combined fixes can be tested by running:
bitcoind -rpcbind=::1 rpcallowip='0.0.0.0/0' -debug=http
and then querying it using:
bitcoin-cli -rpcconnect=::1 getblockchaininfo
TODO: