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 2 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} changes <- svc.Status{State: svc.StartPending}
syslogf("Service start pending") syslogf("Service start pending")
svcAccepts := svc.AcceptStop svcAccepts := svc.AcceptStop | svc.AcceptSessionChange
if flushDNSOnSessionUnlock, _ := syspolicy.GetBoolean(syspolicy.FlushDNSOnSessionUnlock, false); flushDNSOnSessionUnlock {
svcAccepts |= svc.AcceptSessionChange
}
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@ -371,6 +368,7 @@ func handleSessionChange(chgRequest svc.ChangeRequest) {
return return
} }
if flushDNSOnSessionUnlock, _ := syspolicy.GetBoolean(syspolicy.FlushDNSOnSessionUnlock, false); flushDNSOnSessionUnlock {
log.Printf("Received WTS_SESSION_UNLOCK event, initiating DNS flush.") log.Printf("Received WTS_SESSION_UNLOCK event, initiating DNS flush.")
go func() { go func() {
err := dns.Flush() err := dns.Flush()
@ -378,6 +376,7 @@ func handleSessionChange(chgRequest svc.ChangeRequest) {
log.Printf("Error flushing DNS on session unlock: %v", err) log.Printf("Error flushing DNS on session unlock: %v", err)
} }
}() }()
}
} }
var ( var (

Loading…
Cancel
Save