fix: syn.scanner now uses a dedicated pcap handle to prevent deadlocks and improve performances

This commit is contained in:
evilsocket 2019-04-21 20:37:41 +02:00
parent 8257d25ff3
commit cd249687da
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
4 changed files with 87 additions and 80 deletions

View file

@ -33,8 +33,6 @@ type Stats struct {
Errors uint64 `json:"errors"`
}
type PacketCallback func(pkt gopacket.Packet)
type Queue struct {
sync.RWMutex
@ -49,7 +47,6 @@ type Queue struct {
source *gopacket.PacketSource
srcChannel chan gopacket.Packet
writes *sync.WaitGroup
pktCb PacketCallback
active bool
}
@ -69,7 +66,6 @@ func NewQueue(iface *network.Endpoint) (q *Queue, err error) {
writes: &sync.WaitGroup{},
iface: iface,
active: !iface.IsMonitor(),
pktCb: nil,
}
if q.active {
@ -107,21 +103,6 @@ func (q *Queue) MarshalJSON() ([]byte, error) {
return json.Marshal(doc)
}
func (q *Queue) OnPacket(cb PacketCallback) {
q.Lock()
defer q.Unlock()
q.pktCb = cb
}
func (q *Queue) onPacketCallback(pkt gopacket.Packet) {
q.RLock()
defer q.RUnlock()
if q.pktCb != nil {
q.pktCb(pkt)
}
}
func (q *Queue) trackProtocols(pkt gopacket.Packet) {
// gather protocols stats
pktLayers := pkt.Layers()
@ -206,7 +187,6 @@ func (q *Queue) worker() {
pktSize := uint64(len(pkt.Data()))
q.TrackPacket(pktSize)
q.onPacketCallback(pkt)
// decode eth and ipv4 layers
leth := pkt.Layer(layers.LayerTypeEthernet)