Linux Kernel Routing
Fleetinglinux kernel routing
routing tables
- External reference: http://linux-ip.net/html/routing-tables.html
Linux kernel 2.2 and 2.4 support multiple routing tables
multiple routing table system provides a flexible infrastructure on top of which to implement policy routing
Each routing table still operates in the traditional and expected fashion
The two routing tables normally employed are table 255, the local routing table, and table 254, the main routing table.
The ip route and ip rule commands have built in support for the special tables main and local. Any other routing tables can be referred to by number or an administratively maintained mapping file, /etc/iproute2/rt_tables.
Aside from the local routing table, which is maintained by the kernel, and the main routing table which is partially maintained by the kernel, all routing tables are controlled by the administrator or routing software. All routes on a machine can be changed or removed.
two auto managed default tables, main and local
two commonly used routing tables (the local and main routing tables), the kernel supports up to 252 additional routing tables
local table shows broadcast addresses and locally hosted IP
Normally, the local routing table should not be manipulated, but it is available for viewing
The first common use is the specification of broadcast address, necessary only for link layers which support broadcast addressing. The second common type of entry in a local routing table is a route to a locally hosted IP.
main table to deal with new interfaces
The main routing table is the routing table most people think of when considering a linux routing table.
Similarly to the local table, the main table is populated automatically by the kernel when new interfaces are brought up with IP addresses.
route selection
-
External reference: http://linux-ip.net/html/routing-selection.html
Example 4.5. Listing the Routing Policy Database (RPDB)[root@isolde]# ip rule show
- 0: from all lookup local
- 32766: from all lookup main
- 32767: from all lookup 253
pseudo code
Example 4.4. Routing Selection Algorithm in Pseudo-codeif packet.routeCacheLookupKey in routeCache : route = routeCache[ packet.routeCacheLookupKey ] else for rule in rpdb : if packet.rpdbLookupKey in rule : routeTable = rule[ lookupTable ] if packet.routeLookupKey in routeTable : route = route_table[ packet.routeLookup_key ]
routing policy database
- External reference: http://linux-ip.net/html/routing-rpdb.html
routing policy database (RPDB) controls the order in which the kernel searches through the routing tables
kernel iterates over each rule in turn until the packet to be routed matches a rule. When this happens the kernel follows the instructions in that rule
Typically, this causes the kernel to perform a route lookup in a specified routing table.
If a matching route is found in the routing table, the kernel uses that route. If no such route is found, the kernel returns to traverse the RPDB again, until every option has been exhausted