📡 Internet Control Message Protocol (ICMP)

 Comprehensive Study Guide for ECE 422 - Data Communication & Computer Networks

🎯 1. Introduction to ICMP

Definition: ICMP (Internet Control Message Protocol) is a network layer protocol used by network devices to send error messages and operational information, indicating success or failure when communicating with another IP address.

1.1 Purpose and Role

ICMP serves as the diagnostic and error reporting system of the Internet Protocol suite. While IP is responsible for delivering packets to their destination, ICMP handles the communication about problems that occur during delivery.

Key functions of ICMP include:

  • Error Reporting: Notifying the source host when a packet cannot be delivered
  • Diagnostic Testing: Enabling network troubleshooting through echo requests/replies
  • Flow Control: Indicating network congestion or time exceeded conditions
  • Route Redirection: Advising better routing paths to hosts

1.2 ICMP in the TCP/IP Stack

ICMP operates at the Network Layer (Layer 3) of the OSI model, alongside IP. Unlike TCP and UDP, ICMP is not used to transport application data. Instead, it is used by network administrators and operating systems to check network connectivity and diagnose problems.

Important Note: ICMP messages are encapsulated within IP datagrams (Protocol Number = 1 for ICMPv4, 58 for ICMPv6). However, ICMP itself is considered a separate protocol from IP, not a transport layer protocol.

1.3 ICMPv4 vs ICMPv6

Feature ICMPv4 ICMPv6
Protocol Number 1 58
ARP Functionality Handled by separate ARP protocol Integrated into ICMPv6 (Neighbor Discovery)
IGMP Functionality Separate IGMP protocol Integrated into ICMPv6 (Multicast Listener Discovery)
Checksum Calculation Includes ICMP header and data Includes pseudo-header from IPv6

🏗️ 2. ICMP Architecture

2.1 Protocol Positioning

ICMP is an integral part of the Internet Protocol suite. The architectural relationship can be understood as follows:

TCP/IP Protocol Stack
Application
HTTP, FTP, SMTP, DNS, SSH
Transport
TCP, UDP, SCTP
Internet
IP, ICMP, ARP, IGMP
Link
Ethernet, Wi-Fi, PPP
Physical
Cables, Radio, Fiber

2.2 ICMP Message Categories

ICMP messages are broadly classified into two categories:

🔴 Error Messages

Report problems with IP packet processing:

  • Destination Unreachable
  • Time Exceeded
  • Parameter Problem

Never sent in response to ICMP error messages (to prevent storms)

🟢 Query (Informational) Messages

Request and provide network information:

  • Echo Request/Reply (Ping)
  • Timestamp Request/Reply
  • Address Mask Request/Reply

Can be sent in response to other query messages

2.3 Message Processing Rules

Critical Rule: ICMP error messages are never generated for:
  1. ICMP error messages themselves
  2. IP packets with broadcast or multicast destination addresses
  3. IP packets with source address 0.0.0.0 or loopback
  4. Fragments other than the first fragment

📦 3. ICMP Packet Format

3.1 General ICMP Header Structure

All ICMP messages follow a common header format, followed by type-specific data:

ICMP Header Format (8 bytes minimum)
Bits 0-7
Type
// Identifies the ICMP message type
Bits 8-15
Code
// Provides additional context for the type
Bits 16-31
Checksum
// Error detection for ICMP message
Bits 32-63
Rest of Header
// Type-specific content
Variable
Data Section
// Payload (often includes original packet)

3.2 Field Descriptions

Field Size Description
Type 8 bits Identifies the ICMP message type (e.g., 0 = Echo Reply, 8 = Echo Request)
Code 8 bits Sub-type identifier providing additional information about the message
Checksum 16 bits Internet checksum covering the ICMP message (header + data)
Rest of Header 32 bits Content varies by type (e.g., Identifier, Sequence Number for Echo)
Data Variable Additional data; for errors, typically includes IP header + 8 bytes of original data

3.3 Checksum Calculation

Checksum = ~(Sum of all 16-bit words in ICMP message)
If result is 0, checksum is 0xFFFF

The checksum is calculated as the 16-bit one's complement of the one's complement sum of the ICMP message (header and data). For ICMPv6, a pseudo-header from the IPv6 header is included in the calculation.

3.4 Echo Request/Reply Format (Ping)

Echo Request/Reply Message Format
Type (0 or 8)
0 = Echo Reply, 8 = Echo Request
Code (0)
Always 0 for Echo
Checksum
16-bit checksum
Identifier
16-bit ID (usually process ID)
Sequence Number
16-bit sequence (increments per packet)
Optional Data
Timestamp and padding data

📋 4. ICMP Message Types

4.1 Common ICMP Types and Codes

Type Name Code Meaning
0 Echo Reply 0 Response to Echo Request (Ping reply)
3 Destination Unreachable 0-15 Various reasons (Network, Host, Port unreachable, etc.)
5 Redirect 0-3 Router advising better route
8 Echo Request 0 Request for echo (Ping request)
11 Time Exceeded 0-1 TTL expired in transit (0) or during reassembly (1)
12 Parameter Problem 0-2 IP header parameter error
13/14 Timestamp Req/Rep 0 Request and reply for timestamp

4.2 Destination Unreachable (Type 3)

The most common error message, indicating that a packet could not be delivered to its destination:

Code Description Common Cause
0 Network Unreachable No route to destination network
1 Host Unreachable Destination host down or unreachable
2 Protocol Unreachable Protocol not supported on destination
3 Port Unreachable No application listening on port (common for UDP)
4 Fragmentation Needed Packet too large, DF bit set (Path MTU Discovery)
5 Source Route Failed Source routing cannot be completed

4.3 Time Exceeded (Type 11)

⏱️ TTL Expired in Transit (Code 0)

Generated when a router decrements the TTL (Time To Live) field of an IP packet to zero and must discard the packet. This prevents packets from circulating indefinitely in routing loops.

Usage: Traceroute utility sends packets with increasing TTL values to discover the route path.

🧩 Fragment Reassembly Time Exceeded (Code 1)

Generated when the destination host cannot reassemble all fragments of a packet within the time limit (typically 60-120 seconds).

Usage: Indicates network congestion or missing fragments in fragmented packet transmission.

4.4 Redirect Messages (Type 5)

Routers send ICMP Redirect messages to hosts to inform them of a better route to a particular destination:

  • Code 0: Redirect for Network
  • Code 1: Redirect for Host
  • Code 2: Redirect for Type of Service and Network
  • Code 3: Redirect for Type of Service and Host
Security Note: ICMP Redirects can be exploited for man-in-the-middle attacks. Modern operating systems often ignore or disable ICMP Redirect processing by default.

🔧 5. Ping and Traceroute Utilities

5.1 Ping (Packet Internet Groper)

Ping is the most widely used network diagnostic tool, utilizing ICMP Echo Request and Echo Reply messages to test connectivity between two network nodes.

How Ping Works:
  1. Source sends ICMP Echo Request (Type 8, Code 0) to destination
  2. Destination receives request and generates ICMP Echo Reply (Type 0, Code 0)
  3. Source measures round-trip time (RTT) between request and reply
  4. Packet loss is calculated based on missing replies
🖥️ Ping Output Simulation

Click to simulate a ping to google.com (8.8.8.8)

5.2 Ping Statistics Explained

Metric Description Interpretation
RTT (ms) Round-Trip Time Lower is better; indicates network latency
TTL Time To Live Remaining hops; helps identify target OS
Packet Loss % Lost packets / Total sent 0% is ideal; higher indicates network issues
Jitter Variation in RTT Lower is better; important for VoIP/video

5.3 Traceroute (Tracert)

Traceroute discovers the route path by exploiting the ICMP Time Exceeded message or Port Unreachable messages:

UDP Method (Linux/Unix)

  1. Sends UDP to high port (33434+) with TTL=1
  2. Each router decrements TTL
  3. When TTL=0, router sends ICMP Time Exceeded
  4. Source increments TTL and repeats
  5. Destination returns Port Unreachable (or ICMP Unreachable)

ICMP Method (Windows)

  1. Sends ICMP Echo Request with TTL=1
  2. Each router decrements TTL
  3. When TTL=0, router sends ICMP Time Exceeded
  4. Source increments TTL and repeats
  5. Destination returns ICMP Echo Reply
Path MTU Discovery: Modern systems use the "Don't Fragment" (DF) bit in IP headers along with ICMP "Fragmentation Needed" messages to discover the maximum transmission unit (MTU) along a path without fragmentation.

🔒 6. ICMP Security Considerations

6.1 Common ICMP Attacks

💥 Ping Flood (ICMP Flood)

An attacker sends a massive number of ICMP Echo Request packets to overwhelm the target's bandwidth or processing capacity.

Mitigation: Rate limiting, ICMP filtering at firewall, disabling ICMP on external interfaces.

💣 Smurf Attack

Attacker sends ICMP Echo Requests with the victim's spoofed IP address to a broadcast address. All hosts on the network reply to the victim, amplifying the traffic.

Mitigation: Disable directed broadcast on routers, ingress/egress filtering (BCP 38), disable ICMP broadcast responses.

🎯 ICMP Redirect Attack

Attacker sends forged ICMP Redirect messages to redirect traffic through a compromised host (man-in-the-middle).

Mitigation: Disable ICMP Redirect acceptance on hosts (default in modern OS), firewall filtering.

🔍 ICMP Tunneling

Data is encapsulated within ICMP Echo Request/Reply packets to bypass firewalls that don't inspect ICMP payload.

Mitigation: Deep Packet Inspection (DPI), restrict ICMP payload size, monitor for unusual ICMP traffic patterns.

6.2 ICMP and Firewalls

Firewall policies regarding ICMP require careful consideration:

Policy Pros Cons
Block All ICMP Maximum security, prevents reconnaissance Breaks Path MTU Discovery, difficult troubleshooting
Allow All ICMP Full functionality, easy troubleshooting Vulnerable to ICMP attacks, information disclosure
Selective ICMP Balance of security and functionality Complex configuration, requires monitoring
Best Practice: Allow ICMP Type 3 (Destination Unreachable) Code 4 (Fragmentation Needed) for Path MTU Discovery to function. Block or rate-limit Echo Request/Reply on external interfaces while allowing them internally.

🌐 7. Applications and Real-World Usage

7.1 Network Diagnostics

  • Connectivity Testing: Basic reachability verification between hosts
  • Latency Measurement: RTT analysis for performance monitoring
  • Route Analysis: Path discovery and routing loop detection
  • MTU Discovery: Automatic path MTU determination

7.2 Network Management

  • SLA Monitoring: Service Level Agreement verification using ping statistics
  • Topology Discovery: Network mapping using traceroute data
  • Fault Detection: Automated alerting based on ICMP response patterns

7.3 Protocol Support

Path MTU Discovery (PMTUD)

Essential for TCP performance. Uses ICMP "Fragmentation Needed" messages to discover the largest packet size that can traverse a path without fragmentation.

Dead Gateway Detection

Windows uses ICMP to detect when a default gateway fails and switches to backup gateways automatically.

7.4 Modern Variants

ICMPv6: Expanded functionality in IPv6 networks:

  • Neighbor Discovery Protocol (NDP): Replaces ARP (Type 135/136)
  • Router Solicitation/Advertisement: Auto-configuration (Type 133/134)
  • Multicast Listener Discovery (MLD): Replaces IGMP

📝 8. Summary and Key Takeaways

Key Points to Remember:

  • ICMP is a Network Layer (Layer 3) protocol for error reporting and diagnostics
  • ICMP messages are encapsulated in IP datagrams (Protocol 1 for IPv4, 58 for IPv6)
  • Two main categories: Error Messages and Query Messages
  • Common types: Echo (0/8), Destination Unreachable (3), Time Exceeded (11), Redirect (5)
  • Ping uses Echo Request/Reply (Type 8/0) to test connectivity
  • Traceroute uses Time Exceeded or Port Unreachable to trace routes
  • ICMP is essential for Path MTU Discovery and network troubleshooting
  • Security concerns include flooding, smurf attacks, and tunneling

Quick Reference: Common ICMP Type/Code Combinations

Purpose Type Code
Ping Reply 0 0
Network Unreachable 3 0
Host Unreachable 3 1
Port Unreachable 3 3
Fragmentation Needed 3 4
Ping Request 8 0
TTL Expired 11 0
Exam Tip: Remember that ICMP error messages never generate other ICMP error messages (to prevent storms), and they are never sent in response to broadcast/multicast packets.