ing
This commit is contained in:
parent
be4832f7a9
commit
d7f3ea3268
|
@ -2,6 +2,7 @@ package pcap
|
|||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
||||
)
|
||||
|
@ -36,10 +37,13 @@ func ReleaseScanner(zone *model.Zone) {
|
|||
defer mtx.Unlock()
|
||||
|
||||
if ps, ok := instances[zone.Network]; ok {
|
||||
if ps.release() {
|
||||
ps.stop()
|
||||
delete(instances, zone.Network)
|
||||
}
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
if ps.release() {
|
||||
ps.stop()
|
||||
delete(instances, zone.Network)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,6 +197,7 @@ func (ps *pCapScan) release() bool {
|
|||
if 0 > ps.refCount {
|
||||
ps.refCount = 0
|
||||
}
|
||||
|
||||
return 0 == ps.refCount
|
||||
}
|
||||
|
||||
|
@ -243,6 +244,7 @@ func handleReceive(ps *pCapScan) {
|
|||
handlePacket(ps, packet)
|
||||
case <-ps.stopChan:
|
||||
ps.destroy()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,17 +15,26 @@ import (
|
|||
)
|
||||
|
||||
func ScanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}) {
|
||||
defer func() {
|
||||
doneChan <- struct{}{}
|
||||
}()
|
||||
|
||||
ps, err := pcap.RetainScanner(zone)
|
||||
if nil != err {
|
||||
errChan <- fmt.Errorf("Discovery: Cannot retain pcap instance %v", err)
|
||||
// doneChan <- struct{}{}
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
pcap.ReleaseScanner(zone)
|
||||
}()
|
||||
|
||||
cr, err := cidr.NewCIDRRanger(zone.Network)
|
||||
if nil != err {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
hostRanges, err := getTargetHostRange(dh, cr)
|
||||
if nil != err {
|
||||
errChan <- err
|
||||
|
@ -34,11 +43,7 @@ func ScanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interfa
|
|||
|
||||
arpChan := ps.OpenARP()
|
||||
defer func() {
|
||||
if nil != ps {
|
||||
ps.CloseARP(arpChan)
|
||||
pcap.ReleaseScanner(zone)
|
||||
}
|
||||
doneChan <- struct{}{}
|
||||
ps.CloseARP(arpChan)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user