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

Source: Internet
Author: User
Network Interface Structure of Linux kernel 2.4.x (1)-Linux general technology-Linux programming and kernel information. The following is a detailed description. I. Preface

In the Linux source code, the implementation of network interfaces is worth reading. by reading the source code, we not only have a deeper understanding of network protocols, but also help in network programming, more accurate understanding and grasp of application functions.

This article focuses on the overall structure of the network interface program, hoping to serve as some guiding texts when reading the source code.

This article uses the Linux2.4.16 kernel as an object to explain. The kernel source code can be downloaded at www.kernel.org. When I read the source code, I refer to [lxr. linux. no] This poor reference website. I personally think it is a good tool and it is best to go to this website if possible.

   2. Structure of Network Interface Program

Linux network interfaces are divided into four parts: network device interface, network interface core, network protocol family, and network interface socket layer.

The network device interface is mainly responsible for receiving and sending data from physical media. The implemented file is under the linu/driver/net directory. The core part of the network interface is the key part of the entire network interface. It provides a unified sending interface for the network protocol and shields various physical media, at the same time, it is responsible for distributing packets from lower layers to appropriate protocols. It is the central part of the network interface. Its main implementation files are in the linux/net/core directory, where linux/net/core/dev. c is the main file for management.

The network protocol family is part of the implementation of various specific protocols. Linux supports TCP/IP, IPX, X.25, AppleTalk, and other protocols. The source code of various protocols is named in the linux/net/directory. Here we mainly discuss the TCP/IP (IPv4) protocol. The source code is linux/net/ipv4, and linux/net/ipv4/af_inet.c is the main file management.

The network interface Socket layer is the programming interface for network services provided by users. The main source code is linux/net/socket. c.

   Iii. Network Device Interface

There are many different types of network interface devices on the physical layer. In the 28 lines of the File include/linux/if_arp.h, the identifier of the various physical devices that ARP can process is defined. Network Device interfaces are responsible for controlling the specific physical media, receiving and sending data from the physical media, and setting various physical media such as the maximum data packet. Here we take the simple 3Com3c501 ethernet card driver as an example to explain how this layer works. The source code is in Linux/drivers/net/3c501. c.

We intuitively consider that the most important thing for a network card is to receive and send data. Here we will look at the process of receiving and sending data.

Sending is relatively simple, in Linux/drivers/net/3c501. the el_start_xmit () function starting from line 1 of c is the function that actually sends data to the 3Com3c501 ethernet card. The specific sending work is nothing more than reading and writing some registers. The source code comment is clear, let's take a look.

Receiving is relatively complicated. Generally, when a new package arrives or a package is sent, an interruption occurs. In Linux/drivers/net/3c501. in line 2 of c, the first half of the el_interrupt () function processes the report after the packet is sent, and the second half processes a new packet, that is, new data is received. The el_interrupt () function does not perform too much processing on the new package, so it is handed over to the receiving handler el_receive (). El_receive () first checks whether the received package is correct. If it is a "good" package, a buffer structure (dev_alloc_skb () will be allocated to the package ()), in this way, the driver receives the package and calls the netif_rx () (net/core/dev. c1214 rows), and send the package to the upper layer.

Now the driver has the ability to send and receive data. How can the driver establish a connection with the upper layer? That is to say, after receiving the package, how can we send it to the upper layer and how can the upper layer call the sending function of the driver?

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.