Skip to content
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

Closed
wants to merge 10 commits into from

Conversation

bzoz
Copy link
Member

@bzoz bzoz commented Aug 31, 2017

On Linux when connecting, IP addresses 0.0.0.0 and :: are automatically converted to localhost. This adds the same functionality to Windows.

Ref: nodejs/node#14900
Ref: nodejs/node#14111

On Linux when connecting IP addresses 0.0.0.0 and :: are automatically
converted to localhost. This adds same functionality to Windows.
@bzoz
Copy link
Member Author

bzoz commented Aug 31, 2017

@bzoz
Copy link
Member Author

bzoz commented Aug 31, 2017

Another run, with correct Makefile: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/420/

@refack
Copy link
Contributor

refack commented Aug 31, 2017

Ideally I'd go the other way and throw on connect('0.0.0.0') on POSIX as well, since it literally reads as "connect to wherever", but I guess that will cause too much breakage...

So I'm +1 on this

@saghul
Copy link
Member

saghul commented Sep 2, 2017

Some bots had failed with Jenkins issues, I retriggered the build: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/421/

@saghul
Copy link
Member

saghul commented Sep 2, 2017

I'm +1 on this, as long as all Unixen behave like Linux.

Copy link
Member

@bnoordhuis bnoordhuis left a 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.

uv_inet_pton(AF_INET6, "::1", &(dest->sin6_addr));
addr = (const struct sockaddr*) dest;
}
}
Copy link
Member

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.

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));
Copy link
Member

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 = (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,
Copy link
Member

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?


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);
Copy link
Member

Choose a reason for hiding this comment

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

Long line.

@bzoz
Copy link
Member Author

bzoz commented Sep 4, 2017

@bzoz
Copy link
Member Author

bzoz commented Sep 5, 2017

The failures are unrelated, and the automatic mapping of 0.0.0.0 to localhost works on all tested platforms.

Copy link
Member

@saghul saghul left a 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.

struct sockaddr_in* dest;
src = (const struct sockaddr_in*) addr;
dest = (struct sockaddr_in*) storage;
memcpy(dest, src, sizeof(struct sockaddr_in));
Copy link
Member

Choose a reason for hiding this comment

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

style: incorrect indent

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) {
Copy link
Member

Choose a reason for hiding this comment

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

incorrect capitalization?

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Member

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.

dest = (struct sockaddr_in6*) storage;
memcpy(dest, src, sizeof(struct sockaddr_in6));
if (memcmp(&src->sin6_addr,
&uv_addr_ip6_any_.sin6_addr,
Copy link
Member

Choose a reason for hiding this comment

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

style: indent

sizeof(struct in6_addr)) == 0) {
uv_inet_pton(AF_INET6, "::1", &dest->sin6_addr);
}
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

ditto

}
return 0;
} else {
return UV_EINVAL;
Copy link
Member

Choose a reason for hiding this comment

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

ditto


loop = uv_default_loop();

uv_tcp_init(loop, &socket4);
Copy link
Member

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

@bzoz
Copy link
Member Author

bzoz commented Sep 5, 2017

@bzoz
Copy link
Member Author

bzoz commented Sep 14, 2017

ping?

Copy link
Member

@bnoordhuis bnoordhuis left a 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
Copy link
Member

Choose a reason for hiding this comment

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

Also ::, right?

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

Indent error.

struct sockaddr_in* dest;
src = (const struct sockaddr_in*) addr;
dest = (struct sockaddr_in*) storage;
memcpy(dest, src, sizeof(struct sockaddr_in));
Copy link
Member

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).

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);
Copy link
Member

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.

struct sockaddr_in6* dest;
src = (const struct sockaddr_in6*) addr;
dest = (struct sockaddr_in6*) storage;
memcpy(dest, src, sizeof(struct sockaddr_in6));
Copy link
Member

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).

memcpy(dest, src, sizeof(struct sockaddr_in6));
if (memcmp(&src->sin6_addr,
&uv_addr_ip6_any_.sin6_addr,
sizeof(struct in6_addr)) == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Likewise.

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);
Copy link
Member

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?

#include "uv.h"
#include "task.h"

void connect_4(uv_connect_t* req, int status) {
Copy link
Member

Choose a reason for hiding this comment

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

static

ASSERT(status != UV_EADDRNOTAVAIL);
}

void connect_6(uv_connect_t* req, int status) {
Copy link
Member

Choose a reason for hiding this comment

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

static

@bzoz
Copy link
Member Author

bzoz commented Sep 18, 2017

Updated, PTAL

@bzoz
Copy link
Member Author

bzoz commented Sep 28, 2017

ping

@bzoz
Copy link
Member Author

bzoz commented Oct 12, 2017

ping?

@bzoz
Copy link
Member Author

bzoz commented Oct 19, 2017

ping?

@saghul @bnoordhuis

@bnoordhuis
Copy link
Member

@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?

@refack
Copy link
Contributor

refack commented Oct 19, 2017

I'm conflicted as well.
But it does bring uniformity, and enables the

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,
Copy link
Contributor

@imran-iq imran-iq Oct 23, 2017

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?

@bzoz
Copy link
Member Author

bzoz commented Oct 26, 2017

@imran-iq I've followed up on your suggestion, I think that indeed it looks simpler now.

PTAL

@bzoz
Copy link
Member Author

bzoz commented Oct 26, 2017

@bzoz
Copy link
Member Author

bzoz commented Oct 27, 2017

Fixed the test, new CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/539/, PTAL

@bzoz
Copy link
Member Author

bzoz commented Nov 3, 2017

@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/

@bzoz
Copy link
Member Author

bzoz commented Dec 21, 2017

ping?

Copy link
Member

@bnoordhuis bnoordhuis left a 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``
Copy link
Member

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``
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@bzoz
Copy link
Member Author

bzoz commented Dec 28, 2017

bzoz added a commit that referenced this pull request Dec 28, 2017
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>
@bzoz
Copy link
Member Author

bzoz commented Dec 28, 2017

Landed in 2b32e77

@bzoz bzoz closed this Dec 28, 2017
@bnoordhuis
Copy link
Member

Ho @bzoz, there's still a -1 from a collaborator. You'll have to revert this.

@bzoz
Copy link
Member Author

bzoz commented Dec 28, 2017

@saghul commented he is generally +1 on the change and I've addressed his feedback here

@bnoordhuis
Copy link
Member

@saghul Can you update your review if you're okay with this?

@bzoz As long as there's a negative review, you can't merge it.

@bzoz
Copy link
Member Author

bzoz commented Dec 28, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants