ing
This commit is contained in:
parent
51bf633ee8
commit
60e5f1c7c3
|
@ -109,7 +109,7 @@ func sendUDP4(discoverySession session.DiscoverySession, ps pcap.PCapScanner, ho
|
|||
addr := &net.UDPAddr{IP: ip.To4(), Port: portNumber}
|
||||
for i := 0; i < _matcher.PacketCount(); i++ {
|
||||
p := _matcher.Packet(i)
|
||||
if _, err := conn.WriteToUDP(p.Buffer, addr); err != nil {
|
||||
if _, err := conn.WriteToUDP(p.Bytes(), addr); err != nil {
|
||||
log.Print("UDP write error", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ func (ds *ofDiscoverySession) AddHost(host *omd.Host) *omd.Host {
|
|||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
h, modified := ds.findHost(host, true)
|
||||
h, modified := ds.findHost(host)
|
||||
|
||||
if "" == h.Mac && "" != host.Mac {
|
||||
h.Mac = host.Mac
|
||||
|
@ -229,7 +229,7 @@ func (ds *ofDiscoverySession) AddPort(port *omd.Port) *omd.Port {
|
|||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
p, modified := ds.findPort(port, true)
|
||||
p, modified := ds.findPort(port)
|
||||
|
||||
meta, metaModified := ds.appendMeta(p.Meta, port.Meta)
|
||||
if metaModified {
|
||||
|
@ -248,7 +248,7 @@ func (ds *ofDiscoverySession) AddService(service *omd.Service) *omd.Service {
|
|||
ds.discoveredMtx.Lock()
|
||||
defer ds.discoveredMtx.Unlock()
|
||||
|
||||
s, modified := ds.findService(service, true)
|
||||
s, modified := ds.findService(service)
|
||||
|
||||
meta, metaModified := ds.appendMeta(s.Meta, service.Meta)
|
||||
if metaModified {
|
||||
|
@ -286,7 +286,7 @@ func (ds *ofDiscoverySession) DiscoveredPort(host *omd.Host, portNumber int) map
|
|||
ds.discoveredMtx.RLock()
|
||||
defer ds.discoveredMtx.RUnlock()
|
||||
|
||||
h, _ := ds.findHost(host, false)
|
||||
h, _ := ds.findHost(host)
|
||||
if nil == h {
|
||||
return nil
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ func (ds *ofDiscoverySession) DiscoveredService(port *omd.Port, name string) map
|
|||
ds.discoveredMtx.RLock()
|
||||
defer ds.discoveredMtx.RUnlock()
|
||||
|
||||
p, _ := ds.findPort(port, false)
|
||||
p, _ := ds.findPort(port)
|
||||
if nil == p {
|
||||
return nil
|
||||
}
|
||||
|
@ -334,15 +334,12 @@ func (ds *ofDiscoverySession) DiscoveredAllServices() map[*omd.Port]map[string]m
|
|||
return ds.services
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) findHost(host *omd.Host, add bool) (h *omd.Host, modified bool) {
|
||||
func (ds *ofDiscoverySession) findHost(host *omd.Host) (h *omd.Host, modified bool) {
|
||||
modified = false
|
||||
var ok bool
|
||||
|
||||
h, ok = ds.hosts[host.Address]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
ds.hosts[host.Address] = host
|
||||
if "" != host.Mac {
|
||||
ds.includeMachosts[host.Address] = host
|
||||
|
@ -354,41 +351,29 @@ func (ds *ofDiscoverySession) findHost(host *omd.Host, add bool) (h *omd.Host, m
|
|||
return
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) findPort(port *omd.Port, add bool) (p *omd.Port, modified bool) {
|
||||
func (ds *ofDiscoverySession) findPort(port *omd.Port) (p *omd.Port, modified bool) {
|
||||
modified = false
|
||||
var ok bool
|
||||
|
||||
h, _ := ds.findHost(port.Host, false)
|
||||
h, _ := ds.findHost(port.Host)
|
||||
if nil == h {
|
||||
return
|
||||
}
|
||||
|
||||
hostPorts, ok := ds.ports[h]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
|
||||
ds.ports[h] = make(map[json.Number]map[string]*omd.Port)
|
||||
hostPorts = ds.ports[h]
|
||||
}
|
||||
|
||||
ports, ok := hostPorts[port.PortNumber]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
|
||||
hostPorts[port.PortNumber] = make(map[string]*omd.Port)
|
||||
ports = hostPorts[port.PortNumber]
|
||||
}
|
||||
|
||||
p, ok = ports[port.MetaPortType.Key]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
|
||||
ports[port.MetaPortType.Key] = port
|
||||
p = ports[port.MetaPortType.Key]
|
||||
modified = true
|
||||
|
@ -397,41 +382,29 @@ func (ds *ofDiscoverySession) findPort(port *omd.Port, add bool) (p *omd.Port, m
|
|||
return
|
||||
}
|
||||
|
||||
func (ds *ofDiscoverySession) findService(service *omd.Service, add bool) (s *omd.Service, modified bool) {
|
||||
func (ds *ofDiscoverySession) findService(service *omd.Service) (s *omd.Service, modified bool) {
|
||||
modified = false
|
||||
var ok bool
|
||||
|
||||
p, _ := ds.findPort(service.Port, false)
|
||||
p, _ := ds.findPort(service.Port)
|
||||
if nil == p {
|
||||
return
|
||||
}
|
||||
|
||||
portServices, ok := ds.services[p]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
|
||||
ds.services[p] = make(map[string]map[string]*omd.Service)
|
||||
portServices = ds.services[p]
|
||||
}
|
||||
|
||||
services, ok := portServices[service.Key]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
|
||||
portServices[service.Key] = make(map[string]*omd.Service)
|
||||
services = portServices[service.Key]
|
||||
}
|
||||
|
||||
s, ok = services[service.MetaCryptoType.Key]
|
||||
if !ok {
|
||||
if !add {
|
||||
return
|
||||
}
|
||||
|
||||
services[service.MetaCryptoType.Key] = service
|
||||
s = services[service.MetaCryptoType.Key]
|
||||
modified = true
|
||||
|
|
|
@ -2,6 +2,7 @@ package service
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
|
@ -64,7 +65,7 @@ LOOP:
|
|||
|
||||
if nil != discoveredMatcher {
|
||||
// log.Printf("discovered matcher: %s(%s) %v", discoveredMatcher.Name(), discoveredMatcher.Key(), discoveredMatcher)
|
||||
discoverySession.AddService(&omd.Service{
|
||||
s := discoverySession.AddService(&omd.Service{
|
||||
MetaCryptoType: discoveredConnector.metaCryptoType(),
|
||||
Key: discoveredMatcher.Key(),
|
||||
Name: discoveredMatcher.Name(),
|
||||
|
@ -72,6 +73,7 @@ LOOP:
|
|||
DiscoveredDate: omu.NowPtr(),
|
||||
Port: targetPort,
|
||||
})
|
||||
log.Print("Discovered Service: ", s, " \n Port: ", s.Port, " \n Host: ", s.Port.Host)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -105,7 +107,7 @@ LOOP:
|
|||
if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err {
|
||||
return nil
|
||||
}
|
||||
_, err := conn.Write(_packet.Buffer)
|
||||
_, err := conn.Write(_packet.Bytes())
|
||||
if nil != err {
|
||||
return nil
|
||||
}
|
||||
|
@ -162,7 +164,7 @@ LOOP:
|
|||
if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err {
|
||||
break INNER_LOOP
|
||||
}
|
||||
_, err := conn.Write(_packet.Buffer)
|
||||
_, err := conn.Write(_packet.Bytes())
|
||||
if nil != err {
|
||||
break INNER_LOOP
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ func processPrepacket(ch chan *Res, conn net.Conn, m csm.Matcher) {
|
|||
n, _ := conn.Read(bytes)
|
||||
p := csm.NewPacket(bytes, n)
|
||||
|
||||
_, err := conn.Write(m.Packet(i).Buffer)
|
||||
_, err := conn.Write(m.Packet(i).Bytes())
|
||||
if err != nil {
|
||||
ch <- &Res{nil, err}
|
||||
close(ch)
|
||||
|
@ -57,7 +57,7 @@ func processPrepacket(ch chan *Res, conn net.Conn, m csm.Matcher) {
|
|||
|
||||
func processPostpacket(ch chan *Res, conn net.Conn, m csm.Matcher) {
|
||||
for i := 0; i < m.PacketCount(); i++ {
|
||||
_, err := conn.Write(m.Packet(i).Buffer)
|
||||
_, err := conn.Write(m.Packet(i).Bytes())
|
||||
if err != nil {
|
||||
ch <- &Res{nil, err}
|
||||
close(ch)
|
||||
|
|
Loading…
Reference in New Issue
Block a user