mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
fix: 一些包合法性判断上的错误
This commit is contained in:
@@ -29,16 +29,20 @@ type ICMPTracer struct {
|
||||
}
|
||||
|
||||
func (t *ICMPTracer) PrintFunc() {
|
||||
// defer t.wg.Done()
|
||||
defer t.wg.Done()
|
||||
var ttl = 0
|
||||
for {
|
||||
if t.AsyncPrinter != nil {
|
||||
t.AsyncPrinter(&t.res)
|
||||
}
|
||||
if t.RealtimePrinter != nil {
|
||||
// 接收的时候检查一下是不是 3 跳都齐了
|
||||
if len(t.res.Hops)-1 > ttl {
|
||||
if len(t.res.Hops[ttl]) == t.NumMeasurements {
|
||||
t.RealtimePrinter(&t.res, ttl)
|
||||
ttl++
|
||||
if ttl == t.final {
|
||||
|
||||
if ttl == t.final-1 || ttl >= t.MaxHops-1 {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -50,6 +54,7 @@ func (t *ICMPTracer) PrintFunc() {
|
||||
|
||||
func (t *ICMPTracer) Execute() (*Result, error) {
|
||||
t.inflightRequest = make(map[int]chan Hop)
|
||||
|
||||
if len(t.res.Hops) > 0 {
|
||||
return &t.res, ErrTracerouteExecuted
|
||||
}
|
||||
@@ -68,6 +73,7 @@ func (t *ICMPTracer) Execute() (*Result, error) {
|
||||
t.final = -1
|
||||
|
||||
go t.listenICMP()
|
||||
t.wg.Add(1)
|
||||
go t.PrintFunc()
|
||||
for ttl := t.BeginHop; ttl <= t.MaxHops; ttl++ {
|
||||
t.inflightRequestLock.Lock()
|
||||
@@ -81,15 +87,14 @@ func (t *ICMPTracer) Execute() (*Result, error) {
|
||||
go t.send(ttl)
|
||||
}
|
||||
<-time.After(time.Millisecond * 100)
|
||||
if t.AsyncPrinter != nil {
|
||||
t.AsyncPrinter(&t.res)
|
||||
}
|
||||
}
|
||||
|
||||
t.wg.Wait()
|
||||
t.res.reduce(t.final)
|
||||
if t.final != -1 {
|
||||
t.RealtimePrinter(&t.res, t.final-1)
|
||||
if t.RealtimePrinter != nil {
|
||||
t.RealtimePrinter(&t.res, t.final-1)
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < t.NumMeasurements; i++ {
|
||||
t.res.add(Hop{
|
||||
@@ -100,7 +105,9 @@ func (t *ICMPTracer) Execute() (*Result, error) {
|
||||
Error: ErrHopLimitTimeout,
|
||||
})
|
||||
}
|
||||
t.RealtimePrinter(&t.res, t.MaxHops-1)
|
||||
if t.RealtimePrinter != nil {
|
||||
t.RealtimePrinter(&t.res, t.MaxHops-1)
|
||||
}
|
||||
}
|
||||
return &t.res, nil
|
||||
}
|
||||
@@ -293,7 +300,6 @@ func (t *ICMPTracer) send(ttl int) error {
|
||||
h.fetchIPData(t.Config)
|
||||
|
||||
t.res.add(h)
|
||||
|
||||
case <-time.After(t.Timeout):
|
||||
if t.final != -1 && ttl > t.final {
|
||||
return nil
|
||||
|
||||
@@ -135,7 +135,7 @@ func (t *ICMPTracerv6) listenICMP() {
|
||||
if msg.N == nil {
|
||||
continue
|
||||
}
|
||||
if msg.Msg[129] == 0 {
|
||||
if msg.Msg[0] == 129 {
|
||||
rm, err := icmp.ParseMessage(58, msg.Msg[:*msg.N])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -161,7 +161,7 @@ func (t *ICMPTracerv6) listenICMP() {
|
||||
if process_id == int64(os.Getpid()&0x7f) {
|
||||
dstip := net.IP(msg.Msg[32:48])
|
||||
// 无效包本地环回包
|
||||
if dstip.String() != "::" {
|
||||
if dstip.String() == "::" {
|
||||
continue
|
||||
}
|
||||
if dstip.Equal(t.DestIP) || dstip.Equal(net.IPv6zero) {
|
||||
|
||||
Reference in New Issue
Block a user