As we mentioned in the previous article, it’s unworkable to use MAC addresses to figure out where to send data between networks. In order to do this efficiently, some sort of hierarchical structure of node identification is necessary. This is where the internet protocol addresses (IP addresses) come in.
Each node on the internet has an IP address. IP addresses are structured hierarchically, so routers (a router is a device that sends traffic between networks) can use them to drill down from high-level matches to the specific address needed.
IP addresses come in two versions. The older, and universally adopted version, is IPv4. This version has 32 bits, allowing for 4,294,967,295 possible IP addresses. As the internet proliferated, it became clear that we were running out of addresses. Because of this, the newer version, IPv6, uses 128 bits to define addresses.
IPv4
An IPv4 address’s 32 bits are organized into four bytes. The notation of an IPv4 address is four numbers separated by periods, each with a value of 0 to 255.
An IPv4 packet has this structure:
-
- Version. Four bits; identifies the version of the IP packet. For IPv4 packets, this is always
0100
, or 4. - IHL, or Internet Header Length. Since an IPv4 header may or many not include optional parameters (see 11 below), the header size can vary, so the IHL specifies the size.
- DSCP, or Differentiated Services Code Point. Some network hops allow for the use of different types of trasmissions, such as choosing between low-latency and low-loss transmissions. The DSCP field is a way of specifying these.
- ECN, or Explicit Congestion Notification. Allows end-to-end notification of network congestion to find ways of avoiding packet loss.
- Total Length. Total size of the packet, including both headers and payload.
- Identification. If a Transport Layer PDU is larger than the maximum packet limit size, the sender breaks it up into a set of smaller fragments, each with the same ID number. The receiver can then reassemble the PDU when transmission is complete.
- Flags. Three bits:
-
- reserved, always 0.
- DF (don’t fragment) flag; if this flag is set and the packet is a fragment, the packet gets dropped.
- MF (more fragments); if this flag not set then the fragment is the last one, otherwise there are more to come.
-
- Fragment offset. This is the number of bytes from the beginning of the first fragment that the current fragment starts at.
- TTL, or Time to Live. In theory, this is how much time may elapse before the packet either reaches its destination. In practice, though, the TTL field contains the maximum number of hops a packet can take before it reaches its destination. Each router decrements the TTL field by one, and the packet is dropped if the field reaches zero. (IPv6 replaces TTL with a Hop Limit field, reflecting this practice.)
- Protocol. Eight bits, specifying the protocol of the payload as assigned by the IETF. For example, 6 is TCP, 17 is UDP, and 41 is ENCAP, which is used to encapsulate an IPv6 packet for transmission on an IPv4 hop.
- Checksum. Used for identifying corrupt packets.
- Source IP address.
- Destination IP address.
- Options. Allows the specification of a number of optional parameters. (Usually not used.)
- Payload (a Transport Layer PDU).
- Version. Four bits; identifies the version of the IP packet. For IPv4 packets, this is always
IPv6
The internet grew very rapidly in the 1990s. When the 2000s rolled around, it had become clear that four billion IP addresses wouldn’t be enough to keep us from running out of them. In fact, that actually did happen in 2019! In light of this, there has been an ongoing initiative to adopt a newer version of IP address, called IPv6. IPv6 addresses increase the number of bits to 128. Since 128 bits allow for 2^128 possible addresses, running out of IPv6 addresses is beyond unlikely.
An IPv6 packet has this structure:
-
- Version. Four bits: identifies the version of the IP packet. For IPv6 packets, this is always
0110
, or 6. - Traffic class. Analogous to the IPv4 DSCP and ECN fields combined.
- Flow label. Analogous to the IPv4 Identification field.
- Payload length. Size of the payload.
- Next header. Specifies the type of the next header, usually the protocol of the payload as with the IPv4 Protocol field. (“Usually” because the value could be the type of an *extension header*, which is the header of an extension that carries optional information. So, this field also replaces the IPv4 Options field, and, as with that field, is not typically used.)
- Hop limit. Replaces IPv4 TTL field. The maximum number of hops a packet can take before it reaches its destination or is dropped. Each router decrements the Hop limit field by one, and the packet is dropped if the field reaches zero.
- Source address. The 128-bit IPv6 address of the sending node.
- Destination address. The 128-bit IPv6 address of the receiving node.
- Payload (a Transport Layer PDU).
- Version. Four bits: identifies the version of the IP packet. For IPv6 packets, this is always
Notable in IPv6 is the absence of a Checksum field.
The original thinking was that it was best to detect and drop a corrupt packet as soon as possible. This would avoid the overhead of sending a packet all the way to the destination before dropping it. On the other hand, decrementing the hop count alters the packet metadata. Because of this, the routers also need to recalculate the checksum on every hop.
However, it turns out that the overhead of recalculating every good packet on every hop is considerably higher than the overhead of possibly adding extra hops to corrupt packets. Since only a small percentage of packets (roughly five percent on average) are corrupt to begin with, it makes more sense to allow the Transport Layer protocol to check the integrity of its PDU upon arrival at the endpoint. So, IPv6 did away with the Checksum.
Next, we’ll take up how routers use IP addresses to direct internet traffic.