This commit is contained in:
crusader 2018-09-28 19:30:38 +09:00
parent 11ac0def52
commit ab53243acf
2 changed files with 34 additions and 1 deletions

View File

@ -16,7 +16,15 @@ import (
"github.com/google/gopacket/layers"
)
var (
discovererType = omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn)
)
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (err error) {
if !discoverySession.HostNeedScan(targetHost, discovererType) {
return nil
}
ps := discoverySession.PCapScanner()
if nil == ps {
err = fmt.Errorf("Cannot retain pcap instance")
@ -56,7 +64,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (er
}
delay.Store(true)
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:
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() {
if err = sendTCP4(discoverySession, ps, targetHost, stopChan); nil != err {
log.Printf("sendTCP %v", err)

View File

@ -41,6 +41,8 @@ type DiscoverySession interface {
IsTargetPort(port *omd.Port) bool
IsTargetService(service *omd.Service) bool
HostNeedScan(host *omd.Host, discovererType *omm.MetaDiscovererType) bool
SetDiscoveryDelegator(chan<- interface{})
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
privileged bool
hostScanned sync.Map
stopped atomic.Value
stopChan chan struct{}
}
@ -296,6 +300,25 @@ func (ds *ofDiscoverySession) IsTargetService(service *omd.Service) bool {
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 {
ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock()