MCPcopy
hub / github.com/tailscale/tailscale / TestUserspaceEnginePortReconfig

Function TestUserspaceEnginePortReconfig

wgengine/userspace_test.go:255–332  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

253}
254
255func TestUserspaceEnginePortReconfig(t *testing.T) {
256 flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/2855")
257 const defaultPort = 49983
258
259 var knobs controlknobs.Knobs
260
261 bus := eventbustest.NewBus(t)
262
263 // Keep making a wgengine until we find an unused port
264 var ue *userspaceEngine
265 ht := health.NewTracker(bus)
266 reg := new(usermetric.Registry)
267 for range 100 {
268 attempt := uint16(defaultPort + rand.Intn(1000))
269 e, err := NewFakeUserspaceEngine(t.Logf, attempt, &knobs, ht, reg, bus)
270 if err != nil {
271 t.Fatal(err)
272 }
273 ue = e.(*userspaceEngine)
274 if ue.magicConn.LocalPort() == attempt {
275 break
276 }
277 ue.Close()
278 ue = nil
279 }
280 if ue == nil {
281 t.Fatal("could not create a wgengine with a specific port")
282 }
283 t.Cleanup(ue.Close)
284
285 startingPort := ue.magicConn.LocalPort()
286 nodeKey, err := key.ParseNodePublicUntyped(mem.S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
287 if err != nil {
288 t.Fatal(err)
289 }
290 cfg := &wgcfg.Config{
291 Peers: []wgcfg.Peer{
292 {
293 PublicKey: nodeKey,
294 AllowedIPs: []netip.Prefix{
295 netip.PrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32),
296 },
297 },
298 },
299 }
300 routerCfg := &router.Config{}
301 if err := ue.Reconfig(cfg, routerCfg, &dns.Config{}); err != nil {
302 t.Fatal(err)
303 }
304 if got := ue.magicConn.LocalPort(); got != startingPort {
305 t.Errorf("no debug setting changed local port to %d from %d", got, startingPort)
306 }
307
308 knobs.RandomizeClientPort.Store(true)
309 if err := ue.Reconfig(cfg, routerCfg, &dns.Config{}); err != nil {
310 t.Fatal(err)
311 }
312 if got := ue.magicConn.LocalPort(); got == startingPort {

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
ReconfigMethod · 0.95
MarkFunction · 0.92
NewBusFunction · 0.92
NewTrackerFunction · 0.92
ParseNodePublicUntypedFunction · 0.92
IPv4Function · 0.92
NewFakeUserspaceEngineFunction · 0.85
LocalPortMethod · 0.80
FatalMethod · 0.65
CleanupMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…