From 92a454d9ed8cb5f1025513f0f8095b74ef856481 Mon Sep 17 00:00:00 2001 From: mvs Date: Mon, 22 Aug 2022 08:08:46 +0000 Subject: [PATCH] Move PRU_ACCEPT request to (*pru_accept)(). ok bluhm@ --- sys/kern/uipc_usrreq.c | 33 ++++++++++++++++----------- sys/net/pfkeyv2.c | 3 +-- sys/net/rtsock.c | 3 +-- sys/netinet/ip_divert.c | 3 +-- sys/netinet/raw_ip.c | 3 +-- sys/netinet/tcp_usrreq.c | 48 +++++++++++++++++++++++++++------------ sys/netinet/tcp_var.h | 3 ++- sys/netinet/udp_usrreq.c | 6 +---- sys/netinet6/ip6_divert.c | 3 +-- sys/netinet6/raw_ip6.c | 3 +-- sys/sys/protosw.h | 8 ++++--- sys/sys/unpcb.h | 3 ++- 12 files changed, 69 insertions(+), 50 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 5669d522772..c927777482b 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.171 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.172 2022/08/22 08:08:46 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -133,6 +133,7 @@ const struct pr_usrreqs uipc_usrreqs = { .pru_bind = uipc_bind, .pru_listen = uipc_listen, .pru_connect = uipc_connect, + .pru_accept = uipc_accept, }; void @@ -244,18 +245,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, unp_disconnect(unp); break; - case PRU_ACCEPT: - /* - * Pass back name of connected socket, - * if it was bound and we are still connected - * (our peer may have closed already!). - */ - so2 = unp_solock_peer(so); - uipc_setaddr(unp->unp_conn, nam); - if (so2 != NULL && so2 != so) - sounlock(so2); - break; - case PRU_SHUTDOWN: socantsendmore(so); unp_shutdown(unp); @@ -551,6 +540,24 @@ uipc_connect(struct socket *so, struct mbuf *nam) return unp_connect(so, nam, curproc); } +int +uipc_accept(struct socket *so, struct mbuf *nam) +{ + struct socket *so2; + struct unpcb *unp = sotounpcb(so); + + /* + * Pass back name of connected socket, if it was bound and + * we are still connected (our peer may have closed already!). + */ + so2 = unp_solock_peer(so); + uipc_setaddr(unp->unp_conn, nam); + + if (so2 != NULL && so2 != so) + sounlock(so2); + 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 1b9d1350a6f..d0bef3e2227 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.238 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.239 2022/08/22 08:08:46 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -358,7 +358,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: - case PRU_ACCEPT: error = EOPNOTSUPP; break; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 867cacbd73e..8350a4de16e 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.338 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.339 2022/08/22 08:08:46 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -234,7 +234,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: - case PRU_ACCEPT: error = EOPNOTSUPP; break; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 3afc2be71c8..8eda87837c8 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.73 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.74 2022/08/22 08:08:46 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -292,7 +292,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, break; case PRU_CONNECT2: - case PRU_ACCEPT: case PRU_DISCONNECT: case PRU_SENDOOB: case PRU_FASTTIMO: diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 68fa0ac0a64..66c096b0b01 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.133 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.134 2022/08/22 08:08:46 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -543,7 +543,6 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, /* * Not supported. */ - case PRU_ACCEPT: case PRU_SENDOOB: case PRU_RCVD: case PRU_RCVOOB: diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index d151eba11aa..0834800503f 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.191 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.192 2022/08/22 08:08:46 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -118,6 +118,7 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_bind = tcp_bind, .pru_listen = tcp_listen, .pru_connect = tcp_connect, + .pru_accept = tcp_accept, }; static int pr_slowhz = PR_SLOWHZ; @@ -236,20 +237,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, tp = tcp_disconnect(tp); break; - /* - * Accept a connection. Essentially all the work is - * done at higher levels; just return the address - * of the peer, storing through addr. - */ - case PRU_ACCEPT: -#ifdef INET6 - if (inp->inp_flags & INP_IPV6) - in6_setpeeraddr(inp, nam); - else -#endif - in_setpeeraddr(inp, nam); - break; - /* * Mark the connection as being incapable of further output. */ @@ -849,6 +836,37 @@ out: return (error); } +/* + * Accept a connection. Essentially all the work is done at higher + * levels; just return the address of the peer, storing through addr. + */ +int +tcp_accept(struct socket *so, struct mbuf *nam) +{ + struct inpcb *inp; + struct tcpcb *tp; + int error; + short ostate; + + soassertlocked(so); + + if ((error = tcp_sogetpcb(so, &inp, &tp))) + return (error); + + if (so->so_options & SO_DEBUG) + ostate = tp->t_state; + +#ifdef INET6 + if (inp->inp_flags & INP_IPV6) + in6_setpeeraddr(inp, nam); + else +#endif + in_setpeeraddr(inp, nam); + + if (so->so_options & SO_DEBUG) + tcp_trace(TA_USER, ostate, tp, tp, NULL, PRU_ACCEPT, 0); + return (error); +} /* * Initiate (or continue) disconnect. diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 6250b3f12ab..56576270c5c 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.144 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.145 2022/08/22 08:08:46 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -717,6 +717,7 @@ int tcp_detach(struct socket *); int tcp_bind(struct socket *, struct mbuf *, struct proc *); int tcp_listen(struct socket *); int tcp_connect(struct socket *, struct mbuf *); +int tcp_accept(struct socket *, struct mbuf *); void tcp_xmit_timer(struct tcpcb *, int); void tcpdropoldhalfopen(struct tcpcb *, u_int16_t); void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int); diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 2f0c795c112..e8135716a73 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.285 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.286 2022/08/22 08:08:46 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1080,10 +1080,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, error = EOPNOTSUPP; break; - case PRU_ACCEPT: - error = EOPNOTSUPP; - break; - case PRU_DISCONNECT: #ifdef INET6 if (inp->inp_flags & INP_IPV6) { diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index e3b0898568d..050894e1610 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.72 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.73 2022/08/22 08:08:46 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -298,7 +298,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, break; case PRU_CONNECT2: - case PRU_ACCEPT: case PRU_DISCONNECT: case PRU_SENDOOB: case PRU_FASTTIMO: diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index d4bd78e1f39..3809f776044 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.153 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.154 2022/08/22 08:08:46 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -660,7 +660,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, /* * Not supported. */ - case PRU_ACCEPT: case PRU_SENDOOB: case PRU_RCVD: case PRU_RCVOOB: diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index f153e455456..549d489174a 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.40 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.41 2022/08/22 08:08:47 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -69,6 +69,7 @@ struct pr_usrreqs { int (*pru_bind)(struct socket *, struct mbuf *, struct proc *); int (*pru_listen)(struct socket *); int (*pru_connect)(struct socket *, struct mbuf *); + int (*pru_accept)(struct socket *, struct mbuf *); }; struct protosw { @@ -291,8 +292,9 @@ pru_connect(struct socket *so, struct mbuf *nam) static inline int pru_accept(struct socket *so, struct mbuf *nam) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_ACCEPT, NULL, nam, NULL, curproc); + if (so->so_proto->pr_usrreqs->pru_accept) + return (*so->so_proto->pr_usrreqs->pru_accept)(so, nam); + return (EOPNOTSUPP); } static inline int diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index 6498168f4f9..c3196329546 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.30 2022/08/21 22:45:55 mvs Exp $ */ +/* $OpenBSD: unpcb.h,v 1.31 2022/08/22 08:08:47 mvs Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -116,6 +116,7 @@ int uipc_detach(struct socket *); int uipc_bind(struct socket *, struct mbuf *, struct proc *); int uipc_listen(struct socket *); int uipc_connect(struct socket *, struct mbuf *); +int uipc_accept(struct socket *, struct mbuf *); void unp_init(void); int unp_bind(struct unpcb *, struct mbuf *, struct proc *); -- 2.20.1