MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestIsSelfDst

Function TestIsSelfDst

wgengine/netstack/netstack_test.go:1461–1552  ·  view source on GitHub ↗

TestIsSelfDst verifies that isSelfDst correctly identifies packets whose destination IP is a local Tailscale IP assigned to this node.

(t *testing.T)

Source from the content-addressed store, hash-verified

1459// TestIsSelfDst verifies that isSelfDst correctly identifies packets whose
1460// destination IP is a local Tailscale IP assigned to this node.
1461func TestIsSelfDst(t *testing.T) {
1462 var (
1463 selfIP4 = netip.MustParseAddr("100.64.1.2")
1464 selfIP6 = netip.MustParseAddr("fd7a:115c:a1e0::123")
1465 remoteIP4 = netip.MustParseAddr("100.64.99.88")
1466 remoteIP6 = netip.MustParseAddr("fd7a:115c:a1e0::99")
1467 )
1468
1469 ns := makeNetstack(t, func(impl *Impl) {
1470 impl.ProcessLocalIPs = true
1471 impl.atomicIsLocalIPFunc.Store(func(addr netip.Addr) bool {
1472 return addr == selfIP4 || addr == selfIP6
1473 })
1474 })
1475
1476 testCases := []struct {
1477 name string
1478 src, dst netip.AddrPort
1479 want bool
1480 }{
1481 {
1482 name: "self_to_self_v4",
1483 src: netip.AddrPortFrom(selfIP4, 12345),
1484 dst: netip.AddrPortFrom(selfIP4, 8081),
1485 want: true,
1486 },
1487 {
1488 name: "self_to_self_v6",
1489 src: netip.AddrPortFrom(selfIP6, 12345),
1490 dst: netip.AddrPortFrom(selfIP6, 8081),
1491 want: true,
1492 },
1493 {
1494 name: "remote_to_self_v4",
1495 src: netip.AddrPortFrom(remoteIP4, 12345),
1496 dst: netip.AddrPortFrom(selfIP4, 8081),
1497 want: true,
1498 },
1499 {
1500 name: "remote_to_self_v6",
1501 src: netip.AddrPortFrom(remoteIP6, 12345),
1502 dst: netip.AddrPortFrom(selfIP6, 8081),
1503 want: true,
1504 },
1505 {
1506 name: "self_to_remote_v4",
1507 src: netip.AddrPortFrom(selfIP4, 12345),
1508 dst: netip.AddrPortFrom(remoteIP4, 8081),
1509 want: false,
1510 },
1511 {
1512 name: "self_to_remote_v6",
1513 src: netip.AddrPortFrom(selfIP6, 12345),
1514 dst: netip.AddrPortFrom(remoteIP6, 8081),
1515 want: false,
1516 },
1517 {
1518 name: "remote_to_remote_v4",

Callers

nothing calls this directly

Calls 9

makeNetstackFunction · 0.85
makeUDP4PacketBufferFunction · 0.85
makeUDP6PacketBufferFunction · 0.85
DecRefMethod · 0.80
isSelfDstMethod · 0.80
StoreMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65
AddrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…