mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Fix linter errors
This commit is contained in:
parent
e65ae8b55d
commit
f1765a7abb
8 changed files with 24 additions and 18 deletions
|
@ -63,7 +63,8 @@ func (s *StorageInterface) Get(key string) (record.Record, error) {
|
||||||
if len(splitted) >= 2 {
|
if len(splitted) >= 2 {
|
||||||
switch splitted[1] {
|
switch splitted[1] {
|
||||||
case "state":
|
case "state":
|
||||||
return state.GetStateInfo(), nil
|
return state.GetInfo(), nil
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/safing/portbase/modules"
|
"github.com/safing/portbase/modules"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
module *modules.Module
|
module *modules.Module
|
||||||
|
|
||||||
dnsAddress = net.IPv4(127, 0, 0, 1)
|
|
||||||
dnsPort uint16 = 53
|
|
||||||
|
|
||||||
defaultFirewallHandler FirewallHandler
|
defaultFirewallHandler FirewallHandler
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// UDPConnectionTTL defines the duration after which unseen UDP connections are regarded as ended.
|
||||||
UDPConnectionTTL = 10 * time.Minute
|
UDPConnectionTTL = 10 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ import (
|
||||||
"github.com/safing/portmaster/network/socket"
|
"github.com/safing/portmaster/network/socket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StateInfo struct {
|
// Info holds network state information as provided by the system.
|
||||||
|
type Info struct {
|
||||||
record.Base
|
record.Base
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
|
||||||
|
@ -20,8 +21,9 @@ type StateInfo struct {
|
||||||
UDP6Binds []*socket.BindInfo
|
UDP6Binds []*socket.BindInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStateInfo() *StateInfo {
|
// GetInfo returns all system state tables. The returned data must not be modified.
|
||||||
info := &StateInfo{}
|
func GetInfo() *Info {
|
||||||
|
info := &Info{}
|
||||||
|
|
||||||
tcp4Lock.Lock()
|
tcp4Lock.Lock()
|
||||||
updateTCP4Tables()
|
updateTCP4Tables()
|
||||||
|
|
|
@ -39,6 +39,7 @@ var (
|
||||||
baseWaitTime = 3 * time.Millisecond
|
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) {
|
func Lookup(pktInfo *packet.Info) (pid int, inbound bool, err error) {
|
||||||
// auto-detect version
|
// auto-detect version
|
||||||
if pktInfo.Version == 0 {
|
if pktInfo.Version == 0 {
|
||||||
|
|
|
@ -14,8 +14,13 @@ type udpState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UdpConnStateTTL = 72 * time.Hour
|
// UDPConnStateTTL is the maximum time a udp connection state is held.
|
||||||
UdpConnStateShortenedTTL = 3 * time.Hour
|
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
|
AggressiveCleaningThreshold = 256
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,29 +65,29 @@ func getUDPDirection(socketInfo *socket.BindInfo, udpStates map[string]map[strin
|
||||||
return udpConnState.inbound
|
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()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
udp4Lock.Lock()
|
udp4Lock.Lock()
|
||||||
updateUDP4Table()
|
updateUDP4Table()
|
||||||
cleanStates(ctx, udp4Binds, udp4States, now)
|
cleanStates(udp4Binds, udp4States, now)
|
||||||
udp4Lock.Unlock()
|
udp4Lock.Unlock()
|
||||||
|
|
||||||
udp6Lock.Lock()
|
udp6Lock.Lock()
|
||||||
updateUDP6Table()
|
updateUDP6Table()
|
||||||
cleanStates(ctx, udp6Binds, udp6States, now)
|
cleanStates(udp6Binds, udp6States, now)
|
||||||
udp6Lock.Unlock()
|
udp6Lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanStates(
|
func cleanStates(
|
||||||
ctx context.Context,
|
|
||||||
binds []*socket.BindInfo,
|
binds []*socket.BindInfo,
|
||||||
udpStates map[string]map[string]*udpState,
|
udpStates map[string]map[string]*udpState,
|
||||||
now time.Time,
|
now time.Time,
|
||||||
) {
|
) {
|
||||||
// compute thresholds
|
// compute thresholds
|
||||||
threshold := now.Add(-UdpConnStateTTL)
|
threshold := now.Add(-UDPConnStateTTL)
|
||||||
shortThreshhold := now.Add(-UdpConnStateShortenedTTL)
|
shortThreshhold := now.Add(-UDPConnStateShortenedTTL)
|
||||||
|
|
||||||
// make lookup map of all active keys
|
// make lookup map of all active keys
|
||||||
bindKeys := make(map[string]struct{})
|
bindKeys := make(map[string]struct{})
|
||||||
|
|
|
@ -15,7 +15,7 @@ var (
|
||||||
ErrProcessNotFound = errors.New("could not find process in system state tables")
|
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) {
|
func GetProcessByConnection(ctx context.Context, pktInfo *packet.Info) (process *Process, connInbound bool, err error) {
|
||||||
if !enableProcessDetection() {
|
if !enableProcessDetection() {
|
||||||
log.Tracer(ctx).Tracef("process: process detection disabled")
|
log.Tracer(ctx).Tracef("process: process detection disabled")
|
||||||
|
|
|
@ -230,6 +230,7 @@ func upgradeFile(fileToUpgrade string, file *updater.File) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyFile atomically copies a file using the update registry's tmp dir.
|
||||||
func CopyFile(srcPath, dstPath string) (err error) {
|
func CopyFile(srcPath, dstPath string) (err error) {
|
||||||
|
|
||||||
// check tmp dir
|
// check tmp dir
|
||||||
|
|
Loading…
Add table
Reference in a new issue