Network Interface Structure of Linux kernel 2.4.x (2)

Source: Internet
Author: User
Network Interface Structure of Linux kernel 2.4.x (2)-Linux general technology-Linux programming and kernel information. The following is a detailed description. Iv. core parts of Network Interfaces

I just talked about how the driver connects to the core layer of the network interface. The core layer of the network interface knows that the function entry of the driver and the driver is directed to the device chain through * dev_base, and the lower layer is called by the function netif_rx () of this layer () (net/core/dev. c1214 rows) Pass the data to this layer.

The upper layer of the core layer of the network interface is the specific network protocol, and the lower layer is the driver. We have resolved the relationship between the lower layer, but the relationship with the upper layer is not resolved. First, we will discuss the relationship between the core layer of the network interface and the network protocol family. This relationship is essentially the relationship between receiving and sending.

Network protocols, such as IP and ARP, transmit data packets to this layer (the core layer of the network interface) when sending data packets. What functions does this transfer take place? The Network Interface core layer uses dev_queue_xmit () (net/core/dev. c, line975) This function provides a unified sending interface to the upper layer. That is to say, whether it is an IP address or ARP protocol, this function transmits the data to this layer, you can call this function when you want to send data. Dev_queue_xmit () is executed in dev-> hard_start_xmit (), while dev-> hard_start_xmit () calls the actual driver to complete the task of sending. For example, in the above example, calling dev-> hard_start_xmit () actually calls el_start_xmit ().

Now we will discuss the receipt situation. The core layer of the network interface receives the data sent from the lower layer through the function netif_rx () (net/core/dev. c 1214). At this time, the data packet must be sent to the upper layer. All the lower-layer protocols of the protocol family need to receive data, TCP/IP IP protocol and ARP protocol, and SPX/IPX protocol, appleTalk's DDP and AARP protocols both need to receive data directly from the network interface core layer. How does the network interface core layer send packets to these protocols? In this case, the relationship between the layer and its lower layers is very similar. There may be many Nic drivers under the core layer of the network interface, in order to know how to send data to these drivers, as mentioned above, it is solved through the link pointed to by * dev_base. The relationship between the solution and the upper layer is solved through the array static struct packet_ptype_base [16] (net/core/dev. c line 164. This array contains the protocol for receiving data packets and the entry to their receiving functions.

From the above, we can see that the IP protocol receives data through the ip_rcv () function, while the ARP protocol uses arp_rcv, the core layer of the network interface only needs to pass the data through this array to the upper-layer function.

If you want to add yourself to this array through a protocol, you can use dev_add_pack () (net/core/dev. c, line233) Add a function; delete an array through the dev_remove_pack () function. Registration at the Ip layer is performed in the initialization function.
CODE: void _ initip_init (void) (net/ipv4/ip_output.c, line 1003)
{
.........
Dev_add_pack (& ip_packet_type );
.........
}
Related Article

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.