HomeFreeBSD

Simplify ifa/ifp refcounting in the routing stack.

Description

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
Differential Revision: https://reviews.freebsd.org/D28837

(cherry picked from commit 596417283722ee62ed17aed1c875ad90c01cbb0e)

Details

Provenance
melifaroAuthored on Feb 22 2021, 9:42 PM
Reviewer
donner
Differential Revision
D28837: Simplify ifa/ifp refcounting in the routing stack.
Parents
rG04e967d7270e: Add if_try_ref() to simplify refcount handling inside epoch.
Branches
Unknown
Tags
Unknown