Clean up process/proc
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PID querying return codes
|
||||||
const (
|
const (
|
||||||
Success uint8 = iota
|
Success uint8 = iota
|
||||||
NoSocket
|
NoSocket
|
||||||
@@ -48,7 +49,7 @@ func GetPidOfConnection(localIP net.IP, localPort uint16, protocol uint8) (pid i
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPidOfConnection returns the PID of the given incoming connection.
|
// GetPidOfIncomingConnection returns the PID of the given incoming connection.
|
||||||
func GetPidOfIncomingConnection(localIP net.IP, localPort uint16, protocol uint8) (pid int, status uint8) {
|
func GetPidOfIncomingConnection(localIP net.IP, localPort uint16, protocol uint8) (pid int, status uint8) {
|
||||||
uid, inode, ok := getListeningSocket(localIP, localPort, protocol)
|
uid, inode, ok := getListeningSocket(localIP, localPort, protocol)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -5,18 +5,22 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetTCP4PacketInfo searches the network state tables for a TCP4 connection
|
||||||
func GetTCP4PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
func GetTCP4PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
||||||
return search(TCP4, localIP, localPort, pktDirection)
|
return search(TCP4, localIP, localPort, pktDirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTCP6PacketInfo searches the network state tables for a TCP6 connection
|
||||||
func GetTCP6PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
func GetTCP6PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
||||||
return search(TCP6, localIP, localPort, pktDirection)
|
return search(TCP6, localIP, localPort, pktDirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUDP4PacketInfo searches the network state tables for a UDP4 connection
|
||||||
func GetUDP4PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
func GetUDP4PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
||||||
return search(UDP4, localIP, localPort, pktDirection)
|
return search(UDP4, localIP, localPort, pktDirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUDP6PacketInfo searches the network state tables for a UDP6 connection
|
||||||
func GetUDP6PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
func GetUDP6PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
|
||||||
return search(UDP6, localIP, localPort, pktDirection)
|
return search(UDP6, localIP, localPort, pktDirection)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ var (
|
|||||||
pidsByUser = make(map[int][]int)
|
pidsByUser = make(map[int][]int)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetPidOfInode returns the pid of the given uid and socket inode.
|
||||||
func GetPidOfInode(uid, inode int) (int, bool) {
|
func GetPidOfInode(uid, inode int) (int, bool) {
|
||||||
pidsByUserLock.Lock()
|
pidsByUserLock.Lock()
|
||||||
defer pidsByUserLock.Unlock()
|
defer pidsByUserLock.Unlock()
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Cache every step!
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Network Related Constants
|
||||||
const (
|
const (
|
||||||
TCP4 uint8 = iota
|
TCP4 uint8 = iota
|
||||||
UDP4
|
UDP4
|
||||||
@@ -211,7 +212,7 @@ func convertIPv4(data string) net.IP {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(decoded) != 4 {
|
if len(decoded) != 4 {
|
||||||
log.Warningf("process: decoded IPv4 %s has wrong length")
|
log.Warningf("process: decoded IPv4 %s has wrong length", decoded)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ip := net.IPv4(decoded[3], decoded[2], decoded[1], decoded[0])
|
ip := net.IPv4(decoded[3], decoded[2], decoded[1], decoded[0])
|
||||||
@@ -225,7 +226,7 @@ func convertIPv6(data string) net.IP {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(decoded) != 16 {
|
if len(decoded) != 16 {
|
||||||
log.Warningf("process: decoded IPv6 %s has wrong length")
|
log.Warningf("process: decoded IPv6 %s has wrong length", decoded)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ip := net.IP(decoded)
|
ip := net.IP(decoded)
|
||||||
|
|||||||
Reference in New Issue
Block a user