mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 03:31:39 +00:00
tstest/integration/vms: fix bindhost lookup (#2012)
Don't try to do heuristics on the name. Use the net/interfaces package which we already have to do this sort of stuff. Fixes #2011 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
14c1113d2b
commit
fa548c5b96
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/pkg/sftp"
|
"github.com/pkg/sftp"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
|
"tailscale.com/net/interfaces"
|
||||||
"tailscale.com/tstest"
|
"tailscale.com/tstest"
|
||||||
"tailscale.com/tstest/integration"
|
"tailscale.com/tstest/integration"
|
||||||
"tailscale.com/tstest/integration/testcontrol"
|
"tailscale.com/tstest/integration/testcontrol"
|
||||||
@ -614,37 +615,29 @@ func copyFile(t *testing.T, cli *sftp.Client, localSrc, remoteDest string) {
|
|||||||
func deriveBindhost(t *testing.T) string {
|
func deriveBindhost(t *testing.T) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
ifaces, err := net.Interfaces()
|
ifName, err := interfaces.DefaultRouteInterface()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rex := regexp.MustCompile(`^(eth|enp|wlp|wlan)`)
|
var ret string
|
||||||
|
err = interfaces.ForeachInterfaceAddress(func(i interfaces.Interface, prefix netaddr.IPPrefix) {
|
||||||
for _, iface := range ifaces {
|
if ret != "" || i.Name != ifName {
|
||||||
t.Logf("found interface %s: %d", iface.Name, iface.Flags&net.FlagUp)
|
return
|
||||||
if (iface.Flags & net.FlagUp) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if rex.MatchString(iface.Name) {
|
|
||||||
addrs, err := iface.Addrs()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("can't get address for %s: %v", iface.Name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, addr := range addrs {
|
|
||||||
return netaddr.MustParseIPPrefix(addr.String()).IP().String()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
ret = prefix.IP().String()
|
||||||
|
})
|
||||||
|
if ret != "" {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Fatal("can't find a bindhost")
|
t.Fatal("can't find a bindhost")
|
||||||
return "invalid"
|
return "unreachable"
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeriveBindhost(t *testing.T) {
|
func TestDeriveBindhost(t *testing.T) {
|
||||||
t.Skip("broken on some machines; https://github.com/tailscale/tailscale/issues/2011")
|
|
||||||
t.Log(deriveBindhost(t))
|
t.Log(deriveBindhost(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user