Add integrationtest utility

This commit is contained in:
Daniel
2023-03-30 10:33:09 +02:00
parent 253e3f95f8
commit 7d3b45f1a9
7 changed files with 148 additions and 9 deletions

View File

@@ -92,7 +92,7 @@ func (table *tcpTable) lookup(pktInfo *packet.Info, fast bool) (
// If there's a match, check if we have the PID and return.
if socketInfo != nil {
return checkPID(socketInfo, inbound)
return CheckPID(socketInfo, inbound)
}
// DUAL-STACK
@@ -114,7 +114,7 @@ func (table *tcpTable) lookup(pktInfo *packet.Info, fast bool) (
// If there's a match, check if we have the PID and return.
if socketInfo != nil {
return checkPID(socketInfo, inbound)
return CheckPID(socketInfo, inbound)
}
// Search less if we want to be fast.
@@ -199,14 +199,14 @@ func (table *udpTable) lookup(pktInfo *packet.Info, fast bool) (
// connection. This will be the case for pure checking functions
// that do not want to change direction state.
if pktInfo.RemotePort() == 0 {
return checkPID(socketInfo, pktInfo.Inbound)
return CheckPID(socketInfo, pktInfo.Inbound)
}
// Get (and save) the direction of the connection.
connInbound := table.getDirection(socketInfo, pktInfo)
// Check we have the PID and return.
return checkPID(socketInfo, connInbound)
return CheckPID(socketInfo, connInbound)
}
// DUAL-STACK
@@ -232,14 +232,14 @@ func (table *udpTable) lookup(pktInfo *packet.Info, fast bool) (
// connection. This will be the case for pure checking functions
// that do not want to change direction state.
if pktInfo.RemotePort() == 0 {
return checkPID(socketInfo, pktInfo.Inbound)
return CheckPID(socketInfo, pktInfo.Inbound)
}
// Get (and save) the direction of the connection.
connInbound := table.getDirection(socketInfo, pktInfo)
// Check we have the PID and return.
return checkPID(socketInfo, connInbound)
return CheckPID(socketInfo, connInbound)
}
// Search less if we want to be fast.

View File

@@ -1,3 +1,4 @@
//go:build !windows && !linux
// +build !windows,!linux
package state
@@ -38,6 +39,8 @@ func getUDP6Table() (binds []*socket.BindInfo, err error) {
return nil, nil
}
func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
// CheckPID checks the if socket info already has a PID and if not, tries to find it.
// Depending on the OS, this might be a no-op.
func CheckPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
return socketInfo.GetPID(), connInbound, nil
}

View File

@@ -16,7 +16,9 @@ var (
var baseWaitTime = 3 * time.Millisecond
func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
// CheckPID checks the if socket info already has a PID and if not, tries to find it.
// Depending on the OS, this might be a no-op.
func CheckPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
for i := 1; i <= lookupTries; i++ {
// look for PID
pid = proc.GetPID(socketInfo)

View File

@@ -12,6 +12,8 @@ var (
getUDP6Table = iphelper.GetUDP6Table
)
func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
// CheckPID checks the if socket info already has a PID and if not, tries to find it.
// Depending on the OS, this might be a no-op.
func CheckPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) {
return socketInfo.GetPID(), connInbound, nil
}