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

Support for WSL2 v 2.0 in Mirrored mode #714

Closed
Rybasum opened this issue Sep 22, 2023 · 12 comments
Closed

Support for WSL2 v 2.0 in Mirrored mode #714

Rybasum opened this issue Sep 22, 2023 · 12 comments
Labels
enhancement New feature or request WSL Applies to WSL only

Comments

@Rybasum
Copy link

Rybasum commented Sep 22, 2023

The new version of WSL2 (v2.0) offers Mirrored networking mode (https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update). In this mode usbipd can't attach:

usbipd wsl attach -i=0403:6001
usbipd: info: Device with hardware-id '0403:6001' found at busid '4-1'.
usbipd: error: The selected WSL distribution cannot be reached via the WSL virtual switch; try restarting the WSL distribution.

A workaround is this (in WSL2):

sudo usbip attach -r localhost --busid=4-1

but it is not very convenient...

@dorssel
Copy link
Owner

dorssel commented Sep 23, 2023

Thanks for the report!

@benmcmorran
I'll see if I can get this mode auto-detected and supported. Can you review the result? Or any pointers for a head start?

@dorssel dorssel added enhancement New feature or request WSL Applies to WSL only labels Sep 23, 2023
@Rybasum
Copy link
Author

Rybasum commented Sep 27, 2023

@dorssel I can't find a better way to tell in which networking mode WSL2 is, other than checking the version (should be 2.0.0 or newer) and the presence in the .wslconfig file of this:

[experimental]
networkingMode=mirrored

@benmcmorran
Copy link
Collaborator

I'm not currently working on WSL, but I can try to loop in a Microsoft engineer that is.

@benmcmorran
Copy link
Collaborator

Sounds like reading .wslconfig is the only way to detect mirrored mode for now, but the team is planning an improved detection mechanism for a future WSL release.

@craigloewen-msft
Copy link

@dorssel we are looking into a robust way to detect this and will share it as soon as it's available! :)

@craigloewen-msft
Copy link

@dorssel we added a binary called wslinfo into WSL that will be able to tell you the networking mode. Are you able to use this to determine if a user is running in mirrored mode and adjust accordingly?

https://github.com/microsoft/WSL/releases/tag/2.0.4

@Rybasum
Copy link
Author

Rybasum commented Oct 11, 2023

~$ wslinfo --networking-mode
mirrored

It seems to work!

@dorssel
Copy link
Owner

dorssel commented Oct 11, 2023

It seems to work!

Yes, I found the same. However ... usbipd needs to know the networking mode on the Windows (host) side. I have not yet decided if I want to run a remote (WSL) command (which may not be available...), just to get the information that is required on the Windows side, or instead parsing the option in .wslconfig.

In fact, I believe the whole WSL enumeration code needs a refactor. It is rather old, some stuff is no longer required. It was originally designed to determine the 'per-distro' IP address, which actually never worked, as the IP address is the same for all distros anyway, irrespective of the networking mode. In other words: the design doesn't really fit the purpose. Rewrite is incoming, but not very soon...

@Rybasum
Copy link
Author

Rybasum commented Oct 11, 2023

@dorssel Is the following helpful:

PS C:\Users\marci> wsl -e wslinfo --networking-mode
mirrored

@dorssel
Copy link
Owner

dorssel commented Oct 11, 2023

Not really, sorry. This is exactly what I was referring to. This is running a remote command, on the default distro, which may not even be running (or may not even be WSL 2).

@Rybasum
Copy link
Author

Rybasum commented Oct 11, 2023

@dorssel With wsl shut down, the command still works, albeit it takes ten seconds (needs to start wsl, I guess):

PS C:\Users\marci> wsl --shutdown
PS C:\Users\marci> wsl -e wslinfo --networking-mode
mirrored

The command indeed runs on the default distro, but .wslconfig is global, applies to all distros.
Other problems you cited are valid points, but I just wonder if running wsl -e wslinfo --networking-mode from inside usbipd on Windows might cover 90% of use cases. If the command fails - be it, print an error message ...?

@dorssel
Copy link
Owner

dorssel commented Dec 6, 2023

4.0.0 has been released, which supports mirrored networking mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request WSL Applies to WSL only
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants