refactor: add support for bridged networking#462
Conversation
8ada1f5 to
43ada88
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors VMware guest/host IP discovery to add bridged-network support, addressing failures when DHCP-based host IP detection is unavailable for bridged networks (Issue #397).
Changes:
- Use VMware Tools (
vmrun getGuestIPAddress) to retrieve the guest IP for bridged networking (and as a fallback for NAT/host-only). - Update host IP detection to handle bridged networking without relying on
vmnetdhcpconfig files. - Extend the
Driverinterface and mocks to support VMware Tools-based guest IP retrieval.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| builder/vmware/common/ssh.go | Adds bridged logic to prefer VMware Tools guest IP; adds VMware Tools fallback for non-bridged networks. |
| builder/vmware/common/driver_workstation.go | Implements GetGuestIPAddress via vmrun and validates the returned IP. |
| builder/vmware/common/driver_fusion.go | Implements GetGuestIPAddress via vmrun with path normalization and IP validation. |
| builder/vmware/common/driver.go | Extends Driver interface, adds bridged host IP handling + injectable IPFinder, and introduces getHostIPForBridgedNetwork. |
| builder/vmware/common/driver_parser.go | Adjusts DHCP hardware-address parsing constraint in Hardware(). |
| builder/vmware/common/driver_mock.go | Adds mock implementation of GetGuestIPAddress. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func getHostIPForBridgedNetwork() (string, error) { | ||
| interfaces, err := net.Interfaces() | ||
| if err != nil { | ||
| return "", fmt.Errorf("unable to enumerate network interfaces: %s", err) | ||
| } | ||
|
|
||
| for _, iface := range interfaces { | ||
| // Skip loopback and down interfaces. | ||
| if iface.Flags&net.FlagLoopback != 0 || iface.Flags&net.FlagUp == 0 { | ||
| continue | ||
| } | ||
|
|
||
| addrs, err := iface.Addrs() | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| for _, addr := range addrs { | ||
| if ipnet, ok := addr.(*net.IPNet); ok { | ||
| if ipv4 := ipnet.IP.To4(); ipv4 != nil { | ||
| log.Printf("[INFO] Found host IP for bridged network: %s on interface %s", ipv4.String(), iface.Name) | ||
| return ipv4.String(), nil | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return "", fmt.Errorf("unable to find a non-loopback IPv4 address on any interface") |
There was a problem hiding this comment.
getHostIPForBridgedNetwork() returns the first non-loopback IPv4 address across all UP interfaces. On hosts with multiple active interfaces (VPN, Docker/Podman bridges, veths), this can pick an address that is not reachable from the bridged guest, breaking HTTP/communicator connectivity. Consider selecting the interface associated with the default route (or otherwise filtering out virtual/bridge interfaces), or deriving the bridged physical interface from VMware’s networking/bridge mapping configuration before choosing the IP.
b7c69cd to
de3f11b
Compare
Refactors to add support bridged networking. - Adds the ability to retrieve the IP address of the guest operating system from VMware Tools. - Detects the IP address of the host to use when using bridged networking. - Uses the IP address of the guest operating system received from VMware Tools when using bridged networking. - Uses the IP address of the guest operating system received from VMware Tools as a fallback for NAT and host-only networking. Note: The method for NAT and host-only networking may be subsequently refactored to only use the VMware Tools method, but this commit limits the scope to only adding support for bridged networking. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
de3f11b to
e72ff9c
Compare
Summary
Refactors to add support bridged networking.
Note: The method for NAT and host-only networking may be subsequently refactored to only use the VMware Tools method, but this commit limits the scope to only adding support for bridged networking.
Type
fix: Bug Fixfeat: Feature or Enhancementdocs: Documentationrefactor: Refactoringchore: Build, Dependencies, Workflows, etc.other: Other (Please describe.)Breaking Changes?
Tests
Output:
Documentation
Issue References
Resolves #397
Release Note
Additional Information