cmd/tailscaled,net/tstun: fix data race on start-up in TUN mode

Fixes #7894

Change-Id: Ice3f8019405714dd69d02bc07694f3872bb598b8

Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2023-10-13 19:41:10 +00:00
committed by Brad Fitzpatrick
parent 5c555cdcbb
commit 5297bd2cff
7 changed files with 42 additions and 2 deletions

View File

@@ -47,6 +47,10 @@ type System struct {
StateStore SubSystem[ipn.StateStore]
Netstack SubSystem[NetstackImpl] // actually a *netstack.Impl
// onlyNetstack is whether the Tun value is a fake TUN device
// and we're using netstack for everything.
onlyNetstack bool
controlKnobs controlknobs.Knobs
proxyMap proxymap.Mapper
}
@@ -74,6 +78,12 @@ func (s *System) Set(v any) {
case router.Router:
s.Router.Set(v)
case *tstun.Wrapper:
type ft interface {
IsFakeTun() bool
}
if _, ok := v.Unwrap().(ft); ok {
s.onlyNetstack = true
}
s.Tun.Set(v)
case *magicsock.Conn:
s.MagicSock.Set(v)
@@ -97,8 +107,7 @@ func (s *System) IsNetstackRouter() bool {
// IsNetstack reports whether Tailscale is running as a netstack-based TUN-free engine.
func (s *System) IsNetstack() bool {
name, _ := s.Tun.Get().Name()
return name == tstun.FakeTUNName
return s.onlyNetstack
}
// ControlKnobs returns the control knobs for this node.