ing
This commit is contained in:
parent
11ac0def52
commit
ab53243acf
|
@ -16,7 +16,15 @@ import (
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
discovererType = omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn)
|
||||||
|
)
|
||||||
|
|
||||||
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (err error) {
|
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (err error) {
|
||||||
|
if !discoverySession.HostNeedScan(targetHost, discovererType) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
ps := discoverySession.PCapScanner()
|
ps := discoverySession.PCapScanner()
|
||||||
if nil == ps {
|
if nil == ps {
|
||||||
err = fmt.Errorf("Cannot retain pcap instance")
|
err = fmt.Errorf("Cannot retain pcap instance")
|
||||||
|
@ -56,7 +64,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (er
|
||||||
}
|
}
|
||||||
delay.Store(true)
|
delay.Store(true)
|
||||||
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
|
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
|
||||||
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn), p, nil)
|
go discoverySession.AddPort(discovererType, p, nil)
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if false == sendComplete.Load().(bool) {
|
if false == sendComplete.Load().(bool) {
|
||||||
|
@ -71,6 +79,8 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (er
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
log.Print("SYN start ", targetHost.Address)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err = sendTCP4(discoverySession, ps, targetHost, stopChan); nil != err {
|
if err = sendTCP4(discoverySession, ps, targetHost, stopChan); nil != err {
|
||||||
log.Printf("sendTCP %v", err)
|
log.Printf("sendTCP %v", err)
|
||||||
|
|
|
@ -41,6 +41,8 @@ type DiscoverySession interface {
|
||||||
IsTargetPort(port *omd.Port) bool
|
IsTargetPort(port *omd.Port) bool
|
||||||
IsTargetService(service *omd.Service) bool
|
IsTargetService(service *omd.Service) bool
|
||||||
|
|
||||||
|
HostNeedScan(host *omd.Host, discovererType *omm.MetaDiscovererType) bool
|
||||||
|
|
||||||
SetDiscoveryDelegator(chan<- interface{})
|
SetDiscoveryDelegator(chan<- interface{})
|
||||||
|
|
||||||
AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host
|
AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host
|
||||||
|
@ -88,6 +90,8 @@ type ofDiscoverySession struct {
|
||||||
services map[*omd.Port]map[string]*omd.Service
|
services map[*omd.Port]map[string]*omd.Service
|
||||||
privileged bool
|
privileged bool
|
||||||
|
|
||||||
|
hostScanned sync.Map
|
||||||
|
|
||||||
stopped atomic.Value
|
stopped atomic.Value
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
}
|
}
|
||||||
|
@ -296,6 +300,25 @@ func (ds *ofDiscoverySession) IsTargetService(service *omd.Service) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ds *ofDiscoverySession) HostNeedScan(host *omd.Host, discovererType *omm.MetaDiscovererType) bool {
|
||||||
|
_sd, ok := ds.hostScanned.Load(host.Address)
|
||||||
|
if !ok {
|
||||||
|
sd := make(map[string]bool)
|
||||||
|
sd[discovererType.Key] = true
|
||||||
|
ds.hostScanned.Store(host.Address, sd)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
sd := _sd.(map[string]bool)
|
||||||
|
_, ok = sd[discovererType.Key]
|
||||||
|
if !ok {
|
||||||
|
sd[discovererType.Key] = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (ds *ofDiscoverySession) AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host {
|
func (ds *ofDiscoverySession) AddHost(discoveredBy *omm.MetaDiscovererType, host *omd.Host, meta map[string]string) *omd.Host {
|
||||||
ds.discoveredMtx.Lock()
|
ds.discoveredMtx.Lock()
|
||||||
defer ds.discoveredMtx.Unlock()
|
defer ds.discoveredMtx.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user