From 56a1751e62f9cf9b7e3bc3c183460c2024a845c5 Mon Sep 17 00:00:00 2001 From: Patrick Pacher Date: Wed, 15 Apr 2020 08:21:32 +0200 Subject: [PATCH] Fix golangci-lint warnings --- firewall/master.go | 6 +-- intel/entity.go | 72 ++++++++---------------------------- intel/filterlists/updater.go | 2 +- nameserver/nameserver.go | 12 +++--- 4 files changed, 26 insertions(+), 66 deletions(-) diff --git a/firewall/master.go b/firewall/master.go index ce1738b5..ddf09a37 100644 --- a/firewall/master.go +++ b/firewall/master.go @@ -41,9 +41,9 @@ func DecideOnConnection(conn *network.Connection, pkt packet.Packet) { //nolint: log.Infof("filter: re-evaluating verdict on %s", conn) conn.Verdict = network.VerdictUndecided - if conn.Entity != nil { - //conn.Entity.ResetLists() - } + //if conn.Entity != nil { + //conn.Entity.ResetLists() + //} } // grant self diff --git a/intel/entity.go b/intel/entity.go index d1544676..f84b9d6d 100644 --- a/intel/entity.go +++ b/intel/entity.go @@ -22,33 +22,33 @@ import ( type Entity struct { sync.Mutex - Domain string - IP net.IP - Protocol uint8 - Port uint16 + // lists exist for most entity information and + // we need to know which one we loaded + domainListLoaded bool + ipListLoaded bool + countryListLoaded bool + asnListLoaded bool reverseResolveEnabled bool - reverseResolveOnce sync.Once - Country string - ASN uint - location *geoip.Location - fetchLocationOnce sync.Once + 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 - - // lists exist for most entity information and - // we need to know which one we loaded - domainListLoaded bool - ipListLoaded bool - countryListLoaded bool - asnListLoaded bool } // Init initializes the internal state and returns the entity. @@ -57,46 +57,6 @@ func (e *Entity) Init() *Entity { 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. func (e *Entity) FetchData() { e.getLocation() diff --git a/intel/filterlists/updater.go b/intel/filterlists/updater.go index 3be9144f..793f4022 100644 --- a/intel/filterlists/updater.go +++ b/intel/filterlists/updater.go @@ -121,7 +121,7 @@ func performUpdate(ctx context.Context) error { if err := setCacheDatabaseVersion(highestVersion.Version()); err != nil { log.Errorf("intel/filterlists: failed to save cache database version: %s", err) } 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 diff --git a/nameserver/nameserver.go b/nameserver/nameserver.go index 002001b2..7eee0c4d 100644 --- a/nameserver/nameserver.go +++ b/nameserver/nameserver.go @@ -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 // that will happen later anyway. - case network.VerdictUndecided, network.VerdictAccept: + case network.VerdictUndecided, network.VerdictAccept, + network.VerdictRerouteToNameserver, network.VerdictRerouteToTunnel: return - // FIXME(ppacher): how to handle undeterminable and the SPN re-routing here? default: 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 { tracer.Infof("nameserver: failed to find process for request %s, returning NXDOMAIN", conn) returnNXDomain(w, query) - // FIXME(ppacher): if we save the connection (by marking it as failed) - // we might collect A LOT of connections for the UI. - //conn.Failed("Unknown process") + // NOTE(ppacher): saving unknown process connection might end up in a lot of + // processes. Consider disabling that via config. + conn.Failed("Unknown process") return nil } @@ -297,7 +297,7 @@ func handleRequest(ctx context.Context, w dns.ResponseWriter, query *dns.Msg) er m.Extra = rrCache.Extra 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 { tracer.Debugf("nameserver: returning response %s%s to %s", q.FQDN, q.QType, conn.Process()) }