Skip to content

win: map 0.0.0.0 and :: addresses to localhost#1515

Closed
bzoz wants to merge 10 commits intolibuv:v1.xfrom
JaneaSystems:bartek-win-zero-to-localhost
Closed

win: map 0.0.0.0 and :: addresses to localhost#1515
bzoz wants to merge 10 commits intolibuv:v1.xfrom
JaneaSystems:bartek-win-zero-to-localhost

Conversation

@bzoz
Copy link
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Aug 31, 2017

@bzoz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

saghul commented Sep 2, 2017

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

Copy link
Copy Markdown
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.

Comment thread src/win/winsock.c
uv_inet_pton(AF_INET6, "::1", &(dest->sin6_addr));
addr = (const struct sockaddr*) dest;
}
}
Copy link
Copy Markdown
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.

Comment thread 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));
Copy link
Copy Markdown
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.

Comment thread 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,
Copy link
Copy Markdown
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?

Comment thread 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);
Copy link
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Sep 4, 2017

@bzoz
Copy link
Copy Markdown
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
Copy Markdown
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.

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

Choose a reason for hiding this comment

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

style: incorrect indent

Comment thread 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) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread 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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

style: indent

Comment thread src/win/winsock.c Outdated
sizeof(struct in6_addr)) == 0) {
uv_inet_pton(AF_INET6, "::1", &dest->sin6_addr);
}
return 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

Comment thread src/win/winsock.c Outdated
}
return 0;
} else {
return UV_EINVAL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

Comment thread test/test-connect-unspecified.c Outdated

loop = uv_default_loop();

uv_tcp_init(loop, &socket4);
Copy link
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Sep 5, 2017

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 14, 2017

ping?

Copy link
Copy Markdown
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.

Comment thread docs/src/udp.rst Outdated

: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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also ::, right?

Comment thread src/win/winsock.c Outdated
}

int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr,
struct sockaddr_storage* storage) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indent error.

Comment thread 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));
Copy link
Copy Markdown
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).

Comment thread 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);
Copy link
Copy Markdown
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.

Comment thread 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));
Copy link
Copy Markdown
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).

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

Choose a reason for hiding this comment

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

Likewise.

Comment thread 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);
Copy link
Copy Markdown
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?

Comment thread test/test-connect-unspecified.c Outdated
#include "uv.h"
#include "task.h"

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

Choose a reason for hiding this comment

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

static

Comment thread test/test-connect-unspecified.c Outdated
ASSERT(status != UV_EADDRNOTAVAIL);
}

void connect_6(uv_connect_t* req, int status) {
Copy link
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Sep 18, 2017

Updated, PTAL

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 28, 2017

ping

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Oct 12, 2017

ping?

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Oct 19, 2017

ping?

@saghul @bnoordhuis

@bnoordhuis
Copy link
Copy Markdown
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
Copy Markdown
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)...

Comment thread src/win/winsock.c
}
}

int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr,
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Oct 26, 2017

@bzoz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Dec 21, 2017

ping?

Copy link
Copy Markdown
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.

Comment thread 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
Copy Markdown
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.

Comment thread docs/src/udp.rst Outdated

: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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

bzoz commented Dec 28, 2017

Landed in 2b32e77

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

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

@bzoz
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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