What a packet is and how it sits in the network stack
Anatomy of a packet
IP header
- Version: identifies IPv4 or IPv6.
- Header length (IHL) and total length: size of the IP header plus payload.
- Identification, Flags, Fragment Offset: used for fragmentation and reassembly.
- Time to Live (TTL): limits the lifetime of a packet to prevent looping.
- Protocol: indicates the transport protocol carried inside (for example TCP or UDP).
- Header checksum: validates header integrity (for IPv4).
- Source and Destination IP addresses: endpoints of the packet.
- Options: optional fields used for advanced features or debugging.
Transport header
- TCP: source port, destination port, sequence number, acknowledgment number, data offset, flags (SYN, ACK, FIN, etc.), window size, checksum, urgent pointer, and options.
- UDP: source port, destination port, length, checksum.
Payload
The payload is the application data carried by the packet after the headers. This could be anything from a DNS query to a fragment of an HTTP request or a video frame. The receiving end uses the transport header to interpret and pass the payload to the appropriate application.
A concrete, hypothetical example: a packet journey from host to server
Note: the following is a hypothetical example designed to illustrate how the pieces fit together. Values shown are illustrative and not taken from a live capture.
- Scenario: A client on a LAN sends an HTTP request to a web server.
- Layer 4 (transport): TCP is used on port 80. The client opens a TCP connection and sends a GET request as a TCP segment.
- Layer 3 (network): The TCP segment is wrapped in an IPv4 packet. Key header fields might look like:
- Version: 4
- IHL: 5 (20 bytes for the IP header)
- Total length: 60 bytes
- Identification: 12345
- Flags: DF (do not fragment)
- Fragment offset: 0
- TTL: 64
- Protocol: 6 (TCP)
- Source IP: 10.0.0.2
- Destination IP: 10.0.0.10
- Header checksum: (computed)
- Layer 2 (data link): The IPv4 packet is carried in an Ethernet II frame addressed to the first-hop router’s MAC address, with EtherType 0x0800 for IPv4.
- Layer 1 (physical): The frame is transmitted over the local network segment and is routed toward the destination through one or more hops.
- Result: The server receives the IP packet, decapsulates the IP header, and passes the TCP segment to the HTTP server process if the connection is established and the payload is appropriate.
MTU, fragmentation, and encapsulation: why size matters
Maximum Transmission Unit (MTU) is the largest payload size that can be transmitted in a single frame on a given link. When a packet exceeds the MTU of a link, IP fragmentation can occur (for IPv4). Fragmentation splits the packet into smaller pieces, each with its own IP header, and the destination reassembles them. Fragmentation saves the need to drop large packets, but it adds overhead and increases the risk of reassembly errors, out-of-order delivery, and inefficiency.
Key concepts to keep in mind:
- Path MTU: the smallest MTU along the path between source and destination. If any link has a smaller MTU, large packets may be fragmented or dropped.
- Fragment offset and identification fields allow routers to reconstruct the original packet at the destination.
- Fragmentation is more costly for performance because each fragment carries its own headers and can complicate reassembly, especially in high-lidelity or real-time traffic.
- Path MTU Discovery (PMTUD) helps determine the largest packet size that can traverse a path without fragmentation by relying on the DF (do not fragment) bit in IPv4 or the analogous behavior in IPv6.
Practical guidance for engineers
- Map and document the MTU across critical paths. Start with the standard Ethernet MTU of 1500 bytes and adjust for any tunnels or overlays (VPNs, GRE, IPsec) that add headers and reduce usable payload.
- Prefer PMTUD over guessing MTU values for paths with VPNs or middleboxes. If PMTUD is not feasible, plan for a conservative MTU on edges to avoid fragmentation.
- Avoid fragmentation in latency-sensitive or high-throughput paths. Where possible, keep packets within MTU bounds and use large-send optimizations only after validating the path characteristics.
- In tunnels and encapsulated links, account for the extra header overhead. For example, a tunnel that adds 40 extra bytes reduces the effective MTU for the inner packet, so you may need to lower the outer MTU accordingly.
- When troubleshooting, differentiate between problems caused by IP fragmentation and those caused by transport-layer behavior or application-level retries. A packet capture that shows fragmented IP fragments or a high rate of retransmissions can point you to MTU or topology issues.
Common mistakes, limitations, and safety considerations
- Assuming every path supports the same MTU; a smaller link downstream can force fragmentation or drops if DF is not managed correctly.
- Relying on fragmentation for long-lived, high-throughput traffic. While it preserves delivery, it introduces overhead and potential reassembly delays.
- Overlooking tunnel overhead when calculating effective MTU. VPNs, NAT, and encapsulation add headers that eat into the usable payload.
- Ignoring security implications of fragmentation. Some security devices reassemble fragments for inspection, which can impact performance or reveal misconfigurations.
Note: In IPv6, fragmentation is handled differently, and hosts typically perform PMTUD. Some environments still require careful handling of MTU and fragmentation due to tunnels or legacy devices, so treat MTU planning as an explicit design consideration, not an afterthought.
Conclusion
Next step
Next step: select a representative path in your network and perform a path MTU assessment to document the largest non-fragmenting packet size you can safely send across that path, then adjust interface and tunnel configurations accordingly.
Comments
Post a Comment