Skip to content

Commit 56067af

Browse files
authored
Stab at better logging when a relay is being used (#1533)
1 parent 64f202f commit 56067af

File tree

8 files changed

+180
-122
lines changed

8 files changed

+180
-122
lines changed

e2e/handshakes_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ import (
2525

2626
func BenchmarkHotPath(b *testing.B) {
2727
ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
28-
myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", nil)
28+
myControl, myVpnIpNet, myUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "me", "10.128.0.1/24", nil)
2929
theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them", "10.128.0.2/24", nil)
3030

3131
// Put their info in our lighthouse
3232
myControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
33+
theirControl.InjectLightHouseAddr(myVpnIpNet[0].Addr(), myUdpAddr)
3334

3435
// Start the servers
3536
myControl.Start()
@@ -38,13 +39,49 @@ func BenchmarkHotPath(b *testing.B) {
3839
r := router.NewR(b, myControl, theirControl)
3940
r.CancelFlowLogs()
4041

42+
assertTunnel(b, myVpnIpNet[0].Addr(), theirVpnIpNet[0].Addr(), myControl, theirControl, r)
43+
b.ResetTimer()
44+
45+
for n := 0; n < b.N; n++ {
46+
myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
47+
_ = r.RouteForAllUntilTxTun(theirControl)
48+
}
49+
50+
myControl.Stop()
51+
theirControl.Stop()
52+
}
53+
54+
func BenchmarkHotPathRelay(b *testing.B) {
55+
ca, _, caKey, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Now(), time.Now().Add(10*time.Minute), nil, nil, []string{})
56+
myControl, myVpnIpNet, _, _ := newSimpleServer(cert.Version1, ca, caKey, "me ", "10.128.0.1/24", m{"relay": m{"use_relays": true}})
57+
relayControl, relayVpnIpNet, relayUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "relay ", "10.128.0.128/24", m{"relay": m{"am_relay": true}})
58+
theirControl, theirVpnIpNet, theirUdpAddr, _ := newSimpleServer(cert.Version1, ca, caKey, "them ", "10.128.0.2/24", m{"relay": m{"use_relays": true}})
59+
60+
// Teach my how to get to the relay and that their can be reached via the relay
61+
myControl.InjectLightHouseAddr(relayVpnIpNet[0].Addr(), relayUdpAddr)
62+
myControl.InjectRelays(theirVpnIpNet[0].Addr(), []netip.Addr{relayVpnIpNet[0].Addr()})
63+
relayControl.InjectLightHouseAddr(theirVpnIpNet[0].Addr(), theirUdpAddr)
64+
65+
// Build a router so we don't have to reason who gets which packet
66+
r := router.NewR(b, myControl, relayControl, theirControl)
67+
r.CancelFlowLogs()
68+
69+
// Start the servers
70+
myControl.Start()
71+
relayControl.Start()
72+
theirControl.Start()
73+
74+
assertTunnel(b, theirVpnIpNet[0].Addr(), myVpnIpNet[0].Addr(), theirControl, myControl, r)
75+
b.ResetTimer()
76+
4177
for n := 0; n < b.N; n++ {
4278
myControl.InjectTunUDPPacket(theirVpnIpNet[0].Addr(), 80, myVpnIpNet[0].Addr(), 80, []byte("Hi from me"))
4379
_ = r.RouteForAllUntilTxTun(theirControl)
4480
}
4581

4682
myControl.Stop()
4783
theirControl.Stop()
84+
relayControl.Stop()
4885
}
4986

5087
func TestGoodHandshake(t *testing.T) {

e2e/helpers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func deadline(t *testing.T, seconds time.Duration) doneCb {
292292
}
293293
}
294294

295-
func assertTunnel(t *testing.T, vpnIpA, vpnIpB netip.Addr, controlA, controlB *nebula.Control, r *router.R) {
295+
func assertTunnel(t testing.TB, vpnIpA, vpnIpB netip.Addr, controlA, controlB *nebula.Control, r *router.R) {
296296
// Send a packet from them to me
297297
controlB.InjectTunUDPPacket(vpnIpA, 80, vpnIpB, 90, []byte("Hi from B"))
298298
bPacket := r.RouteForAllUntilTxTun(controlA)
@@ -325,15 +325,15 @@ func assertHostInfoPair(t *testing.T, addrA, addrB netip.AddrPort, vpnNetsA, vpn
325325
assert.Equal(t, hBinA.RemoteIndex, hAinB.LocalIndex, "Host B remote index does not match host A local index")
326326
}
327327

328-
func assertUdpPacket(t *testing.T, expected, b []byte, fromIp, toIp netip.Addr, fromPort, toPort uint16) {
328+
func assertUdpPacket(t testing.TB, expected, b []byte, fromIp, toIp netip.Addr, fromPort, toPort uint16) {
329329
if toIp.Is6() {
330330
assertUdpPacket6(t, expected, b, fromIp, toIp, fromPort, toPort)
331331
} else {
332332
assertUdpPacket4(t, expected, b, fromIp, toIp, fromPort, toPort)
333333
}
334334
}
335335

336-
func assertUdpPacket6(t *testing.T, expected, b []byte, fromIp, toIp netip.Addr, fromPort, toPort uint16) {
336+
func assertUdpPacket6(t testing.TB, expected, b []byte, fromIp, toIp netip.Addr, fromPort, toPort uint16) {
337337
packet := gopacket.NewPacket(b, layers.LayerTypeIPv6, gopacket.Lazy)
338338
v6 := packet.Layer(layers.LayerTypeIPv6).(*layers.IPv6)
339339
assert.NotNil(t, v6, "No ipv6 data found")
@@ -352,7 +352,7 @@ func assertUdpPacket6(t *testing.T, expected, b []byte, fromIp, toIp netip.Addr,
352352
assert.Equal(t, expected, data.Payload(), "Data was incorrect")
353353
}
354354

355-
func assertUdpPacket4(t *testing.T, expected, b []byte, fromIp, toIp netip.Addr, fromPort, toPort uint16) {
355+
func assertUdpPacket4(t testing.TB, expected, b []byte, fromIp, toIp netip.Addr, fromPort, toPort uint16) {
356356
packet := gopacket.NewPacket(b, layers.LayerTypeIPv4, gopacket.Lazy)
357357
v4 := packet.Layer(layers.LayerTypeIPv4).(*layers.IPv4)
358358
assert.NotNil(t, v4, "No ipv4 data found")

0 commit comments

Comments
 (0)