From d4502c8d0e2ae63e76c4e716cd856bc6807801e6 Mon Sep 17 00:00:00 2001 From: John Wargo Date: Thu, 3 Oct 2024 12:07:32 -0700 Subject: [PATCH 1/3] Fixed WSL2 IP Address Resolution Signed-off-by: John Wargo --- pkg/rancher-desktop/backend/wsl.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/rancher-desktop/backend/wsl.ts b/pkg/rancher-desktop/backend/wsl.ts index 8e0177fb241..e18b1d63d91 100644 --- a/pkg/rancher-desktop/backend/wsl.ts +++ b/pkg/rancher-desktop/backend/wsl.ts @@ -938,6 +938,10 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend /** Get the IPv4 address of the VM, assuming it's already up. */ get ipAddress(): Promise { return (async() => { + // When using mirrored-mode networking, 127.0.0.1 works just fine! + const networkModeString = await this.captureCommand('wslinfo', '-n', '--networking-mode'); + if (networkModeString === 'mirrored') return '127.0.0.1'; + // We need to locate the _local_ route (netmask) for eth0, and then // look it up in /proc/net/fib_trie to find the local address. const routesString = await this.captureCommand('cat', '/proc/net/route'); From 5a0e51279047f9f72d33ab14d1b92d0362ce9b2f Mon Sep 17 00:00:00 2001 From: John Wargo Date: Thu, 3 Oct 2024 13:31:48 -0700 Subject: [PATCH 2/3] Fixed a bug when wslinfo is missing Signed-off-by: John Wargo --- pkg/rancher-desktop/backend/wsl.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/rancher-desktop/backend/wsl.ts b/pkg/rancher-desktop/backend/wsl.ts index dca697a2c41..a2d75feabc7 100644 --- a/pkg/rancher-desktop/backend/wsl.ts +++ b/pkg/rancher-desktop/backend/wsl.ts @@ -940,10 +940,14 @@ export default class WSLBackend extends events.EventEmitter implements VMBackend return (async() => { // When using mirrored-mode networking, 127.0.0.1 works just fine // ...also, there may not even be an `eth0` to find the IP of! - const networkModeString = await this.captureCommand('wslinfo', '-n', '--networking-mode'); + try { + const networkModeString = await this.captureCommand('wslinfo', '-n', '--networking-mode'); - if (networkModeString === 'mirrored') { - return '127.0.0.1'; + if (networkModeString === 'mirrored') { + return '127.0.0.1'; + } + } catch { + // wslinfo is missing (wsl < 2.0.4) - fall back to old behavior } // We need to locate the _local_ route (netmask) for eth0, and then From ef32112a3fca5b0a6da79430ff0d42750f1cd459 Mon Sep 17 00:00:00 2001 From: John Wargo Date: Thu, 3 Oct 2024 13:32:58 -0700 Subject: [PATCH 3/3] Added wslinfo to spellcheck Signed-off-by: John Wargo --- .github/actions/spelling/expect.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 3a0d8db1705..d1d57a5f955 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -889,6 +889,7 @@ wslconfig WSLENV WSLg wslify +wslinfo WSLINSTALLED WSLIs WSLKERNELOUTDATED