Skip to content

Commit

Permalink
fix(port-service): panic, when getting packets without transportlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcStdt committed Nov 11, 2024
1 parent 0375ef2 commit c73bc69
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/core/services/port_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,24 @@ func (p *PortMonitor) waitForPortActiviy(ctx context.Context, ports []int, inter
continue
}

packetPort := packet.TransportLayer().TransportFlow().Dst().String()
var packetPort = 0

if transportLayer := packet.TransportLayer(); transportLayer != nil {
packetPortStr := transportLayer.TransportFlow().Dst().String()
packetPort, err = strconv.Atoi(packetPortStr)
if err != nil {
packetPort = 0
}
}

var srcIP, dstIP string
if netLayer := packet.NetworkLayer(); netLayer != nil {
srcIP = netLayer.NetworkFlow().Src().String()
dstIP = netLayer.NetworkFlow().Dst().String()
}

packetPortInt, err := strconv.Atoi(packetPort)
if err != nil {
packetPortInt = 0
}
logger.Log().Debug("Packet found on iface",
zap.String("iface", interfaceName), zap.Int("port", packetPortInt),
zap.String("iface", interfaceName), zap.Int("port", packetPort),
zap.String("srcIP", srcIP), zap.String("dstIP", dstIP),
)

Expand All @@ -304,7 +308,7 @@ func (p *PortMonitor) waitForPortActiviy(ctx context.Context, ports []int, inter
// Check if we have reached the packets per minute threshold
if packetCount >= int(ppm) {
logger.Log().Info("PPM threshhold reached", zap.String("iface", interfaceName), zap.Int("ppm", int(ppm)))
return packetPortInt, nil
return packetPort, nil
}
case <-ticker.C:
// Reset packet count every minute
Expand Down

0 comments on commit c73bc69

Please sign in to comment.