Use and establishment of Linux tcp ip protocol

Source: Internet
Author: User

Linux is a major operating system in many enterprises and companies. So how can we build the tcp ip protocol stack on this system? Next, let's take a detailed look at the component process of the Linux tcp ip protocol stack.

Analyze tcp_v4_init, which is in net/ipv4/tcp_ipv4.c:

The function is in net/ipv4/tcp_ipv4.c.

Tcp_inode is of course an inode node, and tcp_socket is equal to tcp_inode.u.socket_ I. They point to the same memory through a pointer. Tcp_socket is used for communication. It can be called TCP controlsocket or communication in the Linux tcp ip protocol stack.

When no socket exists for TCP communication in the socket or TCP/IP protocol stack, the socket acts as the socket. For example, if an RST is sent when SYN is received on a closed port, or the SYN is sent when the three-way handshake is sent, no accept is generated to generate a new socket)

It is worth noting that the ops-> create function is called. We have previously seen that for AF_INET, this callback function is the inet_create function of net/ipv4/af_inet.c, this function is used to create a socket. Because the function is relatively long, the analysis is skipped here. The first analysis is just a rough process.

Because of socket creation and communication, this code is protocol-related, so the code is extracted from the original tcp. c.

The following is the tcp_init function. In net/ipv4/tcp. c, it creates several hash tables and buckets. This Code creates the following global objects:

Global Object

Here, ehash represents establishedhash, and bhash represents bindhash. Of course, they all meet the requirements of TCP_ESTABLISHED <= sk-> state.

The next step is the icmp_init function. In net/ipv4/icmp. c, IPPROTO_TCP in tcp_v4_init is basically the same if it is replaced with IPPROTO_ICMP. The rest of the proc_net_register function has been mentioned before.

So far, we should have some knowledge about the starting work of IP in the Linux tcp ip protocol stack. There are several key functions:

Dev_add_pack: registers a processing function at or above the link layer. It is generally used to use the new Network Layer Protocol. However, if it is repeated during registration, the system sets a copy bit. If it is ETH_P_ALL, all data packets are received. The added elements are stored in the middle of the ptype_all and ptype_basehash linked lists.

Inet_add_protocol: registers a protocol established above the IP layer, such as TCP and UDP.

Proc_net_register has a similar proc_register ):

Create a sub-directory under the/proc/net directory so that the administrator can obtain statistics through the file system.

There are still many obfuscation points. One is the meaning of each member of the struct sk_buff, and the other is the meaning of the struct sock. But these two problems should be known later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.