ing
This commit is contained in:
		
							parent
							
								
									e107b6b207
								
							
						
					
					
						commit
						d178262d08
					
				@ -25,7 +25,6 @@ type DiscoveryData struct {
 | 
			
		||||
	Type   DiscoveryDataType
 | 
			
		||||
	Result interface{}
 | 
			
		||||
	Error  error
 | 
			
		||||
	Time   util.Timestamp
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (dd *DiscoveryData) Release() {
 | 
			
		||||
@ -276,7 +275,6 @@ func retainDiscoveryData(discoveryDataType DiscoveryDataType, t util.Timestamp,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	discoveryData.Type = discoveryDataType
 | 
			
		||||
	discoveryData.Time = t
 | 
			
		||||
	discoveryData.Result = result
 | 
			
		||||
	discoveryData.Error = err
 | 
			
		||||
 | 
			
		||||
@ -287,7 +285,6 @@ func releaseDiscoveryData(discoveryData *DiscoveryData) {
 | 
			
		||||
	discoveryData.Type = DiscoveryDataTypeNone
 | 
			
		||||
	discoveryData.Result = nil
 | 
			
		||||
	discoveryData.Error = nil
 | 
			
		||||
	discoveryData.Time = util.Timestamp{}
 | 
			
		||||
 | 
			
		||||
	discoveryDataPool.Put(discoveryData)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	logging "git.loafle.net/commons/logging-go"
 | 
			
		||||
	occc "git.loafle.net/overflow/commons-go/core/constants"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
	"git.loafle.net/overflow/container_discovery/internal/discoverer"
 | 
			
		||||
)
 | 
			
		||||
@ -41,9 +42,10 @@ var (
 | 
			
		||||
		IncludeUDP: true,
 | 
			
		||||
	}
 | 
			
		||||
	p = &ocmd.Port{
 | 
			
		||||
		Host:       h,
 | 
			
		||||
		PortType:   occc.PortTypeTCP,
 | 
			
		||||
		PortNumber: json.Number(strconv.Itoa(80)),
 | 
			
		||||
		Host:           h,
 | 
			
		||||
		PortType:       occc.PortTypeTCP,
 | 
			
		||||
		PortNumber:     json.Number(strconv.Itoa(80)),
 | 
			
		||||
		DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
	}
 | 
			
		||||
	ds = &ocmd.DiscoverService{
 | 
			
		||||
		IncludeServices: []string{
 | 
			
		||||
 | 
			
		||||
@ -8,11 +8,11 @@ import (
 | 
			
		||||
 | 
			
		||||
	"git.loafle.net/commons/logging-go"
 | 
			
		||||
	"git.loafle.net/commons/util-go/net/cidr"
 | 
			
		||||
	"github.com/google/gopacket"
 | 
			
		||||
	"github.com/google/gopacket/layers"
 | 
			
		||||
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	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 ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
 | 
			
		||||
@ -145,10 +145,12 @@ func handlePacketARP(zone *ocmd.Zone, hostRanges []net.IP, hosts map[string]*ocm
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	h := &ocmd.Host{}
 | 
			
		||||
	h.IPV4 = ip.String()
 | 
			
		||||
	h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
 | 
			
		||||
	h.Zone = zone
 | 
			
		||||
	h := &ocmd.Host{
 | 
			
		||||
		IPV4:           ip.String(),
 | 
			
		||||
		Mac:            net.HardwareAddr(packet.SourceHwAddress).String(),
 | 
			
		||||
		Zone:           zone,
 | 
			
		||||
		DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	hosts[ip.String()] = h
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	"git.loafle.net/commons/logging-go"
 | 
			
		||||
	occc "git.loafle.net/overflow/commons-go/core/constants"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
	"git.loafle.net/overflow/container_discovery/internal/pcap"
 | 
			
		||||
 | 
			
		||||
@ -140,8 +141,9 @@ func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	p := &ocmd.Port{
 | 
			
		||||
		PortType:   occc.PortTypeTCP,
 | 
			
		||||
		PortNumber: json.Number(strconv.Itoa(port)),
 | 
			
		||||
		PortType:       occc.PortTypeTCP,
 | 
			
		||||
		PortNumber:     json.Number(strconv.Itoa(port)),
 | 
			
		||||
		DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
	}
 | 
			
		||||
	p.Host = host
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	"git.loafle.net/commons/logging-go"
 | 
			
		||||
	occc "git.loafle.net/overflow/commons-go/core/constants"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
	"git.loafle.net/overflow/container_discovery/internal/pcap"
 | 
			
		||||
 | 
			
		||||
@ -156,9 +157,10 @@ func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		p := &ocmd.Port{
 | 
			
		||||
			PortType:   occc.PortTypeUDP,
 | 
			
		||||
			PortNumber: json.Number(strconv.Itoa(port)),
 | 
			
		||||
			UDPLayer:   udpLayer,
 | 
			
		||||
			PortType:       occc.PortTypeUDP,
 | 
			
		||||
			PortNumber:     json.Number(strconv.Itoa(port)),
 | 
			
		||||
			UDPLayer:       udpLayer,
 | 
			
		||||
			DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
		}
 | 
			
		||||
		p.Host = host
 | 
			
		||||
		ports[port] = p
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	cuej "git.loafle.net/commons/util-go/encoding/json"
 | 
			
		||||
	occc "git.loafle.net/overflow/commons-go/core/constants"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
	"github.com/google/gopacket/layers"
 | 
			
		||||
)
 | 
			
		||||
@ -23,9 +24,10 @@ func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan inte
 | 
			
		||||
			if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
 | 
			
		||||
				sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
 | 
			
		||||
				s := &ocmd.Service{
 | 
			
		||||
					ServiceName: sName,
 | 
			
		||||
					ServiceName:    sName,
 | 
			
		||||
					DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
					Port:           port,
 | 
			
		||||
				}
 | 
			
		||||
				s.Port = port
 | 
			
		||||
				resultChan <- s
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -35,9 +37,10 @@ func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan inte
 | 
			
		||||
			if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
 | 
			
		||||
				sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
 | 
			
		||||
				s := &ocmd.Service{
 | 
			
		||||
					ServiceName: sName,
 | 
			
		||||
					ServiceName:    sName,
 | 
			
		||||
					DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
					Port:           port,
 | 
			
		||||
				}
 | 
			
		||||
				s.Port = port
 | 
			
		||||
				resultChan <- s
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ 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"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
	"git.loafle.net/overflow/container_discovery/internal/matcher"
 | 
			
		||||
)
 | 
			
		||||
@ -102,8 +103,9 @@ LOOP:
 | 
			
		||||
 | 
			
		||||
			if 0 == packetCount {
 | 
			
		||||
				s = &ocmd.Service{
 | 
			
		||||
					ServiceName: m.Name(),
 | 
			
		||||
					CryptoType:  occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
					ServiceName:    m.Name(),
 | 
			
		||||
					CryptoType:     occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
					DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
				}
 | 
			
		||||
				break LOOP
 | 
			
		||||
			}
 | 
			
		||||
@ -153,8 +155,9 @@ LOOP:
 | 
			
		||||
 | 
			
		||||
			if found {
 | 
			
		||||
				s = &ocmd.Service{
 | 
			
		||||
					ServiceName: m.Name(),
 | 
			
		||||
					CryptoType:  occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
					ServiceName:    m.Name(),
 | 
			
		||||
					CryptoType:     occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
					DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
				}
 | 
			
		||||
				break LOOP
 | 
			
		||||
			}
 | 
			
		||||
@ -210,8 +213,9 @@ LOOP:
 | 
			
		||||
			if nil != err {
 | 
			
		||||
				if !m.HasResponse(j) {
 | 
			
		||||
					s = &ocmd.Service{
 | 
			
		||||
						ServiceName: m.Name(),
 | 
			
		||||
						CryptoType:  occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
						ServiceName:    m.Name(),
 | 
			
		||||
						CryptoType:     occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
						DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
					}
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
@ -223,8 +227,9 @@ LOOP:
 | 
			
		||||
			if m.Match(info, j, csm.NewPacket(buf, rn)) {
 | 
			
		||||
				if packetCount-1 == j {
 | 
			
		||||
					s = &ocmd.Service{
 | 
			
		||||
						ServiceName: m.Name(),
 | 
			
		||||
						CryptoType:  occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
						ServiceName:    m.Name(),
 | 
			
		||||
						CryptoType:     occc.ToCryptoType(sc.CryptoType()),
 | 
			
		||||
						DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
					}
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	csm "git.loafle.net/commons/service_matcher-go"
 | 
			
		||||
	cuej "git.loafle.net/commons/util-go/encoding/json"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
	"git.loafle.net/overflow/container_discovery/internal/matcher"
 | 
			
		||||
)
 | 
			
		||||
@ -25,9 +26,11 @@ func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan i
 | 
			
		||||
 | 
			
		||||
		if m.Match(mi, 0, p) {
 | 
			
		||||
			s := &ocmd.Service{
 | 
			
		||||
				ServiceName: m.Name(),
 | 
			
		||||
				ServiceName:    m.Name(),
 | 
			
		||||
				Port:           port,
 | 
			
		||||
				DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
			}
 | 
			
		||||
			s.Port = port
 | 
			
		||||
 | 
			
		||||
			resultChan <- s
 | 
			
		||||
			return true
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ import (
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	ocmd "git.loafle.net/overflow/commons-go/model/discovery"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -53,10 +54,11 @@ func scanZone(dz *ocmd.DiscoverZone, resultChan chan interface{}, errChan chan e
 | 
			
		||||
			zones = append(zones, ipnet)
 | 
			
		||||
 | 
			
		||||
			z := &ocmd.Zone{
 | 
			
		||||
				Network: ipnet.String(),
 | 
			
		||||
				Iface:   i.Name,
 | 
			
		||||
				Mac:     i.HardwareAddr.String(),
 | 
			
		||||
				IPV4:    strings.Split(addr.String(), "/")[0],
 | 
			
		||||
				Network:        ipnet.String(),
 | 
			
		||||
				Iface:          i.Name,
 | 
			
		||||
				Mac:            i.HardwareAddr.String(),
 | 
			
		||||
				IPV4:           strings.Split(addr.String(), "/")[0],
 | 
			
		||||
				DiscoveredDate: occu.NowPtr(),
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			resultChan <- z
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	cda "git.loafle.net/commons/di-go/annotation"
 | 
			
		||||
	cdr "git.loafle.net/commons/di-go/registry"
 | 
			
		||||
	occu "git.loafle.net/overflow/commons-go/core/util"
 | 
			
		||||
	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"
 | 
			
		||||
@ -131,10 +132,10 @@ func (s *DiscoveryService) handleDiscovery(requesterID string, discoveryFunc fun
 | 
			
		||||
			switch data.Type {
 | 
			
		||||
			case discoverer.DiscoveryDataTypeStart:
 | 
			
		||||
				logging.Logger().Debugf("DiscoveryService.DiscoveryStart")
 | 
			
		||||
				s.ProbeService.Send("DiscoveryService.DiscoveryStart", requesterID, data.Time)
 | 
			
		||||
				s.ProbeService.Send("DiscoveryService.DiscoveryStart", requesterID, occu.Now())
 | 
			
		||||
			case discoverer.DiscoveryDataTypeStop:
 | 
			
		||||
				logging.Logger().Debugf("DiscoveryService.DiscoveryStop")
 | 
			
		||||
				s.ProbeService.Send("DiscoveryService.DiscoveryStop", requesterID, data.Time)
 | 
			
		||||
				s.ProbeService.Send("DiscoveryService.DiscoveryStop", requesterID, occu.Now())
 | 
			
		||||
				data.Release()
 | 
			
		||||
				return nil
 | 
			
		||||
			case discoverer.DiscoveryDataTypeError:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user