HomeFreeBSD

inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()

Description

inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()

A large portion of these functions just determines whether the inpcb can
bind to the address/port. This portion has no side effects, so is a
good candidate to move into its own helper function. This patch does
so, making the callers less complicated and reducing indentation.

While moving this code, also make some changes:

  • Load socket options (SO_REUSEADDR etc.) only once. There is nothing preventing another thread from toggling the socket options, so make this function easier to reason about by avoiding races.
  • When checking whether the bind address is an interface address, make a separate sockaddr rather than temporarily modifying the one passed to in_pcbbind().

Reviewed by: ae, glebius
MFC after: 1 month
Sponsored by: Klara, Inc.
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D47590

(cherry picked from commit 01f8ce83242d7a8e599cf6a78b6277161d79edd4)

Details

Provenance
markjAuthored on Dec 5 2024, 3:00 PM
Reviewer
ae
Differential Revision
D47590: inpcb: Factor out parts of in6_pcbbind() and in_pcbbind_setup()
Parents
rGf1933eda43e6: jail: Handle jail removal in a dedicated thread
Branches
Unknown
Tags
Unknown