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 return
} }
if s.Privileged() {
d.SendMessage(req, types.DiscoveryMessageTypeMode, "Privileged")
} else {
d.SendMessage(req, types.DiscoveryMessageTypeMode, "Unprivileged")
}
d.complexDiscover(s) d.complexDiscover(s)
d.hierarchyDiscover(s) d.hierarchyDiscover(s)
} }

View File

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

View File

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

View File

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