implementationwikipediaicmptracerouteicmpv6

Why does traceroute expect "Destination Unreachable" at the final hop instead of "Echo Reply" when it runs over UDP?


Excerpt from implementation section of Wikipedia page for traceroute:

. . . until the destination is reached and returns an ICMP Destination Unreachable message if UDP packets are being used or an ICMP Echo Reply message if ICMP Echo messages are being used.

It says that at the final hop traceroute is expecting ICMP "Destination Unreachable" when it I was expecting it to use an ICMP "Echo Reply".

I saw the history of the page and it was changed by a person named 'Guy Harris'. He says:

. . . If you use UDP packets, as traceroute does by default, the final hop returns ICMP Destination Unreachable (unless you're unlucky enough to have send a UDP packet to a port with a listener), not ICMP Echo Reply.

Can somebody please throw some light to this?


Solution

  • Because traceroute needs to get message when the UDP datagram has reached the destination.

    Traceroute works as follow:

    1. Sends a UDP datagram with TTL as 1 to the destination host.The router reads the datagram, decrement the TTL and sends back an ICMP time exceeded message.
    2. Traceroute receives the above message and sends another UDP datagram with TTL as 2. Routers on internet read this datagram, each decrement the TTL, and finally sends back the ICMP time exceeded message.
    3. The above steps continue and finally, with TTL as N, the UDP datagram has reached the destination host. Then, what should the host return? It cannot send back ICMP time exceeded message as before -- TTL is not exceeded.

    Traceroute design to send the UDP datagram to a port of host, and it is almost impossible that the port is listened (33435 for example). The destination host receives the UDP datagram, finds the datagram's target port is not listened, and then return "Destination Unreachable" message -- more accurately, "Port Unreachable".

    That's why traceroute expect a "Destination Unreachable" message at the final hop to determine that the UDP datagram has already reached the destination.

    BTW, if the target port is accidentally listened on destination host, that's just the scenario described by Guy Harris: "unless you're unlucky enough to have send a UDP packet to a port with a listener"