This commit is contained in:
crusader 2018-09-28 16:13:45 +09:00
parent 94609b4366
commit d50a6608c0
4 changed files with 72 additions and 29 deletions

View File

@ -28,11 +28,18 @@ import (
// ZONE_MAC = "d0:7e:35:da:26:68"
// )
// const (
// ZONE_NETWORK = "192.168.35"
// ZONE_IFACE = "\\Device\\NPF_{51459A06-A513-4202-9D79-93A4E394566A}"
// ZONE_ADDRESS = "179"
// ZONE_MAC = "08:00:27:f0:dc:35"
// )
const (
ZONE_NETWORK = "192.168.35"
ZONE_IFACE = "\\Device\\NPF_{51459A06-A513-4202-9D79-93A4E394566A}"
ZONE_ADDRESS = "179"
ZONE_MAC = "08:00:27:f0:dc:35"
ZONE_NETWORK = "192.168.1"
ZONE_IFACE = "\\Device\\NPF_{9A232FAC-6AA4-48CE-AAC8-878ABFBFDA5D}"
ZONE_ADDRESS = "221"
ZONE_MAC = "54-04-A6-38-BE-DA"
)
func Zone() *omd.Zone {

View File

@ -162,6 +162,7 @@ LOOP:
s := session.RetainDiscoverySession()
d.processingSessions.Store(req.RequestID(), s)
d.discover(req, s)
log.Print("Discover complete")
select {
case <-time.After(time.Millisecond * 500):
}
@ -171,6 +172,7 @@ LOOP:
d.processingSessions.Delete(req.RequestID())
s.Shutdown()
}
log.Print("Discovery Session Shutdowm")
select {
case <-time.After(time.Millisecond * 500):
@ -178,8 +180,8 @@ LOOP:
session.ReleaseDiscoverySession(s)
req.(*ofDiscoveryRequest).release()
log.Print("Discovery complete")
log.Print("Discovery Session complete")
case <-d.stopChan:
return
}
@ -285,19 +287,27 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
case *omd.Host:
d.SendMessage(s.DiscoveryRequest(), types.DiscoveryMessageTypeHost, target)
if nil != s.DiscoverPort() {
h := target.(*omd.Host)
wg.Add(1)
go func() {
defer wg.Done()
port.Scan(s, target.(*omd.Host))
defer func() {
wg.Done()
}()
port.Scan(s, h)
}()
}
case *omd.Port:
d.SendMessage(s.DiscoveryRequest(), types.DiscoveryMessageTypePort, target)
if nil != s.DiscoverService() {
p := target.(*omd.Port)
wg.Add(1)
go func() {
defer wg.Done()
service.Scan(s, target.(*omd.Port))
defer func() {
wg.Done()
}()
service.Scan(s, p)
}()
}
case *omd.Service:
@ -341,14 +351,18 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
if nil != s.DiscoverHost() {
wg.Add(1)
go func() {
defer wg.Done()
defer func() {
wg.Done()
}()
host.Scan(s)
}()
} else if nil != s.DiscoverPort() {
if nil != s.Host() {
wg.Add(1)
go func() {
defer wg.Done()
defer func() {
wg.Done()
}()
port.Scan(s, s.Host())
}()
}
@ -356,7 +370,9 @@ func (d *ofDiscoverer) hierarchyDiscover(s session.DiscoverySession) {
if nil != s.Port() {
wg.Add(1)
go func() {
defer wg.Done()
defer func() {
wg.Done()
}()
service.Scan(s, s.Port())
}()
}

View File

@ -27,17 +27,24 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
ps.CloseTCP(targetHost.Address, tcpChan)
}()
timerStopped := make(chan struct{})
timerStopped := make(chan struct{}, 0)
stopChan := make(chan struct{})
defer close(stopChan)
go func() {
defer func() {
close(timerStopped)
log.Print("timer close:", targetHost.Address)
}()
ports := make(map[int]*omd.Port)
var delay atomic.Value
delay.Store(false)
ticker := time.NewTicker(time.Millisecond * 1000)
defer ticker.Stop()
ticker := time.NewTicker(time.Millisecond * 3000)
defer func() {
ticker.Stop()
log.Print("ticker stop:", targetHost.Address)
}()
for {
select {
@ -51,8 +58,6 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
}
case <-ticker.C:
if false == delay.Load().(bool) {
log.Print("SYN Timeout IP ", targetHost.Address)
timerStopped <- struct{}{}
return
}
delay.Store(false)
@ -64,9 +69,11 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
log.Printf("sendTCP %v", err)
return nil
}
log.Print("sendTCP4 Complete:", targetHost.Address)
select {
case <-timerStopped:
log.Print("timerStopped:", targetHost.Address)
return nil
case <-discoverySession.StopChan():
return nil
@ -105,9 +112,10 @@ Loop:
}
select {
case <-time.After(time.Microsecond * 100):
// case <-time.After(time.Microsecond * 10):
case <-stopChan:
return nil
default:
}
}
@ -121,8 +129,6 @@ func handlePacketTCP4(discoverySession session.DiscoverySession, host *omd.Host,
dp := discoverySession.DiscoverPort()
log.Print("SYN HandlePacket IP ", host.Address)
if packet.SYN && packet.ACK {
port := int(packet.SrcPort)

View File

@ -21,13 +21,8 @@ func TestPing(t *testing.T) {
// )
targetHost := __test.Host(
"",
"179",
"08-00-27-F0-DC-35",
)
targetPort := __test.Port(
targetHost,
139,
"1",
"00:11:32:7f:20:61",
)
type args struct {
@ -44,12 +39,31 @@ func TestPing(t *testing.T) {
name: "UNKNOWN",
args: args{
service: __test.Service(
targetPort,
__test.Port(
targetHost,
548,
),
omm.MetaCryptoTypeEnumNONE,
"",
),
pingOption: &ounp.PingOption{
Count: 3,
Count: 5,
},
},
},
{
name: "HTTP",
args: args{
service: __test.Service(
__test.Port(
targetHost,
5000,
),
omm.MetaCryptoTypeEnumNONE,
"HTTP",
),
pingOption: &ounp.PingOption{
Count: 5,
},
},
},