mirror of
https://github.com/safing/portmaster
synced 2025-04-09 13:39:10 +00:00
[service] Fix error on unitilized dns monitor
This commit is contained in:
parent
2a9d75433f
commit
ed2338fdb9
4 changed files with 27 additions and 1 deletions
service
firewall/interception/dnsmonitor
integration
network
|
@ -68,6 +68,10 @@ func (l *ETWSession) IsRunning() bool {
|
|||
|
||||
// FlushTrace flushes the trace buffer.
|
||||
func (l *ETWSession) FlushTrace() error {
|
||||
if l.i == nil {
|
||||
return fmt.Errorf("session not initialized")
|
||||
}
|
||||
|
||||
l.shutdownMutex.Lock()
|
||||
defer l.shutdownMutex.Unlock()
|
||||
|
||||
|
@ -86,6 +90,9 @@ func (l *ETWSession) StopTrace() error {
|
|||
|
||||
// DestroySession closes the session and frees the allocated memory. Listener cannot be used after this function is called.
|
||||
func (l *ETWSession) DestroySession() error {
|
||||
if l.i == nil {
|
||||
return fmt.Errorf("session not initialized")
|
||||
}
|
||||
l.shutdownMutex.Lock()
|
||||
defer l.shutdownMutex.Unlock()
|
||||
|
||||
|
|
|
@ -52,6 +52,9 @@ func initializeSessions(module *DNSMonitor, listener *Listener) error {
|
|||
}
|
||||
|
||||
func (l *Listener) flush() error {
|
||||
if l.etw == nil {
|
||||
return fmt.Errorf("etw not initialized")
|
||||
}
|
||||
return l.etw.FlushTrace()
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ package integration
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/safing/portmaster/base/log"
|
||||
"github.com/safing/portmaster/service/mgr"
|
||||
|
@ -24,14 +25,25 @@ func (i *OSIntegration) Initialize() error {
|
|||
if err != nil {
|
||||
log.Errorf("integration: failed to load dll: %s", err)
|
||||
|
||||
callbackLock := sync.Mutex{}
|
||||
// listen for event from the updater and try to load again if any.
|
||||
i.instance.Updates().EventResourcesUpdated.AddCallback("core-dll-loader", func(wc *mgr.WorkerCtx, s struct{}) (cancel bool, err error) {
|
||||
// Make sure no multiple callas are executed at the same time.
|
||||
callbackLock.Lock()
|
||||
defer callbackLock.Unlock()
|
||||
|
||||
// Try to load again.
|
||||
err = i.loadDLL()
|
||||
if err != nil {
|
||||
log.Errorf("integration: failed to load dll: %s", err)
|
||||
} else {
|
||||
log.Info("integration: initialize successful after updater event")
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
|
||||
} else {
|
||||
log.Info("integration: initialize successful")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -550,7 +550,11 @@ func (conn *Connection) GatherConnectionInfo(pkt packet.Packet) (err error) {
|
|||
if module.instance.Resolver().IsDisabled() && conn.shouldWaitForDomain() {
|
||||
// Flush the dns listener buffer and try again.
|
||||
for i := range 4 {
|
||||
_ = module.instance.DNSMonitor().Flush()
|
||||
err = module.instance.DNSMonitor().Flush()
|
||||
if err != nil {
|
||||
// Error flushing, dont try again.
|
||||
break
|
||||
}
|
||||
ipinfo, err = resolver.GetIPInfo(resolver.IPInfoProfileScopeGlobal, pkt.Info().RemoteIP().String())
|
||||
if err == nil {
|
||||
log.Tracer(pkt.Ctx()).Debugf("network: found domain from dnsmonitor after %d tries", i+1)
|
||||
|
|
Loading…
Add table
Reference in a new issue