opnsense-src/sys/netinet6
Robert Watson fa046d8774 Decompose the current single inpcbinfo lock into two locks:
- The existing ipi_lock continues to protect the global inpcb list and
  inpcb counter.  This lock is now relegated to a small number of
  allocation and free operations, and occasional operations that walk
  all connections (including, awkwardly, certain UDP multicast receive
  operations -- something to revisit).

- A new ipi_hash_lock protects the two inpcbinfo hash tables for
  looking up connections and bound sockets, manipulated using new
  INP_HASH_*() macros.  This lock, combined with inpcb locks, protects
  the 4-tuple address space.

Unlike the current ipi_lock, ipi_hash_lock follows the individual inpcb
connection locks, so may be acquired while manipulating a connection on
which a lock is already held, avoiding the need to acquire the inpcbinfo
lock preemptively when a binding change might later be required.  As a
result, however, lookup operations necessarily go through a reference
acquire while holding the lookup lock, later acquiring an inpcb lock --
if required.

A new function in_pcblookup() looks up connections, and accepts flags
indicating how to return the inpcb.  Due to lock order changes, callers
no longer need acquire locks before performing a lookup: the lookup
routine will acquire the ipi_hash_lock as needed.  In the future, it will
also be able to use alternative lookup and locking strategies
transparently to callers, such as pcbgroup lookup.  New lookup flags are,
supplementing the existing INPLOOKUP_WILDCARD flag:

  INPLOOKUP_RLOCKPCB - Acquire a read lock on the returned inpcb
  INPLOOKUP_WLOCKPCB - Acquire a write lock on the returned inpcb

Callers must pass exactly one of these flags (for the time being).

Some notes:

- All protocols are updated to work within the new regime; especially,
  TCP, UDPv4, and UDPv6.  pcbinfo ipi_lock acquisitions are largely
  eliminated, and global hash lock hold times are dramatically reduced
  compared to previous locking.
- The TCP syncache still relies on the pcbinfo lock, something that we
  may want to revisit.
- Support for reverting to the FreeBSD 7.x locking strategy in TCP input
  is no longer available -- hash lookup locks are now held only very
  briefly during inpcb lookup, rather than for potentially extended
  periods.  However, the pcbinfo ipi_lock will still be acquired if a
  connection state might change such that a connection is added or
  removed.
- Raw IP sockets continue to use the pcbinfo ipi_lock for protection,
  due to maintaining their own hash tables.
- The interface in6_pcblookup_hash_locked() is maintained, which allows
  callers to acquire hash locks and perform one or more lookups atomically
  with 4-tuple allocation: this is required only for TCPv6, as there is no
  in6_pcbconnect_setup(), which there should be.
- UDPv6 locking remains significantly more conservative than UDPv4
  locking, which relates to source address selection.  This needs
  attention, as it likely significantly reduces parallelism in this code
  for multithreaded socket use (such as in BIND).
- In the UDPv4 and UDPv6 multicast cases, we need to revisit locking
  somewhat, as they relied on ipi_lock to stablise 4-tuple matches, which
  is no longer sufficient.  A second check once the inpcb lock is held
  should do the trick, keeping the general case from requiring the inpcb
  lock for every inpcb visited.
- This work reminds us that we need to revisit locking of the v4/v6 flags,
  which may be accessed lock-free both before and after this change.
- Right now, a single lock name is used for the pcbhash lock -- this is
  undesirable, and probably another argument is required to take care of
  this (or a char array name field in the pcbinfo?).

This is not an MFC candidate for 8.x due to its impact on lookup and
locking semantics.  It's possible some of these issues could be worked
around with compatibility wrappers, if necessary.

Reviewed by:    bz
Sponsored by:   Juniper Networks, Inc.
2011-05-30 09:43:55 +00:00
..
dest6.c
frag6.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
icmp6.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
icmp6.h
in6.c The statically configured (permanent) ARP entries are removed when an 2011-05-20 19:12:20 +00:00
in6.h correct variable type name in comment 2011-04-25 09:00:52 +00:00
in6_cksum.c Fix more continuous/contiguous typos (cf. r215955) 2010-11-27 21:51:39 +00:00
in6_gif.c
in6_gif.h
in6_ifattach.c Add IFT_L2VLAN to the list that is capable of supplying the ingredients 2010-12-22 11:58:31 +00:00
in6_ifattach.h
in6_mcast.c
in6_pcb.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
in6_pcb.h Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
in6_proto.c Add FEATURE() definitions for IPv4 and IPv6 so that we can use 2011-05-25 00:34:25 +00:00
in6_rmx.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
in6_src.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
in6_var.h
ip6.h
ip6_ecn.h
ip6_forward.c
ip6_id.c
ip6_input.c Fix more continuous/contiguous typos (cf. r215955) 2010-11-27 21:51:39 +00:00
ip6_ipsec.c Make IPsec compile without INET adding appropriate #ifdef checks. 2011-04-27 19:28:42 +00:00
ip6_ipsec.h
ip6_mroute.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
ip6_mroute.h
ip6_output.c Fix more continuous/contiguous typos (cf. r215955) 2010-11-27 21:51:39 +00:00
ip6_var.h Fix more continuous/contiguous typos (cf. r215955) 2010-11-27 21:51:39 +00:00
ip6protosw.h
mld6.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
mld6.h
mld6_var.h
nd6.c - Merge changes to the base system to support OFED. These include 2011-03-21 09:40:01 +00:00
nd6.h
nd6_nbr.c Fix IPv6 ND. After r219562 we in nd6_ns_input() were erroneously always 2011-04-17 16:07:08 +00:00
nd6_rtr.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
pim6.h
pim6_var.h
raw_ip6.c optp may be NULL. 2010-08-20 17:52:49 +00:00
raw_ip6.h
route6.c
scope6.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
scope6_var.h
sctp6_usrreq.c Remove code with any effect. 2011-05-03 20:34:02 +00:00
sctp6_var.h 1) Typo correction in comments and one spacing change. 2011-02-05 12:12:51 +00:00
send.c After some off-list discussion, revert a number of changes to the 2010-11-22 19:32:54 +00:00
send.h
tcp6_var.h
udp6_usrreq.c Decompose the current single inpcbinfo lock into two locks: 2011-05-30 09:43:55 +00:00
udp6_var.h