Routing at the IP layer of the Linux protocol stack

Source: Internet
Author: User

Preface:
Actually, this articleArticleI don't know what the name should be. I don't feel like I'm talking about anything. Alas... In fact, my intention is to describe the IP layer of the Linux protocol stack to route data packets. For example, if there are two Nic devices, where should the data packets go?

And so on

...

First, understand the concept of routing cache:
Although the data structure of route table items provides relatively fast QueryProgramBut the cost for running such a query program for each IP packet is still too high. For this reason, the Linux kernel also has a routing cache used to store the results of the most recent forwarding query to make access faster. Each forwarding operation first queries the route cache. Route table items are queried only when the query is not cached. A new route cache is created for the query results.
The routing cache is used to reduce the time for searching route tables. The core of the route cache is the protocol-independent destination cache (DST. The protocol-independent (DST) section in the cache is a set of dst_entry data structures. In the sk_buff struct, struct dst_entry * DST points to a record in the route high-speed cache. This indicates that it contains information about further packet processing (for example, the NIC through which the packet is sent) or MAC header, that is, Mac Source and Destination Address.

 

The figure above is
The Linux networking architecture: Design and Implementation
Network protocols in the Linux Kernel

Prentice Hall August 01,
2004

I have a closer look, and I found it a little inappropriate. See the red part of my painting.

The following figure is used to describe it.

an IP package can enter the IP layer of the Linux protocol stack from three aspects:
1. receive data groups through the NIC. The entry is the ip_rcv () function
.
This part can be considered as receiving.
first, the ip_rcv () function performs some ipprotocol work, such as checking whether the package is local, the package size, and the package inspection;
enable ip_rcv_finish () on the netfilter hook to further process IP groups, for example, who the group is. Call the ip_route_input () function to query the route cache (based on IP addresses, TOS, physical network devices, etc. If not, discard the group) and set DST for sk_buff. Data Packet processing is determined based on DST: Forwarding ip_forward (), local ip_local_deliver (), error ip_error ();
2 upper-layer protocol interfaces, such as TCP/UDP
.
This part can be viewed as sending.
for TCP, ip_queue_xmit (SKB) checks the SKB-> DST route information. If no, for example, the first package of the socket, use ip_route_output () to select a route. Fill in the fields of the IP package, such as version, header length, and TOS.
for some fragments in the middle, see related documents.
next, use ip_finish_ouput2 to set the link layer packet header. If the link layer header is cached (that is, HH is not empty), copy it to SKB. If not, call neigh_resolve_output and obtain it using ARP.
the IP layer can generate an IP packet, for example, ICMP or IGMP.

In short, it seems that, whether it is the occurrence or acceptance of data packets, the dominantThe Linux route table also contains the hardware NIC address (the last entry in the route table ).


The following is a diagram of oreilly. Understanding. Linux. Network. internals. Dec.2005. You can refer to it.






 

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.