LINUX TCPIP Protocol Stack Source Code Analysis (1)

zhaozj2021-02-16  60

-------------------------------------------------- -------------------------------------------------- -----------------

This article was written three years ago, and the three huge arts TCP V1 / V2 / V3 of Stevens did not mind - because they were too thick. I know that I don't need so much, so detailed. So I have the idea of ​​analyzing the source code ...

I don't provide any guarantee in the text, but welcome to contact me to constantly modify it, and finally provide people who need to know about Linux TCP / IP to provide short-fashionable article content.

Water element

-------------------------------------------------- -------------------------------------------------- -----------------

Part I: Linux TCP / IP implementation overview

Linux provides universal underlying basic services through support for multiple communication protocols. Its first network model version is 4.3 BSD, also known as Net / 1. Today's Linux has already used Net / 4 (Linux 2.2), most of whom have different versions of BSD, but it still supports UINX Multigroup transplantation between platforms.

The mode of Linux network socket implementation is universal standard under UNIX. At the same time, the network layer of NET / 4 is completely stovedinked. First, the new network layer implements parallel processing as much as possible, so its scaling is compared with the previous version, cannot be synonymous. Second, it includes many optimizations to bypass a lot of unreasonably in the realization of the popular operating system network (eg, Windows). So far, Linux is the only operating system that is completely kept compatible with IPv4 and IPv6 protocol standards, while Linux2.4's IPv4 scalability is greatly improved.

LiNux supported six different communication protocols:

1) TCP / IP (Internet protocol "using TCP / IP), the focus of this article discusses this article.

2) UNIX domain protocol (protocol for inter-process communication)

3) X25 protocol

4) AX25 protocol (amateur wireless x25)

5) IPX protocol (Novell IPX)

6) AppleTalk D DP)

1.1 Organization for kernel source code

Table 1 is the Linux Net / 4 network source code for use in this article, most of which are located in the directory /usr/src/linux-2.2.x/net, the list is as follows,

Socket layer

BSD Socket

/NET/Socket.c/net/protocols.c

INET SOCKET

/ipv4/protocol.c/ipv4/af_inet.c/net/ipv4/CORE/SOCK.C protocol layer

TCP / UDP

/NET/IPv4/udp.c /net/ipv4/datagram.c /net/ipv4/tcp_input.c /net/ipv4/tcp_output.c /net/ipv4/tcp.c /net/ipv4/tcp_miniisocks.c/ NET / IPv4 / TCP_Timer.c etc ...

IP

/NET/IPV4/IP_Forward.c/net/ipv4/ip_fragment.c /net/ipv4/ip_input.c/net/ipv4/ip_output.c

Interface layer

Ethernet

......

1.2 TCP / IP network hierarchical structure and implementation in Linux

Linux implements TCP / IP models through a group of adjacent software layers, which consists of a BSD Socket layer, an inetsocket layer, a transport layer, a network layer, and a link layer. The application uses the system call to the kernel function to enter the kernel space, and the kernel function registered in the kernel is processed for the corresponding data structure. Linux's TCP / IP hierarchy and implementation are shown in Figure 1.

to be continued......

转载请注明原文地址:https://www.9cbs.com/read-17582.html

New Post(0)