mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
fix: syn.scanner now uses a dedicated pcap handle to prevent deadlocks and improve performances
This commit is contained in:
parent
8257d25ff3
commit
cd249687da
4 changed files with 87 additions and 80 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue