From: mvs Date: Sun, 21 Aug 2022 17:30:21 +0000 (+0000) Subject: Move PRU_LISTEN request to (*pru_listen)() handler. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cfab0d997bfe35140e70c4bdc0a251f55184426a;p=openbsd Move PRU_LISTEN request to (*pru_listen)() handler. ok bluhm@ --- diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 880e83391d7..4e19579e513 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.169 2022/08/20 23:48:57 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.170 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -131,6 +131,7 @@ const struct pr_usrreqs uipc_usrreqs = { .pru_attach = uipc_attach, .pru_detach = uipc_detach, .pru_bind = uipc_bind, + .pru_listen = uipc_listen, }; void @@ -223,11 +224,6 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - case PRU_LISTEN: - if (unp->unp_vnode == NULL) - error = EINVAL; - break; - case PRU_CONNECT: error = unp_connect(so, nam, p); break; @@ -542,6 +538,16 @@ uipc_bind(struct socket *so, struct mbuf *nam, struct proc *p) return unp_bind(unp, nam, p); } +int +uipc_listen(struct socket *so) +{ + struct unpcb *unp = sotounpcb(so); + + if (unp->unp_vnode == NULL) + return (EINVAL); + 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 00e12d2041c..e61ca87f4bd 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.236 2022/08/20 23:48:57 mvs Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.237 2022/08/21 17:30:21 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -359,7 +359,6 @@ pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m, /* no connect, bind, accept. Socket is connected from the start */ case PRU_CONNECT: case PRU_CONNECT2: - case PRU_LISTEN: case PRU_ACCEPT: error = EOPNOTSUPP; break; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 647b1e8326a..c82433e89a6 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.336 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.337 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -235,7 +235,6 @@ route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, /* no connect, bind, accept. Socket is connected from the start */ case PRU_CONNECT: case PRU_CONNECT2: - case PRU_LISTEN: case PRU_ACCEPT: error = EOPNOTSUPP; break; diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index adf8b091098..949572ab904 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.71 2022/08/21 11:44:54 bluhm Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.72 2022/08/21 17:30:21 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -291,7 +291,6 @@ divert_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, case PRU_SENSE: break; - case PRU_LISTEN: case PRU_CONNECT: case PRU_CONNECT2: case PRU_ACCEPT: diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index e444363025a..a7c71d895f5 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip.c,v 1.131 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: raw_ip.c,v 1.132 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */ /* @@ -553,7 +553,6 @@ rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, /* * Not supported. */ - case PRU_LISTEN: case PRU_ACCEPT: case PRU_SENDOOB: case PRU_RCVD: diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 88aa0d26ed7..48a25660432 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.189 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.190 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -116,6 +116,7 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_attach = tcp_attach, .pru_detach = tcp_detach, .pru_bind = tcp_bind, + .pru_listen = tcp_listen, }; static int pr_slowhz = PR_SLOWHZ; @@ -212,18 +213,6 @@ tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, switch (req) { - /* - * Prepare to accept connections. - */ - case PRU_LISTEN: - if (inp->inp_lport == 0) - error = in_pcbbind(inp, NULL, p); - /* If the in_pcbbind() above is called, the tp->pf - should still be whatever it was before. */ - if (error == 0) - tp->t_state = TCPS_LISTEN; - break; - /* * Initiate connection to peer. * Create a template for use in transmissions on this connection. @@ -800,6 +789,43 @@ tcp_bind(struct socket *so, struct mbuf *nam, struct proc *p) return (error); } +/* + * Prepare to accept connections. + */ +int +tcp_listen(struct socket *so) +{ + struct inpcb *inp; + struct tcpcb *tp, *otp = NULL; + int error; + short ostate; + + soassertlocked(so); + + if ((error = tcp_sogetpcb(so, &inp, &tp))) + return (error); + + if (so->so_options & SO_DEBUG) { + otp = tp; + ostate = tp->t_state; + } + + if (inp->inp_lport == 0) + if ((error = in_pcbbind(inp, NULL, curproc))) + goto out; + + /* + * If the in_pcbbind() above is called, the tp->pf + * should still be whatever it was before. + */ + tp->t_state = TCPS_LISTEN; + +out: + if (otp) + tcp_trace(TA_USER, ostate, tp, otp, NULL, PRU_LISTEN, 0); + return (error); +} + /* * Initiate (or continue) disconnect. * If embryonic state, just send reset (once). diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 7ffa048b459..867a7772e4f 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_var.h,v 1.142 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: tcp_var.h,v 1.143 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ /* @@ -715,6 +715,7 @@ int tcp_usrreq(struct socket *, int tcp_attach(struct socket *, int); int tcp_detach(struct socket *); int tcp_bind(struct socket *, struct mbuf *, struct proc *); +int tcp_listen(struct socket *); 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 06a1252ae72..ea9726c253d 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.283 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.284 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1075,10 +1075,6 @@ udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, */ switch (req) { - case PRU_LISTEN: - error = EOPNOTSUPP; - break; - case PRU_CONNECT: #ifdef INET6 if (inp->inp_flags & INP_IPV6) { diff --git a/sys/netinet6/ip6_divert.c b/sys/netinet6/ip6_divert.c index 679278ebc99..382b4593232 100644 --- a/sys/netinet6/ip6_divert.c +++ b/sys/netinet6/ip6_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_divert.c,v 1.70 2022/08/21 11:44:54 bluhm Exp $ */ +/* $OpenBSD: ip6_divert.c,v 1.71 2022/08/21 17:30:21 mvs Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -297,7 +297,6 @@ divert6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *addr, case PRU_SENSE: break; - case PRU_LISTEN: case PRU_CONNECT: case PRU_CONNECT2: case PRU_ACCEPT: diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index cf311001e2a..6926aebf300 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.151 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.152 2022/08/21 17:30:21 mvs Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -676,7 +676,6 @@ rip6_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, /* * Not supported. */ - case PRU_LISTEN: case PRU_ACCEPT: case PRU_SENDOOB: case PRU_RCVD: diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 560699bfea8..dfcb2cd62e5 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.38 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.39 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -67,6 +67,7 @@ struct pr_usrreqs { int (*pru_attach)(struct socket *, int); int (*pru_detach)(struct socket *); int (*pru_bind)(struct socket *, struct mbuf *, struct proc *); + int (*pru_listen)(struct socket *); }; struct protosw { @@ -273,8 +274,9 @@ pru_bind(struct socket *so, struct mbuf *nam, struct proc *p) static inline int pru_listen(struct socket *so) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_LISTEN, NULL, NULL, NULL, curproc); + if (so->so_proto->pr_usrreqs->pru_listen) + return (*so->so_proto->pr_usrreqs->pru_listen)(so); + return (EOPNOTSUPP); } static inline int diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h index 92bd53acf90..ee11523e730 100644 --- a/sys/sys/unpcb.h +++ b/sys/sys/unpcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unpcb.h,v 1.28 2022/08/20 23:48:58 mvs Exp $ */ +/* $OpenBSD: unpcb.h,v 1.29 2022/08/21 17:30:21 mvs Exp $ */ /* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ /* @@ -114,6 +114,7 @@ int uipc_usrreq(struct socket *, int , struct mbuf *, int uipc_attach(struct socket *, int); int uipc_detach(struct socket *); int uipc_bind(struct socket *, struct mbuf *, struct proc *); +int uipc_listen(struct socket *); void unp_init(void); int unp_bind(struct unpcb *, struct mbuf *, struct proc *);