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