ICMP, Ping and Traceroute
In questa pagina 5
IPv4 (IPv4 Datagram and FragmentationIPv4 is a connectionless, unreliable best-effort service; the header is 20 to 60 bytes (HLen counts 4-byte words), TTL limits hops, Protocol identifies the payload (1 ICMP, 6 TCP, 17 UDP) and the checksum covers only the header; a datagram larger than the link MTU is fragmented (only the payload is split, offsets are in units of 8 bytes, MF is 1 in all fragments but the last) and reassembled only at the destination.IPv4 Datagram and Fragmentation →) has no mechanism to report or correct errors and none to query hosts and routers. ICMP (Internet Control Message Protocol) fills both gaps; it is itself a network-layer protocol (Network Layer and IPv4 AddressingThe network layer delivers datagrams host to host through routers (encapsulation, routing, forwarding); an IPv4 address is 32 bits split into a network prefix and a host suffix, and modern classless addressing (CIDR) gives a block of 2^(32-n) addresses from a.b.c.d/n, with network and broadcast addresses computed through the netmask.Network Layer and IPv4 Addressing →). Its messages are encapsulated in IP datagrams with Protocol .
Two categories
- Error-reporting messages: report problems a router or the destination host finds when processing an IP packet. Always sent to the original source, since the datagram carries only source and destination IPs. ICMP does not correct errors, it only reports them.
- Query messages (request and reply): let a host obtain information from a router or another host: liveness and round-trip time (RTT).
Rules to avoid error storms: no ICMP error in response to an ICMP message, to a non-first fragment, to a multicast datagram, or to a datagram with a special address (such as ).
| category | message | type (codes) |
|---|---|---|
| error | destination unreachable | 3 (0-15) |
| error | time exceeded | 11 (0-1) |
| error | redirect | 5 |
| error | parameter problem | 12 (0-1) |
| query | echo request / reply | 8 / 0 |
| query | timestamp request / reply | 13 / 14 |
Content of error messages: the IP header of the offending datagram plus the first 8 bytes of its data (which contain the port numbers and sequence number, so TCP or UDP can be told). Format: type, code, checksum, 16 unused bits, then header and 64 bits of data.
Error messages
Destination unreachable (type 3), codes 0 to 15. Main ones: 0 network unreachable; 1 host unreachable; 2 protocol unreachable; 3 port unreachable; 4 fragmentation needed but D bit set (the message then carries the next-hop MTU); 5 source route failed; 6/7 destination network/host unknown; 9/10 network/host administratively prohibited; 13 communication administratively prohibited (a filter blocks forwarding).
Time exceeded (type 11): code 0 generated by a router when TTL reaches 0; code 1 generated by the destination when fragments are missing after the reassembly timer expires.
Parameter problem (type 12): code 0 malformed header field (a pointer indicates the field); code 1 unknown option or operation impossible. Example: first byte : version 4 is correct but HLen means bytes, impossible, so the packet is dropped.
Redirect (type 5): routers update routing information continuously, hosts do not take part in routing. If host sends to through but now should forward to on the same network as , then sends a redirect so updates its table (Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →).
Query messages
Echo request (8) and reply (0) check whether a node is alive. Fields: identifier (chosen by the sender and copied back), sequence number (starts at 0, +1 per message), optional data (copied back).
Formula (ICMP checksum). As for IP: one's complement of the one's complement sum of the 16-bit words, with the checksum field set to 0.
Example. Echo request type 8, code 0, identifier , sequence , data "ab" . Words : ; ; (no carry). Checksum . Receiver check: .
Ping for RTT. ping sends echo requests with increasing sequence number and writes the send time in the data; on reply it subtracts it from the arrival time to get the RTT, and shows TTL, RTT and losses.
Ping for path MTU discovery. Send a message with the D bit set; if an ICMP destination unreachable code 4 comes back, reduce the size and retry. When delivered, the MTU is the current size (ping -D -s 1500 host; -s = data bytes, default 56, plus 8 bytes of ICMP header).
Step by step. Source MTU 1500, a link on the path has MTU 1400. (1) Echo with data bytes: datagram bytes with D set. (2) The router before the narrow link can neither forward () nor fragment: it drops it and sends code 4 with next-hop MTU . (3) The source recomputes data bytes and resends: it passes, path MTU . Expected maximum on Ethernet: ICMP bytes, data bytes; default ICMP bytes, IP bytes.
Traceroute
traceroute discovers the path and measures it using time exceeded and destination unreachable. Probes are UDP datagrams to a port deliberately unavailable at the destination, so they never reach its application. With routers in the path it sends probes:
- TTL : the first router drops it and sends time exceeded; its IP is the source of that error, which reveals the router.
- TTL : reveals the second router, and so on.
- When a probe reaches the destination (TTL still ), the destination answers destination unreachable code 3 (port not found): the search ends.
With TTL the packet dies exactly at the -th router, which reveals itself. Traceroute usually sends three probes per TTL value ( packets) to get three RTTs per hop. The time shown for a hop is the RTT to that router, not the delay of that link alone. If no reply comes within 5 s an asterisk is printed (* * *).
Attacks with ICMP
- Smurf: an echo request is sent to the broadcast address of a network with the source address spoofed to the victim's; all hosts reply to the victim, which is flooded (denial of service).
- Redirect: a forged redirect makes the victim use a malicious router as gateway, letting the attacker read or modify the data.
Versione ripasso
- ICMP reports errors and answers queries for IP; messages travel in IP datagrams with Protocol (IPv4 Datagram and FragmentationIPv4 is a connectionless, unreliable best-effort service; the header is 20 to 60 bytes (HLen counts 4-byte words), TTL limits hops, Protocol identifies the payload (1 ICMP, 6 TCP, 17 UDP) and the checksum covers only the header; a datagram larger than the link MTU is fragmented (only the payload is split, offsets are in units of 8 bytes, MF is 1 in all fragments but the last) and reassembled only at the destination.IPv4 Datagram and Fragmentation →). It reports only, never corrects. Errors go to the original source and carry the original IP header + 8 bytes of data. No ICMP errors for ICMP messages, non-first fragments, multicast, special addresses.
- Types: 3 destination unreachable (codes 0-15: 0 net, 1 host, 2 protocol, 3 port, 4 fragmentation needed with D set, 13 filtered), 11 time exceeded (0 TTL, 1 reassembly timeout), 5 redirect, 12 parameter problem, 8/0 echo request/reply, 13/14 timestamp.
- Redirect: the router tells the host a better next hop on the same network (Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →).
- Checksum like IP. Echo example: words sum , checksum .
- Ping: echo request/reply, RTT from the timestamp in the data. Path MTU: send with D set; code 4 returns next-hop MTU. Ethernet maximum data bytes; MTU 1400 gives .
- Traceroute: UDP probes to an unused port with TTL ; each router replies time exceeded (reveals its IP); the destination replies port unreachable (code 3) and ends the search. packets with three probes per hop.
- Attacks: smurf (echo to broadcast, spoofed source = victim), forged redirect.
- Typical errors: thinking ICMP fixes errors; forgetting the 8 bytes of ICMP header in the MTU computation.
Teoria collegata
- Internet Structure, Packet Switching and the TCP-IP Stack
- Network Key Performance Indicators
- Emulating Networks with Katharà
- Firewalls
- Forwarding and Routing Tables
- IPv4 Datagram and Fragmentation
- NAT and Private Addresses
- Network Layer and IPv4 Addressing
- Network Security - Threats and Attacks
- Static Routing and Diagnostic Tools in Katharà
- UDP - User Datagram Protocol