"In-depth understanding of Linux Network Technology Insider" reading notes---routing table

Source: Internet
Author: User

Basic concepts of routing tables

1. Routing is described by a combination of several different data structures, each representing different parts of the routing information. For example, a fib_node corresponds to a separate subnet, and a fib_alias corresponds to a route. The reason for this is that multiple routes can be distinguished by just a subset of the fields. Instead of maintaining a large and bloated structure, the routing subsystem disperses the routes into fragments, which makes it easier to share common information among similar routes, thus separating out different functions and defining a clearer interface between these functions.

The relationship between data structures is as follows: The fib_table structure consists of a vector of 33 pointers, each corresponding to a netmask and pointing to a data structure of type Fn_zone. The Fn_zone structure makes the routing a hash table, with each individual subnet corresponding to a Fib_node instance, identified by a variable fn_key, for example, a subnet 10.1.1.0/24,fn_key of 10.1.1. The different routes of the same destination subnet share the same fib_node, each route has its own fib_alias structure, and each Fib_alias instance is associated with a fib_info structure that holds the actual routing information. It is important to note that Fib_alias and Fib_info are not a one-to-none association, and multiple Fib_alias structures may share the same fib_info structure. For example, there are five routes to different destination networks that happen to use the same next-hop gateway, so the next hop is the same for all five routes, so you can share the same next-hop message. So there are five fib_node structures and five fib_alias structures in this case, but there is only one fib_info structure.

Each fib_info structure can contain one or more fib_nh structures, each FIB_NH structure represents the next hop router, and the information for a next-hop router includes which device can reach the router.

2. Inserting a new route into the routing table is implemented through the Fn_hash_insert function, in fact, there is also a trailing append (append), header append (prepend), change (replace) operation for the processing route, and a call to this function. These different operations are distinguished by the incoming nlm_f_xxx identity parameter. The removal of a route is done by Fn_hash_delete, and it is simpler to delete a route than to add a route because there is only one operation for deleting a route

3, garbage collection: Under certain conditions, Fib_sync_down will be the variable routing table, set the Rtnh_f_dead identity to mark the route entry that satisfies the deletion condition. After that, call Fib_flush to traverse the routing table again and remove the route entry that has the flag set. Note: There is no periodic function to clean up the routing table.

4, for the lookup of the route, always search the route cache first, when the route cache is not found, through the Ip_route_input_slow and Ip_route_output_slow functions to find the routing table

5, regardless of the direction of traffic, are using Fib_lookup to find the routing table, the Fib_lookup function is provided for each routing table contains a Lookup function package function, when Policy routing is not supported, the LOOKUP function version is for the local table and the main table, When Policy routing is supported, the logic is more complex and needs to find the routing table provided by the policy route.

6, all the routing table lookup, regardless of whether the routing table is provided by policy routing, and regardless of traffic direction, is to use Fn_hash_lookup to find. Fn_hash_lookup searches for a fib_node instance that can route packets to a specific destination. Traverse the Fn_zone, and then through the Fn_key as the keyword, find the fn_zone in the hash table corresponding to the Fib_node. After that, it also needs to examine each potential route entry to find a route that matches the other fields in the input parameter struct FLOWI *FLP, which is done by Fib_semantic_match

Fib_semantic_match is called to discover whether there are route entries that match all fields of the search keyword in the route (Fib_alias structure) associated with the given Fib_node.

7. Possible combinations of dst->input and Dst->output as shown:

Input route

The calling procedure for Ip_route_input_slow is as follows:

1, Ip_route_input when calling Fib_lookup to find a successful route, the packet will be sent to the local or forward, but both need to perform some common tasks, such as the reasonableness of the source address check, through the Fib_validate_source to check the deception attempt, Then create and initialize a new cache table entry

"In-depth understanding of Linux Network Technology Insider" reading notes---routing table

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.