On Mon, Aug 22, 2022 at 12:37:20PM +0300, Vitaliy Makkoveev wrote:
> The former tcp_disconnect() was renamed to tcp_dodisconnect().
>
> ok?
OK bluhm@
> Index: sys/kern/uipc_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
> retrieving revision 1.172
> diff -u -p -r1.172 uipc_usrreq.c
> --- sys/kern/uipc_usrreq.c 22 Aug 2022 08:08:46 -0000 1.172
> +++ sys/kern/uipc_usrreq.c 22 Aug 2022 09:27:57 -0000
> @@ -134,6 +134,7 @@ const struct pr_usrreqs uipc_usrreqs = {
> .pru_listen = uipc_listen,
> .pru_connect = uipc_connect,
> .pru_accept = uipc_accept,
> + .pru_disconnect = uipc_disconnect,
> };
>
> void
> @@ -241,10 +242,6 @@ uipc_usrreq(struct socket *so, int req,
> }
> break;
>
> - case PRU_DISCONNECT:
> - unp_disconnect(unp);
> - break;
> -
> case PRU_SHUTDOWN:
> socantsendmore(so);
> unp_shutdown(unp);
> @@ -555,6 +552,15 @@ uipc_accept(struct socket *so, struct mb
>
> if (so2 != NULL && so2 != so)
> sounlock(so2);
> + return (0);
> +}
> +
> +int
> +uipc_disconnect(struct socket *so)
> +{
> + struct unpcb *unp = sotounpcb(so);
> +
> + unp_disconnect(unp);
> return (0);
> }
>
> Index: sys/net/pfkeyv2.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pfkeyv2.c,v
> retrieving revision 1.239
> diff -u -p -r1.239 pfkeyv2.c
> --- sys/net/pfkeyv2.c 22 Aug 2022 08:08:46 -0000 1.239
> +++ sys/net/pfkeyv2.c 22 Aug 2022 09:27:57 -0000
> @@ -171,6 +171,7 @@ void pfkey_init(void);
>
> int pfkeyv2_attach(struct socket *, int);
> int pfkeyv2_detach(struct socket *);
> +int pfkeyv2_disconnect(struct socket *);
> int pfkeyv2_usrreq(struct socket *, int, struct mbuf *, struct mbuf *,
> struct mbuf *, struct proc *);
> int pfkeyv2_output(struct mbuf *, struct socket *, struct sockaddr *,
> @@ -203,6 +204,7 @@ const struct pr_usrreqs pfkeyv2_usrreqs
> .pru_usrreq = pfkeyv2_usrreq,
> .pru_attach = pfkeyv2_attach,
> .pru_detach = pfkeyv2_detach,
> + .pru_disconnect = pfkeyv2_disconnect,
> };
>
> const struct protosw pfkeysw[] = {
> @@ -333,6 +335,13 @@ pfkeyv2_detach(struct socket *so)
> }
>
> int
> +pfkeyv2_disconnect(struct socket *so)
> +{
> + soisdisconnected(so);
> + return (0);
> +}
> +
> +int
> pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m,
> struct mbuf *nam, struct mbuf *control, struct proc *p)
> {
> @@ -361,7 +370,6 @@ pfkeyv2_usrreq(struct socket *so, int re
> error = EOPNOTSUPP;
> break;
>
> - case PRU_DISCONNECT:
> case PRU_ABORT:
> soisdisconnected(so);
> break;
> Index: sys/net/rtsock.c
> ===================================================================
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.339
> diff -u -p -r1.339 rtsock.c
> --- sys/net/rtsock.c 22 Aug 2022 08:08:46 -0000 1.339
> +++ sys/net/rtsock.c 22 Aug 2022 09:27:57 -0000
> @@ -114,6 +114,7 @@ int route_output(struct mbuf *, struct s
> int route_ctloutput(int, struct socket *, int, int, struct mbuf *);
> int route_usrreq(struct socket *, int, struct mbuf *, struct mbuf *,
> struct mbuf *, struct proc *);
> +int route_disconnect(struct socket *);
> void route_input(struct mbuf *m0, struct socket *, sa_family_t);
> int route_arp_conflict(struct rtentry *, struct rt_addrinfo *);
> int route_cleargateway(struct rtentry *, void *, unsigned int);
> @@ -237,7 +238,6 @@ route_usrreq(struct socket *so, int req,
> error = EOPNOTSUPP;
> break;
>
> - case PRU_DISCONNECT:
> case PRU_ABORT:
> soisdisconnected(so);
> break;
> @@ -363,6 +363,13 @@ route_detach(struct socket *so)
> }
>
> int
> +route_disconnect(struct socket *so)
> +{
> + soisdisconnected(so);
> + return (0);
> +}
> +
> +int
> route_ctloutput(int op, struct socket *so, int level, int optname,
> struct mbuf *m)
> {
> @@ -2401,6 +2408,7 @@ const struct pr_usrreqs route_usrreqs =
> .pru_usrreq = route_usrreq,
> .pru_attach = route_attach,
> .pru_detach = route_detach,
> + .pru_disconnect = route_disconnect,
> };
>
> const struct protosw routesw[] = {
> Index: sys/netinet/ip_divert.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_divert.c,v
> retrieving revision 1.74
> diff -u -p -r1.74 ip_divert.c
> --- sys/netinet/ip_divert.c 22 Aug 2022 08:08:46 -0000 1.74
> +++ sys/netinet/ip_divert.c 22 Aug 2022 09:27:57 -0000
> @@ -292,7 +292,6 @@ divert_usrreq(struct socket *so, int req
> break;
>
> case PRU_CONNECT2:
> - case PRU_DISCONNECT:
> case PRU_SENDOOB:
> case PRU_FASTTIMO:
> case PRU_SLOWTIMO:
> Index: sys/netinet/ip_gre.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_gre.c,v
> retrieving revision 1.77
> diff -u -p -r1.77 ip_gre.c
> --- sys/netinet/ip_gre.c 21 Aug 2022 22:45:55 -0000 1.77
> +++ sys/netinet/ip_gre.c 22 Aug 2022 09:27:57 -0000
> @@ -67,6 +67,7 @@ const struct pr_usrreqs gre_usrreqs = {
> .pru_detach = rip_detach,
> .pru_bind = rip_bind,
> .pru_connect = rip_connect,
> + .pru_disconnect = rip_disconnect,
> };
>
> int
> Index: sys/netinet/ip_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_var.h,v
> retrieving revision 1.99
> diff -u -p -r1.99 ip_var.h
> --- sys/netinet/ip_var.h 21 Aug 2022 22:45:55 -0000 1.99
> +++ sys/netinet/ip_var.h 22 Aug 2022 09:27:57 -0000
> @@ -262,6 +262,7 @@ int rip_attach(struct socket *, int);
> int rip_detach(struct socket *);
> int rip_bind(struct socket *so, struct mbuf *, struct proc *);
> int rip_connect(struct socket *, struct mbuf *);
> +int rip_disconnect(struct socket *);
> #ifdef MROUTING
> extern struct socket *ip_mrouter[]; /* multicast routing daemon */
> #endif
> Index: sys/netinet/raw_ip.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/raw_ip.c,v
> retrieving revision 1.134
> diff -u -p -r1.134 raw_ip.c
> --- sys/netinet/raw_ip.c 22 Aug 2022 08:08:46 -0000 1.134
> +++ sys/netinet/raw_ip.c 22 Aug 2022 09:27:57 -0000
> @@ -109,6 +109,7 @@ const struct pr_usrreqs rip_usrreqs = {
> .pru_detach = rip_detach,
> .pru_bind = rip_bind,
> .pru_connect = rip_connect,
> + .pru_disconnect = rip_disconnect,
> };
>
> /*
> @@ -468,14 +469,6 @@ rip_usrreq(struct socket *so, int req, s
>
> switch (req) {
>
> - case PRU_DISCONNECT:
> - if ((so->so_state & SS_ISCONNECTED) == 0) {
> - error = ENOTCONN;
> - break;
> - }
> - soisdisconnected(so);
> - inp->inp_faddr.s_addr = INADDR_ANY;
> - break;
> case PRU_ABORT:
> soisdisconnected(so);
> if (inp == NULL)
> @@ -648,6 +641,22 @@ rip_connect(struct socket *so, struct mb
>
> inp->inp_faddr = addr->sin_addr;
> soisconnected(so);
> +
> + return (0);
> +}
> +
> +int
> +rip_disconnect(struct socket *so)
> +{
> + struct inpcb *inp = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> + if ((so->so_state & SS_ISCONNECTED) == 0)
> + return (ENOTCONN);
> +
> + soisdisconnected(so);
> + inp->inp_faddr.s_addr = INADDR_ANY;
>
> return (0);
> }
> Index: sys/netinet/tcp_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
> retrieving revision 1.192
> diff -u -p -r1.192 tcp_usrreq.c
> --- sys/netinet/tcp_usrreq.c 22 Aug 2022 08:08:46 -0000 1.192
> +++ sys/netinet/tcp_usrreq.c 22 Aug 2022 09:27:57 -0000
> @@ -119,6 +119,7 @@ const struct pr_usrreqs tcp_usrreqs = {
> .pru_listen = tcp_listen,
> .pru_connect = tcp_connect,
> .pru_accept = tcp_accept,
> + .pru_disconnect = tcp_disconnect,
> };
>
> static int pr_slowhz = PR_SLOWHZ;
> @@ -223,21 +224,6 @@ tcp_usrreq(struct socket *so, int req, s
> break;
>
> /*
> - * Initiate disconnect from peer.
> - * If connection never passed embryonic stage, just drop;
> - * else if don't need to let data drain, then can just drop anyways,
> - * else have to begin TCP shutdown process: mark socket disconnecting,
> - * drain unread data, state switch to reflect user close, and
> - * send segment (e.g. FIN) to peer. Socket will be really disconnected
> - * when peer sends FIN and acks ours.
> - *
> - * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
> - */
> - case PRU_DISCONNECT:
> - tp = tcp_disconnect(tp);
> - break;
> -
> - /*
> * Mark the connection as being incapable of further output.
> */
> case PRU_SHUTDOWN:
> @@ -683,7 +669,7 @@ tcp_detach(struct socket *so)
> * which may finish later; embryonic TCB's can just
> * be discarded here.
> */
> - tp = tcp_disconnect(tp);
> + tp = tcp_dodisconnect(tp);
>
> if (otp)
> tcp_trace(TA_USER, ostate, tp, otp, NULL, PRU_DETACH, 0);
> @@ -869,6 +855,42 @@ tcp_accept(struct socket *so, struct mbu
> }
>
> /*
> + * Initiate disconnect from peer.
> + * If connection never passed embryonic stage, just drop;
> + * else if don't need to let data drain, then can just drop anyways,
> + * else have to begin TCP shutdown process: mark socket disconnecting,
> + * drain unread data, state switch to reflect user close, and
> + * send segment (e.g. FIN) to peer. Socket will be really disconnected
> + * when peer sends FIN and acks ours.
> + *
> + * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
> + */
> +int
> +tcp_disconnect(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;
> + }
> +
> + tp = tcp_dodisconnect(tp);
> +
> + if (otp)
> + tcp_trace(TA_USER, ostate, tp, otp, NULL, PRU_DISCONNECT, 0);
> + return (0);
> +}
> +
> +/*
> * Initiate (or continue) disconnect.
> * If embryonic state, just send reset (once).
> * If in ``let data drain'' option and linger null, just drop.
> @@ -877,7 +899,7 @@ tcp_accept(struct socket *so, struct mbu
> * send segment to peer (with FIN).
> */
> struct tcpcb *
> -tcp_disconnect(struct tcpcb *tp)
> +tcp_dodisconnect(struct tcpcb *tp)
> {
> struct socket *so = tp->t_inpcb->inp_socket;
>
> Index: sys/netinet/tcp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_var.h,v
> retrieving revision 1.145
> diff -u -p -r1.145 tcp_var.h
> --- sys/netinet/tcp_var.h 22 Aug 2022 08:08:46 -0000 1.145
> +++ sys/netinet/tcp_var.h 22 Aug 2022 09:27:57 -0000
> @@ -672,7 +672,7 @@ void tcp6_ctlinput(int, struct sockaddr
> void tcp_ctlinput(int, struct sockaddr *, u_int, void *);
> int tcp_ctloutput(int, struct socket *, int, int, struct mbuf *);
> struct tcpcb *
> - tcp_disconnect(struct tcpcb *);
> + tcp_dodisconnect(struct tcpcb *);
> struct tcpcb *
> tcp_drop(struct tcpcb *, int);
> int tcp_dooptions(struct tcpcb *, u_char *, int, struct tcphdr *,
> @@ -718,6 +718,7 @@ int tcp_bind(struct socket *, struct mb
> int tcp_listen(struct socket *);
> int tcp_connect(struct socket *, struct mbuf *);
> int tcp_accept(struct socket *, struct mbuf *);
> +int tcp_disconnect(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.286
> diff -u -p -r1.286 udp_usrreq.c
> --- sys/netinet/udp_usrreq.c 22 Aug 2022 08:08:46 -0000 1.286
> +++ sys/netinet/udp_usrreq.c 22 Aug 2022 09:27:57 -0000
> @@ -128,6 +128,7 @@ const struct pr_usrreqs udp_usrreqs = {
> .pru_detach = udp_detach,
> .pru_bind = udp_bind,
> .pru_connect = udp_connect,
> + .pru_disconnect = udp_disconnect,
> };
>
> const struct sysctl_bounded_args udpctl_vars[] = {
> @@ -1080,33 +1081,6 @@ udp_usrreq(struct socket *so, int req, s
> error = EOPNOTSUPP;
> break;
>
> - case PRU_DISCONNECT:
> -#ifdef INET6
> - if (inp->inp_flags & INP_IPV6) {
> - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
> - error = ENOTCONN;
> - break;
> - }
> - } else
> -#endif /* INET6 */
> - {
> - if (inp->inp_faddr.s_addr == INADDR_ANY) {
> - error = ENOTCONN;
> - break;
> - }
> - }
> -
> -#ifdef INET6
> - if (inp->inp_flags & INP_IPV6)
> - inp->inp_laddr6 = in6addr_any;
> - else
> -#endif /* INET6 */
> - inp->inp_laddr.s_addr = INADDR_ANY;
> - in_pcbdisconnect(inp);
> -
> - so->so_state &= ~SS_ISCONNECTED; /* XXX */
> - break;
> -
> case PRU_SHUTDOWN:
> socantsendmore(so);
> break;
> @@ -1280,6 +1254,37 @@ udp_connect(struct socket *so, struct mb
> return (0);
> }
>
> +int
> +udp_disconnect(struct socket *so)
> +{
> + struct inpcb *inp = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> +#ifdef INET6
> + if (inp->inp_flags & INP_IPV6) {
> + if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6))
> + return (ENOTCONN);
> + } else
> +#endif /* INET6 */
> + {
> + if (inp->inp_faddr.s_addr == INADDR_ANY)
> + return (ENOTCONN);
> + }
> +
> +#ifdef INET6
> + if (inp->inp_flags & INP_IPV6)
> + inp->inp_laddr6 = in6addr_any;
> + else
> +#endif /* INET6 */
> + inp->inp_laddr.s_addr = INADDR_ANY;
> +
> + in_pcbdisconnect(inp);
> + so->so_state &= ~SS_ISCONNECTED; /* XXX */
> +
> + return (0);
> +}
> +
> /*
> * Sysctl for udp variables.
> */
> Index: sys/netinet/udp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/udp_var.h,v
> retrieving revision 1.40
> diff -u -p -r1.40 udp_var.h
> --- sys/netinet/udp_var.h 21 Aug 2022 22:45:55 -0000 1.40
> +++ sys/netinet/udp_var.h 22 Aug 2022 09:27:57 -0000
> @@ -145,5 +145,6 @@ int udp_attach(struct socket *, int);
> int udp_detach(struct socket *);
> int udp_bind(struct socket *, struct mbuf *, struct proc *);
> int udp_connect(struct socket *, struct mbuf *);
> +int udp_disconnect(struct socket *);
> #endif /* _KERNEL */
> #endif /* _NETINET_UDP_VAR_H_ */
> Index: sys/netinet6/ip6_divert.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v
> retrieving revision 1.73
> diff -u -p -r1.73 ip6_divert.c
> --- sys/netinet6/ip6_divert.c 22 Aug 2022 08:08:46 -0000 1.73
> +++ sys/netinet6/ip6_divert.c 22 Aug 2022 09:27:57 -0000
> @@ -298,7 +298,6 @@ divert6_usrreq(struct socket *so, int re
> break;
>
> case PRU_CONNECT2:
> - case PRU_DISCONNECT:
> case PRU_SENDOOB:
> case PRU_FASTTIMO:
> case PRU_SLOWTIMO:
> Index: sys/netinet6/ip6_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_var.h,v
> retrieving revision 1.97
> diff -u -p -r1.97 ip6_var.h
> --- sys/netinet6/ip6_var.h 21 Aug 2022 22:45:55 -0000 1.97
> +++ sys/netinet6/ip6_var.h 22 Aug 2022 09:27:57 -0000
> @@ -357,6 +357,7 @@ int rip6_attach(struct socket *, int);
> int rip6_detach(struct socket *);
> int rip6_bind(struct socket *, struct mbuf *, struct proc *);
> int rip6_connect(struct socket *, struct mbuf *);
> +int rip6_disconnect(struct socket *);
> int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
>
> int dest6_input(struct mbuf **, int *, int, int);
> Index: sys/netinet6/raw_ip6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
> retrieving revision 1.154
> diff -u -p -r1.154 raw_ip6.c
> --- sys/netinet6/raw_ip6.c 22 Aug 2022 08:08:46 -0000 1.154
> +++ sys/netinet6/raw_ip6.c 22 Aug 2022 09:27:57 -0000
> @@ -111,6 +111,7 @@ const struct pr_usrreqs rip6_usrreqs = {
> .pru_detach = rip6_detach,
> .pru_bind = rip6_bind,
> .pru_connect = rip6_connect,
> + .pru_disconnect = rip6_disconnect,
> };
>
> /*
> @@ -583,15 +584,6 @@ rip6_usrreq(struct socket *so, int req,
> }
>
> switch (req) {
> - case PRU_DISCONNECT:
> - if ((so->so_state & SS_ISCONNECTED) == 0) {
> - error = ENOTCONN;
> - break;
> - }
> - in6p->inp_faddr6 = in6addr_any;
> - so->so_state &= ~SS_ISCONNECTED; /* XXX */
> - break;
> -
> case PRU_ABORT:
> soisdisconnected(so);
> if (in6p == NULL)
> @@ -785,6 +777,21 @@ rip6_connect(struct socket *so, struct m
> in6p->inp_laddr6 = *in6a;
> in6p->inp_faddr6 = addr->sin6_addr;
> soisconnected(so);
> + return (0);
> +}
> +
> +int
> +rip6_disconnect(struct socket *so)
> +{
> + struct inpcb *in6p = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> + if ((so->so_state & SS_ISCONNECTED) == 0)
> + return (ENOTCONN);
> +
> + in6p->inp_faddr6 = in6addr_any;
> + so->so_state &= ~SS_ISCONNECTED; /* XXX */
> return (0);
> }
>
> Index: sys/sys/protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/protosw.h,v
> retrieving revision 1.41
> diff -u -p -r1.41 protosw.h
> --- sys/sys/protosw.h 22 Aug 2022 08:08:47 -0000 1.41
> +++ sys/sys/protosw.h 22 Aug 2022 09:27:57 -0000
> @@ -70,6 +70,7 @@ struct pr_usrreqs {
> int (*pru_listen)(struct socket *);
> int (*pru_connect)(struct socket *, struct mbuf *);
> int (*pru_accept)(struct socket *, struct mbuf *);
> + int (*pru_disconnect)(struct socket *);
> };
>
> struct protosw {
> @@ -300,8 +301,9 @@ pru_accept(struct socket *so, struct mbu
> static inline int
> pru_disconnect(struct socket *so)
> {
> - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
> - PRU_DISCONNECT, NULL, NULL, NULL, curproc);
> + if (so->so_proto->pr_usrreqs->pru_disconnect)
> + return (*so->so_proto->pr_usrreqs->pru_disconnect)(so);
> + return (EOPNOTSUPP);
> }
>
> static inline int
> Index: sys/sys/unpcb.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/unpcb.h,v
> retrieving revision 1.31
> diff -u -p -r1.31 unpcb.h
> --- sys/sys/unpcb.h 22 Aug 2022 08:08:47 -0000 1.31
> +++ sys/sys/unpcb.h 22 Aug 2022 09:27:57 -0000
> @@ -117,6 +117,7 @@ int uipc_bind(struct socket *, struct mb
> int uipc_listen(struct socket *);
> int uipc_connect(struct socket *, struct mbuf *);
> int uipc_accept(struct socket *, struct mbuf *);
> +int uipc_disconnect(struct socket *);
>
> void unp_init(void);
> int unp_bind(struct unpcb *, struct mbuf *, struct proc *);