Skip to content

cf-socket: turn off IPV6_V6ONLY on Windows if it is supported - #10975

Closed
lifenjoiner wants to merge 2 commits into
curl:masterfrom
lifenjoiner:ip4m6
Closed

lifenjoiner wants to merge 2 commits into
curl:masterfrom
lifenjoiner:ip4m6

Conversation

@lifenjoiner

Copy link
Copy Markdown
Contributor

It makes support for IPv4-mapped IPv6 addresses.

IPV6_V6ONLY refs:
https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses
https://github.com/golang/go/blob/master/src/net/ipsock_posix.go
https://en.wikipedia.org/wiki/Unix-like
off:
https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html#proc-sys-net-ipv6-variables
https://man.netbsd.org/inet6.4
https://man.freebsd.org/cgi/man.cgi?query=inet6
https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man4/inet6.4
on:
https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
acts like off, but returns 1 and dummy setting:
https://man.dragonflybsd.org/?command=inet6
https://man.dragonflybsd.org/?command=ip6
unsupported and read-only returns 1:
https://man.openbsd.org/inet6.4

default value refs:
https://datatracker.ietf.org/doc/html/rfc3493#section-5.3
https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html#proc-sys-net-ipv6-variables

IPV6_V6ONLY refs:
https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses
https://github.com/golang/go/blob/master/src/net/ipsock_posix.go
https://en.wikipedia.org/wiki/Unix-like
off:
https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html#proc-sys-net-ipv6-variables
https://man.netbsd.org/inet6.4
https://man.freebsd.org/cgi/man.cgi?query=inet6
https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man4/inet6.4
on:
https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options
acts like off, but returns 1 and dummy setting:
https://man.dragonflybsd.org/?command=inet6
https://man.dragonflybsd.org/?command=ip6
unsupported and read-only returns 1:
https://man.openbsd.org/inet6.4

default value refs:
https://datatracker.ietf.org/doc/html/rfc3493#section-5.3
https://www.kernel.org/doc/html/latest/networking/ip-sysctl.html#proc-sys-net-ipv6-variables
@bagder

bagder commented Apr 16, 2023

Copy link
Copy Markdown
Member

Quoting section 5.3 of RFC 3493:

Note - This option has no effect on the use of IPv4 Mapped addresses

Which sounds like the opposite to the reason for this PR?

@lifenjoiner

lifenjoiner commented Apr 17, 2023 •

Copy link
Copy Markdown
Contributor Author

The whole note in section 5.3 of RFC 3493:

Note - This option has no effect on the use of IPv4 Mapped addresses
which enter a node as a valid IPv6 addresses for IPv6 communications
as defined by Stateless IP/ICMP Translation Algorithm (SIIT) [5].

That is confusing. I guess it means in separate translator "boxes" by the SIIT (rfc2765) abstract section:

The algorithm
translates between IPv4 and IPv6 packet headers (including ICMP
headers) in separate translator "boxes" in the network without
requiring any per-connection state in those "boxes".

Some facts on IPv4-mapped IPv6 addresses support:

  • Turning off IPV6_V6ONLY does make it work on IPv4-mapped IPv6 addresses with dual-stack socket.
  • Most OSes works on it by default. while Windows don't.
  • Browsers like Chrome can visit them, while IE and Firefox don't, on Windows.
  • Windows, ping works, while nslookup doesn't. dig does.

Edit: I had a golang compiled proxy for Firefox. Golang runtime has the capability by default.

@lifenjoiner

Copy link
Copy Markdown
Contributor Author

The problem is Windows doesn't follow the RFC to set IPV6_V6ONLY off by default, but requires users to do it when they want to create dual-stack socket for IPv4-mapped IPv6 addresses support.
Search IPV6_V6ONLY in the options table.

@jay

jay commented Apr 19, 2023

Copy link
Copy Markdown
Member

Does it really need a separate function?

#if defined(IPV6_V6ONLY) && defined(WIN32)
  /* Allow IPv4 with AF_INET6 sockets on Windows. Other OSes allow this by default. */
  {
    int on = 0;
    setsockopt(ctx->sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on));
  }
#endif

@lifenjoiner

Copy link
Copy Markdown
Contributor Author

Does it really need a separate function?

Not really.

A function is for other place to reuse it. And, if not, the line is longer than 79 chars with (void) return. Compilers would optimize it for binaries :p

@lifenjoiner

Copy link
Copy Markdown
Contributor Author

Does it really need a separate function?

Not really.

A function is for other place to reuse it. And, if not, the line is longer than 79 chars with (void) return. Compilers would optimize it for binaries :p

The real reason is, I saw "we write C89 code", just recalled.

Since we write C89 code, **//** comments are not allowed. They were not

Comment thread lib/cf-socket.c Resolved
@bagder bagder added the Windows Windows-specific label Apr 26, 2023
@bagder bagder closed this in ca3f6de Apr 26, 2023
@bagder

bagder commented Apr 26, 2023

Copy link
Copy Markdown
Member

Thanks!

@lifenjoiner
lifenjoiner deleted the ip4m6 branch July 15, 2023 00:05
vszakats added a commit to vszakats/curl that referenced this pull request Nov 30, 2025
The macro is present in all supported Windows toolchains.

It's present in mingw-w64 v3+, and in MS SDK 6.0A+ (possibly earlier).

Note: It may not be supported by `USE_LWIPSOCK`.

Follow-up to a28f5f6 curl#18010
Follow-up to ca3f6de curl#10975
vszakats added a commit that referenced this pull request Nov 30, 2025
The macro is present in all supported Windows toolchains.

It's present in mingw-w64 v3+, and in MS SDK 6.0A+ (maybe earlier).

Also:
- restrict this logic to `USE_WINSOCK` (was: `_WIN32`), to exclude
  alternate socket libraries (i.e. lwIP). lwIP supports `IPV6_V6ONLY`
  since its 2.0.0 (2016-11-10) release and it's disabled by default,
  unlike in Winsock.
  Ref: lwip-tcpip/lwip@e65202f
- delete interim setter function/dummy macro `set_ipv6_v6only()`.

Follow-up to a28f5f6 #18010
Follow-up to ca3f6de #10975

Closes #19769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants