MCPcopy Create free account
hub / github.com/ddev/ddev / GetWSL2NetworkingMode

Function GetWSL2NetworkingMode

pkg/nodeps/wsl.go:44–61  ·  view source on GitHub ↗

GetWSL2NetworkingMode returns the current WSL2 networking mode. Valid modes are "nat", "mirrored", "virtioproxy", "none", and "bridged". See https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfig

()

Source from the content-addressed store, hash-verified

42// Valid modes are "nat", "mirrored", "virtioproxy", "none", and "bridged".
43// See https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-settings-for-wslconfig
44func GetWSL2NetworkingMode() (string, error) {
45 out, err := exec.Command("wslinfo", "--networking-mode").Output()
46 if err != nil {
47 return "", fmt.Errorf("failed to run wslinfo: %w", err)
48 }
49 mode := strings.TrimSpace(strings.ToLower(string(bytes.TrimSpace(out))))
50 validModes := map[string]bool{
51 "nat": true,
52 "mirrored": true,
53 "virtioproxy": true,
54 "none": true,
55 "bridged": true,
56 }
57 if !validModes[mode] {
58 return "", fmt.Errorf("unrecognized networking mode %q", mode)
59 }
60 return mode, nil
61}
62
63// IsWSL2VirtioProxyMode returns true if running WSL2 in virtioproxy mode.
64func IsWSL2VirtioProxyMode() bool {

Callers 7

wsl2EnvironmentFunction · 0.92
checkWSL2ConfigurationFunction · 0.92
IsWSL2MirroredModeFunction · 0.85
IsWSL2VirtioProxyModeFunction · 0.85
IsWSL2NoneModeFunction · 0.85
IsWSL2BridgedModeFunction · 0.85

Calls 2

CommandMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected