ing
This commit is contained in:
parent
ec0e83e38b
commit
4868d241cc
|
@ -36,6 +36,9 @@ type DiscoverySession interface {
|
|||
DiscoverService() *omd.DiscoverService
|
||||
|
||||
TargetHosts() []net.IP
|
||||
IsTargetHost(host *omd.Host) bool
|
||||
IsTargetPort(port *omd.Port) bool
|
||||
IsTargetService(service *omd.Service) bool
|
||||
|
||||
SetDiscoveryDelegator(chan<- interface{})
|
||||
|
||||
|
@ -232,6 +235,52 @@ func (ds *ofDiscoverySession) TargetHosts() []net.IP {
|
|||
return ds.targetHosts
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) IsTargetHost(host *omd.Host) bool {
|
||||
for _, targetHost := range ds.targetHosts {
|
||||
if targetHost.String() == host.Address {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) IsTargetPort(port *omd.Port) bool {
|
||||
if nil == ds.discoverPort {
|
||||
return false
|
||||
}
|
||||
|
||||
portNumber, err := ouej.NumberToInt(port.PortNumber)
|
||||
if nil != err {
|
||||
return false
|
||||
}
|
||||
|
||||
if !ds.IsTargetHost(port.Host) {
|
||||
return false
|
||||
}
|
||||
|
||||
if nil != ds.discoverPort.ExcludePorts {
|
||||
for _, exPortNumber := range ds.discoverPort.ExcludePorts {
|
||||
if portNumber == exPortNumber {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if portNumber < ds.discoverPort.FirstScanRange || portNumber > ds.discoverPort.LastScanRange {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) IsTargetService(service *omd.Service) bool {
|
||||
if nil == ds.discoverService {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host {
|
||||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
@ -468,6 +517,23 @@ func (ds *ofDiscoverySession) StopChan() <-chan struct{} {
|
|||
}
|
||||
|
||||
func (ds *ofDiscoverySession) delegate(data interface{}) {
|
||||
switch v := data.(type) {
|
||||
case *omd.Host:
|
||||
if !ds.IsTargetHost(v) {
|
||||
return
|
||||
}
|
||||
case *omd.Port:
|
||||
if !ds.IsTargetPort(v) {
|
||||
return
|
||||
}
|
||||
case *omd.Service:
|
||||
if !ds.IsTargetService(v) {
|
||||
return
|
||||
}
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
if nil != ds.discoveryDelegator {
|
||||
ds.discoveryDelegator <- data
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user