mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Split unattributed connections into to Unidentified App and Network Noise
This commit is contained in:
parent
014ac058ce
commit
7a9001b7de
11 changed files with 78 additions and 24 deletions
|
@ -317,7 +317,11 @@ func NewConnectionFromFirstPacket(pkt packet.Packet) *Connection {
|
||||||
proc, inbound, err := process.GetProcessByConnection(pkt.Ctx(), pkt.Info())
|
proc, inbound, err := process.GetProcessByConnection(pkt.Ctx(), pkt.Info())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracer(pkt.Ctx()).Debugf("network: failed to find process of packet %s: %s", pkt, err)
|
log.Tracer(pkt.Ctx()).Debugf("network: failed to find process of packet %s: %s", pkt, err)
|
||||||
proc = process.GetUnidentifiedProcess(pkt.Ctx())
|
if inbound {
|
||||||
|
proc = process.GetUnsolicitedProcess(pkt.Ctx())
|
||||||
|
} else {
|
||||||
|
proc = process.GetUnidentifiedProcess(pkt.Ctx())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the (remote) entity.
|
// Create the (remote) entity.
|
||||||
|
|
|
@ -23,7 +23,7 @@ func GetPID(socketInfo socket.Info) (pid int) {
|
||||||
currentPid := socketInfo.GetPID()
|
currentPid := socketInfo.GetPID()
|
||||||
|
|
||||||
// If the current PID already is valid (ie. not unidentified), return it immediately.
|
// If the current PID already is valid (ie. not unidentified), return it immediately.
|
||||||
if currentPid != socket.UnidentifiedProcessID {
|
if currentPid != socket.UndefinedProcessID {
|
||||||
return currentPid
|
return currentPid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ func findPID(uid, inode int) (pid int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket.UnidentifiedProcessID
|
return socket.UndefinedProcessID
|
||||||
}
|
}
|
||||||
|
|
||||||
func findSocketFromPid(pid int, socketName string) bool {
|
func findSocketFromPid(pid int, socketName string) bool {
|
||||||
|
|
|
@ -149,7 +149,7 @@ func getTableFromSource(stack uint8, procFile string) (connections []*socket.Con
|
||||||
IP: localIP,
|
IP: localIP,
|
||||||
Port: uint16(localPort),
|
Port: uint16(localPort),
|
||||||
},
|
},
|
||||||
PID: socket.UnidentifiedProcessID,
|
PID: socket.UndefinedProcessID,
|
||||||
UID: int(uid),
|
UID: int(uid),
|
||||||
Inode: int(inode),
|
Inode: int(inode),
|
||||||
})
|
})
|
||||||
|
@ -164,7 +164,7 @@ func getTableFromSource(stack uint8, procFile string) (connections []*socket.Con
|
||||||
IP: localIP,
|
IP: localIP,
|
||||||
Port: uint16(localPort),
|
Port: uint16(localPort),
|
||||||
},
|
},
|
||||||
PID: socket.UnidentifiedProcessID,
|
PID: socket.UndefinedProcessID,
|
||||||
UID: int(uid),
|
UID: int(uid),
|
||||||
Inode: int(inode),
|
Inode: int(inode),
|
||||||
})
|
})
|
||||||
|
@ -191,7 +191,7 @@ func getTableFromSource(stack uint8, procFile string) (connections []*socket.Con
|
||||||
IP: remoteIP,
|
IP: remoteIP,
|
||||||
Port: uint16(remotePort),
|
Port: uint16(remotePort),
|
||||||
},
|
},
|
||||||
PID: socket.UnidentifiedProcessID,
|
PID: socket.UndefinedProcessID,
|
||||||
UID: int(uid),
|
UID: int(uid),
|
||||||
Inode: int(inode),
|
Inode: int(inode),
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,8 +6,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// UnidentifiedProcessID is originally defined in the process pkg, but duplicated here because of import loops.
|
// UndefinedProcessID signifies that the process ID is unknown.
|
||||||
UnidentifiedProcessID = -1
|
// It must match portmaster/process.UndefinedProcessID
|
||||||
|
// It is duplicated here because of import loops.
|
||||||
|
UndefinedProcessID = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConnectionInfo holds socket information returned by the system.
|
// ConnectionInfo holds socket information returned by the system.
|
||||||
|
|
|
@ -60,7 +60,7 @@ func Lookup(pktInfo *packet.Info, fast bool) (pid int, inbound bool, err error)
|
||||||
return udp6Table.lookup(pktInfo, fast)
|
return udp6Table.lookup(pktInfo, fast)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return socket.UnidentifiedProcessID, false, errors.New("unsupported protocol for finding process")
|
return socket.UndefinedProcessID, false, errors.New("unsupported protocol for finding process")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ func (table *tcpTable) lookup(pktInfo *packet.Info, fast bool) (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket.UnidentifiedProcessID, pktInfo.Inbound, ErrConnectionNotFound
|
return socket.UndefinedProcessID, pktInfo.Inbound, ErrConnectionNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *tcpTable) findSocket(pktInfo *packet.Info) (
|
func (table *tcpTable) findSocket(pktInfo *packet.Info) (
|
||||||
|
@ -201,7 +201,7 @@ func (table *udpTable) lookup(pktInfo *packet.Info, fast bool) (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket.UnidentifiedProcessID, pktInfo.Inbound, ErrConnectionNotFound
|
return socket.UndefinedProcessID, pktInfo.Inbound, ErrConnectionNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *udpTable) findSocket(pktInfo *packet.Info, isInboundMulticast bool) (socketInfo *socket.BindInfo) {
|
func (table *udpTable) findSocket(pktInfo *packet.Info, isInboundMulticast bool) (socketInfo *socket.BindInfo) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool,
|
||||||
for i := 0; i <= lookupRetries; i++ {
|
for i := 0; i <= lookupRetries; i++ {
|
||||||
// look for PID
|
// look for PID
|
||||||
pid = proc.GetPID(socketInfo)
|
pid = proc.GetPID(socketInfo)
|
||||||
if pid != socket.UnidentifiedProcessID {
|
if pid != socket.UndefinedProcessID {
|
||||||
// if we found a PID, return
|
// if we found a PID, return
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,15 @@ func GetProcessByConnection(ctx context.Context, pktInfo *packet.Info) (process
|
||||||
return nil, pktInfo.Inbound, err
|
return nil, pktInfo.Inbound, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback to special profiles if PID could not be found.
|
||||||
|
if pid == UndefinedProcessID {
|
||||||
|
if connInbound {
|
||||||
|
pid = UnsolicitedProcessID
|
||||||
|
} else {
|
||||||
|
pid = UnidentifiedProcessID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process, err = GetOrFindProcess(ctx, pid)
|
process, err = GetOrFindProcess(ctx, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracer(ctx).Debugf("process: failed to find (primary) process with PID: %s", err)
|
log.Tracer(ctx).Debugf("process: failed to find (primary) process with PID: %s", err)
|
||||||
|
|
|
@ -131,6 +131,8 @@ func loadProcess(ctx context.Context, pid int) (*Process, error) {
|
||||||
switch pid {
|
switch pid {
|
||||||
case UnidentifiedProcessID:
|
case UnidentifiedProcessID:
|
||||||
return GetUnidentifiedProcess(ctx), nil
|
return GetUnidentifiedProcess(ctx), nil
|
||||||
|
case UnsolicitedProcessID:
|
||||||
|
return GetUnsolicitedProcess(ctx), nil
|
||||||
case SystemProcessID:
|
case SystemProcessID:
|
||||||
return GetSystemProcess(ctx), nil
|
return GetSystemProcess(ctx), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ func (p *Process) GetProfile(ctx context.Context) (changed bool, err error) {
|
||||||
switch p.Pid {
|
switch p.Pid {
|
||||||
case UnidentifiedProcessID:
|
case UnidentifiedProcessID:
|
||||||
profileID = profile.UnidentifiedProfileID
|
profileID = profile.UnidentifiedProfileID
|
||||||
|
case UnsolicitedProcessID:
|
||||||
|
profileID = profile.UnsolicitedProfileID
|
||||||
case SystemProcessID:
|
case SystemProcessID:
|
||||||
profileID = profile.SystemProfileID
|
profileID = profile.SystemProfileID
|
||||||
case ownPID:
|
case ownPID:
|
||||||
|
|
|
@ -8,29 +8,43 @@ import (
|
||||||
"golang.org/x/sync/singleflight"
|
"golang.org/x/sync/singleflight"
|
||||||
|
|
||||||
"github.com/safing/portbase/log"
|
"github.com/safing/portbase/log"
|
||||||
|
"github.com/safing/portmaster/profile"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// UnidentifiedProcessID is the PID used for anything that could not be
|
|
||||||
// attributed to a PID for any reason.
|
|
||||||
UnidentifiedProcessID = -1
|
|
||||||
|
|
||||||
// UndefinedProcessID is not used by any (virtual) process and signifies that
|
// UndefinedProcessID is not used by any (virtual) process and signifies that
|
||||||
// the PID is unset.
|
// the PID is unset.
|
||||||
UndefinedProcessID = -2
|
UndefinedProcessID = -1
|
||||||
|
|
||||||
|
// UnidentifiedProcessID is the PID used for outgoing connections that could
|
||||||
|
// not be attributed to a PID for any reason.
|
||||||
|
UnidentifiedProcessID = -2
|
||||||
|
|
||||||
|
// UnsolicitedProcessID is the PID used for incoming connections that could
|
||||||
|
// not be attributed to a PID for any reason.
|
||||||
|
UnsolicitedProcessID = -3
|
||||||
|
|
||||||
// NetworkHostProcessID is the PID used for requests served to the network.
|
// NetworkHostProcessID is the PID used for requests served to the network.
|
||||||
NetworkHostProcessID = -255
|
NetworkHostProcessID = -255
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// unidentifiedProcess is used when a process cannot be found.
|
// unidentifiedProcess is used for non-attributed outgoing connections.
|
||||||
unidentifiedProcess = &Process{
|
unidentifiedProcess = &Process{
|
||||||
UserID: UnidentifiedProcessID,
|
UserID: UnidentifiedProcessID,
|
||||||
UserName: "Unknown",
|
UserName: "Unknown",
|
||||||
Pid: UnidentifiedProcessID,
|
Pid: UnidentifiedProcessID,
|
||||||
ParentPid: UnidentifiedProcessID,
|
ParentPid: UnidentifiedProcessID,
|
||||||
Name: "Unidentified Processes",
|
Name: profile.UnidentifiedProfileName,
|
||||||
|
}
|
||||||
|
|
||||||
|
// unsolicitedProcess is used for non-attributed incoming connections.
|
||||||
|
unsolicitedProcess = &Process{
|
||||||
|
UserID: UnsolicitedProcessID,
|
||||||
|
UserName: "Unknown",
|
||||||
|
Pid: UnsolicitedProcessID,
|
||||||
|
ParentPid: UnsolicitedProcessID,
|
||||||
|
Name: profile.UnsolicitedProfileName,
|
||||||
}
|
}
|
||||||
|
|
||||||
// systemProcess is used to represent the Kernel.
|
// systemProcess is used to represent the Kernel.
|
||||||
|
@ -39,17 +53,22 @@ var (
|
||||||
UserName: "Kernel",
|
UserName: "Kernel",
|
||||||
Pid: SystemProcessID,
|
Pid: SystemProcessID,
|
||||||
ParentPid: SystemProcessID,
|
ParentPid: SystemProcessID,
|
||||||
Name: "Operating System",
|
Name: profile.SystemProfileName,
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpecialProcessSingleInflight singleflight.Group
|
getSpecialProcessSingleInflight singleflight.Group
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUnidentifiedProcess returns the special process assigned to unidentified processes.
|
// GetUnidentifiedProcess returns the special process assigned to non-attributed outgoing connections.
|
||||||
func GetUnidentifiedProcess(ctx context.Context) *Process {
|
func GetUnidentifiedProcess(ctx context.Context) *Process {
|
||||||
return getSpecialProcess(ctx, unidentifiedProcess)
|
return getSpecialProcess(ctx, unidentifiedProcess)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUnsolicitedProcess returns the special process assigned to non-attributed incoming connections.
|
||||||
|
func GetUnsolicitedProcess(ctx context.Context) *Process {
|
||||||
|
return getSpecialProcess(ctx, unsolicitedProcess)
|
||||||
|
}
|
||||||
|
|
||||||
// GetSystemProcess returns the special process used for the Kernel.
|
// GetSystemProcess returns the special process used for the Kernel.
|
||||||
func GetSystemProcess(ctx context.Context) *Process {
|
func GetSystemProcess(ctx context.Context) *Process {
|
||||||
return getSpecialProcess(ctx, systemProcess)
|
return getSpecialProcess(ctx, systemProcess)
|
||||||
|
|
|
@ -10,13 +10,26 @@ const (
|
||||||
// UnidentifiedProfileID is the profile ID used for unidentified processes.
|
// UnidentifiedProfileID is the profile ID used for unidentified processes.
|
||||||
UnidentifiedProfileID = "_unidentified"
|
UnidentifiedProfileID = "_unidentified"
|
||||||
// UnidentifiedProfileName is the name used for unidentified processes.
|
// UnidentifiedProfileName is the name used for unidentified processes.
|
||||||
UnidentifiedProfileName = "Unidentified Processes"
|
UnidentifiedProfileName = "Unidentified App"
|
||||||
// UnidentifiedProfileDescription is the description used for unidentified processes.
|
// UnidentifiedProfileDescription is the description used for unidentified processes.
|
||||||
UnidentifiedProfileDescription = `This is not a real application, but a collection of connections that could not be attributed to a process. This could be because the Portmaster failed to identify the process, or simply because there is no process waiting for an incoming connection.
|
UnidentifiedProfileDescription = `Connections that could not be attributed to a specific app.
|
||||||
|
|
||||||
Seeing a lot of incoming connections here is normal, as this resembles the network chatter of other devices.
|
The Portmaster attributes connections (only TCP/UDP) to specific apps. When attribution for a connection fails, it ends up here.
|
||||||
|
|
||||||
|
Connections from unsupported protocols (like ICMP/"ping") are always collected here.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// UnsolicitedProfileID is the profile ID used for unsolicited connections.
|
||||||
|
UnsolicitedProfileID = "_unsolicited"
|
||||||
|
// UnsolicitedProfileName is the name used for unsolicited connections.
|
||||||
|
UnsolicitedProfileName = "Network Noise"
|
||||||
|
// UnsolicitedProfileDescription is the description used for unsolicited connections.
|
||||||
|
UnsolicitedProfileDescription = `Common connections coming from your Local Area Network.
|
||||||
|
|
||||||
|
Local Area Networks usually have quite a lot of traffic from applications that are trying to find things on the network. This might be a computer trying to find a printer, or a file sharing application searching for local peers. These network packets will automatically arrive at your device.
|
||||||
|
|
||||||
|
These connections - the "network noise" - can be found in this app.`
|
||||||
|
|
||||||
// SystemProfileID is the profile ID used for the system/kernel.
|
// SystemProfileID is the profile ID used for the system/kernel.
|
||||||
SystemProfileID = "_system"
|
SystemProfileID = "_system"
|
||||||
// SystemProfileName is the name used for the system/kernel.
|
// SystemProfileName is the name used for the system/kernel.
|
||||||
|
@ -68,6 +81,9 @@ func updateSpecialProfileMetadata(profile *Profile, binaryPath string) (ok, chan
|
||||||
case UnidentifiedProfileID:
|
case UnidentifiedProfileID:
|
||||||
newProfileName = UnidentifiedProfileName
|
newProfileName = UnidentifiedProfileName
|
||||||
newDescription = UnidentifiedProfileDescription
|
newDescription = UnidentifiedProfileDescription
|
||||||
|
case UnsolicitedProfileID:
|
||||||
|
newProfileName = UnsolicitedProfileName
|
||||||
|
newDescription = UnsolicitedProfileDescription
|
||||||
case SystemProfileID:
|
case SystemProfileID:
|
||||||
newProfileName = SystemProfileName
|
newProfileName = SystemProfileName
|
||||||
newDescription = SystemProfileDescription
|
newDescription = SystemProfileDescription
|
||||||
|
|
Loading…
Add table
Reference in a new issue