ing
This commit is contained in:
parent
cb620f2a4c
commit
7d2e8170d7
|
@ -1,7 +1,7 @@
|
||||||
package discovery
|
package discovery
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ocsm "git.loafle.net/overflow/commons-go/sensorconfig/model"
|
ocmsc "git.loafle.net/overflow/commons-go/model/sensorconfig"
|
||||||
"git.loafle.net/overflow/crawler-go"
|
"git.loafle.net/overflow/crawler-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ func (c *DiscoveryCrawler) Auth(auth map[string]interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *DiscoveryCrawler) Get(sensorConfig *ocsm.SensorConfig) (map[string]string, error) {
|
func (c *DiscoveryCrawler) Get(sensorConfig *ocmsc.SensorConfig) (map[string]string, error) {
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@ package discoverer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.loafle.net/commons/util-go/net/cidr"
|
"git.loafle.net/commons/util-go/net/cidr"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
"git.loafle.net/overflow/commons-go/core/util"
|
||||||
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiscoveryDataType int
|
type DiscoveryDataType int
|
||||||
|
@ -25,7 +25,7 @@ type DiscoveryData struct {
|
||||||
Type DiscoveryDataType
|
Type DiscoveryDataType
|
||||||
Result interface{}
|
Result interface{}
|
||||||
Error error
|
Error error
|
||||||
Time time.Time
|
Time util.Timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dd *DiscoveryData) Release() {
|
func (dd *DiscoveryData) Release() {
|
||||||
|
@ -44,10 +44,10 @@ func GetDiscoverer() Discoverer {
|
||||||
type Discoverer interface {
|
type Discoverer interface {
|
||||||
Retain() chan *DiscoveryData
|
Retain() chan *DiscoveryData
|
||||||
Release(dataChan chan *DiscoveryData)
|
Release(dataChan chan *DiscoveryData)
|
||||||
DiscoverZone(dataChan chan *DiscoveryData, dz *ocdm.DiscoveryZone)
|
DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoveryZone)
|
||||||
DiscoverHost(dataChan chan *DiscoveryData, zone *ocdm.Zone, dh *ocdm.DiscoveryHost)
|
DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoveryHost)
|
||||||
DiscoverPort(dataChan chan *DiscoveryData, host *ocdm.Host, dp *ocdm.DiscoveryPort)
|
DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoveryPort)
|
||||||
DiscoverSerice(dataChan chan *DiscoveryData, port *ocdm.Port, ds *ocdm.DiscoveryService)
|
DiscoverSerice(dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoveryService)
|
||||||
}
|
}
|
||||||
|
|
||||||
type defaultDiscoverer struct {
|
type defaultDiscoverer struct {
|
||||||
|
@ -75,11 +75,11 @@ func (d *defaultDiscoverer) Stop(dataChan chan *DiscoveryData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) DiscoverZone(dataChan chan *DiscoveryData, dz *ocdm.DiscoveryZone) {
|
func (d *defaultDiscoverer) DiscoverZone(dataChan chan *DiscoveryData, dz *ocmd.DiscoveryZone) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
d.stopChan = make(chan struct{})
|
d.stopChan = make(chan struct{})
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, util.Now(), nil, nil)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverZone(&wg, dataChan, dz)
|
go d.innerDiscoverZone(&wg, dataChan, dz)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -88,14 +88,14 @@ func (d *defaultDiscoverer) DiscoverZone(dataChan chan *DiscoveryData, dz *ocdm.
|
||||||
d.stopChan = nil
|
d.stopChan = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) DiscoverHost(dataChan chan *DiscoveryData, zone *ocdm.Zone, dh *ocdm.DiscoveryHost) {
|
func (d *defaultDiscoverer) DiscoverHost(dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
d.stopChan = make(chan struct{})
|
d.stopChan = make(chan struct{})
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, util.Now(), nil, nil)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverHost(&wg, dataChan, zone, dh)
|
go d.innerDiscoverHost(&wg, dataChan, zone, dh)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -104,14 +104,14 @@ func (d *defaultDiscoverer) DiscoverHost(dataChan chan *DiscoveryData, zone *ocd
|
||||||
d.stopChan = nil
|
d.stopChan = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) DiscoverPort(dataChan chan *DiscoveryData, host *ocdm.Host, dp *ocdm.DiscoveryPort) {
|
func (d *defaultDiscoverer) DiscoverPort(dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoveryPort) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
d.stopChan = make(chan struct{})
|
d.stopChan = make(chan struct{})
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, util.Now(), nil, nil)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverPort(&wg, dataChan, host, dp)
|
go d.innerDiscoverPort(&wg, dataChan, host, dp)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -120,14 +120,14 @@ func (d *defaultDiscoverer) DiscoverPort(dataChan chan *DiscoveryData, host *ocd
|
||||||
d.stopChan = nil
|
d.stopChan = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) DiscoverSerice(dataChan chan *DiscoveryData, port *ocdm.Port, ds *ocdm.DiscoveryService) {
|
func (d *defaultDiscoverer) DiscoverSerice(dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoveryService) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
d.stopChan = make(chan struct{})
|
d.stopChan = make(chan struct{})
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStart, util.Now(), nil, nil)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverSerice(&wg, dataChan, port, ds)
|
go d.innerDiscoverSerice(&wg, dataChan, port, ds)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -136,10 +136,10 @@ func (d *defaultDiscoverer) DiscoverSerice(dataChan chan *DiscoveryData, port *o
|
||||||
d.stopChan = nil
|
d.stopChan = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, time.Now(), nil, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeStop, util.Now(), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan *DiscoveryData, dz *ocdm.DiscoveryZone) {
|
func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan *DiscoveryData, dz *ocmd.DiscoveryZone) {
|
||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -149,11 +149,11 @@ func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan
|
||||||
scanZone(dz, resultChan, errChan, doneChan, stopChan)
|
scanZone(dz, resultChan, errChan, doneChan, stopChan)
|
||||||
},
|
},
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
z := result.(*ocdm.Zone)
|
z := result.(*ocmd.Zone)
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeZone, time.Now(), z, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeZone, util.Now(), z, nil)
|
||||||
if nil != dz.DiscoveryHost {
|
if nil != dz.DiscoveryHost {
|
||||||
cr, _ := cidr.NewCIDRRanger(z.Network)
|
cr, _ := cidr.NewCIDRRanger(z.Network)
|
||||||
dh := &ocdm.DiscoveryHost{
|
dh := &ocmd.DiscoveryHost{
|
||||||
FirstScanRange: cr.First().String(),
|
FirstScanRange: cr.First().String(),
|
||||||
LastScanRange: cr.Last().String(),
|
LastScanRange: cr.Last().String(),
|
||||||
DiscoveryPort: dz.DiscoveryHost.DiscoveryPort,
|
DiscoveryPort: dz.DiscoveryHost.DiscoveryPort,
|
||||||
|
@ -163,12 +163,12 @@ func (d *defaultDiscoverer) innerDiscoverZone(wg *sync.WaitGroup, dataChan chan
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(err error) {
|
func(err error) {
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, time.Now(), nil, err)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, util.Now(), nil, err)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan *DiscoveryData, zone *ocdm.Zone, dh *ocdm.DiscoveryHost) {
|
func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan *DiscoveryData, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) {
|
||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -178,20 +178,20 @@ func (d *defaultDiscoverer) innerDiscoverHost(wg *sync.WaitGroup, dataChan chan
|
||||||
scanHost(zone, dh, resultChan, errChan, doneChan, stopChan)
|
scanHost(zone, dh, resultChan, errChan, doneChan, stopChan)
|
||||||
},
|
},
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
h := result.(*ocdm.Host)
|
h := result.(*ocmd.Host)
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeHost, time.Now(), h, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeHost, util.Now(), h, nil)
|
||||||
if nil != dh.DiscoveryPort {
|
if nil != dh.DiscoveryPort {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverPort(wg, dataChan, h, dh.DiscoveryPort)
|
go d.innerDiscoverPort(wg, dataChan, h, dh.DiscoveryPort)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(err error) {
|
func(err error) {
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, time.Now(), nil, err)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, util.Now(), nil, err)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan *DiscoveryData, host *ocdm.Host, dp *ocdm.DiscoveryPort) {
|
func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan *DiscoveryData, host *ocmd.Host, dp *ocmd.DiscoveryPort) {
|
||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -201,20 +201,20 @@ func (d *defaultDiscoverer) innerDiscoverPort(wg *sync.WaitGroup, dataChan chan
|
||||||
scanPort(host, dp, resultChan, errChan, doneChan, stopChan)
|
scanPort(host, dp, resultChan, errChan, doneChan, stopChan)
|
||||||
},
|
},
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
p := result.(*ocdm.Port)
|
p := result.(*ocmd.Port)
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypePort, time.Now(), p, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypePort, util.Now(), p, nil)
|
||||||
if nil != dp.DiscoveryService {
|
if nil != dp.DiscoveryService {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go d.innerDiscoverSerice(wg, dataChan, p, dp.DiscoveryService)
|
go d.innerDiscoverSerice(wg, dataChan, p, dp.DiscoveryService)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(err error) {
|
func(err error) {
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, time.Now(), nil, err)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, util.Now(), nil, err)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *defaultDiscoverer) innerDiscoverSerice(wg *sync.WaitGroup, dataChan chan *DiscoveryData, port *ocdm.Port, ds *ocdm.DiscoveryService) {
|
func (d *defaultDiscoverer) innerDiscoverSerice(wg *sync.WaitGroup, dataChan chan *DiscoveryData, port *ocmd.Port, ds *ocmd.DiscoveryService) {
|
||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -224,11 +224,11 @@ func (d *defaultDiscoverer) innerDiscoverSerice(wg *sync.WaitGroup, dataChan cha
|
||||||
scanService(port, ds, resultChan, errChan, doneChan, stopChan)
|
scanService(port, ds, resultChan, errChan, doneChan, stopChan)
|
||||||
},
|
},
|
||||||
func(result interface{}) {
|
func(result interface{}) {
|
||||||
s := result.(*ocdm.Service)
|
s := result.(*ocmd.Service)
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeService, time.Now(), s, nil)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeService, util.Now(), s, nil)
|
||||||
},
|
},
|
||||||
func(err error) {
|
func(err error) {
|
||||||
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, time.Now(), nil, err)
|
dataChan <- retainDiscoveryData(DiscoveryDataTypeError, util.Now(), nil, err)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ func taskScan(d *defaultDiscoverer,
|
||||||
|
|
||||||
var discoveryDataPool sync.Pool
|
var discoveryDataPool sync.Pool
|
||||||
|
|
||||||
func retainDiscoveryData(discoveryDataType DiscoveryDataType, t time.Time, result interface{}, err error) *DiscoveryData {
|
func retainDiscoveryData(discoveryDataType DiscoveryDataType, t util.Timestamp, result interface{}, err error) *DiscoveryData {
|
||||||
v := discoveryDataPool.Get()
|
v := discoveryDataPool.Get()
|
||||||
var discoveryData *DiscoveryData
|
var discoveryData *DiscoveryData
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
@ -287,7 +287,7 @@ func releaseDiscoveryData(discoveryData *DiscoveryData) {
|
||||||
discoveryData.Type = DiscoveryDataTypeNone
|
discoveryData.Type = DiscoveryDataTypeNone
|
||||||
discoveryData.Result = nil
|
discoveryData.Result = nil
|
||||||
discoveryData.Error = nil
|
discoveryData.Error = nil
|
||||||
discoveryData.Time = time.Time{}
|
discoveryData.Time = util.Timestamp{}
|
||||||
|
|
||||||
discoveryDataPool.Put(discoveryData)
|
discoveryDataPool.Put(discoveryData)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanHost(zone *ocdm.Zone, dh *ocdm.DiscoveryHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
func scanHost(zone *ocmd.Zone, dh *ocmd.DiscoveryHost, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
||||||
defer func() {
|
defer func() {
|
||||||
doneChan <- struct{}{}
|
doneChan <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -10,11 +10,11 @@ import (
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/pcap"
|
"git.loafle.net/overflow/container_discovery/internal/pcap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanHost(zone *ocdm.Zone, dh *ocdm.DiscoveryHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoveryHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
||||||
ps, err := pcap.RetainScanner(zone)
|
ps, err := pcap.RetainScanner(zone)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
errChan <- fmt.Errorf("Discovery: Cannot retain pcap instance %v", err)
|
errChan <- fmt.Errorf("Discovery: Cannot retain pcap instance %v", err)
|
||||||
|
@ -43,7 +43,7 @@ func ScanHost(zone *ocdm.Zone, dh *ocdm.DiscoveryHost, resultChan chan interface
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
hosts := make(map[string]*ocdm.Host)
|
hosts := make(map[string]*ocmd.Host)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case packet, ok := <-arpChan:
|
case packet, ok := <-arpChan:
|
||||||
|
@ -76,7 +76,7 @@ func ScanHost(zone *ocdm.Zone, dh *ocdm.DiscoveryHost, resultChan chan interface
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendARP(ps pcap.PCapScanner, zone *ocdm.Zone, hostRanges []net.IP, stopChan chan struct{}) error {
|
func sendARP(ps pcap.PCapScanner, zone *ocmd.Zone, hostRanges []net.IP, stopChan chan struct{}) error {
|
||||||
hwAddr, err := net.ParseMAC(zone.Mac)
|
hwAddr, err := net.ParseMAC(zone.Mac)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return err
|
return err
|
||||||
|
@ -111,7 +111,7 @@ func sendARP(ps pcap.PCapScanner, zone *ocdm.Zone, hostRanges []net.IP, stopChan
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePacketARP(zone *ocdm.Zone, hostRanges []net.IP, hosts map[string]*ocdm.Host, packet *layers.ARP) *ocdm.Host {
|
func handlePacketARP(zone *ocmd.Zone, hostRanges []net.IP, hosts map[string]*ocmd.Host, packet *layers.ARP) *ocmd.Host {
|
||||||
if packet.Operation != layers.ARPReply {
|
if packet.Operation != layers.ARPReply {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func handlePacketARP(zone *ocdm.Zone, hostRanges []net.IP, hosts map[string]*ocd
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &ocdm.Host{}
|
h := &ocmd.Host{}
|
||||||
h.IP = ip.String()
|
h.IP = ip.String()
|
||||||
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
|
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
|
||||||
h.Zone = zone
|
h.Zone = zone
|
||||||
|
@ -142,7 +142,7 @@ func handlePacketARP(zone *ocdm.Zone, hostRanges []net.IP, hosts map[string]*ocd
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTargetHostRange(dh *ocdm.DiscoveryHost, cr cidr.CIDRRanger) ([]net.IP, error) {
|
func getTargetHostRange(dh *ocmd.DiscoveryHost, cr cidr.CIDRRanger) ([]net.IP, error) {
|
||||||
var firstIP net.IP
|
var firstIP net.IP
|
||||||
if "" != dh.FirstScanRange {
|
if "" != dh.FirstScanRange {
|
||||||
firstIP = net.ParseIP(dh.FirstScanRange)
|
firstIP = net.ParseIP(dh.FirstScanRange)
|
||||||
|
|
|
@ -3,10 +3,10 @@ package ipv4
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanPort(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
func ScanPort(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
if dp.IncludeTCP {
|
if dp.IncludeTCP {
|
||||||
|
|
|
@ -10,14 +10,14 @@ import (
|
||||||
|
|
||||||
"git.loafle.net/commons/logging-go"
|
"git.loafle.net/commons/logging-go"
|
||||||
occc "git.loafle.net/overflow/commons-go/core/constants"
|
occc "git.loafle.net/overflow/commons-go/core/constants"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/pcap"
|
"git.loafle.net/overflow/container_discovery/internal/pcap"
|
||||||
|
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanPortTCP(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
|
func scanPortTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
|
||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -37,7 +37,7 @@ func scanPortTCP(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interf
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ports := make(map[int]*ocdm.Port)
|
ports := make(map[int]*ocmd.Port)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -70,7 +70,7 @@ func scanPortTCP(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendTCP(host *ocdm.Host, dp *ocdm.DiscoveryPort, stopChan chan struct{}) error {
|
func sendTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, stopChan chan struct{}) error {
|
||||||
tcpPacket, err := makePacketPortTCP(host)
|
tcpPacket, err := makePacketPortTCP(host)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return err
|
return err
|
||||||
|
@ -112,7 +112,7 @@ Loop:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePacketTCP(host *ocdm.Host, dp *ocdm.DiscoveryPort, ports map[int]*ocdm.Port, packet *layers.TCP) *ocdm.Port {
|
func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoveryPort, ports map[int]*ocmd.Port, packet *layers.TCP) *ocmd.Port {
|
||||||
if nil == packet || packet.DstPort != 60000 {
|
if nil == packet || packet.DstPort != 60000 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func handlePacketTCP(host *ocdm.Host, dp *ocdm.DiscoveryPort, ports map[int]*ocd
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &ocdm.Port{
|
p := &ocmd.Port{
|
||||||
PortType: occc.PortTypeTCP,
|
PortType: occc.PortTypeTCP,
|
||||||
PortNumber: json.Number(strconv.Itoa(port)),
|
PortNumber: json.Number(strconv.Itoa(port)),
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ type PortPacketTCP struct {
|
||||||
PacketConn net.PacketConn
|
PacketConn net.PacketConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func makePacketPortTCP(host *ocdm.Host) (*PortPacketTCP, error) {
|
func makePacketPortTCP(host *ocmd.Host) (*PortPacketTCP, error) {
|
||||||
packetTCP := &PortPacketTCP{}
|
packetTCP := &PortPacketTCP{}
|
||||||
|
|
||||||
srcIP := net.ParseIP(host.Zone.IP)
|
srcIP := net.ParseIP(host.Zone.IP)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"git.loafle.net/commons/logging-go"
|
"git.loafle.net/commons/logging-go"
|
||||||
occc "git.loafle.net/overflow/commons-go/core/constants"
|
occc "git.loafle.net/overflow/commons-go/core/constants"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/pcap"
|
"git.loafle.net/overflow/container_discovery/internal/pcap"
|
||||||
|
|
||||||
"git.loafle.net/overflow/container_discovery/internal/matcher"
|
"git.loafle.net/overflow/container_discovery/internal/matcher"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanPortUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
|
func scanPortUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}, wg *sync.WaitGroup) {
|
||||||
defer func() {
|
defer func() {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
@ -38,7 +38,7 @@ func scanPortUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interf
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ports := make(map[int]*ocdm.Port)
|
ports := make(map[int]*ocmd.Port)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -71,7 +71,7 @@ func scanPortUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, stopChan chan struct{}) error {
|
func sendUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, stopChan chan struct{}) error {
|
||||||
ip := net.ParseIP(host.IP)
|
ip := net.ParseIP(host.IP)
|
||||||
if nil == ip {
|
if nil == ip {
|
||||||
return fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP)
|
return fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP)
|
||||||
|
@ -125,7 +125,7 @@ func sendUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, stopChan chan struct{}) er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePacketUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, ports map[int]*ocdm.Port, packet gopacket.Packet) *ocdm.Port {
|
func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoveryPort, ports map[int]*ocmd.Port, packet gopacket.Packet) *ocmd.Port {
|
||||||
ipLayer := packet.Layer(layers.LayerTypeIPv4)
|
ipLayer := packet.Layer(layers.LayerTypeIPv4)
|
||||||
|
|
||||||
if ipLayer.(*layers.IPv4).SrcIP.String() == host.Zone.IP {
|
if ipLayer.(*layers.IPv4).SrcIP.String() == host.Zone.IP {
|
||||||
|
@ -143,7 +143,7 @@ func handlePacketUDP(host *ocdm.Host, dp *ocdm.DiscoveryPort, ports map[int]*ocd
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &ocdm.Port{
|
p := &ocmd.Port{
|
||||||
PortType: occc.PortTypeUDP,
|
PortType: occc.PortTypeUDP,
|
||||||
PortNumber: json.Number(strconv.Itoa(port)),
|
PortNumber: json.Number(strconv.Itoa(port)),
|
||||||
UDPLayer: udpLayer,
|
UDPLayer: udpLayer,
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
|
|
||||||
cuej "git.loafle.net/commons/util-go/encoding/json"
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
||||||
occc "git.loafle.net/overflow/commons-go/core/constants"
|
occc "git.loafle.net/overflow/commons-go/core/constants"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanService(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
func ScanService(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
||||||
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
||||||
|
@ -22,7 +22,7 @@ func ScanService(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan int
|
||||||
|
|
||||||
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
|
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
|
||||||
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
||||||
s := &ocdm.Service{
|
s := &ocmd.Service{
|
||||||
ServiceName: sName,
|
ServiceName: sName,
|
||||||
}
|
}
|
||||||
s.Port = port
|
s.Port = port
|
||||||
|
@ -34,7 +34,7 @@ func ScanService(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan int
|
||||||
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
|
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
|
||||||
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
|
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
|
||||||
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
|
||||||
s := &ocdm.Service{
|
s := &ocmd.Service{
|
||||||
ServiceName: sName,
|
ServiceName: sName,
|
||||||
}
|
}
|
||||||
s.Port = port
|
s.Port = port
|
||||||
|
|
|
@ -8,11 +8,11 @@ import (
|
||||||
csm "git.loafle.net/commons/service_matcher-go"
|
csm "git.loafle.net/commons/service_matcher-go"
|
||||||
cuej "git.loafle.net/commons/util-go/encoding/json"
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
||||||
occc "git.loafle.net/overflow/commons-go/core/constants"
|
occc "git.loafle.net/overflow/commons-go/core/constants"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/matcher"
|
"git.loafle.net/overflow/container_discovery/internal/matcher"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanServiceTCP(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
func scanServiceTCP(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
||||||
|
|
||||||
hostIP := port.Host.IP
|
hostIP := port.Host.IP
|
||||||
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
||||||
|
@ -22,7 +22,7 @@ func scanServiceTCP(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan
|
||||||
}
|
}
|
||||||
|
|
||||||
info := csm.NewMatchInfo(hostIP, portNumber)
|
info := csm.NewMatchInfo(hostIP, portNumber)
|
||||||
var s *ocdm.Service
|
var s *ocmd.Service
|
||||||
|
|
||||||
scs := []serviceConnector{
|
scs := []serviceConnector{
|
||||||
&normalServiceConn{
|
&normalServiceConn{
|
||||||
|
@ -74,7 +74,7 @@ func scanServiceTCP(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func hadlePrePacket(info csm.MatchInfo, sc serviceConnector, conn net.Conn, packet *csm.Packet) *ocdm.Service {
|
func hadlePrePacket(info csm.MatchInfo, sc serviceConnector, conn net.Conn, packet *csm.Packet) *ocmd.Service {
|
||||||
defer func() {
|
defer func() {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}()
|
}()
|
||||||
|
@ -84,7 +84,7 @@ func hadlePrePacket(info csm.MatchInfo, sc serviceConnector, conn net.Conn, pack
|
||||||
|
|
||||||
ms := matcher.GetTCPMatchers(true)
|
ms := matcher.GetTCPMatchers(true)
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
var s *ocdm.Service
|
var s *ocmd.Service
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
for i := 0; i < len(ms); i++ {
|
for i := 0; i < len(ms); i++ {
|
||||||
|
@ -94,7 +94,7 @@ Loop:
|
||||||
packetCount := m.PacketCount()
|
packetCount := m.PacketCount()
|
||||||
|
|
||||||
if 0 == packetCount {
|
if 0 == packetCount {
|
||||||
s = &ocdm.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.Type()),
|
CryptoType: occc.ToCryptoType(sc.Type()),
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ Loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
s = &ocdm.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.Type()),
|
CryptoType: occc.ToCryptoType(sc.Type()),
|
||||||
}
|
}
|
||||||
|
@ -148,10 +148,10 @@ Loop:
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func hadlePostPacket(info csm.MatchInfo, sc serviceConnector) *ocdm.Service {
|
func hadlePostPacket(info csm.MatchInfo, sc serviceConnector) *ocmd.Service {
|
||||||
ms := matcher.GetTCPMatchers(false)
|
ms := matcher.GetTCPMatchers(false)
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
var s *ocdm.Service
|
var s *ocmd.Service
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
for i := 0; i < len(ms); i++ {
|
for i := 0; i < len(ms); i++ {
|
||||||
|
@ -181,7 +181,7 @@ Loop:
|
||||||
rn, err := conn.Read(buf)
|
rn, err := conn.Read(buf)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
if !m.HasResponse(j) {
|
if !m.HasResponse(j) {
|
||||||
s = &ocdm.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.Type()),
|
CryptoType: occc.ToCryptoType(sc.Type()),
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ Loop:
|
||||||
|
|
||||||
if m.Match(info, j, csm.NewPacket(buf, rn)) {
|
if m.Match(info, j, csm.NewPacket(buf, rn)) {
|
||||||
if packetCount-1 == j {
|
if packetCount-1 == j {
|
||||||
s = &ocdm.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.Type()),
|
CryptoType: occc.ToCryptoType(sc.Type()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
|
|
||||||
csm "git.loafle.net/commons/service_matcher-go"
|
csm "git.loafle.net/commons/service_matcher-go"
|
||||||
cuej "git.loafle.net/commons/util-go/encoding/json"
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/matcher"
|
"git.loafle.net/overflow/container_discovery/internal/matcher"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanServiceUDP(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
|
||||||
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
portNumber, err := cuej.NumberToInt(port.PortNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
|
||||||
|
@ -24,7 +24,7 @@ func scanServiceUDP(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan
|
||||||
p := csm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
|
p := csm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
|
||||||
|
|
||||||
if m.Match(mi, 0, p) {
|
if m.Match(mi, 0, p) {
|
||||||
s := &ocdm.Service{
|
s := &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
}
|
}
|
||||||
s.Port = port
|
s.Port = port
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package ipv6
|
package ipv6
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanHost(zone *ocdm.Zone, dh *ocdm.DiscoveryHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoveryHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package ipv6
|
package ipv6
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanPort(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
func ScanPort(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package ipv6
|
package ipv6
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanService(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
func ScanService(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanPort(host *ocdm.Host, dp *ocdm.DiscoveryPort, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
func scanPort(host *ocmd.Host, dp *ocmd.DiscoveryPort, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
||||||
defer func() {
|
defer func() {
|
||||||
doneChan <- struct{}{}
|
doneChan <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv4"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer/ipv6"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanService(port *ocdm.Port, ds *ocdm.DiscoveryService, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
func scanService(port *ocmd.Port, ds *ocmd.DiscoveryService, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
||||||
defer func() {
|
defer func() {
|
||||||
doneChan <- struct{}{}
|
doneChan <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -5,10 +5,10 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
func scanZone(dz *ocdm.DiscoveryZone, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
func scanZone(dz *ocmd.DiscoveryZone, resultChan chan interface{}, errChan chan error, doneChan chan<- struct{}, stopChan chan struct{}) {
|
||||||
defer func() {
|
defer func() {
|
||||||
doneChan <- struct{}{}
|
doneChan <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
@ -52,7 +52,7 @@ func scanZone(dz *ocdm.DiscoveryZone, resultChan chan interface{}, errChan chan
|
||||||
|
|
||||||
zones = append(zones, ipnet)
|
zones = append(zones, ipnet)
|
||||||
|
|
||||||
z := &ocdm.Zone{
|
z := &ocmd.Zone{
|
||||||
Network: ipnet.String(),
|
Network: ipnet.String(),
|
||||||
Iface: i.Name,
|
Iface: i.Name,
|
||||||
Mac: i.HardwareAddr.String(),
|
Mac: i.HardwareAddr.String(),
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mtx sync.Mutex
|
var mtx sync.Mutex
|
||||||
|
@ -14,7 +14,7 @@ func init() {
|
||||||
instances = make(map[string]PCapScanner, 0)
|
instances = make(map[string]PCapScanner, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RetainScanner(zone *ocdm.Zone) (PCapScanner, error) {
|
func RetainScanner(zone *ocmd.Zone) (PCapScanner, error) {
|
||||||
mtx.Lock()
|
mtx.Lock()
|
||||||
defer mtx.Unlock()
|
defer mtx.Unlock()
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func RetainScanner(zone *ocdm.Zone) (PCapScanner, error) {
|
||||||
return ps, nil
|
return ps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReleaseScanner(zone *ocdm.Zone) {
|
func ReleaseScanner(zone *ocmd.Zone) {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
|
|
@ -5,13 +5,13 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"github.com/google/gopacket"
|
"github.com/google/gopacket"
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
"github.com/google/gopacket/pcap"
|
"github.com/google/gopacket/pcap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newPCapScanner(zone *ocdm.Zone) PCapScanner {
|
func newPCapScanner(zone *ocmd.Zone) PCapScanner {
|
||||||
ps := &pCapScan{
|
ps := &pCapScan{
|
||||||
zone: zone,
|
zone: zone,
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ type PCapScanner interface {
|
||||||
|
|
||||||
type pCapScan struct {
|
type pCapScan struct {
|
||||||
pCapHandle *pcap.Handle
|
pCapHandle *pcap.Handle
|
||||||
zone *ocdm.Zone
|
zone *ocmd.Zone
|
||||||
|
|
||||||
arpListenerChanMtx sync.RWMutex
|
arpListenerChanMtx sync.RWMutex
|
||||||
arpListenerChans []chan *layers.ARP
|
arpListenerChans []chan *layers.ARP
|
||||||
|
|
6
main.go
6
main.go
|
@ -10,7 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.loafle.net/commons/logging-go"
|
"git.loafle.net/commons/logging-go"
|
||||||
ocpcc "git.loafle.net/overflow/commons-go/probe/constants"
|
occp "git.loafle.net/overflow/commons-go/config/probe"
|
||||||
"git.loafle.net/overflow/container_discovery/server"
|
"git.loafle.net/overflow/container_discovery/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pidFilePath = flag.String(ocpcc.FlagPidFilePathName, "./dist/discovery.pid", "PID file path")
|
pidFilePath = flag.String(occp.FlagPidFilePathName, "./dist/discovery.pid", "PID file path")
|
||||||
loggingConfigFilePath := flag.String(ocpcc.FlagLoggingConfigFilePathName, "", "logging config path")
|
loggingConfigFilePath := flag.String(occp.FlagLoggingConfigFilePathName, "", "logging config path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logging.InitializeLogger(*loggingConfigFilePath)
|
logging.InitializeLogger(*loggingConfigFilePath)
|
||||||
|
|
|
@ -9,7 +9,8 @@ import (
|
||||||
|
|
||||||
cda "git.loafle.net/commons/di-go/annotation"
|
cda "git.loafle.net/commons/di-go/annotation"
|
||||||
cdr "git.loafle.net/commons/di-go/registry"
|
cdr "git.loafle.net/commons/di-go/registry"
|
||||||
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
|
ocscd "git.loafle.net/overflow/commons-go/service/container/discovery"
|
||||||
ocs "git.loafle.net/overflow/container-go/service"
|
ocs "git.loafle.net/overflow/container-go/service"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer"
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiscoveryService struct {
|
type DiscoveryService struct {
|
||||||
|
ocscd.DiscoveryService
|
||||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||||||
|
|
||||||
ProbeService *ocs.ProbeService `annotation:"@Inject()"`
|
ProbeService *ocs.ProbeService `annotation:"@Inject()"`
|
||||||
|
@ -50,7 +52,7 @@ func (s *DiscoveryService) DestroyService() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocdm.DiscoveryZone) error {
|
func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocmd.DiscoveryZone) error {
|
||||||
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
||||||
s.discoverer.DiscoverZone(dataChan, dz)
|
s.discoverer.DiscoverZone(dataChan, dz)
|
||||||
})
|
})
|
||||||
|
@ -58,7 +60,7 @@ func (s *DiscoveryService) DiscoverZone(requesterID string, dz *ocdm.DiscoveryZo
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocdm.Zone, dh *ocdm.DiscoveryHost) error {
|
func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocmd.Zone, dh *ocmd.DiscoveryHost) error {
|
||||||
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
||||||
s.discoverer.DiscoverHost(dataChan, zone, dh)
|
s.discoverer.DiscoverHost(dataChan, zone, dh)
|
||||||
})
|
})
|
||||||
|
@ -66,7 +68,7 @@ func (s *DiscoveryService) DiscoverHost(requesterID string, zone *ocdm.Zone, dh
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocdm.Host, dp *ocdm.DiscoveryPort) error {
|
func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocmd.Host, dp *ocmd.DiscoveryPort) error {
|
||||||
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
||||||
s.discoverer.DiscoverPort(dataChan, host, dp)
|
s.discoverer.DiscoverPort(dataChan, host, dp)
|
||||||
})
|
})
|
||||||
|
@ -74,7 +76,7 @@ func (s *DiscoveryService) DiscoverPort(requesterID string, host *ocdm.Host, dp
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocdm.Port, ds *ocdm.DiscoveryService) error {
|
func (s *DiscoveryService) DiscoverService(requesterID string, port *ocmd.Port, ds *ocmd.DiscoveryService) error {
|
||||||
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
go s.handleDiscovery(requesterID, func(dataChan chan *discoverer.DiscoveryData) {
|
||||||
s.discoverer.DiscoverSerice(dataChan, port, ds)
|
s.discoverer.DiscoverSerice(dataChan, port, ds)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user