cmd/tailscaled: flush DNS if FlushDNSOnSessionUnlock is true upon receiving a session change notification

In this PR, we move the syspolicy.FlushDNSOnSessionUnlock check from service startup
to when a session change notification is received. This ensures that the most recent policy
setting value is used if it has changed since the service started.

We also plan to handle session change notifications for unrelated reasons
and need to decouple notification subscriptions from DNS anyway.

Updates #12687
Updates tailscale/corp#18342

Signed-off-by: Nick Khyl <nickk@tailscale.com>
pull/14196/head
Nick Khyl 5 days ago committed by Nick Khyl
parent 8e5cfbe4ab
commit 50bf32a0ba

@ -160,10 +160,7 @@ func (service *ipnService) Execute(args []string, r <-chan svc.ChangeRequest, ch
changes <- svc.Status{State: svc.StartPending}
syslogf("Service start pending")
svcAccepts := svc.AcceptStop
if flushDNSOnSessionUnlock, _ := syspolicy.GetBoolean(syspolicy.FlushDNSOnSessionUnlock, false); flushDNSOnSessionUnlock {
svcAccepts |= svc.AcceptSessionChange
}
svcAccepts := svc.AcceptStop | svc.AcceptSessionChange
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -371,6 +368,7 @@ func handleSessionChange(chgRequest svc.ChangeRequest) {
return
}
if flushDNSOnSessionUnlock, _ := syspolicy.GetBoolean(syspolicy.FlushDNSOnSessionUnlock, false); flushDNSOnSessionUnlock {
log.Printf("Received WTS_SESSION_UNLOCK event, initiating DNS flush.")
go func() {
err := dns.Flush()
@ -379,6 +377,7 @@ func handleSessionChange(chgRequest svc.ChangeRequest) {
}
}()
}
}
var (
kernel32 = windows.NewLazySystemDLL("kernel32.dll")

Loading…
Cancel
Save