From 94b0822958d17d21744eef4d9f216afecd44427e Mon Sep 17 00:00:00 2001 From: mvs Date: Mon, 12 Feb 2024 22:48:27 +0000 Subject: [PATCH] Pass protosw instead of domain structure to soalloc() to get real `pr_type'. The corresponding domain is referenced as `pr_domain'. Otherwise dp->dom_protosw->pr_type of inet sockets always points to inetsw[0]. ok bluhm --- sys/kern/uipc_socket.c | 9 +++++---- sys/kern/uipc_socket2.c | 4 ++-- sys/sys/socketvar.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 6d7422c798a..85032afee9d 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.319 2024/02/11 21:36:49 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.320 2024/02/12 22:48:27 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -132,8 +132,9 @@ soinit(void) } struct socket * -soalloc(const struct domain *dp, int wait) +soalloc(const struct protosw *prp, int wait) { + const struct domain *dp = prp->pr_domain; struct socket *so; so = pool_get(&socket_pool, (wait == M_WAIT ? PR_WAITOK : PR_NOWAIT) | @@ -153,7 +154,7 @@ soalloc(const struct domain *dp, int wait) switch (dp->dom_family) { case AF_INET: case AF_INET6: - switch (dp->dom_protosw->pr_type) { + switch (prp->pr_type) { case SOCK_DGRAM: case SOCK_RAW: so->so_rcv.sb_flags |= SB_MTXLOCK; @@ -188,7 +189,7 @@ socreate(int dom, struct socket **aso, int type, int proto) return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); - so = soalloc(pffinddomain(dom), M_WAIT); + so = soalloc(prp, M_WAIT); so->so_type = type; if (suser(p) == 0) so->so_state = SS_PRIV; diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 9322cd2735c..70f7c150f76 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.143 2024/02/11 18:14:26 mvs Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.144 2024/02/12 22:48:27 mvs Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -188,7 +188,7 @@ sonewconn(struct socket *head, int connstatus, int wait) return (NULL); if (head->so_qlen + head->so_q0len > head->so_qlimit * 3) return (NULL); - so = soalloc(head->so_proto->pr_domain, wait); + so = soalloc(head->so_proto, wait); if (so == NULL) return (NULL); so->so_type = head->so_type; diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index f1922f6b6d7..9ef1cafe71a 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.123 2024/02/11 18:14:27 mvs Exp $ */ +/* $OpenBSD: socketvar.h,v 1.124 2024/02/12 22:48:27 mvs Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -375,7 +375,7 @@ int soconnect(struct socket *, struct mbuf *); int soconnect2(struct socket *, struct socket *); int socreate(int, struct socket **, int, int); int sodisconnect(struct socket *); -struct socket *soalloc(const struct domain *, int); +struct socket *soalloc(const struct protosw *, int); void sofree(struct socket *, int); int sogetopt(struct socket *, int, int, struct mbuf *); void sohasoutofband(struct socket *); -- 2.20.1