From 621c53d49dfd63bfabc7d7c40d326e408173afe3 Mon Sep 17 00:00:00 2001 From: mvs Date: Thu, 1 Sep 2022 18:21:22 +0000 Subject: [PATCH] Move PRU_CONNECT2 request to (*pru_connect2)(). ok bluhm@ --- sys/kern/uipc_usrreq.c | 41 +++++++++++++++++++++++---------------- sys/net/pfkeyv2.c | 7 +------ sys/net/rtsock.c | 7 +------ sys/netinet/ip_divert.c | 3 +-- sys/netinet/raw_ip.c | 6 +----- sys/netinet/tcp_usrreq.c | 9 +-------- sys/netinet/udp_usrreq.c | 6 +----- sys/netinet6/ip6_divert.c | 3 +-- sys/netinet6/raw_ip6.c | 6 +----- sys/sys/protosw.h | 8 +++++--- sys/sys/unpcb.h | 3 ++- 11 files changed, 39 insertions(+), 60 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 3df75016711..a85c60ff7a8 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.181 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.182 2022/09/01 18:21:22 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -140,6 +140,7 @@ const struct pr_usrreqs uipc_usrreqs = { .pru_send = uipc_send, .pru_abort = uipc_abort, .pru_sense = uipc_sense, + .pru_connect2 = uipc_connect2, }; void @@ -215,7 +216,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct proc *p) { struct unpcb *unp = sotounpcb(so); - struct unpcb *unp2; struct socket *so2; int error = 0; @@ -232,21 +232,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_CONNECT2: - error = unp_connect2(so, (struct socket *)nam); - if (!error) { - unp->unp_connid.uid = p->p_ucred->cr_uid; - unp->unp_connid.gid = p->p_ucred->cr_gid; - unp->unp_connid.pid = p->p_p->ps_pid; - unp->unp_flags |= UNP_FEIDS; - unp2 = sotounpcb((struct socket *)nam); - unp2->unp_connid.uid = p->p_ucred->cr_uid; - unp2->unp_connid.gid = p->p_ucred->cr_gid; - unp2->unp_connid.pid = p->p_p->ps_pid; - unp2->unp_flags |= UNP_FEIDS; - } - break; - case PRU_SOCKADDR: uipc_setaddr(unp, nam); break; @@ -596,6 +581,28 @@ uipc_sense(struct socket *so, struct stat *sb) return (0); } +int +uipc_connect2(struct socket *so, struct socket *so2) +{ + struct unpcb *unp = sotounpcb(so), *unp2; + int error; + + if ((error = unp_connect2(so, so2))) + return (error); + + unp->unp_connid.uid = curproc->p_ucred->cr_uid; + unp->unp_connid.gid = curproc->p_ucred->cr_gid; + unp->unp_connid.pid = curproc->p_p->ps_pid; + unp->unp_flags |= UNP_FEIDS; + unp2 = sotounpcb(so2); + unp2->unp_connid.uid = curproc->p_ucred->cr_uid; + unp2->unp_connid.gid = curproc->p_ucred->cr_gid; + unp2->unp_connid.pid = curproc->p_p->ps_pid; + unp2->unp_flags |= UNP_FEIDS; + + return (0); +} + int uipc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index b1e71cc6c29..a384076d728 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.248 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.249 2022/09/01 18:21:23 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -412,11 +412,6 @@ pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, } switch (req) { - /* no connect, bind, accept. Socket is connected from the start */ - case PRU_CONNECT2: - error = EOPNOTSUPP; - break; - /* minimal support, just implement a fake peer address */ case PRU_SOCKADDR: error = EINVAL; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index a5262ec08f8..ce8e46be628 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.349 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.350 2022/09/01 18:21:23 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -237,11 +237,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, } switch (req) { - /* no connect, bind, accept. Socket is connected from the start */ - case PRU_CONNECT2: - error = EOPNOTSUPP; - break; - /* minimal support, just implement a fake peer address */ case PRU_SOCKADDR: error = EINVAL; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 6d83c594e08..b5d6195df67 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.82 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.83 2022/09/01 18:21:23 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -279,7 +279,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, in_setpeeraddr(inp, addr); break; - case PRU_CONNECT2: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 4bc2d11ae17..58c3325d69c 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.143 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.144 2022/09/01 18:21:23 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -478,10 +478,6 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_CONNECT2: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: in_setsockaddr(inp, nam); break; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 2cede08b16d..350eb598fd7 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.202 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.203 2022/09/01 18:21:23 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -223,13 +223,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - /* - * Create a TCP connection between two sockets. - */ - case PRU_CONNECT2: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: #ifdef INET6 if (inp->inp_flags & INP_IPV6) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 86d05c8f541..02b74513a86 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.297 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.298 2022/09/01 18:21:23 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1089,10 +1089,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, */ switch (req) { - case PRU_CONNECT2: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: #ifdef INET6 if (inp->inp_flags & INP_IPV6) diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 461250d057a..8f1c4763f58 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.81 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.82 2022/09/01 18:21:23 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -285,7 +285,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, in6_setpeeraddr(inp, addr); break; - case PRU_CONNECT2: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index fc685070dde..20b4032cc6c 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.164 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.165 2022/09/01 18:21:23 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -593,10 +593,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, } switch (req) { - case PRU_CONNECT2: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: in6_setsockaddr(in6p, nam); break; diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index ecd56e90290..c9e8bd43d08 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.50 2022/08/31 21:23:02 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.51 2022/09/01 18:21:23 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -81,6 +81,7 @@ struct pr_usrreqs { int (*pru_rcvoob)(struct socket *, struct mbuf *, int); int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); + int (*pru_connect2)(struct socket *, struct socket *); }; struct protosw { @@ -395,8 +396,9 @@ pru_peeraddr(struct socket *so, struct mbuf *addr) static inline int pru_connect2(struct socket *so1, struct socket *so2) { - return (*so1->so_proto->pr_usrreqs->pru_usrreq)(so1, - PRU_CONNECT2, NULL, (struct mbuf *)so2, NULL, curproc); + if (so1->so_proto->pr_usrreqs->pru_connect2) + return (*so1->so_proto->pr_usrreqs->pru_connect2)(so1, so2); + return (EOPNOTSUPP); } #endif diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index de6da21017c..0275d511ca4 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.37 2022/08/28 21:35:12 mvs Exp $ */ +/* $OpenBSD: unpcb.h,v 1.38 2022/09/01 18:21:23 mvs Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -127,6 +127,7 @@ int uipc_send(struct socket *, struct mbuf *, struct mbuf *, struct mbuf *); int uipc_abort(struct socket *); int uipc_sense(struct socket *, struct stat *); +int uipc_connect2(struct socket *, struct socket *); void unp_init(void); int unp_bind(struct unpcb *, struct mbuf *, struct proc *); -- 2.20.1