carp_detach() calls carp_multicast_cleanup() with the softc mutex held.
in_leavegroup() and in6_leavegroup() take in_multi_sx and in6_multi_sx,
so removing the last CARP address of a family from an interface gives:
lock order reversal: (sleepable after non-sleepable)
1st carp_softc (carp_softc, sleep mutex) @ sys/netinet/ip_carp.c:2329
2nd in_multi_sx (in_multi_sx, sx) @ sys/netinet/in_mcast.c:1280
and the same with in6_multi_sx for IPv6.
The memberships belong to the carp_if and are protected by carp_sx,
which carp_detach() holds throughout; carp_attach() already joins the
groups without the softc lock. Leave them once the softc is unlocked
or destroyed, before the carp_if may be freed. The groups of a family
are left only when no CARP address of that family remains on the
interface, and only softcs with an address of a family send
advertisements through its multicast options, so no sender uses them
by then.
Fixes: f3e1324b41e5 ("Separate list manipulation locking from...")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")