From f1765a7abbc70b5e027c73fcd2f1e9650c3f7b03 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 20 May 2020 14:53:03 +0200 Subject: [PATCH] Fix linter errors --- network/database.go | 3 ++- network/module.go | 5 ----- network/state/exists.go | 1 + network/state/info.go | 8 +++++--- network/state/lookup.go | 1 + network/state/udp.go | 21 +++++++++++++-------- process/find.go | 2 +- updates/upgrader.go | 1 + 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/network/database.go b/network/database.go index 460307c0..a44a379c 100644 --- a/network/database.go +++ b/network/database.go @@ -63,7 +63,8 @@ func (s *StorageInterface) Get(key string) (record.Record, error) { if len(splitted) >= 2 { switch splitted[1] { case "state": - return state.GetStateInfo(), nil + return state.GetInfo(), nil + default: } } } diff --git a/network/module.go b/network/module.go index 70f2fd24..a1ee69f5 100644 --- a/network/module.go +++ b/network/module.go @@ -1,17 +1,12 @@ package network import ( - "net" - "github.com/safing/portbase/modules" ) var ( module *modules.Module - dnsAddress = net.IPv4(127, 0, 0, 1) - dnsPort uint16 = 53 - defaultFirewallHandler FirewallHandler ) diff --git a/network/state/exists.go b/network/state/exists.go index f64e4a64..7b308608 100644 --- a/network/state/exists.go +++ b/network/state/exists.go @@ -8,6 +8,7 @@ import ( ) const ( + // UDPConnectionTTL defines the duration after which unseen UDP connections are regarded as ended. UDPConnectionTTL = 10 * time.Minute ) diff --git a/network/state/info.go b/network/state/info.go index 292a8ec7..5d4b0d4d 100644 --- a/network/state/info.go +++ b/network/state/info.go @@ -8,7 +8,8 @@ import ( "github.com/safing/portmaster/network/socket" ) -type StateInfo struct { +// Info holds network state information as provided by the system. +type Info struct { record.Base sync.Mutex @@ -20,8 +21,9 @@ type StateInfo struct { UDP6Binds []*socket.BindInfo } -func GetStateInfo() *StateInfo { - info := &StateInfo{} +// GetInfo returns all system state tables. The returned data must not be modified. +func GetInfo() *Info { + info := &Info{} tcp4Lock.Lock() updateTCP4Tables() diff --git a/network/state/lookup.go b/network/state/lookup.go index 8346072e..5aadf7fa 100644 --- a/network/state/lookup.go +++ b/network/state/lookup.go @@ -39,6 +39,7 @@ var ( baseWaitTime = 3 * time.Millisecond ) +// Lookup looks for the given connection in the system state tables and returns the PID of the associated process and whether the connection is inbound. func Lookup(pktInfo *packet.Info) (pid int, inbound bool, err error) { // auto-detect version if pktInfo.Version == 0 { diff --git a/network/state/udp.go b/network/state/udp.go index 46966961..f49b1d04 100644 --- a/network/state/udp.go +++ b/network/state/udp.go @@ -14,8 +14,13 @@ type udpState struct { } const ( - UdpConnStateTTL = 72 * time.Hour - UdpConnStateShortenedTTL = 3 * time.Hour + // UDPConnStateTTL is the maximum time a udp connection state is held. + UDPConnStateTTL = 72 * time.Hour + + // UDPConnStateShortenedTTL is a shortened maximum time a udp connection state is held, if there more entries than defined by AggressiveCleaningThreshold. + UDPConnStateShortenedTTL = 3 * time.Hour + + // AggressiveCleaningThreshold defines the soft limit of udp connection state held per udp socket. AggressiveCleaningThreshold = 256 ) @@ -60,29 +65,29 @@ func getUDPDirection(socketInfo *socket.BindInfo, udpStates map[string]map[strin return udpConnState.inbound } -func CleanUDPStates(ctx context.Context) { +// CleanUDPStates cleans the udp connection states which save connection directions. +func CleanUDPStates(_ context.Context) { now := time.Now().UTC() udp4Lock.Lock() updateUDP4Table() - cleanStates(ctx, udp4Binds, udp4States, now) + cleanStates(udp4Binds, udp4States, now) udp4Lock.Unlock() udp6Lock.Lock() updateUDP6Table() - cleanStates(ctx, udp6Binds, udp6States, now) + cleanStates(udp6Binds, udp6States, now) udp6Lock.Unlock() } func cleanStates( - ctx context.Context, binds []*socket.BindInfo, udpStates map[string]map[string]*udpState, now time.Time, ) { // compute thresholds - threshold := now.Add(-UdpConnStateTTL) - shortThreshhold := now.Add(-UdpConnStateShortenedTTL) + threshold := now.Add(-UDPConnStateTTL) + shortThreshhold := now.Add(-UDPConnStateShortenedTTL) // make lookup map of all active keys bindKeys := make(map[string]struct{}) diff --git a/process/find.go b/process/find.go index a7e214cf..50070949 100644 --- a/process/find.go +++ b/process/find.go @@ -15,7 +15,7 @@ var ( ErrProcessNotFound = errors.New("could not find process in system state tables") ) -// GetProcessByEndpoints returns the process that owns the described link. +// GetProcessByConnection returns the process that owns the described connection. func GetProcessByConnection(ctx context.Context, pktInfo *packet.Info) (process *Process, connInbound bool, err error) { if !enableProcessDetection() { log.Tracer(ctx).Tracef("process: process detection disabled") diff --git a/updates/upgrader.go b/updates/upgrader.go index b109c913..47f8ea36 100644 --- a/updates/upgrader.go +++ b/updates/upgrader.go @@ -230,6 +230,7 @@ func upgradeFile(fileToUpgrade string, file *updater.File) error { return nil } +// CopyFile atomically copies a file using the update registry's tmp dir. func CopyFile(srcPath, dstPath string) (err error) { // check tmp dir