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

Function TestShouldSendToHost

wgengine/netstack/netstack_test.go:1214–1375  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1212}
1213
1214func TestShouldSendToHost(t *testing.T) {
1215 var (
1216 selfIP4 = netip.MustParseAddr("100.64.1.2")
1217 selfIP6 = netip.MustParseAddr("fd7a:115c:a1e0::123")
1218 tailscaleServiceIP4 = netip.MustParseAddr("100.99.55.111")
1219 tailscaleServiceIP6 = netip.MustParseAddr("fd7a:115c:a1e0::abcd")
1220 )
1221
1222 makeTestNetstack := func(tb testing.TB) *Impl {
1223 impl := makeNetstack(tb, func(impl *Impl) {
1224 impl.ProcessSubnets = false
1225 impl.ProcessLocalIPs = false
1226 impl.atomicIsLocalIPFunc.Store(func(addr netip.Addr) bool {
1227 return addr == selfIP4 || addr == selfIP6
1228 })
1229 impl.atomicIsVIPServiceIPFunc.Store(func(addr netip.Addr) bool {
1230 return addr == tailscaleServiceIP4 || addr == tailscaleServiceIP6
1231 })
1232 })
1233
1234 prefs := ipn.NewPrefs()
1235 prefs.AdvertiseRoutes = []netip.Prefix{
1236 // $ tailscale debug via 7 10.1.1.0/24
1237 // fd7a:115c:a1e0:b1a:0:7:a01:100/120
1238 netip.MustParsePrefix("fd7a:115c:a1e0:b1a:0:7:a01:100/120"),
1239 }
1240 _, err := impl.lb.EditPrefs(&ipn.MaskedPrefs{
1241 Prefs: *prefs,
1242 AdvertiseRoutesSet: true,
1243 })
1244 if err != nil {
1245 tb.Fatalf("EditPrefs: %v", err)
1246 }
1247 return impl
1248 }
1249
1250 testCases := []struct {
1251 name string
1252 src, dst netip.AddrPort
1253 want bool
1254 }{
1255 // Reply from service IP to localhost should be sent to host,
1256 // not over WireGuard.
1257 {
1258 name: "from_service_ip_to_localhost",
1259 src: netip.AddrPortFrom(serviceIP, 53),
1260 dst: netip.MustParseAddrPort("127.0.0.1:9999"),
1261 want: true,
1262 },
1263 {
1264 name: "from_service_ip_to_localhost_v6",
1265 src: netip.AddrPortFrom(serviceIPv6, 53),
1266 dst: netip.MustParseAddrPort("[::1]:9999"),
1267 want: true,
1268 },
1269 // A reply from the local IP to a remote host isn't sent to the
1270 // host, but rather over WireGuard.
1271 {

Callers

nothing calls this directly

Calls 11

NewPrefsFunction · 0.92
makeNetstackFunction · 0.85
makeUDP4PacketBufferFunction · 0.85
makeUDP6PacketBufferFunction · 0.85
shouldSendToHostMethod · 0.80
StoreMethod · 0.65
EditPrefsMethod · 0.65
FatalfMethod · 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…