On Sun, Aug 21, 2022 at 08:07:10PM +0300, Vitaliy Makkoveev wrote:
> ok?
OK bluhm@
> Index: sys/kern/uipc_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
> retrieving revision 1.169
> diff -u -p -r1.169 uipc_usrreq.c
> --- sys/kern/uipc_usrreq.c 20 Aug 2022 23:48:57 -0000 1.169
> +++ sys/kern/uipc_usrreq.c 21 Aug 2022 16:52:47 -0000
> @@ -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,
>
> switch (req) {
>
> - case PRU_LISTEN:
> - if (unp->unp_vnode == NULL)
> - error = EINVAL;
> - break;
> -
> case PRU_CONNECT:
> error = unp_connect(so, nam, p);
> break;
> @@ -540,6 +536,16 @@ uipc_bind(struct socket *so, struct mbuf
> struct unpcb *unp = sotounpcb(so);
>
> 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
> Index: sys/net/pfkeyv2.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pfkeyv2.c,v
> retrieving revision 1.236
> diff -u -p -r1.236 pfkeyv2.c
> --- sys/net/pfkeyv2.c 20 Aug 2022 23:48:57 -0000 1.236
> +++ sys/net/pfkeyv2.c 21 Aug 2022 16:52:47 -0000
> @@ -359,7 +359,6 @@ pfkeyv2_usrreq(struct socket *so, int re
> /* 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;
> Index: sys/net/rtsock.c
> ===================================================================
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.336
> diff -u -p -r1.336 rtsock.c
> --- sys/net/rtsock.c 20 Aug 2022 23:48:58 -0000 1.336
> +++ sys/net/rtsock.c 21 Aug 2022 16:52:47 -0000
> @@ -235,7 +235,6 @@ route_usrreq(struct socket *so, int req,
> /* 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;
> Index: sys/netinet/ip_divert.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_divert.c,v
> retrieving revision 1.71
> diff -u -p -r1.71 ip_divert.c
> --- sys/netinet/ip_divert.c 21 Aug 2022 11:44:54 -0000 1.71
> +++ sys/netinet/ip_divert.c 21 Aug 2022 16:52:47 -0000
> @@ -291,7 +291,6 @@ divert_usrreq(struct socket *so, int req
> case PRU_SENSE:
> break;
>
> - case PRU_LISTEN:
> case PRU_CONNECT:
> case PRU_CONNECT2:
> case PRU_ACCEPT:
> Index: sys/netinet/raw_ip.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/raw_ip.c,v
> retrieving revision 1.131
> diff -u -p -r1.131 raw_ip.c
> --- sys/netinet/raw_ip.c 20 Aug 2022 23:48:58 -0000 1.131
> +++ sys/netinet/raw_ip.c 21 Aug 2022 16:52:47 -0000
> @@ -553,7 +553,6 @@ rip_usrreq(struct socket *so, int req, s
> /*
> * Not supported.
> */
> - case PRU_LISTEN:
> case PRU_ACCEPT:
> case PRU_SENDOOB:
> case PRU_RCVD:
> Index: sys/netinet/tcp_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
> retrieving revision 1.189
> diff -u -p -r1.189 tcp_usrreq.c
> --- sys/netinet/tcp_usrreq.c 20 Aug 2022 23:48:58 -0000 1.189
> +++ sys/netinet/tcp_usrreq.c 21 Aug 2022 16:52:48 -0000
> @@ -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;
> @@ -213,18 +214,6 @@ tcp_usrreq(struct socket *so, int req, s
> 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.
> * Enter SYN_SENT state, and mark socket as connecting.
> @@ -797,6 +786,43 @@ tcp_bind(struct socket *so, struct mbuf
>
> if (so->so_options & SO_DEBUG)
> tcp_trace(TA_USER, ostate, tp, tp, NULL, PRU_BIND, 0);
> + 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);
> }
>
> Index: sys/netinet/tcp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_var.h,v
> retrieving revision 1.142
> diff -u -p -r1.142 tcp_var.h
> --- sys/netinet/tcp_var.h 20 Aug 2022 23:48:58 -0000 1.142
> +++ sys/netinet/tcp_var.h 21 Aug 2022 16:52:48 -0000
> @@ -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);
> Index: sys/netinet/udp_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
> retrieving revision 1.283
> diff -u -p -r1.283 udp_usrreq.c
> --- sys/netinet/udp_usrreq.c 20 Aug 2022 23:48:58 -0000 1.283
> +++ sys/netinet/udp_usrreq.c 21 Aug 2022 16:52:48 -0000
> @@ -1075,10 +1075,6 @@ udp_usrreq(struct socket *so, int req, s
> */
> switch (req) {
>
> - case PRU_LISTEN:
> - error = EOPNOTSUPP;
> - break;
> -
> case PRU_CONNECT:
> #ifdef INET6
> if (inp->inp_flags & INP_IPV6) {
> Index: sys/netinet6/ip6_divert.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v
> retrieving revision 1.70
> diff -u -p -r1.70 ip6_divert.c
> --- sys/netinet6/ip6_divert.c 21 Aug 2022 11:44:54 -0000 1.70
> +++ sys/netinet6/ip6_divert.c 21 Aug 2022 16:52:48 -0000
> @@ -297,7 +297,6 @@ divert6_usrreq(struct socket *so, int re
> case PRU_SENSE:
> break;
>
> - case PRU_LISTEN:
> case PRU_CONNECT:
> case PRU_CONNECT2:
> case PRU_ACCEPT:
> Index: sys/netinet6/raw_ip6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
> retrieving revision 1.151
> diff -u -p -r1.151 raw_ip6.c
> --- sys/netinet6/raw_ip6.c 20 Aug 2022 23:48:58 -0000 1.151
> +++ sys/netinet6/raw_ip6.c 21 Aug 2022 16:52:48 -0000
> @@ -676,7 +676,6 @@ rip6_usrreq(struct socket *so, int req,
> /*
> * Not supported.
> */
> - case PRU_LISTEN:
> case PRU_ACCEPT:
> case PRU_SENDOOB:
> case PRU_RCVD:
> Index: sys/sys/protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/protosw.h,v
> retrieving revision 1.38
> diff -u -p -r1.38 protosw.h
> --- sys/sys/protosw.h 20 Aug 2022 23:48:58 -0000 1.38
> +++ sys/sys/protosw.h 21 Aug 2022 16:52:48 -0000
> @@ -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
> 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
> Index: sys/sys/unpcb.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/unpcb.h,v
> retrieving revision 1.28
> diff -u -p -r1.28 unpcb.h
> --- sys/sys/unpcb.h 20 Aug 2022 23:48:58 -0000 1.28
> +++ sys/sys/unpcb.h 21 Aug 2022 16:52:48 -0000
> @@ -114,6 +114,7 @@ int uipc_usrreq(struct socket *, int , s
> 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 *);