This commit is contained in:
crusader 2018-09-14 19:08:22 +09:00
commit efdfd3060b
4 changed files with 25 additions and 1 deletions

View File

@ -198,6 +198,12 @@ func (d *ofDiscoverer) discover(req types.DiscoveryRequest, s session.DiscoveryS
return
}
if s.Privileged() {
d.SendMessage(req, types.DiscoveryMessageTypeMode, "Privileged")
} else {
d.SendMessage(req, types.DiscoveryMessageTypeMode, "Unprivileged")
}
d.complexDiscover(s)
d.hierarchyDiscover(s)
}

View File

@ -55,6 +55,7 @@ type DiscoverySession interface {
DiscoveredService(port *omd.Port, name string) *omd.Service
DiscoveredServices(port *omd.Port) map[string]*omd.Service
DiscoveredAllServices() map[*omd.Port]map[string]*omd.Service
Privileged() bool
Shutdown()
StopChan() <-chan struct{}
@ -85,6 +86,7 @@ type ofDiscoverySession struct {
includeMachosts map[string]*omd.Host
ports map[*omd.Host]map[json.Number]map[string]*omd.Port
services map[*omd.Port]map[string]*omd.Service
privileged bool
stopped atomic.Value
stopChan chan struct{}
@ -194,9 +196,11 @@ func (ds *ofDiscoverySession) InitWithRequest(request types.DiscoveryRequest) er
_pCapScanner := pcap.NewPCapScanner(ds.zone)
if err := _pCapScanner.Start(); nil == err {
ds.pCapScanner = _pCapScanner
ds.privileged = true
log.Print("Privileged mode")
} else {
log.Print(err)
ds.privileged = false
log.Print("Unprivileged mode")
}
@ -207,6 +211,10 @@ func (ds *ofDiscoverySession) PCapScanner() pcap.PCapScanner {
return ds.pCapScanner
}
func (ds *ofDiscoverySession) Privileged() bool {
return ds.privileged
}
func (ds *ofDiscoverySession) SetDiscoveryDelegator(discoveryDelegator chan<- interface{}) {
ds.discoveryDelegator = discoveryDelegator
}

View File

@ -7,6 +7,7 @@ const (
DiscoveryMessageTypeQueueing
DiscoveryMessageTypeQueueingFailed
DiscoveryMessageTypeQueueingTimeout
DiscoveryMessageTypeMode
DiscoveryMessageTypeStart
DiscoveryMessageTypeStop
DiscoveryMessageTypeError

View File

@ -72,6 +72,15 @@ func (s *DiscoveryService) InitService() {
),
"/scanner",
)
case types.DiscoveryMessageTypeMode:
s.PubSub.Pub(
rpc.MakeRPCMessage(
[]string{request.RequesterID()},
"DiscoveryService.DiscoveryMode",
datas,
),
"/scanner",
)
// log.Print("Queueing ", data)
case types.DiscoveryMessageTypeQueueingFailed:
s.PubSub.Pub(