On Sun, Aug 28, 2022 at 01:05:41AM +0300, Vitaliy Makkoveev wrote:
> PRU_ABORT is another candidate to change return type to void. Also
> actually we abort only the sockets which are linked to `so_q' or `so_q0'
> queues of listening socket. Such sockets have no corresponding file
> descriptor and are not accessed from userland, so PRU_ABORT used to
> destroy them on listening socket destruction.
>
> Currently all our sockets support PRU_ABORT request, but actually it
> required only for tcp(4) and unix(4) sockets, so we could make it
> optional. However, the attached diff keeps PRU_ABORT requests. Should I
> remove them with separate diff, or rework this one?
separate diff
> Also, we should destroy socket on PRU_ABORT requset, but route and key
> management sockets keep it alive. I fixed this, but it doesn't make
> sense because this code never called.
Just leave the wrong soisdisconnected(so) logic and remove
the function in the next diff.
OK bluhm@
> Index: sys/kern/uipc_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
> retrieving revision 1.176
> diff -u -p -r1.176 uipc_usrreq.c
> --- sys/kern/uipc_usrreq.c 27 Aug 2022 20:28:01 -0000 1.176
> +++ sys/kern/uipc_usrreq.c 27 Aug 2022 21:49:18 -0000
> @@ -138,6 +138,7 @@ const struct pr_usrreqs uipc_usrreqs = {
> .pru_shutdown = uipc_shutdown,
> .pru_rcvd = uipc_rcvd,
> .pru_send = uipc_send,
> + .pru_abort = uipc_abort,
> };
>
> void
> @@ -245,11 +246,6 @@ uipc_usrreq(struct socket *so, int req,
> }
> break;
>
> - case PRU_ABORT:
> - unp_detach(unp);
> - sofree(so, 0);
> - break;
> -
> case PRU_SENSE: {
> struct stat *sb = (struct stat *)m;
>
> @@ -588,6 +584,17 @@ out:
> m_freem(m);
>
> return (error);
> +}
> +
> +int
> +uipc_abort(struct socket *so)
> +{
> + struct unpcb *unp = sotounpcb(so);
> +
> + unp_detach(unp);
> + sofree(so, 0);
> +
> + return (0);
> }
>
> int
> Index: sys/net/pfkeyv2.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pfkeyv2.c,v
> retrieving revision 1.243
> diff -u -p -r1.243 pfkeyv2.c
> --- sys/net/pfkeyv2.c 27 Aug 2022 20:28:01 -0000 1.243
> +++ sys/net/pfkeyv2.c 27 Aug 2022 21:49:18 -0000
> @@ -175,6 +175,7 @@ int pfkeyv2_disconnect(struct socket *);
> int pfkeyv2_shutdown(struct socket *);
> int pfkeyv2_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int pfkeyv2_abort(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 *,
> @@ -210,6 +211,7 @@ const struct pr_usrreqs pfkeyv2_usrreqs
> .pru_disconnect = pfkeyv2_disconnect,
> .pru_shutdown = pfkeyv2_shutdown,
> .pru_send = pfkeyv2_send,
> + .pru_abort = pfkeyv2_abort,
> };
>
> const struct protosw pfkeysw[] = {
> @@ -382,6 +384,15 @@ out:
> }
>
> int
> +pfkeyv2_abort(struct socket *so)
> +{
> + pfkeyv2_detach(so);
> + so->so_state |= SS_NOFDREF;
> + sofree(so, 0);
> + return (0);
> +}
> +
> +int
> pfkeyv2_usrreq(struct socket *so, int req, struct mbuf *m,
> struct mbuf *nam, struct mbuf *control, struct proc *p)
> {
> @@ -410,9 +421,6 @@ pfkeyv2_usrreq(struct socket *so, int re
> error = EOPNOTSUPP;
> break;
>
> - case PRU_ABORT:
> - soisdisconnected(so);
> - break;
> case PRU_SENSE:
> /* stat: don't bother with a blocksize. */
> break;
> Index: sys/net/rtsock.c
> ===================================================================
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.343
> diff -u -p -r1.343 rtsock.c
> --- sys/net/rtsock.c 27 Aug 2022 20:28:01 -0000 1.343
> +++ sys/net/rtsock.c 27 Aug 2022 21:49:18 -0000
> @@ -119,6 +119,7 @@ int route_shutdown(struct socket *);
> int route_rcvd(struct socket *);
> int route_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int route_abort(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);
> @@ -242,9 +243,6 @@ route_usrreq(struct socket *so, int req,
> error = EOPNOTSUPP;
> break;
>
> - case PRU_ABORT:
> - soisdisconnected(so);
> - break;
> case PRU_SENSE:
> /* stat: don't bother with a blocksize. */
> break;
> @@ -406,6 +404,15 @@ out:
> }
>
> int
> +route_abort(struct socket *so)
> +{
> + route_detach(so);
> + so->so_state |= SS_NOFDREF;
> + sofree(so, 0);
> + return (0);
> +}
> +
> +int
> route_ctloutput(int op, struct socket *so, int level, int optname,
> struct mbuf *m)
> {
> @@ -2448,6 +2455,7 @@ const struct pr_usrreqs route_usrreqs =
> .pru_shutdown = route_shutdown,
> .pru_rcvd = route_rcvd,
> .pru_send = route_send,
> + .pru_abort = route_abort,
> };
>
> const struct protosw routesw[] = {
> Index: sys/netinet/ip_divert.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_divert.c,v
> retrieving revision 1.78
> diff -u -p -r1.78 ip_divert.c
> --- sys/netinet/ip_divert.c 27 Aug 2022 20:28:01 -0000 1.78
> +++ sys/netinet/ip_divert.c 27 Aug 2022 21:49:18 -0000
> @@ -69,6 +69,7 @@ const struct pr_usrreqs divert_usrreqs =
> .pru_bind = divert_bind,
> .pru_shutdown = divert_shutdown,
> .pru_send = divert_send,
> + .pru_abort = divert_abort,
> };
>
> int divbhashsize = DIVERTHASHSIZE;
> @@ -270,11 +271,6 @@ divert_usrreq(struct socket *so, int req
> }
> switch (req) {
>
> - case PRU_ABORT:
> - soisdisconnected(so);
> - in_pcbdetach(inp);
> - break;
> -
> case PRU_SOCKADDR:
> in_setsockaddr(inp, addr);
> break;
> @@ -369,6 +365,19 @@ divert_send(struct socket *so, struct mb
>
> soassertlocked(so);
> return (divert_output(inp, m, addr, control));
> +}
> +
> +int
> +divert_abort(struct socket *so)
> +{
> + struct inpcb *inp = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> + soisdisconnected(so);
> + in_pcbdetach(inp);
> +
> + return (0);
> }
>
> int
> Index: sys/netinet/ip_divert.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_divert.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 ip_divert.h
> --- sys/netinet/ip_divert.h 27 Aug 2022 20:28:01 -0000 1.19
> +++ sys/netinet/ip_divert.h 27 Aug 2022 21:49:18 -0000
> @@ -78,5 +78,6 @@ int divert_bind(struct socket *, struct
> int divert_shutdown(struct socket *);
> int divert_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int divert_abort(struct socket *);
> #endif /* _KERNEL */
> #endif /* _IP_DIVERT_H_ */
> Index: sys/netinet/ip_gre.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_gre.c,v
> retrieving revision 1.80
> diff -u -p -r1.80 ip_gre.c
> --- sys/netinet/ip_gre.c 27 Aug 2022 20:28:01 -0000 1.80
> +++ sys/netinet/ip_gre.c 27 Aug 2022 21:49:18 -0000
> @@ -70,6 +70,7 @@ const struct pr_usrreqs gre_usrreqs = {
> .pru_disconnect = rip_disconnect,
> .pru_shutdown = rip_shutdown,
> .pru_send = gre_send,
> + .pru_abort = rip_abort,
> };
>
> int
> Index: sys/netinet/ip_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_var.h,v
> retrieving revision 1.102
> diff -u -p -r1.102 ip_var.h
> --- sys/netinet/ip_var.h 27 Aug 2022 20:28:01 -0000 1.102
> +++ sys/netinet/ip_var.h 27 Aug 2022 21:49:18 -0000
> @@ -266,6 +266,7 @@ int rip_disconnect(struct socket *);
> int rip_shutdown(struct socket *);
> int rip_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int rip_abort(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.139
> diff -u -p -r1.139 raw_ip.c
> --- sys/netinet/raw_ip.c 27 Aug 2022 20:28:01 -0000 1.139
> +++ sys/netinet/raw_ip.c 27 Aug 2022 21:49:18 -0000
> @@ -112,6 +112,7 @@ const struct pr_usrreqs rip_usrreqs = {
> .pru_disconnect = rip_disconnect,
> .pru_shutdown = rip_shutdown,
> .pru_send = rip_send,
> + .pru_abort = rip_abort,
> };
>
> /*
> @@ -477,17 +478,6 @@ rip_usrreq(struct socket *so, int req, s
>
> switch (req) {
>
> - case PRU_ABORT:
> - soisdisconnected(so);
> - if (inp == NULL)
> - panic("rip_abort");
> -#ifdef MROUTING
> - if (so == ip_mrouter[inp->inp_rtableid])
> - ip_mrouter_done(so);
> -#endif
> - in_pcbdetach(inp);
> - break;
> -
> case PRU_CONNECT2:
> error = EOPNOTSUPP;
> break;
> @@ -685,3 +675,19 @@ out:
> return (error);
> }
>
> +int
> +rip_abort(struct socket *so)
> +{
> + struct inpcb *inp = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> + soisdisconnected(so);
> +#ifdef MROUTING
> + if (so == ip_mrouter[inp->inp_rtableid])
> + ip_mrouter_done(so);
> +#endif
> + in_pcbdetach(inp);
> +
> + return (0);
> +}
> Index: sys/netinet/tcp_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
> retrieving revision 1.196
> diff -u -p -r1.196 tcp_usrreq.c
> --- sys/netinet/tcp_usrreq.c 27 Aug 2022 20:28:01 -0000 1.196
> +++ sys/netinet/tcp_usrreq.c 27 Aug 2022 21:49:18 -0000
> @@ -123,6 +123,7 @@ const struct pr_usrreqs tcp_usrreqs = {
> .pru_shutdown = tcp_shutdown,
> .pru_rcvd = tcp_rcvd,
> .pru_send = tcp_send,
> + .pru_abort = tcp_abort,
> };
>
> static int pr_slowhz = PR_SLOWHZ;
> @@ -226,13 +227,6 @@ tcp_usrreq(struct socket *so, int req, s
> error = EOPNOTSUPP;
> break;
>
> - /*
> - * Abort the TCP.
> - */
> - case PRU_ABORT:
> - tp = tcp_drop(tp, ECONNABORTED);
> - break;
> -
> case PRU_SENSE:
> ((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
> break;
> @@ -960,6 +954,34 @@ out:
> m_freem(m);
>
> return (error);
> +}
> +
> +/*
> + * Abort the TCP.
> + */
> +int
> +tcp_abort(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_drop(tp, ECONNABORTED);
> +
> + if (otp)
> + tcp_trace(TA_USER, ostate, tp, otp, NULL, PRU_ABORT, 0);
> + return (0);
> }
>
> /*
> Index: sys/netinet/tcp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_var.h,v
> retrieving revision 1.149
> diff -u -p -r1.149 tcp_var.h
> --- sys/netinet/tcp_var.h 27 Aug 2022 20:28:01 -0000 1.149
> +++ sys/netinet/tcp_var.h 27 Aug 2022 21:49:18 -0000
> @@ -723,6 +723,7 @@ int tcp_shutdown(struct socket *);
> int tcp_rcvd(struct socket *);
> int tcp_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int tcp_abort(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.291
> diff -u -p -r1.291 udp_usrreq.c
> --- sys/netinet/udp_usrreq.c 27 Aug 2022 20:28:01 -0000 1.291
> +++ sys/netinet/udp_usrreq.c 27 Aug 2022 21:49:18 -0000
> @@ -131,6 +131,7 @@ const struct pr_usrreqs udp_usrreqs = {
> .pru_disconnect = udp_disconnect,
> .pru_shutdown = udp_shutdown,
> .pru_send = udp_send,
> + .pru_abort = udp_abort,
> };
>
> const struct sysctl_bounded_args udpctl_vars[] = {
> @@ -1087,11 +1088,6 @@ udp_usrreq(struct socket *so, int req, s
> error = EOPNOTSUPP;
> break;
>
> - case PRU_ABORT:
> - soisdisconnected(so);
> - in_pcbdetach(inp);
> - break;
> -
> case PRU_SOCKADDR:
> #ifdef INET6
> if (inp->inp_flags & INP_IPV6)
> @@ -1302,6 +1298,19 @@ udp_send(struct socket *so, struct mbuf
> error = udp_output(inp, m, addr, control);
>
> return (error);
> +}
> +
> +int
> +udp_abort(struct socket *so)
> +{
> + struct inpcb *inp = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> + soisdisconnected(so);
> + in_pcbdetach(inp);
> +
> + return (0);
> }
>
> /*
> Index: sys/netinet/udp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/udp_var.h,v
> retrieving revision 1.43
> diff -u -p -r1.43 udp_var.h
> --- sys/netinet/udp_var.h 27 Aug 2022 20:28:01 -0000 1.43
> +++ sys/netinet/udp_var.h 27 Aug 2022 21:49:18 -0000
> @@ -149,5 +149,6 @@ int udp_disconnect(struct socket *);
> int udp_shutdown(struct socket *);
> int udp_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int udp_abort(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.77
> diff -u -p -r1.77 ip6_divert.c
> --- sys/netinet6/ip6_divert.c 27 Aug 2022 20:28:01 -0000 1.77
> +++ sys/netinet6/ip6_divert.c 27 Aug 2022 21:49:18 -0000
> @@ -70,6 +70,7 @@ const struct pr_usrreqs divert6_usrreqs
> .pru_bind = divert6_bind,
> .pru_shutdown = divert6_shutdown,
> .pru_send = divert6_send,
> + .pru_abort = divert6_abort,
> };
>
> int divb6hashsize = DIVERTHASHSIZE;
> @@ -276,11 +277,6 @@ divert6_usrreq(struct socket *so, int re
> }
> switch (req) {
>
> - case PRU_ABORT:
> - soisdisconnected(so);
> - in_pcbdetach(inp);
> - break;
> -
> case PRU_SOCKADDR:
> in6_setsockaddr(inp, addr);
> break;
> @@ -377,6 +373,18 @@ divert6_send(struct socket *so, struct m
>
> soassertlocked(so);
> return (divert6_output(inp, m, addr, control));
> +}
> +
> +int
> +divert6_abort(struct socket *so)
> +{
> + struct inpcb *inp = sotoinpcb(so);
> +
> + soassertlocked(so);
> + soisdisconnected(so);
> + in_pcbdetach(inp);
> +
> + return (0);
> }
>
> int
> Index: sys/netinet6/ip6_divert.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_divert.h,v
> retrieving revision 1.17
> diff -u -p -r1.17 ip6_divert.h
> --- sys/netinet6/ip6_divert.h 27 Aug 2022 20:28:01 -0000 1.17
> +++ sys/netinet6/ip6_divert.h 27 Aug 2022 21:49:18 -0000
> @@ -78,6 +78,7 @@ int divert6_bind(struct socket *, struc
> int divert6_shutdown(struct socket *);
> int divert6_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int divert6_abort(struct socket *);
> #endif /* _KERNEL */
>
> #endif /* _IP6_DIVERT_H_ */
> Index: sys/netinet6/ip6_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_var.h,v
> retrieving revision 1.100
> diff -u -p -r1.100 ip6_var.h
> --- sys/netinet6/ip6_var.h 27 Aug 2022 20:28:01 -0000 1.100
> +++ sys/netinet6/ip6_var.h 27 Aug 2022 21:49:18 -0000
> @@ -361,6 +361,7 @@ int rip6_disconnect(struct socket *);
> int rip6_shutdown(struct socket *);
> int rip6_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int rip6_abort(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.159
> diff -u -p -r1.159 raw_ip6.c
> --- sys/netinet6/raw_ip6.c 27 Aug 2022 20:28:01 -0000 1.159
> +++ sys/netinet6/raw_ip6.c 27 Aug 2022 21:49:18 -0000
> @@ -114,6 +114,7 @@ const struct pr_usrreqs rip6_usrreqs = {
> .pru_disconnect = rip6_disconnect,
> .pru_shutdown = rip6_shutdown,
> .pru_send = rip6_send,
> + .pru_abort = rip6_abort,
> };
>
> /*
> @@ -592,20 +593,6 @@ rip6_usrreq(struct socket *so, int req,
> }
>
> switch (req) {
> - case PRU_ABORT:
> - soisdisconnected(so);
> - if (in6p == NULL)
> - panic("%s", __func__);
> -#ifdef MROUTING
> - if (so == ip6_mrouter[in6p->inp_rtableid])
> - ip6_mrouter_done(so);
> -#endif
> - free(in6p->inp_icmp6filt, M_PCB, sizeof(struct icmp6_filter));
> - in6p->inp_icmp6filt = NULL;
> -
> - in_pcbdetach(in6p);
> - break;
> -
> case PRU_CONNECT2:
> error = EOPNOTSUPP;
> break;
> @@ -817,6 +804,26 @@ out:
> m_freem(m);
>
> return (error);
> +}
> +
> +int
> +rip6_abort(struct socket *so)
> +{
> + struct inpcb *in6p = sotoinpcb(so);
> +
> + soassertlocked(so);
> +
> + soisdisconnected(so);
> +#ifdef MROUTING
> + if (so == ip6_mrouter[in6p->inp_rtableid])
> + ip6_mrouter_done(so);
> +#endif
> + free(in6p->inp_icmp6filt, M_PCB, sizeof(struct icmp6_filter));
> + in6p->inp_icmp6filt = NULL;
> +
> + in_pcbdetach(in6p);
> +
> + return (0);
> }
>
> int
> Index: sys/sys/protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/protosw.h,v
> retrieving revision 1.45
> diff -u -p -r1.45 protosw.h
> --- sys/sys/protosw.h 27 Aug 2022 20:28:01 -0000 1.45
> +++ sys/sys/protosw.h 27 Aug 2022 21:49:18 -0000
> @@ -75,6 +75,7 @@ struct pr_usrreqs {
> int (*pru_rcvd)(struct socket *);
> int (*pru_send)(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> + int (*pru_abort)(struct socket *);
> };
>
> struct protosw {
> @@ -334,8 +335,7 @@ pru_send(struct socket *so, struct mbuf
> static inline int
> pru_abort(struct socket *so)
> {
> - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
> - PRU_ABORT, NULL, NULL, NULL, curproc);
> + return (*so->so_proto->pr_usrreqs->pru_abort)(so);
> }
>
> static inline int
> Index: sys/sys/unpcb.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/unpcb.h,v
> retrieving revision 1.35
> diff -u -p -r1.35 unpcb.h
> --- sys/sys/unpcb.h 27 Aug 2022 20:28:01 -0000 1.35
> +++ sys/sys/unpcb.h 27 Aug 2022 21:49:18 -0000
> @@ -122,6 +122,7 @@ int uipc_shutdown(struct socket *);
> int uipc_rcvd(struct socket *);
> int uipc_send(struct socket *, struct mbuf *, struct mbuf *,
> struct mbuf *);
> +int uipc_abort(struct socket *);
>
> void unp_init(void);
> int unp_bind(struct unpcb *, struct mbuf *, struct proc *);