Linux kernel Analysis

Source: Internet
Author: User
Tags hash

routing table

There are routing table fib_table_hash and routing cache table rt_hash_table in the kernel. The Routing cache table is primarily designed to speed up routing lookups, and each routing query first finds the routing cache and then finds the routing table. This and cache is a truth, cache storage of the most recently used routing items, small capacity, Find Fast; The routing table stores all routing items with large capacity and slow lookups.

First of all, you should understand the meaning of the routing table, the following is the route command to see the routing table:

A route is actually to tell the host to reach a destination address, where the next hop should go. For example, send the 192.168.22.3 message to the Challo by the table, will get the next hop to 192.168.123.254, and then send it out. In the routing table entry, there is also an important attribute-scope, which represents the distance to the destination network.

Routing SCOPE desirable value: Rt_scope_universe, Rt_scope_link, Rt_scope_host

In the process of message forwarding, it is obvious that each forwarding must make the distance to reach the destination network will be smaller or unchanged, or not reach the destination network at all. The scope described above is a good implementation of this feature, in the Lookup routing table, the scope of the table entry must be a smaller or equal scope (for example, Rt_scope_link, the table item scope can only be Rt_scope_link or rt_scope_host).

Routing Caching

Routing caching is used to speed up routing lookups, and when a message or a paper is sent, the routing cache is queried first, and the kernel is organized into a hash table, which is rt_hash_table.

static struct Rt_hash_bucket *rt_hash_table __read_mostly; [NET/IPV4/ROUTE.C]

The hash value is computed by Ip_route_input (), first in the cache operation, through [Src_ip, DST_IP, Iif,rt_genid]

hash = Rt_hash (daddr, Saddr, IIF, Rt_genid (net));

At this point Rt_hash_table[hash].chain is the list of cached table entries to manipulate, such as traversing the list

for (rth = Rt_hash_table[hash].chain; rth; rth = rth->u.dst.rt_next)

So, look up a table entry in the cache, first calculate the hash value, take out the set of table entries, and then traverse the list to find the specified table entry, which needs to match exactly [Src_ip, Dst_ip, IIF, TOS, Mark, net], actually struct Rtable has special properties for cached lookup key values –struct flowi.

/* Cache Lookup keys * *

struct FLOWI fl;

When the table entry is found, the last access time for the table entry is updated and DST is removed

Dst_use (&RTH->U.DST, jiffies);

Skb_dst_set (SKB, &RTH->U.DST);

Routing Cache creation

Inet_init ()-> ip_init ()-> ip_rt_init ()

rt_hash_table = (struct Rt_hash_bucket *)

Alloc_large_system_hash ("IP route Cache",

sizeof (struct rt_hash_bucket),

Rhash_entries,

(totalram_pages >= 128 * 1024)?

15:17,

0,

&rt_hash_log,

&rt_hash_mask,

Rhash_entries? 0:512 * 1024);

Where Rt_hash_mask represents the size of the table, Rt_hash_log = log (Rt_hash_mask), and the structure after the creation is as shown in the figure:

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.