send discovery mode msg

This commit is contained in:
insanity 2018-09-14 16:44:09 +09:00
parent 7db69d4551
commit 03ec5c7b74
4 changed files with 25 additions and 1 deletions

View File

@ -193,6 +193,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

@ -54,6 +54,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{}
@ -84,6 +85,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
stopChan chan struct{}
}
@ -191,9 +193,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")
}
@ -204,6 +208,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(