wgengine/magicsock: make trivial natlab test pass.
Signed-off-by: David Anderson <danderson@tailscale.com>reviewable/pr544/r1
parent
6c74065053
commit
977381f9cc
|
@ -188,13 +188,13 @@ func TestPickDERPFallback(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeConfigs(t *testing.T, ports []uint16) []wgcfg.Config {
|
func makeConfigs(t *testing.T, addrs []netaddr.IPPort) []wgcfg.Config {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
var privKeys []wgcfg.PrivateKey
|
var privKeys []wgcfg.PrivateKey
|
||||||
var addresses [][]wgcfg.CIDR
|
var addresses [][]wgcfg.CIDR
|
||||||
|
|
||||||
for i := range ports {
|
for i := range addrs {
|
||||||
privKey, err := wgcfg.NewPrivateKey()
|
privKey, err := wgcfg.NewPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -207,14 +207,14 @@ func makeConfigs(t *testing.T, ports []uint16) []wgcfg.Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
var cfgs []wgcfg.Config
|
var cfgs []wgcfg.Config
|
||||||
for i, port := range ports {
|
for i, addr := range addrs {
|
||||||
cfg := wgcfg.Config{
|
cfg := wgcfg.Config{
|
||||||
Name: fmt.Sprintf("peer%d", i+1),
|
Name: fmt.Sprintf("peer%d", i+1),
|
||||||
PrivateKey: privKeys[i],
|
PrivateKey: privKeys[i],
|
||||||
Addresses: addresses[i],
|
Addresses: addresses[i],
|
||||||
ListenPort: port,
|
ListenPort: addr.Port,
|
||||||
}
|
}
|
||||||
for peerNum, port := range ports {
|
for peerNum, addr := range addrs {
|
||||||
if peerNum == i {
|
if peerNum == i {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -222,8 +222,8 @@ func makeConfigs(t *testing.T, ports []uint16) []wgcfg.Config {
|
||||||
PublicKey: privKeys[peerNum].Public(),
|
PublicKey: privKeys[peerNum].Public(),
|
||||||
AllowedIPs: addresses[peerNum],
|
AllowedIPs: addresses[peerNum],
|
||||||
Endpoints: []wgcfg.Endpoint{{
|
Endpoints: []wgcfg.Endpoint{{
|
||||||
Host: "127.0.0.1",
|
Host: addr.IP.String(),
|
||||||
Port: port,
|
Port: addr.Port,
|
||||||
}},
|
}},
|
||||||
PersistentKeepalive: 25,
|
PersistentKeepalive: 25,
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,6 @@ func TestTwoDevicePing(t *testing.T) {
|
||||||
testTwoDevicePing(t, false)
|
testTwoDevicePing(t, false)
|
||||||
})
|
})
|
||||||
t.Run("natlab", func(t *testing.T) {
|
t.Run("natlab", func(t *testing.T) {
|
||||||
t.Skip("TODO: finish")
|
|
||||||
testTwoDevicePing(t, true)
|
testTwoDevicePing(t, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -366,15 +365,18 @@ func testTwoDevicePing(t *testing.T, useNatlab bool) {
|
||||||
|
|
||||||
var stunTestIP = "127.0.0.1"
|
var stunTestIP = "127.0.0.1"
|
||||||
var stunMachine, machine1, machine2 *natlab.Machine
|
var stunMachine, machine1, machine2 *natlab.Machine
|
||||||
|
var conn1IP, conn2IP = netaddr.IPv4(127, 0, 0, 1), netaddr.IPv4(127, 0, 0, 1)
|
||||||
if useNatlab {
|
if useNatlab {
|
||||||
stunMachine = &natlab.Machine{Name: "stun"}
|
stunMachine = &natlab.Machine{Name: "stun"}
|
||||||
machine1 = &natlab.Machine{Name: "machine1"}
|
machine1 = &natlab.Machine{Name: "machine1"}
|
||||||
machine2 = &natlab.Machine{Name: "machine2"}
|
machine2 = &natlab.Machine{Name: "machine2"}
|
||||||
internet := natlab.NewInternet()
|
internet := natlab.NewInternet()
|
||||||
stunIf := stunMachine.Attach("eth0", internet)
|
stunIf := stunMachine.Attach("eth0", internet)
|
||||||
machine1.Attach("eth0", internet)
|
m1If := machine1.Attach("eth0", internet)
|
||||||
machine2.Attach("eth0", internet)
|
m2If := machine2.Attach("eth0", internet)
|
||||||
stunTestIP = stunIf.V4().String()
|
stunTestIP = stunIf.V4().String()
|
||||||
|
conn1IP = m1If.V4()
|
||||||
|
conn2IP = m2If.V4()
|
||||||
}
|
}
|
||||||
|
|
||||||
stunAddr, stunCleanupFn := stuntest.ServeWithPacketListener(t, packetConn(stunMachine))
|
stunAddr, stunCleanupFn := stuntest.ServeWithPacketListener(t, packetConn(stunMachine))
|
||||||
|
@ -431,16 +433,11 @@ func testTwoDevicePing(t *testing.T, useNatlab bool) {
|
||||||
conn2.Start()
|
conn2.Start()
|
||||||
conn2.SetDERPMap(derpMap)
|
conn2.SetDERPMap(derpMap)
|
||||||
|
|
||||||
ports := []uint16{conn1.LocalPort(), conn2.LocalPort()}
|
addrs := []netaddr.IPPort{
|
||||||
if useNatlab {
|
{IP: conn1IP, Port: conn1.LocalPort()},
|
||||||
// TODO: ...
|
{IP: conn2IP, Port: conn2.LocalPort()},
|
||||||
} else {
|
|
||||||
addrs := []netaddr.IPPort{
|
|
||||||
// netaddr.IPPort
|
|
||||||
}
|
|
||||||
_ = addrs
|
|
||||||
}
|
}
|
||||||
cfgs := makeConfigs(t, ports)
|
cfgs := makeConfigs(t, addrs)
|
||||||
|
|
||||||
if err := conn1.SetPrivateKey(cfgs[0].PrivateKey); err != nil {
|
if err := conn1.SetPrivateKey(cfgs[0].PrivateKey); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue