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

usbip: make more reliable by using default route #444

Merged
merged 3 commits into from
Apr 17, 2024
Merged

Conversation

SuperSandro2000
Copy link
Member

@SuperSandro2000 SuperSandro2000 commented Apr 2, 2024

The nameserver does not necessarily need to be the windows host.

/cc @terlar

The nameserver does not necessarily need to be the windows host.
@terlar
Copy link
Contributor

terlar commented Apr 2, 2024

Will this work? When I use this command I get quite a bit of results, none which is the correct one.

$ ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\2/p' | wc -l
115

I am currently using networkingMode=mirrored, which is not working with the current implementation either. Then I need to use 127.0.0.1 or if I use wsl-vpnkit I have to use 192.0.0.1.

Would be nice to have a solution that worked with all the various setups. Perhaps make it a configuration option if there is no reliable way to get the correct IP.

@SuperSandro2000
Copy link
Member Author

SuperSandro2000 commented Apr 3, 2024

Then I need to use 127.0.0.1

We can add a condition for that. We can't as it is written into .wslconfig not /etc/wsl.conf. I don't think I want to add anything related to wsl-vpnkit as it got redundant with the network changes recently.

Would be nice to have a solution that worked with all the various setups. Perhaps make it a configuration option if there is no reliable way to get the correct IP.

There is none and the IP isn't hardcoded by default, hence we cannot hardcode it.


Microsoft also does not have a better way https://learn.microsoft.com/en-us/windows/wsl/networking

@SuperSandro2000
Copy link
Member Author

I've added an option to allow to customize the snippet to obtain the ip address. It is also possible to just hardcode an IP. This should suffice for all listed usecases even if it involves a little bit of manual work.

@terlar
Copy link
Contributor

terlar commented Apr 3, 2024

That works for me, currently I used this one:

busid="$1"

wsl2_gateway_ip=192.0.0.1
ip="127.0.0.1"

if ping -q -w 1 -c 1 "$wsl2_gateway_ip" >/dev/null; then
  ip="$wsl2_gateway_ip"
fi

I agree that we shouldn't add any custom logic to support wsl-vpnkit. Hopefully it is possible to get rid of it at some point. The VPN my company uses, still doesn't work without it, no matter what network mode/configuration is used.

I guess other option could be a list of static IP addresses and then fall-back to the lookup you have. Or just leave it totally up to the user as you have done here.

For example something like this, and a ping check could be done for each IP in the list and then fallback to the command.

{
  hostIpAddresses = lib.mkOption {
    type = with lib.types; listOf str;
    default = [];
    example = ["127.0.0.1"];
  };
}

@SuperSandro2000
Copy link
Member Author

Since checking each IP with ping takes one second and it will increase the complexity more than I want it to right now, I will just leave it up to the end user to configure it correct.

@SuperSandro2000 SuperSandro2000 merged commit fc58f5c into main Apr 17, 2024
25 checks passed
@SuperSandro2000 SuperSandro2000 deleted the usbip-ns branch April 17, 2024 10:02
@nzbr nzbr added the enhancement New feature or request label Jul 7, 2024
@terlar
Copy link
Contributor

terlar commented Jul 26, 2024

I tried this with NAT and it didn't work due to weird Nix string escape, not sure if it is a Nix lang regression.

nix-repl> "$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\2/p')"
"$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/2/p')"

nix-repl> "$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\\2/p')"
"$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\\2/p')"

So with one escape the \ disappears and with two \\ it is not escaped...

@terlar
Copy link
Contributor

terlar commented Jul 26, 2024

Or I guess that is just the representation of the string:

nix-repl> ''$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\2/p')''
"$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\\2/p')"

So I think it needs to be double escaped.

nix-repl> :p "$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\\2/p')"
$(ip route list | sed -nE 's/(default)? via (.*) dev eth0 proto kernel/\2/p')

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

Successfully merging this pull request may close these issues.

3 participants