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

Mirrored networking IPv6 localhost (and localhost addresses) and hostAddressLoopback (for assigned addresses) not working from host (WSL2) #10803

Open
1 of 2 tasks
sgryphon opened this issue Nov 21, 2023 · 9 comments

Comments

@sgryphon
Copy link

sgryphon commented Nov 21, 2023

Windows Version

Microsoft Windows [Version 10.0.22631.2787]

WSL Version

2.0.9.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.133.1-microsoft-standard-WSL2

Distro Version

Ubuntu 22.04.2 LTS

Other Software

No response

Repro Steps

Steps to reproduce:

  1. Configure WSL with networkMode=mirrored and hostAddressLoopback=true
  2. Ensure Windows firewall allows inbound port 8001 (or is turned off)
  3. Have a WSL machine available, e.g. Ubuntu
  4. Start a WSL Ubuntu window in Windows Terminal
  5. Use 'tmux' in Ubuntu as an easy way to get multiple panes, i.e.: tmux
  6. Ctrl-B % to split the window vertically
  7. Run a simple HTTP server via Python: python3 -m http.server --bind :: 8001
  8. Ctrl-B ; to toggle back to the first pane
  9. Checks from the WSL machine (works, both IPv4 and IPv6):
    a. Check IPv4 access from WSL (works): curl -v4 http://localhost:8001
    b. Check IPv6 access from WSL (works): curl -v6 http://localhost:8001
    c. Check IPv4 with local IP (works, change IP addresses as per your networking): curl http://192.168.1.174:8001
    d. Check IPv6 with local IP (works): curl http://[2407:8800:bc61:1340::899]:8001
  10. Check from another machine on the same network (works, both IPv4 and IPv6):
    a. Check IPv4 with IP (works): curl http://192.168.1.174:8001
    b. Check IPv6 with IP (works): curl http://[2407:8800:bc61:1340::899]:8001
  11. Open a second Windows Terminal window with PowerShell, on the Windows host (running WSL)
  12. From Windows host, check IPv4 (works):
    a. Check IPv4 localhost (works): curl -v4 http://localhost:8001
    b. Check IPv4 local address (works): curl http://127.0.0.1:8001
    c. Check IPv4 with IP (works): curl http://192.168.1.174:8001
  13. From Windows host fails to connect via IPv6 (fails):
    a. Check IPv6 localhost (fails): curl -v6 http://localhost:8001
    b. Check IPv6 local address (fails): curl -v6 http://[::1]:8001
    c. Check IPv6 with IP (fails): curl http://[2407:8800:bc61:1340::899]:8001
  14. Error is: curl: (28) Failed to connect to localhost port 8001 after 21048 ms: Couldn't connect to server

Screen shot:

  • The Python server is in the top right.
  • The first four connections are from WSL on IPv4 and IPv6, for local host and local IP addresses (works)
  • The next two (from 192.168.1.206 and 2407:...:4d23) are IPv4 and IPv6 from a separate machine on the network (works) -- the calls from the other machine are on the left.
  • The next three are connections from the Windows host on IPv4 for -v4 localhost, 127.0.0.1, and the local IP address -- the last of these can be seen in the middle window
  • The bottom of the middle window has the three IPv6 failures, from the Windows host to localhost and local IPv6.

wsl-ipv6-localhost-fail

Expected Behavior

What should happen

IPv6 (and IPv4) connections to localhost and local IP addresses, from the Windows host, should be forwarded to WSL (as are other IPv6 connections).

Actual Behavior

Issue / what happens

  1. From Windows host, unable to connect to the WSL localhost port via IPv6, only IPv4 (both work from WSL).
  2. From Windows host, unable to connect to the WSL hostAddressLoopback port via IPv6, only IPv4 (both work from WSL and from the network).
Destination WSL guest Windows host Network
localhost IPv4 yes yes -
localhost IPv6 yes FAILS -
127.0.0.1 (IPv4) yes yes -
[::] yes (IPv6) FAILS -
IPv4 host address, e.g. 192.168.1.174 yes yes (1) yes
IPv6 host address, e.g. [2407:8800:bc61:1340::899] yes FAILS (1) yes

(1) with hostAddressLoopback; without setting loopback to host address is not available on either v4 or v6 (by design)

This breaks applications trying to explicitly connect to IPv6, e.g. [::1], or that only resolve/try the IPv6 address for 'localhost'.

Error trying to use curl to connect is: curl: (28) Failed to connect to localhost port 8001 after 21048 ms: Couldn't connect to server

Mitigation: Systems that try both IPv6 and IPv4 resolutions of 'localhost' may still work (e.g. a browser with happy eyeballs may try both).

Notes

This also happens with hostAddressLoopback turned off (default), with none of the local IPs working (as expected), i.e. localhost still doesn't work. I turned it on to see if it fixed the issue (it didn't).

The python web server was used as a simple example/reproduction of the forwarding failing for IPv6, with the original issue occurring trying to access a service running in Podman hosted in WSL, i.e. a container, with Podman IPv6 enabled, trying to expose the port, and the IPv4 worked but IPv6 didn't. However the issue had nothing to do with Podman or containers, but can be reproduced as above with a simple HTTP server running on a WSL Ubuntu machine.

Diagnostic Logs

Failure messages (from Windows host):

(First response is an IPv4 success)

PS C:\Users\Sly> curl http://192.168.1.174:8001

<title>Directory listing for /</title>

Directory listing for /



PS C:\Users\Sly> curl -v6 http://localhost:8001 * Trying [::1]:8001... * connect to ::1 port 8001 failed: Timed out * Failed to connect to localhost port 8001 after 21437 ms: Couldn't connect to server * Closing connection curl: (28) Failed to connect to localhost port 8001 after 21437 ms: Couldn't connect to server PS C:\Users\Sly> curl http://[::1]:8001 curl: (28) Failed to connect to ::1 port 8001 after 21057 ms: Couldn't connect to server PS C:\Users\Sly> curl http://[2407:8800:bc61:1340::899]:8001 curl: (28) Failed to connect to 2407:8800:bc61:1340::899 port 8001 after 22279 ms: Couldn't connect to server PS C:\Users\Sly>

Environment:

PS C:\Users\Sly> wsl --version
WSL version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.2787

PS C:\Users\Sly> ipconfig
Windows IP Configuration
Ethernet adapter Ethernet0:
Connection-specific DNS Suffix . : lan
IPv6 Address. . . . . . . . . . . : 2407:8800:bc61:1340::899
IPv6 Address. . . . . . . . . . . : fd7c:e25e:67e8:40::899
IPv6 Address. . . . . . . . . . . : fd7c:e25e:67e8:40:5c3:271c:adcc:4e6b
Temporary IPv6 Address. . . . . . : 2407:8800:bc61:1340:8035:3724:ed35:c20c
IPv6 Address. . . . . . . . . . . : 2407:8800:bc61:1340:e952:3110:2901:7499
Temporary IPv6 Address. . . . . . : fd7c:e25e:67e8:40:8035:3724:ed35:c20c
Link-local IPv6 Address . . . . . : fe80::4d6d:9ea:a521:d435%7
IPv4 Address. . . . . . . . . . . : 192.168.1.174
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

PS C:\Users\Sly> cat .wslconfig
[experimental]
networkingMode=mirrored
hostAddressLoopback=True

On the WSL instance:

sly@VMWIN2023:~$ uname -a
Linux VMWIN2023 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

sly@VMWIN2023:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1492 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:8b:52:b1 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.174/24 brd 192.168.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 2407:8800:bc61:1340::899/128 scope global nodad noprefixroute
valid_lft forever preferred_lft forever
inet6 fd7c:e25e:67e8:40:5c3:271c:adcc:4e6b/64 scope global nodad deprecated noprefixroute
valid_lft forever preferred_lft 0sec
inet6 fd7c:e25e:67e8:40:8035:3724:ed35:c20c/128 scope global nodad noprefixroute
valid_lft forever preferred_lft forever
inet6 fd7c:e25e:67e8:40::899/128 scope global nodad noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::4d6d:9ea:a521:d435/64 scope link nodad noprefixroute
valid_lft forever preferred_lft forever
3: loopback0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:67:c2:f2 brd ff:ff:ff:ff:ff:ff

Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@ghost
Copy link

ghost commented Nov 21, 2023

Thanks for writing this up. I'm pretty sure this is due to our lack of support for dual mode sockets.

Same type of bug as #4851, though the port tracking here is different than what's in use by the localhost relay in nat mode.

@sgryphon sgryphon changed the title WSL localhostForwarding and hostAddressLoopback not working for IPv6 WSL localhostForwarding and hostAddressLoopback not working for IPv6 in mirrored networking Nov 30, 2023
@sgryphon sgryphon changed the title WSL localhostForwarding and hostAddressLoopback not working for IPv6 in mirrored networking Mirrored networking IPv6 localhostForwarding and hostAddressLoopback not working from host (WSL2); works elsewhere Nov 30, 2023
@sgryphon sgryphon changed the title Mirrored networking IPv6 localhostForwarding and hostAddressLoopback not working from host (WSL2); works elsewhere Mirrored networking IPv6 localhostForwarding and hostAddressLoopback not working from host (WSL2) Nov 30, 2023
@chanpreetdhanjal
Copy link

Could you please follow the steps below and attach the diagnostic logs? https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#collect-wsl-logs-for-networking-issues

@sgryphon
Copy link
Author

Diagnostic logs as requested.

I followed the reproduction steps, i.e. 9 successful queries (4 mixed from WSL guest, 2 mixed from network, 3 IPv4 only from the host).

I then ran the 3 failing queries (IPv6 from the host), then repeated that 2 more times (9 in total). Each had a 21s timeout then fails.

WslNetworkingLogs-2023-12-15_23-45-39.zip

@CatalinFetoiu
Copy link
Collaborator

@sgryphon thanks for following up and sorry for the delayed response.

At the moment the hostAddressLoopback setting works only for IPv4, it is not supported for IPv6

@CatalinFetoiu
Copy link
Collaborator

@sgryphon regarding "localhostForwarding", this flag is ignored in mirrored mode, as mirrored mode already provides a way to communicate between Windows and Linux over loopback without the need for this flag.

We'll update the documentation to mention that "localhostForwarding" is ignored in mirrored mode
And that mirrored mode currently supports loopback communication only using IPv4

I am closing the issue

@sgryphon sgryphon changed the title Mirrored networking IPv6 localhostForwarding and hostAddressLoopback not working from host (WSL2) Mirrored networking IPv6 localhost (and localhost addresses) and hostAddressLoopback (for assigned addresses) not working from host (WSL2) Jan 10, 2024
@sgryphon
Copy link
Author

sgryphon commented Jan 10, 2024

hostAddressLoopback is only relevant for one of the three failing cases.

I probably shouldn't have included localhostForwarding in the issue title (which has default true), as you are right, it has nothing to do with the issue, which is really about networkingMode = mirrored.

The issue is that they don't work by for IPv6, i.e. "mirrored mode currently supports loopback communication only using IPv4" is precisely the issue that I want fixed.

Unless you are saying this is by design and you won't fix -- which is silly -- why would you have mirrored mode only support IPv6 over the network but not from the host (which is what this issue is about)?

(I could understand not having IPv6 at all, but having only half an implementation -- supporting network but not host -- is incomplete.)

Please do not close this issue until you have added supported for IPv6 from the host to mirrored mode. Thanks.

@bayeslearner
Copy link

bayeslearner commented Jan 10, 2024

Can I understand mirrored mode as kind of like sharing the same network namespace by containers in the same pod in kubernetes? I read the doc, but still find it very confusing.

@CatalinFetoiu
Copy link
Collaborator

@sgryphon thanks for your reply and feedback. I reopened the issue

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

No branches or pull requests

5 participants