NixOS-WSL icon indicating copy to clipboard operation
NixOS-WSL copied to clipboard

usbip: fix default snippetIpAddress command

Open terlar opened this issue 1 year ago • 3 comments

This fixes some bugs that I discovered in the default command.

The nix string escaping was wrong so the \ got lost and when I tested this the command had a trailing space that made it fail still.

Also this didn't work when I was using network-mode mirrored since it includes metric in the output:

$ ip route list
default via 192.168.1.1 dev eth0 proto kernel metric 35
192.168.1.0/24 dev eth0 proto kernel scope link metric 291
192.168.1.1 dev eth0 proto kernel scope link metric 35

This also adds a target so you can batch restart the services. This is handy when having multiple YubiKeys and or switching between VPN. Perhaps there could even be some auto-restart thing. Will have to think about if that is a hack or not.

terlar avatar Jul 26 '24 21:07 terlar

Seems it is still brittle when connected to VPN with multiple routes or any other case where you have multiple routes. This solves it for me:

"$(ip route list | sed -nE 's/(default)? via (.*) dev .*/\\2/p' | head -n1)";

terlar avatar Jul 26 '24 22:07 terlar

Networking mode NAT

$ wslinfo --networking-mode
nat
$ ip route list
default via 172.17.176.1 dev eth0 proto kernel
172.17.176.0/20 dev eth0 proto kernel scope link src 172.17.181.191
$ ip route list | sed -nE 's/(default)? via (.*) dev .*/\2/p' | head -n1
172.17.176.1

Networking mode mirrored

$ wslinfo --networking-mode
mirrored
$ ip route list
default via 192.168.1.1 dev eth0 proto kernel metric 35
192.168.1.0/24 dev eth0 proto kernel scope link metric 291
192.168.1.1 dev eth0 proto kernel scope link metric 35
$ ip route list | sed -nE 's/(default)? via (.*) dev .*/\2/p' | head -n1
192.168.1.1

Networking mode mirrored + wslvpnkit

$ wslinfo --networking-mode
mirrored
$ ip route list
default via 192.168.127.1 dev wsltap
<-- SNIP VERY LONG LIST OF ROUTES (all on eth0) -->
$ ip route list | sed -nE 's/(default)? via (.*) dev .*/\2/p' | head -n1
192.168.127.1

terlar avatar Jul 26 '24 22:07 terlar

Is there any reason not to always grab the default route?

terlar avatar Jul 26 '24 22:07 terlar