Fix linter errors

This commit is contained in:
Daniel 2020-05-20 14:53:03 +02:00
parent e65ae8b55d
commit f1765a7abb
8 changed files with 24 additions and 18 deletions

View file

@ -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:
}
}
}

View file

@ -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
)

View file

@ -8,6 +8,7 @@ import (
)
const (
// UDPConnectionTTL defines the duration after which unseen UDP connections are regarded as ended.
UDPConnectionTTL = 10 * time.Minute
)

View file

@ -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()

View file

@ -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 {

View file

@ -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{})

View file

@ -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")

View file

@ -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