IPv4 Message Processing Flow
1, the physical Layer network card receives the message, generates the interrupt to enter the interrupt processing program: Net_interrupt, the judgment interruption is from receives to the packet raises, the control right transfers to NET_RX;
2, the NET_RX function assigns a new SK_BUF, removes the packet contents from the network card to the memory;
3. NETIF_RX is responsible for placing the received packets on a CPU-specific wait queue, marking soft interrupts: NET_RX_SOFTIRQ, and exiting the interrupt context;
4. Net_rx_action takes a socket buffer (grouping) from the waiting queue, parses the grouping type so that packets are passed to the network layer's receive function according to the grouping type, such as IP_RCV;
5, IP_RCV inspection packet, including checksum consistency, whether the packet reached the minimum length of IP header, the protocol number of the packet is IPv4), after the check call NetFilter Hook (nf_ip_pre_route), so that the user space can operate on the packet data, After the hook position processing is complete (the groupings may have been modified), routing (ip_route_input) is required for further processing, local processing (ip_local_deliver) or packet forwarding (ip_forward);
6a, Ip_local_deliver, if the IP is fragmented, call Ip_defrag to regroup the parts of the Shard grouping, and each shard belonging to the same group is saved in a separate wait queue until all shards arrive, ip_frag_ Reasm the individual shards together, releasing the socket buffer, leaving the Shard cache (the kernel manages individual shards belonging to a single packet in a separate cache), and if the grouped shards do not reach all, IP_DEFRAG returns a null pointer, terminating the packet processing of the network layer, After all shards have arrived, resume processing;
7a, after the grouping shard merge completes, calls NetFilter hooks nf_ip_local_in, restores in the Ip_local_deliver_finish function the processing, invokes the transport layer corresponding receiving routine, TCP_V4_RCV/UDP _rcv
6b, Ip_forward, packet forwarding: If the target computer is not on the local network, the neighboring network structure and associated egress path information is required (routing table provided, routing table is implemented and managed by the kernel through a variety of data structures), Ip_forward discards the grouping at ttl<=1. Otherwise, the NetFilter hook Nf_if_forward is called, and the kernel resumes processing in ip_forward_finish, and the packet is passed to the Send function that was selected during routing and saved in Skb->dst->output.
8, Ip_queue_xmit (the network layer sends the data function), looks for the route which can use for this grouping, when sends the first grouping, the kernel needs to look for a new route. After Ip_send_check generates checksums for the packet, the kernel calls NetFilter hook nf_ip_local_out, and then calls the Dst_output function (skb->dst->output:ip_output)
9, Ip_output, first call Hook nf_if_post_routing, followed by Ip_finish_output. If it is necessary to group shards, call Ip_fragment, otherwise, call Ip_finish_output2 directly, the function calls the function set by the routing layer when there is enough space to hold the hardware header dst->neighbour-> Output (usually pointing to dev_queue_xmit)
SOURCE Location: Include/net
Related documents: Skbuff.h NET/CORE/DEV.C
Correlation function: Register_netdev
Related commands: Ls-l/sys/class/net
TCP/IP Model: Application layer (HTTP, FTP), Transport layer (TCP, UDP), Network layer (IP, ICMP, IGMP), Physical layer (MAC)
Physical layer in Linux as a network card driver, struct Net_device describes the network card, the physical layer interface through DMAC to determine whether to send and receive messages (multicast, broadcast and unicast), fast turn (Find Fast-forwarding table items forward messages)
The network layer is responsible for routing packets, grouping, assigning IP addresses,
The transport layer is responsible for building services that are either connection-oriented or non-connected
Application layer uses (Ip_addr,port) unique identities to provide real-world applications such as HTTP, FTP, POP3, Telnet, etc.
In order to guarantee the performance of the message processing during the sending and receiving, avoid copying the packet data between the layers, the kernel uses a special struct struct sk_buff description message, and uses the Sk_buff_head header to implement the waiting queue of the socket buffer for managing the grouping (bidirectional loop list)
Linux Web Learning