freenode
Kernel & Low-Level

IPv6 route caches can ignore newer routes indefinitely

David Ahern proposes validating destinations against the namespace route generation, the way IPv4 already does, after a stale cache entry bypassed a more-specific route.

Linux can keep using an IPv6 route after a more specific one has been installed, and keep doing so until the cached destination is dropped for some other reason. David Ahern, in an RFC posted to the kernel networking list, says the bug is in when the cache records its validity token, not in any one cache user, and that OpenVPN hit it in practice.

IPv6 destinations are checked against a cookie taken from the routing node that produced the route. That cookie is sampled when a socket, a transform bundle, or another cache stores the destination, which is later than the lookup that found it. If another CPU inserts a more specific route in that window, for example a blackhole for a single address, and bumps the node's serial number, the holder can record the new number against the old destination. The next check then sees a match and accepts a route that should have been superseded. Because the same late sampling exists in every long-lived cache, including sockets, IPsec bundles, SCTP, the flow table, IPVS, and RDMA over Ethernet, patching each caller would leave the next one exposed.

Ahern's series moves validity into the destination itself, matching IPv4. Every destination would carry the network namespace's route generation from the moment it was built, and the check would compare that stamp with the current generation. Holders would no longer supply their own token. The generation is sampled before the forwarding table is walked and carried with the lookup result, so a change that lands between the walk and allocation cannot be folded into the stamp. Writers bump the generation only after the new route is visible, so a lookup that read the old tree cannot have sampled the new value.

Shared destinations are never re-stamped. Per-CPU and exception entries are used by every socket and cache that holds them; refreshing one would make a stale route look valid again for all of them. A stale per-CPU entry is dropped and rebuilt. A stale exception is treated as a miss.

The series also narrows what a generation bump means. When a default router's neighbour fails, only that destination is cleared, not every route under the node, because a failing router can hit this path on every packet. Two nexthop-group updates that previously left IPv6 destinations valid, replacing a member used only through a group, and removing a member without republishing a new generation, now bump when IPv6 routes use that nexthop. Path-MTU and redirect exceptions no longer invalidate every destination in the namespace; they clear only the per-CPU destinations of the affected nexthop, as IPv4 already does, so a burst of packet-too-big messages does not force every socket to look up its route again. Route dumps, which notice tree changes through a node serial number, get a separate per-table exception counter so they still restart when an exception is inserted on the root without a namespace-wide bump.

The generation bump itself becomes a counter increment, as on IPv4, instead of a walk that rewrites a serial number on every node of every table. Address, nexthop, and rule changes stop touching the serial numbers dumps use, so a dump is no longer restarted by events that do not change the tree. The series is an RFC and has not been merged.