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
()
| 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 |
| 44 | func 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. |
| 64 | func IsWSL2VirtioProxyMode() bool { |
no test coverage detected