-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support WSL2 distros accessing private (apiserver, ssh, cockpit) serv…
…ices Bind Windows host-side vSock ports to the Window's machines IP on the WSL2 network allowing both Windows host and WSL2 to connect to VM services that aren't shared publically.
- Loading branch information
1 parent
5d48458
commit a1a76cf
Showing
5 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package machine | ||
|
||
func VsockPrivateAddress() (addrStr string) { | ||
return "127.0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package machine | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/crc-org/crc/pkg/crc/logging" | ||
"github.com/crc-org/crc/pkg/os/windows/powershell" | ||
) | ||
|
||
const ( | ||
fallbackPrivateAddress = "127.0.0.1" | ||
adapterName = "vEthernet (WSL)" | ||
) | ||
|
||
// On Windows it would be useful if WSL2 can access VSock resources as well | ||
// This address should work on both the windows side and the WSL2 side | ||
func VsockPrivateAddress() (addrStr string) { | ||
cmd := fmt.Sprintf(`(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "%s").IPAddress`, adapterName) | ||
stdout, stderr, err := powershell.Execute(cmd) | ||
if err != nil { | ||
logging.Debugf("Unable to find IP address for WSL vswitch: %v: %s", err, stderr) | ||
return fallbackPrivateAddress | ||
} | ||
if strings.TrimSpace(stdout) == "" { | ||
return fallbackPrivateAddress | ||
} | ||
return strings.TrimSpace(stdout) | ||
} |