A detailed explanation of IPv4 and IPv6 protocols

Most of the work some time ago was related to the communication protocol. With the deepening of the protocol-related work, the analysis of related data packets took up a lot of working time. During the data packet analysis, it was found that the content of the IP protocol had been returned to the teacher during college, and the relevant knowledge was completely lost. This article can be regarded as a review article to re-learn the relevant IP protocol.

  • Detailed Explanation of IPv4 Protocol
  • Detailed Explanation of IPv6 Protocol
  • Comparison of IPv4 IPv6 packets

1. IPv4

  • Introduction to IPv4 Protocol
  • Number of IPv4 addresses
  • Features of IPv4 Protocol
  • IPv4 packet structure
  • Maximum length of an IPv4 packet

1.1 Introduction to IPv4

IPv4(Internet Protocol version 4)It is the fourth revision of the Internet Protocol and the first widely deployed and used version of the protocol. It is described in RFC791 issued by the IETF in September 1981 , and is a kind of 面向无连接的协议, yes 在使用分组交换的链路层(如以太网)上运行. In terms of data transmission, the IPv4 protocol will 尽最大努力交付数据包, however 不能保证所有数据包能够成功到达目的地,或者按照正确的顺序到达,这些方面由上层的传输协议(如TCP协议)处理.

IPV4 Protocol Packet Structure

1.2 Number of IPv4 addresses

IPv4 protocol 使用32位(4字节)地址, its address space 为4,294,967,296(2^32)个. Some of these addresses are reserved for specific purposes, such as private networks (about 18 million addresses) and multicast addresses (about 270 million addresses), which reduces the number of addresses available for Internet routing.
As addresses are allocated to end users, the problem of IPv4 address exhaustion is becoming more and more serious. Although address structure reconstruction based on classified networks, classless inter-domain routing, and network address translation slows down address depletion, in 2019年11月26日,全球近43亿个IPv4地址已分配完毕.

The limitation on the number of IPv4 addresses has spurred the deployment of IPv6, the only long-term solution.
IPv6使用128位地址空间, providing more addresses, as well as better security and performance. The widespread deployment of IPv6 will take time and effort, but it has become the main way to solve the shortage of IPv4 addresses.

1.3 Features of IPv4 protocol

  • 面向无连接:
    IPv4 is a connectionless protocol, each data packet is independent, and the transmission of data packets does not need to establish and maintain a connection state. This makes the transmission speed of IPv4 data packets faster, but it also increases the challenges of reliability and security of data packet transmission.
  • 分组交换:
    The IPv4 protocol uses packet switching technology to divide data into a series of small data packets for transmission. Each data packet contains necessary control information such as destination address and source address, which makes data transmission more efficient and flexible. At the same time, the IPv4 protocol also supports a variety of transmission protocols, such as TCP, UDP, etc., which can adapt to different data transmission requirements.
  • 简单、可靠、稳定:
    The design of the IPv4 protocol is very simple, reliable and stable, and has been widely used in various network environments such as the Internet and local area networks, and has good compatibility and stability.
  • 地址格式:
    An IPv4 address is a 32-bit binary number, usually expressed in dotted decimal notation, divided into four segments, and each segment can take an integer between 0-255. The shortage of IPv4 addresses became a problem, so technologies such as private addresses and network address translation were introduced to alleviate the shortage of IPv4 addresses.
  • 安全性:
    The security of the IPv4 protocol is low, and it is vulnerable to various network attacks, such as IP spoofing and data packet forgery. Therefore, in order to improve the security of the IPv4 protocol, network security devices such as routers and firewalls are usually required to strengthen and protect it.

1.4 IPv4 packet structure

The maximum length of an IPv4 packet 65,535字节is determined by the fields in the IP packet 16位总长度. The following figure shows the structure of an IPv4 packet:

IPv4 protocol header packet structure

IPV4 protocol header packet capture

  • 版本(Version):
    Occupied 4比特位, indicating the version number of the IP protocol, the value of IPv4 is 4.
  • 首部长度(Internet Header Length):
    Occupied 4比特位, indicating the length of the IP header, and the length of the header indicates how many 32-bit words (4 bytes, that is to say, the unit is 4字节) in the header. The minimum value of this field is 5 (binary 0101), which is equivalent to 5*4=20字节; the maximum decimal value is 15, which is equivalent to15*4=60字节
  • 服务类型(Type of Service,TOS):
    Occupied 8比特位, indicating the service type of the IP packet, used to specify parameters such as QoS (Quality of Service) and flow control.
  • 总长度(Total Length):
    Occupied 16比特位, indicating the length of the entire IP datagram, including the IP header and data part, in bytes. The minimum value of this field is 20 (20 bytes header + 0 bytes data), and the maximum value is 2^16-1=65,535.
  • 标识(Identification):
    Occupied 16比特位, this field is mainly used to uniquely identify all the fragments of a message, because the fragments do not necessarily arrive in order, so it is necessary to know the message to which the fragment belongs when reassembling. Each time a datagram is generated, the counter is incremented by 1 and assigned to this field.
  • 标志(Flags):
    Occupied 3比特位, used to identify the status of IP fragmentation.
    • Bit 0: Reserved, must be 0;
    • Bit 1: Fragmentation is prohibited (Don't Fragment, DF), fragmentation is only allowed when DF=0;
    • Bit 2: More Fragments (More Fragment, MF), MF=1 means there are still fragments behind, MF=0 means it is the last fragment.
  • 分片偏移(Fragment Offset):
    Occupation 13比特位, used to indicate the offset of the fragment relative to the original datagram.
  • 生存时间(Time to Live):
    Occupied 8比特位, indicating the maximum number of routers that datagrams can pass through in the network, used to prevent datagrams from infinitely looping in the network.
  • 协议(Protocol):
    Occupied 8比特位, indicating the protocol type used by the data part in the datagram, such as TCP, UDP, ICMP, etc.
  • 校验和(Header Checksum):
    Occupied 16比特位, used to detect whether there is an error in the IP header during transmission.
  • 源地址(Source Address):
    Occupied 32比特位, indicating the IP address of the sender of the datagram.
  • 目标地址(Destination Address):
    Occupied 32比特位, indicating the IP address of the receiver of the datagram.
  • 选项(Options)
    Additional header fields optionally follow the destination address, but this is not often used, 从1到40个字节不等. 如果首部长度大于5,那么选项字段必然存在.

1.5 IPv4 packet length

The maximum length of an IPv4 packet is determined 65,535字节by the fields in the IP packet . 16位总长度The maximum value for this field is 65535,因为它是一个16位无符号整数,所以IP报文的最大长度不能超过该值.

It should be noted that, in actual situations, IP报文的长度usually 会受到网络设备(如路由器、防火墙等)和网络链路的限制, in addition, due to the existence of network transmission MTU(Maximum Transmission Unit)的限制, 实际上能够传输的最大数据长度通常不会超过MTU值, is generally 1500个字节左右, therefore 实际传输的IP报文长度可能会比最大长度小得多.

Network transport MTU(Maximum Transmission Unit)大小并不是固定的, it's 大小取决于底层网络传输协议和网络设备的配置. Different network transmission protocols and devices may have different MTU size limitations.
以太网It is one of the most common network transmission protocols MTU大小通常为1500字节. If the data packet transmitted on the Ethernet exceeds 1500 bytes, it will be divided into multiple small blocks for transmission. The MTU size of other network transmission protocols may be different. For example, the MTU size of the PPP protocol is usually 1480 bytes, and the MTU size of the ATM network is usually 48 bytes.
In addition, MTU is also affected by the configuration of network devices. For example, network devices such as routers and switches can optimize network transmission efficiency and reduce delays by configuring the MTU size. In practical applications, in order to ensure the stability and efficiency of network transmission, it is necessary to set the MTU size according to the specific network environment and requirements, and perform necessary optimization and adjustment.

Two, IPv6

  • Introduction to IPv6 Protocol
  • Number of IPv6 addresses
  • Features of IPv6 Protocol
  • IPv6 packet structure
  • IPv6 payload length

2.1 Introduction to IPv6

IPv6(Internet Protocol version 6)It is the latest version of the Internet protocol, mainly 为了解决IPv4地址枯竭问题, and it also has many improvements to IPv4 in other aspects. The protocol is defined by RFC2960 published in December 1998 .

IPv6的设计目的是取代IPv4However, IPv4 still occupies a dominant position in Internet traffic for a long time, and the use of IPv6 is growing slowly. In April 2022, the percentage of users using Google services over IPv6 will exceed 40% for the first time.
Although IPv6 was designated by the IETF as the next-generation standard of IPv4 in 1994, due to the need to rewrite the early ones 路由器, 防火墙及相关应用程序there are relatively few network services deployed using IPv6 worldwide compared with IPv4 技术上仍以双架构并存居多.

2.2 Number of IPv6 addresses

The total length of the IPv6 address is 128比特位(16字节), 分为8组(每组2个字节)and each group 4个十六进制数is expressed in the form, and the groups are separated by colons. For example:FC00:0000:130F:0000:0000:09C0:876A:130B

Because of IPv6地址usage 128位(16字节)representation, its 可以支持约3.4×10²³(2^128)个唯一地址. This number is much larger than the IPv4 address space (4.3 billion addresses), which can meet the development needs of the Internet in the next few decades. The huge size of the IPv6 address space can not only support more devices to connect to the Internet, but also provide better network security and performance.

2.3 Features of IPv6 protocol

  • 更大的地址空间:
    An IPv6 address is represented by a 128-bit length, which can support about 3.4×10²³ (2^128) unique addresses, which is much larger than the IPv4 address space (4.3 billion addresses), and can meet the development needs of the Internet in the next few decades .
  • 改进的寻址和路由机制:
    The IPv6 protocol introduces some new addressing and routing mechanisms, including multicast addressing, anycast addressing and mobile IPv6, etc., making network routing more efficient and flexible.
  • 简化的头部结构:
    The IPv6 protocol header length is fixed at 40 bytes, which is simpler than the IPv4 header structure and can improve network data transmission efficiency.
  • 可选的扩展首部:
    IPv6 defines many optional extension headers, which not only provide more functions than IPv4, but also improve the processing efficiency of routers, because routers do not process other extension headers except the hop-by-hop extension header.
  • 更好的安全性和隐私保护:
    The IPv6 protocol provides better security and privacy protection, including mandatory support of the IPsec protocol, address privacy extension, etc., which can effectively protect the privacy of the network and users.
  • 更好的流量控制和服务质量:
    The IPv6 protocol introduces flow control and quality of service (QoS) mechanisms, which can better manage network traffic and provide different quality of service to improve user experience.

2.4 IPv6 packet structure

IPv6The datagram 首部长度is 固定的40字节that all extension headers in IPv6 do not belong to the header of the IPv6 datagram, and the extension header and the following data part are combined to form 有效载荷.

IPv6 packet header and payload

IPv6 protocol header packet structure

IPV6 protocol header packet capture

  • 版本号(Version):
    Occupied 4比特位, used to indicate the version number of the IPv6 protocol used by the packet, which is fixed at 6.
  • 流量类别(Traffic Class):
    Occupied 8比特位, used to distinguish the category or priority of different IPv6 datagrams. .
  • 流量标签(Flow Label):
    Occupation 20比特位, IPv6 proposes the abstract concept of flow, which is a series of IPv6 datagrams (such as the transmission of real-time audio and video data) from a specific source to a specific destination (unicast or multicast) on the Internet. All IPv6 datagrams belonging to the same flow have the same flow label ( 相同的流量标签可进行同样的数据优先级设定). Therefore, the flow label is particularly useful for the transmission of real-time audio and video data, and the flow label is not very useful for traditional non-real-time data.
  • 负载长度(Payload Length):
    占用16比特位, used to indicate the length of the payload (Payload) in the IPv6 packet, 不包括IPv6头部的长度.
  • 下一个报头(Next Header):
    占用8比特位, used to indicate the type of the next header after the IPv6 header, such as TCP header, UDP header, ICMPv6 header, etc.
  • 跳数限制(Hop Limit):
    占用8比特位, which is similar to the time-to-live (TTL) field in IPv4, and is used to limit the maximum number of hops that a packet passes through the network.
  • 源地址(Source Address):
    占用128比特位, indicating the IPv6 address of the sender.
  • 目标地址(Destination Address):
    占用128比特位, indicating the IPv6 address of the receiving end.

2.5 IPv6 Payload Length

关于 IPv6 有效载荷长度

  • The length of the payload of the IPv6 message is mainly Payload Lengthdetermined by the field, and Payload Lengththe field is 16比特位used to indicate the length of the payload, that is, the part except the IPv6 header (fixed at 40 bytes). Given that this field is 16 bits, its maximum value is 2^16 - 1, ie 65,535字节.
  • However, IPv6 also supports an Jumbo Payloadoption called . When this option is used, the payload length can be indicated by an extended header named Jumbo Payload Option, and a 32-bit (4-byte) field in the extended header indicates the payload length. Therefore, the maximum payload length can be reached 2^32 - 1, i.e. 4,294,967,295bytes.

Although IPv6有效载荷the maximum length can be reached 4294967295字节, the transport layer protocol data (such as TCP, UDP) carried by it is still limited by the IPv6 network MTU的限制, so 仍然需要遵循最大报文长度65,535字节的限制.

3. Comparison of IPv4 and IPv6 packets

IPv4 packet header structure

IPv6 packet header and payload

IPv6The datagram 首部长度is that 固定的40字节all extension headers do not belong to the header of the IPv6 datagram 扩展首部与其后面的数据部分合起来构成有效载荷.

Since the length of the IPv6 address is extended to 128 bits, the length of the basic header of the IPv6 datagram is increased to 40 bytes, which is 20 bytes longer than the length of the fixed part of the IPv4 datagram header (20 bytes).

Compared with IPv4 packets:

  • 取消了首部长度字段: The header length of the IPv6 datagram is 固定的40字节.
  • 取消了服务类型字段: The traffic class and traffic label fields in the IPv6 datagram header realize the function of distinguishing service fields.
  • 取消了总长度字段: Use the payload length field instead. This is because the header length of an IPv6 datagram is fixed at 40 bytes, and only the payload length behind it is variable.
  • 取消了标识、标志和片偏移字段: These functions have been included in the fragmentation extension header of the IPv6 datagram.
  • 把生存时间TTL字段改称为跳数限制字段: This way the name and function are more consistent.
  • 取消了协议字段: Use the next header field instead.
  • 取消了首部检验和字段: It can speed up the router's processing speed of IPv6 datagrams.
  • 取消了选项字段: Use the extension header instead to implement the option function.

reference

Definition IPv4:
https://en.wikipedia.org/wiki/IPv4

RFC791 IPV4:
https://datatracker.ietf.org/doc/html/rfc791

Definition IPv6:
https://en.wikipedia.org/wiki/IPv4

RFC2460 IPV6:
https://datatracker.ietf.org/doc/html/rfc2460

= THE END =

The article was first published on the official account "CODING Technology Pavilion". If the article is helpful to you, please pay attention to my official account.

Guess you like

Origin blog.csdn.net/aiwusheng/article/details/131173572