IPV4 : A postal service on the wire(Part-1)

Aditya JindalAditya Jindal
9 min read

Understanding the Internet protocol(IP)

Internet Protocol is used to communicate data over the Internet. It's like a virtual postman that delivers data packets from one device to another. The Internet Protocol is responsible for routing data packets between devices on the Internet. The IP protocol operates at the network layer of the TCP/IP networking model, and it is responsible for addressing, routing, and fragmenting data packets. When a device sends data over the internet, the data is divided into smaller packets, and each packet is tagged with the IP address of the destination device. The packets are then transmitted over the network, and each device along the way uses the IP address to route the packet to the correct destination.

IPV4: Architecture and working

To understand the working of IPV4 we can compare it with postal service. Just like when you send a letter to your friend you need to put the proper address and other details on the envelope of the letter, IP also does something very similar. It attaches the data with additional information called IP header which contains some crucial information. Without this header, it is not possible to deliver the data to the expected receiver.

IPv4 is a connectionless protocol, and operates on a best-effort delivery model, in that it does not guarantee delivery, nor does it assure proper sequencing or avoidance of duplicate delivery. These aspects, including data integrity, are addressed by an upper-layer transport protocol, such as the Transmission Control Protocol (TCP). TCP ensures the delivery of messages unlike IP, which waits for acknowledgement from the receiver. IP does not care about any response from the receiver it just sends the message and assumes that the receiver has received it successfully. We can say IP is not as reliable as TCP.

For understanding how IP works we first need to look at the IP header. This header is attached to every datagram(packet) that passed through the network layer. IP header helps in guiding the packet to its destination. The size of the IP header can vary from 20 bytes(minimum length) to 60 bytes(maximum length). There are several fields in the IP header that we are gonna discuss :

  1. Version: The first 4-bit version field in the IPv4 header is used to indicate the current version of the Internet Protocol (IP) being used. With 4 bits we can represent a maximum of 15 means we can go up to 15 versions of IP as of today. It is due to these 4 bits it is known to the receiver how to interpret the message it is receiving. As all the messages are in binary 0-1 and we have several versions of IP it is important to know which version of IP is used to send the message so the receiver can interpret it in the same version on its side.

  2. Header Length: The next 4- bits are used to represent the length of the header. As we know that an IP header can go from 20 bytes to 60 bytes. I know what you are thinking how can 4 bits represent such big numbers? The decimal representation of these bits is multiplied by a scaling factor of 4 to get the actual value of the header For eg. if the value of header length bits is 7 then the actual length of the header is 7x4 = 28 bytes. That is why the minimum value a header length field can represent is not 0 but 5 because the minimum length of the IP header is 20 bytes (20/4 =5).

  3. Type of Service(TOS): Next 8 bits of the IP header are reserved for representing the type of service meaning these bits represent special and exclusive conditions applied to some packets.The first 3 bits of this field represent the precedence/priority of the packet, the higher the value higher the precedence. The following next bits represent delay, throughput, reliability, cost and reserved I think these names are self-explanatory. Generally, we are not allowed to set these values because if general users are allowed to set these bits then everyone will send their packet with the highest priority and it becomes the new normal, only ISP's and other authorised entities are authorised to set these bits.

  4. Total Length: The next 16-bits represent the total length of the IP datagram comprising both header and the data. As the minimum length of the data bytes can be zero but the for header it's 20 bytes the IPV4 packet has a maximum size of 65,535 bytes. Since the maximum field total length is 16 bits in the IPV4 header, the maximum size is 2^16−1=65,535−1=65,535.

    It is important to note that IP is byte addressable means every byte is counted as opposed to other protocols like TCP where every packet is counted.

For understanding the next set of fields, first we need to learn about fragmentation and why we really need it.

Fragmentation and why we need it

IP works on top of the data link layer(DLL) meaning every IPV4 packet has to sit inside a DLL frame before transmission. IPv4 is utilized in various data link layers, each with its own unique maximum frame size or Maximum Transmission Unit (MTU). The MTU refers to the largest packet that a data link layer can transmit, inclusive of its header. The following are examples of MTU values for frequently employed data link layers.

As observed in the above table, it is evident that the MTU values for all the data link layers are considerably smaller compared to the maximum size(65,535B) of an IPv4 packet. Consequently, in order to securely transmit data across the network, the oversized IPv4 packet is fragmented into multiple IPv4 packets. This process of dividing an IP packet is known as fragmentation.

Fragmentation makes communication between networks of different MTU possible. But it also has some drawbacks as it adds an extra overhead on the size of data finally transmitted and it also required rearranging the packets on the receiver end.

The IP packets are not divided arbitrarily but there are rules and calculations to precisely divide a packet into smaller chunks. These rules and calculations are not relevant at this point so we can proceed with the next set of fields in IPV4 header.

  1. Identification: If the IP packet is fragmented then each fragmented packet will use the same 16-bit identification number to identify to which IP packet they belong to. This helps the receiver to identify which parent packets the child packets belong to. The receiver has to rearrange all the packets it receives to get back the original unfragmented packet and the identifications field helps it to identify the packets belonging to the same unfragmented packet.

  2. Null Bit: This is an extra bit which is always 0. It serves no purpose in IPV4 communications it's probably there as a padding bit.

  3. DF (Don't fragment): This bit works as a flag and if set to 1 then it indicates the underlying network to not fragment the original packet. No router on the way fragments the packet if the network has a smaller MTU than the packet size and simply returns the packet to the sender. Sender then fragments the packet accordingly and transmits the packet.

  4. MF (More fragments): It is a single-bit indicator that signifies whether there are additional fragments of the frame. In all the fragmented packets, this indicator is set to 1, except for the last packet where it is set to 0. This indicator, in combination with the fragment offset, aids the receiver in accurately sequencing the fragments during the reassembly process.

  5. Time to Live(TTL): The next 8 bits represent Time to Live which is a setting that determines how long your data (in packet form) is valid and available from within a network before the router clears it. We can also refer to this time as “hops,” which is the number of times it bounces between different routers. Once the TTL expires, the router will need to retrieve the information again, along with its updates. A packet can never exceed the number of hops. Every time a packet is passed through a router or a network it's TTL value is decreased by one. If the packet doesn't reach to it's destination in the assigned number of TTL then it is discarded by the underlying router or network.

  6. Protocol: This field specifies the upper-layer protocol that is encapsulated within the IPv4 packet. It indicates the type of data that is carried in the payload of the IPv4 packet. An IP packet can have TCP, UDP, ICMP, IGMP etc. segments inside it, so its important to have a marking in IP header that indicates what protocol it is holding inside. It's a 8-bit field and every protocol is represented by a different value.

  7. Header Checksum: This field is used for error detection. It is a simple error-checking mechanism that verifies the integrity of the IPv4 header during transmission. It only verifies the integrity of the header not the data part of IP packet. When a device, such as a router or a host, receives an IPv4 packet, it can recalculate the header checksum using the same algorithm and compare it with the value in the header checksum field. If the calculated checksum matches the value in the header checksum field, it indicates that the header has not been modified during transmission and that the packet has not been corrupted else if the packet is discarded if the checksum fails.

  8. Source IP address: The source IP address field is a 32-bit field that identifies the sender or source of a network packet. It is a fundamental part of the IPv4 header. The IPv4 address is represented in decimal form, separated by periods, such as "192.168.1.100". Each of the four octets (8 bits each) in the 32-bit IPv4 address represents a part of the network address, and the combination of all four octets identifies a specific device on the network.

  9. Destination IP address: The destination IP address field is a 32-bit field that identifies the intended recipient or destination of a network packet. Similar to the source address it is also represented in decimal form, separated by periods.

    How these addresses are actually assigned is a whole different topic in itself I will cover someday. But as of now, it is not very crucial to understand the working of IPv4.

  10. Options: This is an optional field of the IPv4 header. It is used only when the value of the Header Length is set to more than 5. These options contain values and settings for things related to security. Record route and time stamp etc. You will find that the list of options component ends with an End of Options or EOL in many cases. This field can vary anywhere from 0 to 40-bytes depending on the option used.

  11. Data: The data part comes after the IP header ends it can vary from 0 bytes to a maximum of 65,535 bytes. This data actually comes from the Transport layer from above and contains packet with transport layer protocols like TCP, UDP, ICMP, IGMP etc.

    With this, we have covered the whole architecture of an IPv4 datagram I hope it might have helped you in understanding IPv4 better.

Conclusion

IPv4 is a vast topic and can not be concluded in one blog, in the next part I will try to show you practically the significance IPv4 header by using some packet tracer software like wireshark or cisco packet tracer. This will be helpful in understanding the protocol more practically. I will also cover some Linux commands based on Internet protocol. Till then stay tuned and give you feedback on this blog so I can improve in future.

0
Subscribe to my newsletter

Read articles from Aditya Jindal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aditya Jindal
Aditya Jindal