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:
02020-06-24T01:49:04Z libevent: getaddrinfo: nodename nor servname provided, or not known
12020-06-24T01:49:04Z Binding RPC on address ::1 port 8332 failed
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():
0evhttp_bind_socket_with_handle()
1 bind_socket()
2 make_addrinfo()
3 evutil_getaddrinfo()
4 if #USE_NATIVE_GETADDRINFO
5 #ifndef AI_ADDRCONFIG
6 evutil_adjust_hints_for_addrconfig_()
7 evutil_check_interfaces()
8 evutil_check_ifaddrs()
9 evutil_found_ifaddr()
10 // miss identifies ipv6 as ipv4?
11 #endif
12 evutil_getaddrinfo_common_()
The problem is falling into "#ifndef AI_ADDRCONFIG":
0#ifndef AI_ADDRCONFIG
1 /* Not every system has AI_ADDRCONFIG, so fake it. */
2 if (hints.ai_family == PF_UNSPEC &&
3 (hints.ai_flags & EVUTIL_AI_ADDRCONFIG)) {
4 evutil_adjust_hints_for_addrconfig_(&hints);
5 }
6#endif
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 to 0x501
(XP).
This obviously predates Vista (0x0600
), which is when the AI_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:
- Open an issue upstream. https://github.com/libevent/libevent/issues/1041