mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Fix golangci-lint warnings
This commit is contained in:
parent
3d4c7311ff
commit
56a1751e62
4 changed files with 26 additions and 66 deletions
|
@ -41,9 +41,9 @@ func DecideOnConnection(conn *network.Connection, pkt packet.Packet) { //nolint:
|
||||||
log.Infof("filter: re-evaluating verdict on %s", conn)
|
log.Infof("filter: re-evaluating verdict on %s", conn)
|
||||||
conn.Verdict = network.VerdictUndecided
|
conn.Verdict = network.VerdictUndecided
|
||||||
|
|
||||||
if conn.Entity != nil {
|
//if conn.Entity != nil {
|
||||||
//conn.Entity.ResetLists()
|
//conn.Entity.ResetLists()
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// grant self
|
// grant self
|
||||||
|
|
|
@ -22,33 +22,33 @@ import (
|
||||||
type Entity struct {
|
type Entity struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
Domain string
|
|
||||||
IP net.IP
|
|
||||||
Protocol uint8
|
|
||||||
Port uint16
|
|
||||||
reverseResolveEnabled bool
|
|
||||||
reverseResolveOnce sync.Once
|
|
||||||
|
|
||||||
Country string
|
|
||||||
ASN uint
|
|
||||||
location *geoip.Location
|
|
||||||
fetchLocationOnce sync.Once
|
|
||||||
|
|
||||||
Lists []string
|
|
||||||
ListsMap filterlists.LookupMap
|
|
||||||
|
|
||||||
// we only load each data above at most once
|
|
||||||
loadDomainListOnce sync.Once
|
|
||||||
loadIPListOnce sync.Once
|
|
||||||
loadCoutryListOnce sync.Once
|
|
||||||
loadAsnListOnce sync.Once
|
|
||||||
|
|
||||||
// lists exist for most entity information and
|
// lists exist for most entity information and
|
||||||
// we need to know which one we loaded
|
// we need to know which one we loaded
|
||||||
domainListLoaded bool
|
domainListLoaded bool
|
||||||
ipListLoaded bool
|
ipListLoaded bool
|
||||||
countryListLoaded bool
|
countryListLoaded bool
|
||||||
asnListLoaded bool
|
asnListLoaded bool
|
||||||
|
reverseResolveEnabled bool
|
||||||
|
|
||||||
|
Protocol uint8
|
||||||
|
Port uint16
|
||||||
|
Domain string
|
||||||
|
IP net.IP
|
||||||
|
|
||||||
|
Country string
|
||||||
|
ASN uint
|
||||||
|
location *geoip.Location
|
||||||
|
|
||||||
|
Lists []string
|
||||||
|
ListsMap filterlists.LookupMap
|
||||||
|
|
||||||
|
// we only load each data above at most once
|
||||||
|
fetchLocationOnce sync.Once
|
||||||
|
reverseResolveOnce sync.Once
|
||||||
|
loadDomainListOnce sync.Once
|
||||||
|
loadIPListOnce sync.Once
|
||||||
|
loadCoutryListOnce sync.Once
|
||||||
|
loadAsnListOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the internal state and returns the entity.
|
// Init initializes the internal state and returns the entity.
|
||||||
|
@ -57,46 +57,6 @@ func (e *Entity) Init() *Entity {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergeDomain copies the Domain from other to e. It does
|
|
||||||
// not lock e or other so the caller must ensure
|
|
||||||
// proper locking of entities.
|
|
||||||
func (e *Entity) MergeDomain(other *Entity) *Entity {
|
|
||||||
|
|
||||||
// FIXME(ppacher): should we disable reverse lookups now?
|
|
||||||
e.Domain = other.Domain
|
|
||||||
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
// MergeLists merges the intel lists stored in other with the
|
|
||||||
// lists stored in e. Neither e nor other are locked so the
|
|
||||||
// caller must ensure proper locking on both entities.
|
|
||||||
// MergeLists ensures list entries are unique and sorted.
|
|
||||||
func (e *Entity) MergeLists(other *Entity) *Entity {
|
|
||||||
e.Lists = mergeStringList(e.Lists, other.Lists)
|
|
||||||
e.ListsMap = buildLookupMap(e.Lists)
|
|
||||||
|
|
||||||
// mark every list other has loaded also as
|
|
||||||
// loaded in e. Don't copy values of lists
|
|
||||||
// not loaded in other because they might have
|
|
||||||
// been loaded in e.
|
|
||||||
|
|
||||||
if other.domainListLoaded {
|
|
||||||
e.domainListLoaded = true
|
|
||||||
}
|
|
||||||
if other.ipListLoaded {
|
|
||||||
e.ipListLoaded = true
|
|
||||||
}
|
|
||||||
if other.countryListLoaded {
|
|
||||||
e.countryListLoaded = true
|
|
||||||
}
|
|
||||||
if other.asnListLoaded {
|
|
||||||
e.asnListLoaded = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
// FetchData fetches additional information, meant to be called before persisting an entity record.
|
// FetchData fetches additional information, meant to be called before persisting an entity record.
|
||||||
func (e *Entity) FetchData() {
|
func (e *Entity) FetchData() {
|
||||||
e.getLocation()
|
e.getLocation()
|
||||||
|
|
|
@ -121,7 +121,7 @@ func performUpdate(ctx context.Context) error {
|
||||||
if err := setCacheDatabaseVersion(highestVersion.Version()); err != nil {
|
if err := setCacheDatabaseVersion(highestVersion.Version()); err != nil {
|
||||||
log.Errorf("intel/filterlists: failed to save cache database version: %s", err)
|
log.Errorf("intel/filterlists: failed to save cache database version: %s", err)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("intel/filterlists: successfully migrated cache database to %s", highestVersion)
|
log.Infof("intel/filterlists: successfully migrated cache database to %s", highestVersion.Version())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -190,10 +190,10 @@ func handleRequest(ctx context.Context, w dns.ResponseWriter, query *dns.Msg) er
|
||||||
|
|
||||||
// for undecided or accepted connections we don't save them yet because
|
// for undecided or accepted connections we don't save them yet because
|
||||||
// that will happen later anyway.
|
// that will happen later anyway.
|
||||||
case network.VerdictUndecided, network.VerdictAccept:
|
case network.VerdictUndecided, network.VerdictAccept,
|
||||||
|
network.VerdictRerouteToNameserver, network.VerdictRerouteToTunnel:
|
||||||
return
|
return
|
||||||
|
|
||||||
// FIXME(ppacher): how to handle undeterminable and the SPN re-routing here?
|
|
||||||
default:
|
default:
|
||||||
log.Warningf("nameserver: unexpected verdict %s for connection %s, not saving", conn.Verdict, conn)
|
log.Warningf("nameserver: unexpected verdict %s for connection %s, not saving", conn.Verdict, conn)
|
||||||
}
|
}
|
||||||
|
@ -202,9 +202,9 @@ func handleRequest(ctx context.Context, w dns.ResponseWriter, query *dns.Msg) er
|
||||||
if conn.Process().Profile() == nil {
|
if conn.Process().Profile() == nil {
|
||||||
tracer.Infof("nameserver: failed to find process for request %s, returning NXDOMAIN", conn)
|
tracer.Infof("nameserver: failed to find process for request %s, returning NXDOMAIN", conn)
|
||||||
returnNXDomain(w, query)
|
returnNXDomain(w, query)
|
||||||
// FIXME(ppacher): if we save the connection (by marking it as failed)
|
// NOTE(ppacher): saving unknown process connection might end up in a lot of
|
||||||
// we might collect A LOT of connections for the UI.
|
// processes. Consider disabling that via config.
|
||||||
//conn.Failed("Unknown process")
|
conn.Failed("Unknown process")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ func handleRequest(ctx context.Context, w dns.ResponseWriter, query *dns.Msg) er
|
||||||
m.Extra = rrCache.Extra
|
m.Extra = rrCache.Extra
|
||||||
|
|
||||||
if err := w.WriteMsg(m); err != nil {
|
if err := w.WriteMsg(m); err != nil {
|
||||||
log.Warningf("nameserver: failed to return reponse %s%s to %s: %s", q.FQDN, q.QType, conn.Process(), err)
|
log.Warningf("nameserver: failed to return response %s%s to %s: %s", q.FQDN, q.QType, conn.Process(), err)
|
||||||
} else {
|
} else {
|
||||||
tracer.Debugf("nameserver: returning response %s%s to %s", q.FQDN, q.QType, conn.Process())
|
tracer.Debugf("nameserver: returning response %s%s to %s", q.FQDN, q.QType, conn.Process())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue