HomeFreeBSD

Update udp6_output() inp locking to avoid concurrency issues with

Description

Update udp6_output() inp locking to avoid concurrency issues with
route cache updates.

Bring over locking changes applied to udp_output() for the route cache
in r297225 and fixed in r306559 which achieve multiple things:
(1) acquire an exclusive inp lock earlier depending on the expected

conditions; we add a comment explaining this in udp6,

(2) having acquired the exclusive lock earlier eliminates a slight

possible chance for a race condition which was present in v4 for
multiple years as well and is now gone, and

(3) only pass the inp_route6 to ip6_output() if we are holding an

exclusive inp lock, so that possible route cache updates in case
of routing table generation number changes can happen safely.

In addition this change (as the legacy IP counterpart) decomposes the
tracking of inp and pcbinfo lock and adds extra assertions, that the
two together are acquired correctly.

PR: 230950
Reviewed by: karels, markj
Approved by: re (gjb)
Pointyhat to: bz (for completely missing this bit)
Differential Revision: https://reviews.freebsd.org/D17230