Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Linux kernel network subsystem analysis     - Locale files under Ubuntu (Linux)

- MySQL stored procedures execute dynamic sql statement (Database)

- CentOS6.7 text installation system (Linux)

- Into the Java keyword instanceof (Programming)

- AppCode developed Mac OS X application or shared library experience summary (Programming)

- Linux Network Statistics Tools / Command (Linux)

- In addition to wget and curl, what better alternatives (Linux)

- JavaScript basic tools list (Programming)

- Talk about Java in the collection (Programming)

- SolrCloud-5.2.1 cluster deployment and testing (Server)

- Ubuntu FAQ solutions (Linux)

- Let Ubuntu 14.04 Save screen luminance value (Linux)

- Ubuntu Tutorial - Manually install Oracle Java JDK 8 (Linux)

- To create a problem by the statement date comparison of the difference between MySQL and Oracle (Database)

- Ubuntu resolve sudo: source: command not found error (Linux)

- Ubuntu install video conversion tool Selene (Linux)

- Expand an existing RAID arrays and remove the failed disk in a RAID (Linux)

- Linux permissions Detailed (Linux)

- Linux network security probing tools Hping2 (Linux)

- Linux system performance analysis and top command ps.pstree Comments (Linux)

 
         
  Linux kernel network subsystem analysis
     
  Add Date : 2018-11-21      
         
         
         
  1. Select a route

To send a packet to PC2, then the Linux system through the routing table found 168.1.1.10 (the destination address) of the gateway address is 192.168.1.1, this time Linux system selects the card 1 transmits packets.

2. neighborhood subsystem (up the neighbor information through arp protocol)

When you select the card transmits data 1, the first packet to the neighbor (the gateway), and then forwarded by neighbors to the back, to be sent to a neighbor, you must know the MAC address of the neighbor, the neighbor does not know the MAC address, you need to arp request packet to obtain the MAC address of the neighbor.

Linux network architecture consists of the following five parts 1) system call interface 2) protocol-independent interfaces 3) Network Protocol 4) Device-independent device driver interface 5. The following are brief five parts:

    1) system call interface

    System call interface is user-space applications access the kernel only legal way (the terminal and can also be accessed into the kernel). Such as:

    asmlingkage long sys_getpid (void)

    {

    return current-> pid;

    }

    System calls are generally made at the beginning of sys, front modifier is asmlingkage, showing the function parameters obtained by the stack.

    2) protocol independent interface

    Protocol-independent interfaces are implemented by the socket. It provides a common set of functions to support a variety of protocols.

    Communication via the network stack needs to socket to operate. Linux in the socket structure is struct sock, this structure is in linux / include / net / sock.h defined. This huge structure contains all the state information required for a particular socket, including the particular protocol used by the socket on the socket and some of the operations that can be performed.

    Network subsystem is defined by a unique structure of its own functions to understand the available protocols. Each protocol maintains a structure called proto (found in linux / include / net / sock.h in). This structure defines the socket can perform specific actions from the socket layer to the transport layer

    3) Network Protocol

    Linux supports multiple network protocols, can be found in the supported network protocols in in:

    #define AF_UNIX 1 / * Unix domain sockets * /

    #define AF_LOCAL 1 / * POSIX name for AF_UNIX * /

    #define AF_INET 2 / * Internet IP Protocol * /

    #define AF_AX25 3 / * Amateur Radio AX.25 * /

    #define AF_IPX 4 / * Novell IPX

    ... ...

    Wherein each of the protocols supported by the corresponding net_family [] an array, net_family [] is a pointer to an array of structures, each of which is a structure pointer to a structure net_proto_family

    struct net_proto_family {

    int family;

    int (* create) (struct socket * sock, int protocol);

    short authentication;

    short encryption;

    short encrypt_net;

    struct module * owner;

    }; This structure registered information about the protocol.

    4) Device independent interface

    Device-independent interface is implemented by net_device implemented. Any device and is independent interface overlay communication through net_device equipment.

    It has a number of agreements with various functions of hardware devices connected together. This layer provides a common set of functions for the underlying network device driver to use, so they can operate on the high-level protocol stack.

    First, the device driver may or by calling register_netdevice unregister_netdevice register or log in the kernel. The caller first fill net_device structure and then passes this structure to register. Kernel calls its init function (if the definition of this function), and then perform a sanity check, and creates a sysfs entry, and then add a new device to the device list (list of active devices in the kernel). In linux / include / linux / netdevice.h net_device can be found in this structure. These functions are in linux / net / core / dev.c implemented.

    Sk_buff sent from the protocol layer to the device, you need to use dev_queue_xmit function. This function can be queued for sk_buff, thereby performing the low-level device drivers, a final transmission (use sk_buff referenced net_device or sk_buff-> dev defined network equipment). dev structure contains a method called hard_start_xmit, wherein the preservation of driver functions initiated sk_buff transport used.

    The received message is usually performed using netif_rx. When the underlying device driver receives a packet (contained in the allocated sk_buff in), by calling netif_rx will sk_buff will be uploaded to the network layer. Then, this function will sk_buff by netif_rx_schedule queued in the upper layer protocol queue for later processing. You can find dev_queue_xmit and netif_rx function in linux / net / core / dev.c in.

    5) Device Drivers

    The bottom of the network stack is responsible for managing the physical network device driver device. For example, SLIP driver package using serial and Ethernet drivers for the Ethernet device is this layer of the device.

    During initialization, the device driver will be assigned a net_device structure, and then use the program must be initialized. These programs are a dev-> hard_start_xmit, which defines how to sk_buff upper queued for transmission. The parameters of this program is sk_buff. The operation of this function depends on the underlying hardware, but usually sk_buff described packets are moved to hardware ring or queue. Is the same as the device-independent layer as described, for NAPI-compliant network driver, the frame is received and used netif_rx netif_receive_skb interface. NAPI driver will have the ability to make some of the underlying hardware limitations.

Analysis of the kernel code:

1. Send UDP packets

In the application

() Function to create a socket by socket, then write () function writes data socket sent to speak

In the kernel:

a. In the system call level and protocol-independent layer

First, find the application in the kernel entry through socket_file_ops structure, its function is sock_aio_write, immediately call do_sock_write ---__ sock_sendmsg ---__ sock_sendmsg_nosec

b. at the network protocol layer

Call udp_sendmsg --- ip_route_output_flow (routing) udp_flush_pending_frames --- ip_flush_pending_frames (ip protocol entrance) --- ip_local_out --- dst_output --- ip_finish_output --- ip_finish_output2 --- arp_generic_ops-> neigh_resolve_output (established neighbor information)

c. In the device-independent interface

Call dev_queue_ximt --- dev_hard_start_xmit

d. in the driver layer

Call ndo_start_xmit

2. Receive IP packets

In the application

Recvmsg function call through the system to obtain the contents of the package

In the kernel:

After the card receives a packet interruption by netif_rx (here trigger a soft interrupt, when the processor is idle reprocessing) function package handed upper netif_rx_action (except for the driver layer, above the entrance to four total), continue to call netif_receive_skb (which is determined by the processing of the protocol packet) --- deliver_skb, then the packet submitted to the ip protocol layer processing (ip_rcv-ip protocol stack layer processing entrance), there followed threw udp protocol layer processing (udp_rcv- udp protocol stack layer processing entrance), after udp layer processed, submitted to the sock-> ops-> recvmsg, namely recvmsg system calls the corresponding function.
     
         
         
         
  More:      
 
- Tomcat installation under Linux (Server)
- Linux disk and File System Concepts (Linux)
- Oracle 12c detailing the new features (Database)
- High-performance open-source http accelerator Varnish introduce (Server)
- Linux performance monitoring - CPU, Memory, IO, Network (Linux)
- CentOS 7 Add yum source (Linux)
- Docker command Detailed (Linux)
- What happens after the MySQL disk space is full (Database)
- Plasma 5.4 How to install on Kubuntu 15.04 (Linux)
- Use netcat [nc] command on Linux and Unix port scan (Server)
- Linux Mint 17 set up the Ruby environment (Linux)
- Keepalived achieve high availability Nginx Reverse Proxy (Server)
- BusyBox making the file system (Linux)
- CentOS 7 virt-manager can not connect a local hypervisor (Linux)
- C ++ hash function (Programming)
- Android memory optimization of the optimal load Bitmap (Linux)
- Linux rpm command Detailed (Linux)
- Repair Maven project developed default Maven Plugin folder (Linux)
- sa weak passwords intrusion prevention (Linux)
- grep search from files and display the file name (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.