Skip to content

Commit ebfb549

Browse files
committed
vmnet: add broker and network option detection
Add functions to detect vmnet-broker installation and vmnet-helper --network option support: - brokerInstalled(): checks if vmnet-broker launchd plist exists - helperSupportsNetwork(): parses --help output for --network option - SupportsNetwork field in helperInfo for caching detection result This prepares for using vmnet-broker managed networks when available.
1 parent b42d3ba commit ebfb549

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

pkg/drivers/common/vmnet/vmnet.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const (
5353
installPath = "/opt/vmnet-helper/bin/vmnet-helper"
5454
// Installed via Homebrew (macOS 26+ only).
5555
brewInstallPath = "/opt/homebrew/opt/vmnet-helper/libexec/vmnet-helper"
56+
57+
// vmnet-broker launchd plist path.
58+
brokerPlistPath = "/Library/LaunchDaemons/com.github.nirs.vmnet-broker.plist"
5659
)
5760

5861
// Helper manages the vmnet-helper process.
@@ -84,10 +87,11 @@ type helperVersion struct {
8487

8588
// helperInfo contains cached information about vmnet-helper.
8689
type helperInfo struct {
87-
Path string
88-
Version helperVersion
89-
NeedsSudo bool
90-
Err error
90+
Path string
91+
Version helperVersion
92+
NeedsSudo bool
93+
SupportsNetwork bool // true if helper supports --network option
94+
Err error
9195
}
9296

9397
var (
@@ -113,6 +117,10 @@ func getHelperInfo() (helperInfo, error) {
113117
return
114118
}
115119
cached.NeedsSudo, cached.Err = helperNeedsSudo(cached.Version, macosVersion)
120+
if cached.Err != nil {
121+
return
122+
}
123+
cached.SupportsNetwork = helperSupportsNetwork(cached.Path)
116124
})
117125
return cached, cached.Err
118126
}
@@ -153,8 +161,8 @@ func ValidateHelper(options *run.CommandOptions) error {
153161
}
154162
}
155163

156-
log.Debugf("Validated vmnet-helper (path=%q, version=%q, commit=%q, needsSudo=%v)",
157-
helper.Path, helper.Version.Version, helper.Version.Commit, helper.NeedsSudo)
164+
log.Debugf("Validated vmnet-helper (path=%q, version=%q, commit=%q, needsSudo=%v, supportsNetwork=%v)",
165+
helper.Path, helper.Version.Version, helper.Version.Commit, helper.NeedsSudo, helper.SupportsNetwork)
158166

159167
return nil
160168
}
@@ -443,6 +451,20 @@ func findHelper() (string, error) {
443451
return "", &Error{Kind: reason.NotFoundVmnetHelper, Err: err}
444452
}
445453

454+
// brokerInstalled returns true if the vmnet-broker launchd plist is installed.
455+
func brokerInstalled() bool {
456+
_, err := os.Stat(brokerPlistPath)
457+
return err == nil
458+
}
459+
460+
// helperSupportsNetwork returns true if vmnet-helper supports the --network option.
461+
func helperSupportsNetwork(path string) bool {
462+
// Use CombinedOutput since help may go to stderr.
463+
out, _ := exec.Command(path, "--help").CombinedOutput()
464+
// Check for the specific option format to avoid false positives.
465+
return strings.Contains(string(out), "[--network NAME]")
466+
}
467+
446468
// helperNeedsSudo returns true if vmnet-helper needs sudo to run based on the
447469
// helper version and macOS version.
448470
func helperNeedsSudo(version helperVersion, macosVersion string) (bool, error) {

0 commit comments

Comments
 (0)