Simplify ifa/ifp refcounting in the routing stack.
authorAlexander V. Chernikov <melifaro@FreeBSD.org>
Mon, 22 Feb 2021 21:42:27 +0000 (21:42 +0000)
committerAlexander V. Chernikov <melifaro@FreeBSD.org>
Mon, 22 Feb 2021 23:37:59 +0000 (23:37 +0000)
commit596417283722ee62ed17aed1c875ad90c01cbb0e
tree11e31c33043680edd9b442cac726499d8268f3fc
parent7563019bc69301a382abefbac3b0fea1d876410e
Simplify ifa/ifp refcounting in the routing stack.

The routing stack control depends on quite a tree of functions to
 determine the proper attributes of a route such as a source address (ifa)
 or transmit ifp of a route.

When actually inserting a route, the stack needs to ensure that ifa and ifp
 points to the entities that are still valid.
Validity means slightly more than just pointer validity - stack need guarantee
 that the provided objects are not scheduled for deletion.

Currently, callers either ignore it (most ifp parts, historically) or try to
 use refcounting (ifa parts). Even in case of ifa refcounting it's not always
 implemented in fully-safe manner. For example, some codepaths inside
 rt_getifa_fib() are referencing ifa while not holding any locks, resulting in
 possibility of referencing scheduled-for-deletion ifa.

Instead of trying to fix all of the callers by enforcing proper refcounting,
 switch to a different model.
As the rib_action() already requires epoch, do not require any stability guarantees
 other than the epoch-provided one.
Use newly-added conditional versions of the refcounting functions
 (ifa_try_ref(), if_try_ref()) and fail if any of these fails.

Reviewed by: donner
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D28837
sys/net/route.c
sys/net/route/nhop_ctl.c
sys/net/route/route_ctl.c
sys/net/route/route_ifaddrs.c