-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
win: map 0.0.0.0 and :: addresses to localhost #1515
Conversation
On Linux when connecting IP addresses 0.0.0.0 and :: are automatically converted to localhost. This adds same functionality to Windows.
Another run, with correct Makefile: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/420/ |
Ideally I'd go the other way and throw on So I'm +1 on this |
Some bots had failed with Jenkins issues, I retriggered the build: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/421/ |
I'm +1 on this, as long as all Unixen behave like Linux. |
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 know if we should adopt this behavior on Windows because I don't know if it is universal across Unices.
src/win/winsock.c
Outdated
uv_inet_pton(AF_INET6, "::1", &(dest->sin6_addr)); | ||
addr = (const struct sockaddr*) dest; | ||
} | ||
} |
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.
} else {
abort();
// or:
// return UV_EINVAL;
}
There is no need for this function to return a pointer, it could return an int. In fact, I'd argue it somewhat obscures the fact that the second argument is used as an out parameter.
src/win/winsock.c
Outdated
dest = (struct sockaddr_in*) storage; | ||
if (src->sin_addr.S_un.S_addr == 0) { | ||
memcpy(dest, src, sizeof(struct sockaddr_in)); | ||
uv_inet_pton(AF_INET, "127.0.0.1", &(dest->sin_addr.s_addr)); |
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.
Superfluous parens. Ditto a few lines below.
src/win/winsock.c
Outdated
src = (const struct sockaddr_in6*) addr; | ||
dest = (struct sockaddr_in6*) storage; | ||
if (memcmp(src->sin6_addr.u.Byte, | ||
uv_addr_ip6_any_.sin6_addr.u.Byte, |
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.
Just &src->sin6_addr
and &uv_addr_ip6_any_.sin6_addr
? Or is there some subtlety I'm missing?
test/test-connect-unspecified.c
Outdated
|
||
uv_tcp_init(loop, &socket4); | ||
uv_ip4_addr("0.0.0.0", 80, &addr4); | ||
uv_tcp_connect(&connect4, &socket4, (const struct sockaddr*)&addr4, connect_4); |
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.
Long line.
Updated, PTAL. New CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/434/ |
The failures are unrelated, and the automatic mapping of |
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'd say this needs a mention in the docs.
src/win/winsock.c
Outdated
struct sockaddr_in* dest; | ||
src = (const struct sockaddr_in*) addr; | ||
dest = (struct sockaddr_in*) storage; | ||
memcpy(dest, src, sizeof(struct sockaddr_in)); |
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.
style: incorrect indent
src/win/winsock.c
Outdated
src = (const struct sockaddr_in*) addr; | ||
dest = (struct sockaddr_in*) storage; | ||
memcpy(dest, src, sizeof(struct sockaddr_in)); | ||
if (src->sin_addr.S_un.S_addr == 0) { |
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.
incorrect capitalization?
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.
What do you mean?
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.
src->sin_addr.s_addr
intead of the union.
src/win/winsock.c
Outdated
dest = (struct sockaddr_in6*) storage; | ||
memcpy(dest, src, sizeof(struct sockaddr_in6)); | ||
if (memcmp(&src->sin6_addr, | ||
&uv_addr_ip6_any_.sin6_addr, |
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.
style: indent
src/win/winsock.c
Outdated
sizeof(struct in6_addr)) == 0) { | ||
uv_inet_pton(AF_INET6, "::1", &dest->sin6_addr); | ||
} | ||
return 0; |
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.
ditto
src/win/winsock.c
Outdated
} | ||
return 0; | ||
} else { | ||
return UV_EINVAL; |
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.
ditto
test/test-connect-unspecified.c
Outdated
|
||
loop = uv_default_loop(); | ||
|
||
uv_tcp_init(loop, &socket4); |
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.
assert for error in all these
Updated, PTAL. CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/442/ |
ping? |
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.
Left some comments. I still don't know if this is something we should actually do.
docs/src/udp.rst
Outdated
@@ -259,6 +263,8 @@ API | |||
|
|||
:returns: 0 on success, or an error code < 0 on failure. | |||
|
|||
.. versionchanged:: 1.15.0 added ``0.0.0.0`` to ``localhost`` mapping |
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.
Also ::
, right?
src/win/winsock.c
Outdated
@@ -559,3 +559,34 @@ int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO* info_in, | |||
return SOCKET_ERROR; | |||
} | |||
} | |||
|
|||
int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr, | |||
struct sockaddr_storage* storage) { |
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.
Indent error.
src/win/winsock.c
Outdated
struct sockaddr_in* dest; | ||
src = (const struct sockaddr_in*) addr; | ||
dest = (struct sockaddr_in*) storage; | ||
memcpy(dest, src, sizeof(struct sockaddr_in)); |
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.
sizeof(*src)
or sizeof(dest)
.
src/win/winsock.c
Outdated
dest = (struct sockaddr_in*) storage; | ||
memcpy(dest, src, sizeof(struct sockaddr_in)); | ||
if (src->sin_addr.s_addr == 0) { | ||
uv_inet_pton(AF_INET, "127.0.0.1", &dest->sin_addr.s_addr); |
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.
dest->sin_addr.s_addr = INADDR_LOOPBACK;
? Or doesn't that exist on Windows? You could use htonl(0x7F000001)
instead.
src/win/winsock.c
Outdated
struct sockaddr_in6* dest; | ||
src = (const struct sockaddr_in6*) addr; | ||
dest = (struct sockaddr_in6*) storage; | ||
memcpy(dest, src, sizeof(struct sockaddr_in6)); |
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.
sizeof(*src)
or sizeof(dest)
.
src/win/winsock.c
Outdated
memcpy(dest, src, sizeof(struct sockaddr_in6)); | ||
if (memcmp(&src->sin6_addr, | ||
&uv_addr_ip6_any_.sin6_addr, | ||
sizeof(struct in6_addr)) == 0) { |
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.
Likewise.
src/win/winsock.c
Outdated
if (memcmp(&src->sin6_addr, | ||
&uv_addr_ip6_any_.sin6_addr, | ||
sizeof(struct in6_addr)) == 0) { | ||
uv_inet_pton(AF_INET6, "::1", &dest->sin6_addr); |
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.
IN6ADDR_LOOPBACK_INIT
or in6addr_loopback
?
test/test-connect-unspecified.c
Outdated
#include "uv.h" | ||
#include "task.h" | ||
|
||
void connect_4(uv_connect_t* req, int status) { |
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.
static
test/test-connect-unspecified.c
Outdated
ASSERT(status != UV_EADDRNOTAVAIL); | ||
} | ||
|
||
void connect_6(uv_connect_t* req, int status) { |
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.
static
Updated, PTAL |
ping |
ping? |
ping? |
@bzoz I've dismissed my review but like I said, I don't know if I agree that this is a change for the better. I won't block this PR but I can't say I wholeheartedly endorse it either. @libuv/collaborators WDYT? |
I'm conflicted as well. server.bind(0, '0.0.0.0');
client.connect(server.port, server.address); pattern which is useful for IPC (and testing which is also nice)... |
@@ -559,3 +559,32 @@ int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO* info_in, | |||
return SOCKET_ERROR; | |||
} | |||
} | |||
|
|||
int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr, |
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.
Couldnt this method could be cleaned up using a union and switch similar to the code found here?
@imran-iq I've followed up on your suggestion, I think that indeed it looks simpler now. PTAL |
Fixed the test, new CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/539/, PTAL |
@libuv/collaborators ping? I know it might be controversial. But it eases out differences between platforms, and fixes real world use case. CI, since last 404ed: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/555/ |
ping? |
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 guess I'll sign off on this because it brings Windows closer to the out-of-the-box behavior on Linux.
docs/src/tcp.rst
Outdated
The callback is made when the connection has been established or when a | ||
connection error happened. | ||
|
||
.. versionchanged:: 1.15.0 added ``0.0.0.0`` and ``::`` to ``localhost`` |
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.
Version number needs an update.
docs/src/udp.rst
Outdated
@@ -259,6 +263,9 @@ API | |||
|
|||
:returns: 0 on success, or an error code < 0 on failure. | |||
|
|||
.. versionchanged:: 1.15.0 added ``0.0.0.0`` and ``::`` to ``localhost`` |
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.
Ditto.
CI after rebase: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/641 |
On Linux when connecting IP addresses 0.0.0.0 and :: are automatically converted to localhost. This adds same functionality to Windows. PR-URL: #1515 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Landed in 2b32e77 |
Ho @bzoz, there's still a -1 from a collaborator. You'll have to revert this. |
@saghul commented he is generally +1 on the change and I've addressed his feedback here |
Should I make a PR for revert or just push a revert commit? Also, @saghul did not respond to my pings for some time now, how can I get this merged then? |
On Linux when connecting, IP addresses
0.0.0.0
and::
are automatically converted tolocalhost
. This adds the same functionality to Windows.Ref: nodejs/node#14900
Ref: nodejs/node#14111