summaryrefslogtreecommitdiff
path: root/sys/netinet/ip_mroute.c
diff options
context:
space:
mode:
authorVitaliy Makkoveev <mvs@cvs.openbsd.org>2024-02-11 18:14:28 +0000
committerVitaliy Makkoveev <mvs@cvs.openbsd.org>2024-02-11 18:14:28 +0000
commitbb062a4e741dca51d854faeca9d0ff736ac0b299 (patch)
tree884985284b6b808580fef5b1f4322a9cdd4a0bba /sys/netinet/ip_mroute.c
parent20022b34fb3a0689e5e431c5b4452768f5022a4d (diff)
Use `sb_mtx' instead of `inp_mtx' in receive path for inet sockets.
In soreceve(), we only touch `so_rcv' socket buffer, which has it's own `sb_mtx' mutex(9) for protection. So, we can avoid solock() in this path - it's enough to hold `sb_mtx' in soreceive() and around corresponding sbappend*(). But not right now :) This time we use shared netlock for some inet sockets in the soreceive() path. To protect `so_rcv' buffer we use `inp_mtx' mutex(9) and the pru_lock() to acquire this mutex(9) in socket layer. But the `inp_mtx' mutex belongs to the PCB. We initialize socket before PCB, tcp(4) sockets could exist without PCB, so use `sb_mtx' mutex(9) to protect sockbuf stuff. This diff mechanically replaces `inp_mtx' by `sb_mtx' in the receive path. Only for sockets which already use `inp_mtx'. All other sockets left as is. They will be converted later. Since the `sb_mtx' is optional, the new SB_MTXLOCK flag introduced. If this flag is set on `sb_flags', the `sb_mtx' mutex(9) should be taken. New sb_mtx_lock() and sb_mtx_unlock() was introduced to hide this check. They are temporary and will be replaced by mtx_enter() when all this area will be converted to `sb_mtx' mutex(9). Also, the new sbmtxassertlocked() function introduced to throw corresponding assertion for SB_MTXLOCK marked buffers. This time only sbappendaddr() calls it. This function is also temporary and will be replaced by MTX_ASSERT_LOCKED() later. ok bluhm
Diffstat (limited to 'sys/netinet/ip_mroute.c')
-rw-r--r--sys/netinet/ip_mroute.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c
index e318493fcd0..3e9b00ec265 100644
--- a/sys/netinet/ip_mroute.c
+++ b/sys/netinet/ip_mroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_mroute.c,v 1.140 2023/12/06 09:27:17 bluhm Exp $ */
+/* $OpenBSD: ip_mroute.c,v 1.141 2024/02/11 18:14:26 mvs Exp $ */
/* $NetBSD: ip_mroute.c,v 1.85 2004/04/26 01:31:57 matt Exp $ */
/*
@@ -1051,12 +1051,11 @@ int
socket_send(struct socket *so, struct mbuf *mm, struct sockaddr_in *src)
{
if (so != NULL) {
- struct inpcb *inp = sotoinpcb(so);
int ret;
- mtx_enter(&inp->inp_mtx);
+ mtx_enter(&so->so_rcv.sb_mtx);
ret = sbappendaddr(so, &so->so_rcv, sintosa(src), mm, NULL);
- mtx_leave(&inp->inp_mtx);
+ mtx_leave(&so->so_rcv.sb_mtx);
if (ret != 0) {
sorwakeup(so);