IP (Internet Protocol)

IP stands for Internet Protocol, is a set of rules for routing and addressing packets so that they can travel across the network and arrive at correct places

Once they arrive at the destination, they will be handled by Transport protocol (TCP (Transmission Control Protocol) or UDP (User Diagram Protocol))

Pasted image 20240505154739.png

IPV4 Structure

packet-beta
title IPv4 Header Structure
0-3: "Version"
4-7: "IHL (Header Length)"
8-15: "Type of Service or DiffServ"
16-31: "Total Length"
32-47: "Identifier"
48-50: "Flags"
51-63: "Fragment Offset"
64-71: "Time to Live (TTL)"
72-79: "Protocol"
80-95: "Header Checksum"
96-127: "Source IP Address"
128-159: "Destination IP Address"
160-183: "Options (if IHL > 5)"
184-191: "Padding"

Version (4 bit)

Use 4 if IPv4, 6 if IPv6. The full list of table is here:

DecimalVersion / Protocol NameDescription / Status
0ReservedHistorically reserved or used in early experimental prototypes.
1–3UnassignedReserved for future allocation.
4IPv4Internet Protocol version 4. Current primary global standard.
5ST / ST2Internet Stream Protocol. Used for experimental multimedia streaming; now Historic.
6IPv6Internet Protocol version 6. Current standard for massive address space.
7TP/IXThe Next Internet. Proposed in 1993; now Historic.
8PIPP Internet Protocol. Proposed in 1994; now Historic.
9TUBATCP and UDP over Bigger Addresses. Proposed in 1992; now Historic.
10–14UnassignedCurrently reserved; includes various non-standard drafts like "IPv10".
15ReservedReserved for experimental or future use.

Header length (4 bit)

Specify how much data is this single header. Because there is an Options field, the size of the header could be varied from 20 bytes to 60 bytes.

The value provided in this number is 32-bit-word (i.e $\times 4{bytes}$) so if we specify 5 it will be 5x4=20 which is the standard for this IPv4 header.

ToS or DiffServ

For this fields there are 2 types of data. One is DSCP (DiffServ Code Points) and ECN (Explicit Congestion Notification). Another one is Type of Service

If we set ECN, we have last 2 bit for ECN and first 5 bits for DSCP

packet-beta
title DSCP & ECN contains 8 bits
0-5: "DSCP"
6-7: "ECN"

For ECN, if we set 11 that means congestion

Total Length (2 byte - 16 bits)

Total length of the packet including the headers and data payload in octet (bytes).

[!danger]
This does not include EthernetII header

Identifier (16 bits)

Packet will be break into smaller fagment if it exceeds MTU (Maximum Transmission unit). Maximum size of the packet is the MTU. For those that're break into fragment, they need to have the same identifier number.

Flags (4 bits)

3 bit:

  • First bit: unused
  • Second bit: Don't fragment (DF) if we set this bit, the router cannot fragment the packet. If it exceeds MTU (Maximum Transmission unit) and cannot be forwarded, it will send an error message to the source.

Flagment Offset (8 bits)

The id of the fragment since the fragment might not be in sequence. This is to use to sort the fragment after

TTL (8 bits)

As packet passed from router to router, each router decrement this number, if the number reaches 0, the packet will be discard.

This is to prevent lost packet to wander around.

The recommended TTL value is 64.

Protocol (8 bits)

Set the type of protocol

DecimalKeywordProtocol Name / Description
0HOPOPTIPv6 Hop-by-Hop Option
1ICMPInternet Control Message Protocol
2IGMPInternet Group Management Protocol
4IPv4IPv4 encapsulation (IP-in-IP)
6TCPTransmission Control Protocol
17UDPUser Datagram Protocol
41IPv6IPv6 encapsulation (6to4, etc.)
47GREGeneric Routing Encapsulation
50ESPEncapsulating Security Payload (IPsec)
51AHAuthentication Header (IPsec)
58IPv6-ICMPICMP for IPv6
88EIGRPEnhanced Interior Gateway Routing Protocol
89OSPFOpen Shortest Path First
103PIMProtocol Independent Multicast
112VRRPVirtual Router Redundancy Protocol
115L2TPLayer Two Tunneling Protocol
132SCTPStream Control Transmission Protocol
253–254Use for experimentation and testing
255Reserved

Header check sum (16 bits)

Check sum calculate by the origin of the packet. Different protocols have different ways of calculating checksum.

Sender will calculate the checksum and put there, the receiver will calculate the check sum again (including the sender checksum in the header). The end checksum needs to compliment each other (sum up to 0)

Source and destination IP (32 bit)

32 bit IPv4 address of the originator of the packet

Option (varied length)

Optional fiels normally used for testing. For example:

  1. Timestamp: packet keep track of the timestamp where it was
  2. Loose source routing: list of IP addresses packet needs to pass through
  3. Strict source routing: list of IP addresses where packet must pass through exactly in the same order