From d760e758100bba67de24703e0d18b2f708d76d7e Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Fri, 20 Oct 2023 00:46:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=20bug:=20=E5=BD=93=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E5=88=B0=E7=94=B1=E8=87=AA=E8=BA=AB=E5=8F=91=E5=87=BA=E7=9A=84?= =?UTF-8?q?DestinationUnreachable=E5=8C=85=E6=97=B6=E8=A7=86=E4=B8=BA?= =?UTF-8?q?=E6=9C=89=E6=95=88=E4=BF=A1=E6=81=AF=EF=BC=8C=E6=AD=A4=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E7=94=B1=20@XQZR=20=E6=8F=90=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trace/icmp_ipv4.go | 9 +++++++++ trace/icmp_ipv6.go | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/trace/icmp_ipv4.go b/trace/icmp_ipv4.go index 7e1b86e..6e9a44a 100644 --- a/trace/icmp_ipv4.go +++ b/trace/icmp_ipv4.go @@ -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() diff --git a/trace/icmp_ipv6.go b/trace/icmp_ipv6.go index 82cac1e..b0a5ea4 100644 --- a/trace/icmp_ipv6.go +++ b/trace/icmp_ipv6.go @@ -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()