I was confused if ICMP is a network layer protocol why does it send transport layer fields in its error reporting messages.
ICMP is a protocol working in the Network Layer. Why does it send few fields of the transport layer while reporting an error?
Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you can post and accept your own answer.– Ron Maupin ♦Dec 17, 2020 at 17:39
Because it is his very purpose.
ICMP was specifically created and designed to do so.
Occasionally a gateway or destination host will communicate with a source host, for example, to report an error in datagram processing. For such purposes this protocol, the Internet Control Message Protocol (ICMP), is used.
ICMP messages are sent in several situations: for example, when a datagram cannot reach its destination, when the gateway does not have the buffering capacity to forward a datagram, and when the gateway can direct the host to send traffic on a shorter route.
The ICMP messages typically report errors in the processing of
Also remember that the layered model is juts that, a model, there's many things that cross layer boundaries.
ICMP errors will return part of the packet that caused the error. This is to provide information about which connection caused the error. If I simply return "time exceeded" with no context, the originator will (a) not know who I am -- being a random transit router, and (b) not have any clue which connection is in error. If I include the IP header in the error, then the originator can tell which connection caused it. (i.e. "my packet to X failed at Y for reason Z")