This commit is contained in:
crusader 2018-09-03 14:24:30 +09:00
parent f8a302e632
commit 76eb21a8d5
3 changed files with 22 additions and 1 deletions

View File

@ -18,7 +18,7 @@ import (
)
func Scan(discoverySession session.DiscoverySession) error {
oub.Elapsed("mDNS")
oub.Elapsed("ARP")
targetHosts := discoverySession.TargetHosts()
if nil == targetHosts || 0 == len(targetHosts) {
@ -59,6 +59,7 @@ func Scan(discoverySession session.DiscoverySession) error {
delay.Store(true)
if h := handlePacketARP(zone, targetHosts, hosts, packet); nil != h {
if h != nil {
// log.Print("Host ", h)
discoverySession.AddHost(h)
}

View File

@ -59,6 +59,7 @@ func scanV4(discoverySession session.DiscoverySession) error {
delay.Store(true)
if h := handlePacketICMP4(zone, targetHosts, hosts, packet); nil != h {
if h != nil {
// log.Print("Host ", h)
discoverySession.AddHost(h)
}

View File

@ -60,6 +60,7 @@ type ofDiscoverySession struct {
discoveryDelegator chan<- interface{}
discoveredMtx sync.RWMutex
hosts map[string]*omd.Host
includeMachosts map[string]*omd.Host
ports map[*omd.Host]map[json.Number]map[string]*omd.Port
@ -201,6 +202,9 @@ func (ds *ofDiscoverySession) TargetHosts() []net.IP {
}
func (ds *ofDiscoverySession) AddHost(host *omd.Host) *omd.Host {
ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock()
h, modified := ds.findHost(host, true)
if "" == h.Mac && "" != host.Mac {
@ -222,6 +226,9 @@ func (ds *ofDiscoverySession) AddHost(host *omd.Host) *omd.Host {
}
func (ds *ofDiscoverySession) AddPort(port *omd.Port) *omd.Port {
ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock()
p, modified := ds.findPort(port, true)
meta, metaModified := ds.appendMeta(p.Meta, port.Meta)
@ -238,6 +245,9 @@ func (ds *ofDiscoverySession) AddPort(port *omd.Port) *omd.Port {
}
func (ds *ofDiscoverySession) AddService(service *omd.Service) *omd.Service {
ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock()
s, modified := ds.findService(service, true)
meta, metaModified := ds.appendMeta(s.Meta, service.Meta)
@ -254,6 +264,9 @@ func (ds *ofDiscoverySession) AddService(service *omd.Service) *omd.Service {
}
func (ds *ofDiscoverySession) DiscoveredHost(address string) *omd.Host {
ds.discoveredMtx.RLock()
defer ds.discoveredMtx.RUnlock()
h, ok := ds.hosts[address]
if !ok {
return nil
@ -270,6 +283,9 @@ func (ds *ofDiscoverySession) DiscoveredAllHosts(includeMac bool) map[string]*om
}
func (ds *ofDiscoverySession) DiscoveredPort(host *omd.Host, portNumber int) map[string]*omd.Port {
ds.discoveredMtx.RLock()
defer ds.discoveredMtx.RUnlock()
h, _ := ds.findHost(host, false)
if nil == h {
return nil
@ -293,6 +309,9 @@ func (ds *ofDiscoverySession) DiscoveredAllPorts() map[*omd.Host]map[json.Number
}
func (ds *ofDiscoverySession) DiscoveredService(port *omd.Port, name string) map[string]*omd.Service {
ds.discoveredMtx.RLock()
defer ds.discoveredMtx.RUnlock()
p, _ := ds.findPort(port, false)
if nil == p {
return nil