MCPcopy
hub / github.com/tailscale/tailscale / makeNetstack

Function makeNetstack

wgengine/netstack/netstack_test.go:106–147  ·  view source on GitHub ↗
(tb testing.TB, config func(*Impl))

Source from the content-addressed store, hash-verified

104}
105
106func makeNetstack(tb testing.TB, config func(*Impl)) *Impl {
107 tunDev := tstun.NewFake()
108 sys := tsd.NewSystem()
109 sys.Set(new(mem.Store))
110 dialer := new(tsdial.Dialer)
111 logf := tstest.WhileTestRunningLogger(tb)
112 eng, err := wgengine.NewUserspaceEngine(logf, wgengine.Config{
113 Tun: tunDev,
114 Dialer: dialer,
115 SetSubsystem: sys.Set,
116 HealthTracker: sys.HealthTracker.Get(),
117 Metrics: sys.UserMetricsRegistry(),
118 EventBus: sys.Bus.Get(),
119 })
120 if err != nil {
121 tb.Fatal(err)
122 }
123 tb.Cleanup(func() { eng.Close() })
124 sys.Set(eng)
125
126 ns, err := Create(logf, sys.Tun.Get(), eng, sys.MagicSock.Get(), dialer, sys.DNSManager.Get(), sys.ProxyMapper())
127 if err != nil {
128 tb.Fatal(err)
129 }
130 tb.Cleanup(func() { ns.Close() })
131 sys.Set(ns)
132
133 lb, err := ipnlocal.NewLocalBackend(logf, logid.PublicID{}, sys, 0)
134 if err != nil {
135 tb.Fatalf("NewLocalBackend: %v", err)
136 }
137 tb.Cleanup(lb.Shutdown)
138
139 ns.atomicIsLocalIPFunc.Store(func(netip.Addr) bool { return true })
140 if config != nil {
141 config(ns)
142 }
143 if err := ns.Start(lb); err != nil {
144 tb.Fatalf("Start: %v", err)
145 }
146 return ns
147}
148
149func TestShouldHandlePing(t *testing.T) {
150 srcIP := netip.AddrFrom4([4]byte{1, 2, 3, 4})

Callers 9

TestShouldHandlePingFunction · 0.85
TestShouldProcessInboundFunction · 0.85
TestTCPForwardLimitsFunction · 0.85
TestHandleLocalPacketsFunction · 0.85
TestShouldSendToHostFunction · 0.85
TestIsSelfDstFunction · 0.85
TestInjectLoopbackFunction · 0.85

Calls 15

SetMethod · 0.95
UserMetricsRegistryMethod · 0.95
ProxyMapperMethod · 0.95
NewFakeFunction · 0.92
NewSystemFunction · 0.92
WhileTestRunningLoggerFunction · 0.92
NewUserspaceEngineFunction · 0.92
NewLocalBackendFunction · 0.92
CreateFunction · 0.70
GetMethod · 0.65
FatalMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…