Subject: Re: kern/3508 bug: cached ip route and interface up/down.
To: Tad Hunt <>
From: Greg Troxel <>
List: tech-net
Date: 11/13/2002 09:28:19
Perhaps I am being too glib here, but checks for more/less specific
routes sound overly complicated (and probably hard to get right) for
fairly little benefit.  The current scheme does:

  A route is looked up for a host, and cached for later reuse for the
  same host.

Such a scheme is correct if every time a cached route is used, the
same route would have been found by a new search.  Clearing the cached
route every time it is used is safe but inefficient (for back to back
packets with huge table, which is presumably the point).

With this definition of correctness, every time the routing table or
anything else is changed in such a way that changes which route would
be found for the current cached route, the cached route must be
cleared or updated.  The easy and safe solution is to clear the cached
route _every time_ the routing table is changed (which includes
interface up/down due to the network route for the interface), which
surely includes every time that it needs to be cleared.
Routing table changes are expensive enough compared to route lookups
that this doesn't seem like a big efficiency hit.

With this change, cache usage will be correct, rather than the current
situation of accurate enough given that routing table changes are not
incredibly frequent and packets are often to different destinations.

There is a similar problem in caching of SAs.  See sys/netkey/key.c
NetBSD 1.63 (KAME 1.234) line 553 for a similar (but more complex,
since policy can be system default or it could be an unconnected
datagram socket) situation and comment.  The problem fixed by not
using the SA cache actually caused persistent lossage for us (on
FreeBSD 3 at the time, I think).

        Greg Troxel <>