ing
This commit is contained in:
parent
e107b6b207
commit
d178262d08
|
@ -25,7 +25,6 @@ type DiscoveryData struct {
|
||||||
Type DiscoveryDataType
|
Type DiscoveryDataType
|
||||||
Result interface{}
|
Result interface{}
|
||||||
Error error
|
Error error
|
||||||
Time util.Timestamp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dd *DiscoveryData) Release() {
|
func (dd *DiscoveryData) Release() {
|
||||||
|
@ -276,7 +275,6 @@ func retainDiscoveryData(discoveryDataType DiscoveryDataType, t util.Timestamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
discoveryData.Type = discoveryDataType
|
discoveryData.Type = discoveryDataType
|
||||||
discoveryData.Time = t
|
|
||||||
discoveryData.Result = result
|
discoveryData.Result = result
|
||||||
discoveryData.Error = err
|
discoveryData.Error = err
|
||||||
|
|
||||||
|
@ -287,7 +285,6 @@ func releaseDiscoveryData(discoveryData *DiscoveryData) {
|
||||||
discoveryData.Type = DiscoveryDataTypeNone
|
discoveryData.Type = DiscoveryDataTypeNone
|
||||||
discoveryData.Result = nil
|
discoveryData.Result = nil
|
||||||
discoveryData.Error = nil
|
discoveryData.Error = nil
|
||||||
discoveryData.Time = util.Timestamp{}
|
|
||||||
|
|
||||||
discoveryDataPool.Put(discoveryData)
|
discoveryDataPool.Put(discoveryData)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
logging "git.loafle.net/commons/logging-go"
|
logging "git.loafle.net/commons/logging-go"
|
||||||
occc "git.loafle.net/overflow/commons-go/core/constants"
|
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"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"git.loafle.net/overflow/container_discovery/internal/discoverer"
|
"git.loafle.net/overflow/container_discovery/internal/discoverer"
|
||||||
)
|
)
|
||||||
|
@ -41,9 +42,10 @@ var (
|
||||||
IncludeUDP: true,
|
IncludeUDP: true,
|
||||||
}
|
}
|
||||||
p = &ocmd.Port{
|
p = &ocmd.Port{
|
||||||
Host: h,
|
Host: h,
|
||||||
PortType: occc.PortTypeTCP,
|
PortType: occc.PortTypeTCP,
|
||||||
PortNumber: json.Number(strconv.Itoa(80)),
|
PortNumber: json.Number(strconv.Itoa(80)),
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
ds = &ocmd.DiscoverService{
|
ds = &ocmd.DiscoverService{
|
||||||
IncludeServices: []string{
|
IncludeServices: []string{
|
||||||
|
|
|
@ -8,11 +8,11 @@ import (
|
||||||
|
|
||||||
"git.loafle.net/commons/logging-go"
|
"git.loafle.net/commons/logging-go"
|
||||||
"git.loafle.net/commons/util-go/net/cidr"
|
"git.loafle.net/commons/util-go/net/cidr"
|
||||||
"github.com/google/gopacket"
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
"github.com/google/gopacket/layers"
|
|
||||||
|
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
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/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &ocmd.Host{}
|
h := &ocmd.Host{
|
||||||
h.IPV4 = ip.String()
|
IPV4: ip.String(),
|
||||||
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String()
|
Mac: net.HardwareAddr(packet.SourceHwAddress).String(),
|
||||||
h.Zone = zone
|
Zone: zone,
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
|
}
|
||||||
|
|
||||||
hosts[ip.String()] = h
|
hosts[ip.String()] = h
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,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"
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
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"
|
||||||
|
|
||||||
|
@ -140,8 +141,9 @@ func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &ocmd.Port{
|
p := &ocmd.Port{
|
||||||
PortType: occc.PortTypeTCP,
|
PortType: occc.PortTypeTCP,
|
||||||
PortNumber: json.Number(strconv.Itoa(port)),
|
PortNumber: json.Number(strconv.Itoa(port)),
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
p.Host = host
|
p.Host = host
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,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"
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
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"
|
||||||
|
|
||||||
|
@ -156,9 +157,10 @@ func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &ocmd.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,
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
p.Host = host
|
p.Host = host
|
||||||
ports[port] = p
|
ports[port] = p
|
||||||
|
|
|
@ -5,6 +5,7 @@ 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"
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
"github.com/google/gopacket/layers"
|
"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 {
|
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 := &ocmd.Service{
|
s := &ocmd.Service{
|
||||||
ServiceName: sName,
|
ServiceName: sName,
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
|
Port: port,
|
||||||
}
|
}
|
||||||
s.Port = port
|
|
||||||
resultChan <- s
|
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 {
|
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 := &ocmd.Service{
|
s := &ocmd.Service{
|
||||||
ServiceName: sName,
|
ServiceName: sName,
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
|
Port: port,
|
||||||
}
|
}
|
||||||
s.Port = port
|
|
||||||
resultChan <- s
|
resultChan <- s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ 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"
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
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"
|
||||||
)
|
)
|
||||||
|
@ -102,8 +103,9 @@ LOOP:
|
||||||
|
|
||||||
if 0 == packetCount {
|
if 0 == packetCount {
|
||||||
s = &ocmd.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
break LOOP
|
break LOOP
|
||||||
}
|
}
|
||||||
|
@ -153,8 +155,9 @@ LOOP:
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
s = &ocmd.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
break LOOP
|
break LOOP
|
||||||
}
|
}
|
||||||
|
@ -210,8 +213,9 @@ LOOP:
|
||||||
if nil != err {
|
if nil != err {
|
||||||
if !m.HasResponse(j) {
|
if !m.HasResponse(j) {
|
||||||
s = &ocmd.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -223,8 +227,9 @@ 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 = &ocmd.Service{
|
s = &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
CryptoType: occc.ToCryptoType(sc.CryptoType()),
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ 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"
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
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"
|
||||||
)
|
)
|
||||||
|
@ -25,9 +26,11 @@ func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan i
|
||||||
|
|
||||||
if m.Match(mi, 0, p) {
|
if m.Match(mi, 0, p) {
|
||||||
s := &ocmd.Service{
|
s := &ocmd.Service{
|
||||||
ServiceName: m.Name(),
|
ServiceName: m.Name(),
|
||||||
|
Port: port,
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
s.Port = port
|
|
||||||
resultChan <- s
|
resultChan <- s
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
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)
|
zones = append(zones, ipnet)
|
||||||
|
|
||||||
z := &ocmd.Zone{
|
z := &ocmd.Zone{
|
||||||
Network: ipnet.String(),
|
Network: ipnet.String(),
|
||||||
Iface: i.Name,
|
Iface: i.Name,
|
||||||
Mac: i.HardwareAddr.String(),
|
Mac: i.HardwareAddr.String(),
|
||||||
IPV4: strings.Split(addr.String(), "/")[0],
|
IPV4: strings.Split(addr.String(), "/")[0],
|
||||||
|
DiscoveredDate: occu.NowPtr(),
|
||||||
}
|
}
|
||||||
|
|
||||||
resultChan <- z
|
resultChan <- z
|
||||||
|
|
|
@ -9,6 +9,7 @@ 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"
|
||||||
|
occu "git.loafle.net/overflow/commons-go/core/util"
|
||||||
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
|
||||||
ocscd "git.loafle.net/overflow/commons-go/service/container/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"
|
||||||
|
@ -131,10 +132,10 @@ func (s *DiscoveryService) handleDiscovery(requesterID string, discoveryFunc fun
|
||||||
switch data.Type {
|
switch data.Type {
|
||||||
case discoverer.DiscoveryDataTypeStart:
|
case discoverer.DiscoveryDataTypeStart:
|
||||||
logging.Logger().Debugf("DiscoveryService.DiscoveryStart")
|
logging.Logger().Debugf("DiscoveryService.DiscoveryStart")
|
||||||
s.ProbeService.Send("DiscoveryService.DiscoveryStart", requesterID, data.Time)
|
s.ProbeService.Send("DiscoveryService.DiscoveryStart", requesterID, occu.Now())
|
||||||
case discoverer.DiscoveryDataTypeStop:
|
case discoverer.DiscoveryDataTypeStop:
|
||||||
logging.Logger().Debugf("DiscoveryService.DiscoveryStop")
|
logging.Logger().Debugf("DiscoveryService.DiscoveryStop")
|
||||||
s.ProbeService.Send("DiscoveryService.DiscoveryStop", requesterID, data.Time)
|
s.ProbeService.Send("DiscoveryService.DiscoveryStop", requesterID, occu.Now())
|
||||||
data.Release()
|
data.Release()
|
||||||
return nil
|
return nil
|
||||||
case discoverer.DiscoveryDataTypeError:
|
case discoverer.DiscoveryDataTypeError:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user