Skip to content

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

Closed
lifenjoiner wants to merge 2 commits intocurl:masterfrom
lifenjoiner:ip4m6
Closed

cf-socket: turn off IPV6_V6ONLY on Windows if it is supported#10975
lifenjoiner wants to merge 2 commits intocurl:masterfrom
lifenjoiner:ip4m6

Conversation

@bagder
Copy link
Member

bagder commented Apr 16, 2023

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

lifenjoiner commented Apr 17, 2023

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

jay commented Apr 19, 2023

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

@bagder bagder added the Windows Windows-specific label Apr 26, 2023
@bagder bagder closed this in ca3f6de Apr 26, 2023
@bagder
Copy link
Member

bagder commented Apr 26, 2023

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