fix bug: 当接收到由自身发出的DestinationUnreachable包时视为有效信息,此增强由 @XQZR 提出。

This commit is contained in:
tsosunchia
2023-10-20 00:46:58 +08:00
parent 99409089b2
commit d760e75810
2 changed files with 16 additions and 0 deletions

View File

@@ -164,6 +164,9 @@ func (t *ICMPTracer) listenICMP() {
t.handleICMPMessage(msg, 0, rm.Body.(*icmp.TimeExceeded).Data, int(ttl))
case ipv4.ICMPTypeEchoReply:
t.handleICMPMessage(msg, 1, rm.Body.(*icmp.Echo).Data, int(ttl))
//unreachable
case ipv4.ICMPTypeDestinationUnreachable:
t.handleICMPMessage(msg, 2, rm.Body.(*icmp.DstUnreach).Data, int(ttl))
default:
// log.Println("received icmp message of unknown type", rm.Type)
}
@@ -176,6 +179,12 @@ func (t *ICMPTracer) listenICMP() {
}
func (t *ICMPTracer) handleICMPMessage(msg ReceivedMessage, icmpType int8, data []byte, ttl int) {
if icmpType == 2 {
if t.DestIP.String() != msg.Peer.String() {
return
}
}
t.inflightRequestRWLock.RLock()
defer t.inflightRequestRWLock.RUnlock()

View File

@@ -189,6 +189,8 @@ func (t *ICMPTracerv6) listenICMP() {
t.handleICMPMessage(msg, 0, rm.Body.(*icmp.TimeExceeded).Data, int(ttl))
case ipv6.ICMPTypeEchoReply:
t.handleICMPMessage(msg, 1, rm.Body.(*icmp.Echo).Data, int(ttl))
case ipv6.ICMPTypeDestinationUnreachable:
t.handleICMPMessage(msg, 2, rm.Body.(*icmp.DstUnreach).Data, int(ttl))
default:
// log.Println("received icmp message of unknown type", rm.Type)
}
@@ -232,6 +234,11 @@ func (t *ICMPTracerv6) listenICMP() {
}
func (t *ICMPTracerv6) handleICMPMessage(msg ReceivedMessage, icmpType int8, data []byte, ttl int) {
if icmpType == 2 {
if t.DestIP.String() != msg.Peer.String() {
return
}
}
t.inflightRequestRWLock.RLock()
defer t.inflightRequestRWLock.RUnlock()