mirror of
https://github.com/safing/portmaster
synced 2025-04-22 11:59:09 +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.
|
// FlushTrace flushes the trace buffer.
|
||||||
func (l *ETWSession) FlushTrace() error {
|
func (l *ETWSession) FlushTrace() error {
|
||||||
|
if l.i == nil {
|
||||||
|
return fmt.Errorf("session not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
l.shutdownMutex.Lock()
|
l.shutdownMutex.Lock()
|
||||||
defer l.shutdownMutex.Unlock()
|
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.
|
// DestroySession closes the session and frees the allocated memory. Listener cannot be used after this function is called.
|
||||||
func (l *ETWSession) DestroySession() error {
|
func (l *ETWSession) DestroySession() error {
|
||||||
|
if l.i == nil {
|
||||||
|
return fmt.Errorf("session not initialized")
|
||||||
|
}
|
||||||
l.shutdownMutex.Lock()
|
l.shutdownMutex.Lock()
|
||||||
defer l.shutdownMutex.Unlock()
|
defer l.shutdownMutex.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,9 @@ func initializeSessions(module *DNSMonitor, listener *Listener) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listener) flush() error {
|
func (l *Listener) flush() error {
|
||||||
|
if l.etw == nil {
|
||||||
|
return fmt.Errorf("etw not initialized")
|
||||||
|
}
|
||||||
return l.etw.FlushTrace()
|
return l.etw.FlushTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/safing/portmaster/base/log"
|
"github.com/safing/portmaster/base/log"
|
||||||
"github.com/safing/portmaster/service/mgr"
|
"github.com/safing/portmaster/service/mgr"
|
||||||
|
@ -24,14 +25,25 @@ func (i *OSIntegration) Initialize() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("integration: failed to load dll: %s", err)
|
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.
|
// 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) {
|
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()
|
err = i.loadDLL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("integration: failed to load dll: %s", err)
|
log.Errorf("integration: failed to load dll: %s", err)
|
||||||
|
} else {
|
||||||
|
log.Info("integration: initialize successful after updater event")
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
log.Info("integration: initialize successful")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -550,7 +550,11 @@ func (conn *Connection) GatherConnectionInfo(pkt packet.Packet) (err error) {
|
||||||
if module.instance.Resolver().IsDisabled() && conn.shouldWaitForDomain() {
|
if module.instance.Resolver().IsDisabled() && conn.shouldWaitForDomain() {
|
||||||
// Flush the dns listener buffer and try again.
|
// Flush the dns listener buffer and try again.
|
||||||
for i := range 4 {
|
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())
|
ipinfo, err = resolver.GetIPInfo(resolver.IPInfoProfileScopeGlobal, pkt.Info().RemoteIP().String())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Tracer(pkt.Ctx()).Debugf("network: found domain from dnsmonitor after %d tries", i+1)
|
log.Tracer(pkt.Ctx()).Debugf("network: found domain from dnsmonitor after %d tries", i+1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue