Sunday, October 25, 2009

Section 33.6.  Flushing the Routing Cache










33.6. Flushing the Routing Cache




Whenever a change in the system takes place that could cause some of the information in the cache to become out of date, the kernel flushes the routing cache. In many cases, only selected entries are out of date, but to keep things simple the kernel removes all entries. The main events that trigger flushing
are:



A device comes up or goes down


Some addresses that used to be reachable through a given device may not be reachable anymore, or may be reachable through a different device with a better route.


An IP address is added to or removed from a device


We saw in the sections "Adding an IP address" and "Removing an IP address" in Chapter 32 that Linux creates a special route for each locally configured IP address. When an address is removed, any associated route in the cache also has to be removed. The removed address was most likely configured with a netmask different from /32, so all the cache entries associated with addresses within the same subnet should go away[*] as well. Finally, if one of the addresses in the same subnet was used as a gateway for other indirect routes, all of them should go away. Flushing the entire cache is simpler than keeping track of all of these possible cases.

[*] This is not true when you remove a secondary address. See the section "Removing an IP address" in Chapter 32.


The global forwarding status, or the forwarding status of a device, has changed


If you disable forwarding, you need to remove all the cached routes that were used to forward traffic. See the section "Enabling and Disabling Forwarding" in Chapter 36.


A route is removed


All the cached entries associated with the deleted route need to be removed.


An administrative flush is requested via the /proc interface


This is described in the section "The /proc/sys/net/ipv4/route Directory" in Chapter 36.


The routine used to flush the cache is rt_run_flush, but it is never called directly. Requests to flush the cache are done via rt_cache_flush, which will either flush the cache right away or start a timer, depending on the value of the input timeout provided by the caller:



Less than 0


The cache is flushed after the number of seconds specified by the kernel parameter ip_rt_min_delay, which can be tuned via /proc as described in the section "The /proc/sys/net/ipv4/route Directory" in Chapter 36.


0


The cache is flushed right away.


Greater than 0


The cache is flushed after the specified amount of time.


Once a flush request is submitted, a flush is guaranteed to take place within ip_rt_max_delay seconds, which is set to 8 by default. When a flush request is submitted and there is already one pending, the timer is restarted to reflect the new request; however, the new request cannot ask the timer to expire later than ip_rt_max_delay seconds since the previous timer was fired. This is accomplished by using the global variable rt_deadline.


In addition, the cache is periodically flushed by means of a periodic timer, rt_secret_timer, that expires every ip_rt_secret_interval seconds (see the section "The /proc/sys/net/ipv4/route Directory" in Chapter 36 for its default value). When the timer expires, the handler rt_secret_rebuild flushes the cache and restarts the timer. ip_rt_secret_interval is configurable via /proc.












No comments:

Post a Comment