TestIsSelfDst verifies that isSelfDst correctly identifies packets whose destination IP is a local Tailscale IP assigned to this node.
(t *testing.T)
| 1459 | // TestIsSelfDst verifies that isSelfDst correctly identifies packets whose |
| 1460 | // destination IP is a local Tailscale IP assigned to this node. |
| 1461 | func 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", |
nothing calls this directly
no test coverage detected
searching dependent graphs…