Internet Protocol (IP) provides support at the network layer of the OSI model. All transport protocol data packets such as UDP or TCP are encapsulated in IP data packets to be carried from one host to another. IP is a connection-less unreliable service meaning there is no guarantee that the data will reach the intended host. The datagrams may be damaged upon arrival, out of order, or not arrive at all (Sounds like some mail services, doesn’t it?). Therefore the layers above IP such as TCP are responsible for being sure correct data is delivered. IP provides for:
- Type of service specification.
- Fragmentation and re-assembly.
IP Message Format
IP is defined by RFC 791.
- Version (4 bits) – The IP protocol version, currently 4 or 6.
- Header length (4 bits) – The number of 32 bit words in the header
- Type of service (TOS) (8 bits) – Only 4 bits are used which are minimize delay, maximize throughput, maximize reliability, and minimize monetary cost. Only one of these bits can be on. If all bits are off, the service is normal. Some networks allow a set precedences to control priority of messages the bits are as follows:
- – Bits 0-2 – Precedence.
- – 111 – Network Control
- – 110 – Internetwork Control
- – 101 – CRITIC/ECP
- – 100 – Flash Override
- – 011 – Flash
- – 010 – Immediate
- – 001 – Priority
- – 000 – Routine
- – Bit 3 – A value of 0 means normal delay. A value of 1 means low delay.
- – Bit 4 – Sets throughput. A value of 0 means normal and a 1 means high throughput.
- – Bit 5 – A value of 0 means normal reliability and a 1 means high reliability.
- – Bit 6-7 are reserved for future use.
- – Bits 0-2 – Precedence.
- Total length of the IP data message in bytes (16 bits)
- Identification (16 bits) – Uniquely identifies each datagram. This is used to re-assemble the datagram. Each fragment of the datagram contains this same unique number.
- flags (3 bits) – One bit is the more fragments bit
- Bit 0 – reserved.
- Bit 1 – The fragment bit. A value of 0 means the packet may be fragmented while a 1 means it cannot be fragmented. If this value is set and the packet needs further fragmentation, an ICMP error message is generated.
- Bit 2 – This value is set on all fragments except the last one since a value of 0 means this is the last fragment.
- Fragment offset (13 bits) – The offset in 8 byte units of this fragment from the beginning of the original datagram.
- Time to live (TTL) (8 bits) – Limits the number of routers the datagram can pass through. Usually set to 32 or 64. Every time the datagram passes through a router this value is decremented by a value of one or more. This is to keep the datagram from circulating in an infinite loop forever.
- Protocol (8 bits) – It identifies which protocol is encapsulated in the next data area. This is may be one or more of TCP(6), UDP(17), ICMP(1), IGMP(2), or OSPF(89). A list of these protocols and their associated numbers may be found in the /etc/protocols file on Unix or Linux systems.
- Header checksum (16 bits) – For the IP header, not including the options and data.
- Source IP address (32 bits) – The IP address of the card sending the data.
- Destination IP address (32 bits) – The IP address of the network card the data is intended for.
- Options – Options are:
- Security and handling restrictions
- Record route – Each router records its IP address
- Time stamp – Each router records its IP address and time
- Loose source routing – Specifies a set of IP addresses the datagram must go through.
- Strict source routing – The datagram can go through only the IP addresses specified.
- Data – Encapsulated hardware data such as ethernet data.
The message order of bits transmitted is 0-7, then 8-15, in network byte order. Fragmentation is handled at the IP network layer and the messages are reassembled when they reach their final destination. If one fragment of a datagram is lost, the entire datagram must be retransmitted. This is why fragmentation is avoided by TCP. The data on the last line, item 14, is ethernet data, or data depending on the type of physical network.
TCP/IP Illustrated, Volume1, The Protocols
Author:W. Richard Stevens, Publisher: Addison Wesley. ISBN 0201633469