ping

> On 17 Sep 2022, at 22:44, Vitaliy Makkoveev <[email protected]> wrote:
> 
> We have no interest on pru_abort() return value. Also we call it only
> through soabort() which is dummy pru_abort() wrapper and has no return
> value.
> 
> Also only the connection oriented sockets need to implement
> (*pru_abort)() handler. Such sockets are tcp(4) and unix(4) sockets, so
> we could remove existing code for all others. Also the route domain and
> key management sockets have the wrong handlers because they don't
> destroy passed socket, but only disconnect it.
> 
> We call soabort()/pru_abort() only to destroy the sockets linked to
> the `so_q' and `so_q1' of listening socket. Such sockets are not yet
> exported to the userland and have no associated file descriptor.
> 
> We have two cases when we destroy them. The first case is the soclose()
> when we destroy the listening socket. The second one is the
> syn_cache_get() when we destroy newly created socket in the error path
> of incoming connection.
> 
> Also, I like to have the diagnostic block within pru_rcvd() and
> pru_abort() wrappers. The requests handlers are optional, but they have
> no "pru_ != NULL" check, so something like below could be reasonable
> 
> pru_abort(struct socket *so)
> {
> #ifdef DIAGNOSTIC
>        if (so->so_proto->pr_usrreqs->pru_abort == NULL)
>                panic("Inappropriate %s call for socket of proto %d type %d",
>                    __func__, so->so_proto->pr_protocol,
>                    so->so_proto->pr_type);
> #endif
> 
>        (*so->so_proto->pr_usrreqs->pru_abort)(so);
> }
> 
> 
> Index: sys/kern/uipc_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v
> retrieving revision 1.188
> diff -u -p -r1.188 uipc_usrreq.c
> --- sys/kern/uipc_usrreq.c    17 Sep 2022 12:40:52 -0000      1.188
> +++ sys/kern/uipc_usrreq.c    17 Sep 2022 19:06:09 -0000
> @@ -501,15 +501,13 @@ out:
>       return (error);
> }
> 
> -int
> +void
> 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.252
> diff -u -p -r1.252 pfkeyv2.c
> --- sys/net/pfkeyv2.c 3 Sep 2022 22:43:38 -0000       1.252
> +++ sys/net/pfkeyv2.c 17 Sep 2022 19:06:10 -0000
> @@ -175,7 +175,6 @@ 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_sockaddr(struct socket *, struct mbuf *);
> int pfkeyv2_peeraddr(struct socket *, struct mbuf *);
> int pfkeyv2_output(struct mbuf *, struct socket *);
> @@ -209,7 +208,6 @@ const struct pr_usrreqs pfkeyv2_usrreqs 
>       .pru_disconnect = pfkeyv2_disconnect,
>       .pru_shutdown   = pfkeyv2_shutdown,
>       .pru_send       = pfkeyv2_send,
> -     .pru_abort      = pfkeyv2_abort,
>       .pru_sockaddr   = pfkeyv2_sockaddr,
>       .pru_peeraddr   = pfkeyv2_peeraddr,
> };
> @@ -380,13 +378,6 @@ out:
>       m_freem(m);
> 
>       return (error);
> -}
> -
> -int
> -pfkeyv2_abort(struct socket *so)
> -{
> -     soisdisconnected(so);
> -     return (0);
> }
> 
> int
> Index: sys/net/rtsock.c
> ===================================================================
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.356
> diff -u -p -r1.356 rtsock.c
> --- sys/net/rtsock.c  13 Sep 2022 09:05:47 -0000      1.356
> +++ sys/net/rtsock.c  17 Sep 2022 19:06:10 -0000
> @@ -118,7 +118,6 @@ int       route_shutdown(struct socket *);
> void  route_rcvd(struct socket *);
> int   route_send(struct socket *, struct mbuf *, struct mbuf *,
>           struct mbuf *);
> -int  route_abort(struct socket *);
> int   route_sockaddr(struct socket *, struct mbuf *);
> int   route_peeraddr(struct socket *, struct mbuf *);
> void  route_input(struct mbuf *m0, struct socket *, sa_family_t);
> @@ -345,13 +344,6 @@ out:
> }
> 
> int
> -route_abort(struct socket *so)
> -{
> -     soisdisconnected(so);
> -     return (0);
> -}
> -
> -int
> route_sockaddr(struct socket *so, struct mbuf *nam)
> {
>       return (EINVAL);
> @@ -2406,7 +2398,6 @@ const struct pr_usrreqs route_usrreqs = 
>       .pru_shutdown   = route_shutdown,
>       .pru_rcvd       = route_rcvd,
>       .pru_send       = route_send,
> -     .pru_abort      = route_abort,
>       .pru_sockaddr   = route_sockaddr,
>       .pru_peeraddr   = route_peeraddr,
> };
> Index: sys/netinet/ip_divert.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_divert.c,v
> retrieving revision 1.87
> diff -u -p -r1.87 ip_divert.c
> --- sys/netinet/ip_divert.c   5 Sep 2022 14:56:09 -0000       1.87
> +++ sys/netinet/ip_divert.c   17 Sep 2022 19:06:10 -0000
> @@ -70,7 +70,6 @@ const struct pr_usrreqs divert_usrreqs =
>       .pru_bind       = divert_bind,
>       .pru_shutdown   = divert_shutdown,
>       .pru_send       = divert_send,
> -     .pru_abort      = divert_abort,
>       .pru_control    = in_control,
>       .pru_sockaddr   = in_sockaddr,
>       .pru_peeraddr   = in_peeraddr,
> @@ -333,19 +332,6 @@ 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.22
> diff -u -p -r1.22 ip_divert.h
> --- sys/netinet/ip_divert.h   5 Sep 2022 14:56:09 -0000       1.22
> +++ sys/netinet/ip_divert.h   17 Sep 2022 19:06:10 -0000
> @@ -78,6 +78,5 @@ 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.84
> diff -u -p -r1.84 ip_gre.c
> --- sys/netinet/ip_gre.c      3 Sep 2022 22:43:38 -0000       1.84
> +++ sys/netinet/ip_gre.c      17 Sep 2022 19:06:10 -0000
> @@ -71,7 +71,6 @@ const struct pr_usrreqs gre_usrreqs = {
>       .pru_disconnect = rip_disconnect,
>       .pru_shutdown   = rip_shutdown,
>       .pru_send       = gre_send,
> -     .pru_abort      = rip_abort,
>       .pru_control    = in_control,
>       .pru_sockaddr   = in_sockaddr,
>       .pru_peeraddr   = in_peeraddr,
> Index: sys/netinet/ip_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_var.h,v
> retrieving revision 1.105
> diff -u -p -r1.105 ip_var.h
> --- sys/netinet/ip_var.h      13 Sep 2022 09:05:02 -0000      1.105
> +++ sys/netinet/ip_var.h      17 Sep 2022 19:06:10 -0000
> @@ -266,7 +266,6 @@ 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.148
> diff -u -p -r1.148 raw_ip.c
> --- sys/netinet/raw_ip.c      13 Sep 2022 09:05:02 -0000      1.148
> +++ sys/netinet/raw_ip.c      17 Sep 2022 19:06:10 -0000
> @@ -113,7 +113,6 @@ const struct pr_usrreqs rip_usrreqs = {
>       .pru_disconnect = rip_disconnect,
>       .pru_shutdown   = rip_shutdown,
>       .pru_send       = rip_send,
> -     .pru_abort      = rip_abort,
>       .pru_control    = in_control,
>       .pru_sockaddr   = in_sockaddr,
>       .pru_peeraddr   = in_peeraddr,
> @@ -643,21 +642,4 @@ out:
>       m_freem(m);
> 
>       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.208
> diff -u -p -r1.208 tcp_usrreq.c
> --- sys/netinet/tcp_usrreq.c  13 Sep 2022 09:05:47 -0000      1.208
> +++ sys/netinet/tcp_usrreq.c  17 Sep 2022 19:06:10 -0000
> @@ -865,18 +865,17 @@ out:
> /*
>  * Abort the TCP.
>  */
> -int
> +void
> 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 (tcp_sogetpcb(so, &inp, &tp))
> +             return;
> 
>       if (so->so_options & SO_DEBUG) {
>               otp = tp;
> @@ -887,7 +886,6 @@ tcp_abort(struct socket *so)
> 
>       if (otp)
>               tcp_trace(TA_USER, ostate, tp, otp, NULL, PRU_ABORT, 0);
> -     return (0);
> }
> 
> int
> Index: sys/netinet/tcp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_var.h,v
> retrieving revision 1.158
> diff -u -p -r1.158 tcp_var.h
> --- sys/netinet/tcp_var.h     13 Sep 2022 09:05:47 -0000      1.158
> +++ sys/netinet/tcp_var.h     17 Sep 2022 19:06:10 -0000
> @@ -728,7 +728,7 @@ int        tcp_shutdown(struct socket *);
> void   tcp_rcvd(struct socket *);
> int    tcp_send(struct socket *, struct mbuf *, struct mbuf *,
>            struct mbuf *);
> -int   tcp_abort(struct socket *);
> +void  tcp_abort(struct socket *);
> int    tcp_sockaddr(struct socket *, struct mbuf *);
> int    tcp_peeraddr(struct socket *, struct mbuf *);
> int    tcp_sense(struct socket *, struct stat *);
> Index: sys/netinet/udp_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
> retrieving revision 1.302
> diff -u -p -r1.302 udp_usrreq.c
> --- sys/netinet/udp_usrreq.c  5 Sep 2022 14:56:09 -0000       1.302
> +++ sys/netinet/udp_usrreq.c  17 Sep 2022 19:06:10 -0000
> @@ -132,7 +132,6 @@ const struct pr_usrreqs udp_usrreqs = {
>       .pru_disconnect = udp_disconnect,
>       .pru_shutdown   = udp_shutdown,
>       .pru_send       = udp_send,
> -     .pru_abort      = udp_abort,
>       .pru_control    = in_control,
>       .pru_sockaddr   = in_sockaddr,
>       .pru_peeraddr   = in_peeraddr,
> @@ -149,7 +148,6 @@ const struct pr_usrreqs udp6_usrreqs = {
>       .pru_disconnect = udp_disconnect,
>       .pru_shutdown   = udp_shutdown,
>       .pru_send       = udp_send,
> -     .pru_abort      = udp_abort,
>       .pru_control    = in6_control,
>       .pru_sockaddr   = in6_sockaddr,
>       .pru_peeraddr   = in6_peeraddr,
> @@ -1258,19 +1256,6 @@ 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.47
> diff -u -p -r1.47 udp_var.h
> --- sys/netinet/udp_var.h     5 Sep 2022 14:56:09 -0000       1.47
> +++ sys/netinet/udp_var.h     17 Sep 2022 19:06:10 -0000
> @@ -153,6 +153,5 @@ 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.86
> diff -u -p -r1.86 ip6_divert.c
> --- sys/netinet6/ip6_divert.c 5 Sep 2022 14:56:09 -0000       1.86
> +++ sys/netinet6/ip6_divert.c 17 Sep 2022 19:06:10 -0000
> @@ -71,7 +71,6 @@ const struct pr_usrreqs divert6_usrreqs 
>       .pru_bind       = divert6_bind,
>       .pru_shutdown   = divert6_shutdown,
>       .pru_send       = divert6_send,
> -     .pru_abort      = divert6_abort,
>       .pru_control    = in6_control,
>       .pru_sockaddr   = in6_sockaddr,
>       .pru_peeraddr   = in6_peeraddr,
> @@ -341,18 +340,6 @@ 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.20
> diff -u -p -r1.20 ip6_divert.h
> --- sys/netinet6/ip6_divert.h 5 Sep 2022 14:56:09 -0000       1.20
> +++ sys/netinet6/ip6_divert.h 17 Sep 2022 19:06:10 -0000
> @@ -78,7 +78,6 @@ 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.103
> diff -u -p -r1.103 ip6_var.h
> --- sys/netinet6/ip6_var.h    13 Sep 2022 09:05:02 -0000      1.103
> +++ sys/netinet6/ip6_var.h    17 Sep 2022 19:06:10 -0000
> @@ -361,7 +361,6 @@ 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.169
> diff -u -p -r1.169 raw_ip6.c
> --- sys/netinet6/raw_ip6.c    13 Sep 2022 09:05:02 -0000      1.169
> +++ sys/netinet6/raw_ip6.c    17 Sep 2022 19:06:10 -0000
> @@ -115,7 +115,6 @@ const struct pr_usrreqs rip6_usrreqs = {
>       .pru_disconnect = rip6_disconnect,
>       .pru_shutdown   = rip6_shutdown,
>       .pru_send       = rip6_send,
> -     .pru_abort      = rip6_abort,
>       .pru_control    = in6_control,
>       .pru_sockaddr   = in6_sockaddr,
>       .pru_peeraddr   = in6_peeraddr,
> @@ -777,26 +776,6 @@ 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.56
> diff -u -p -r1.56 protosw.h
> --- sys/sys/protosw.h 13 Sep 2022 09:05:47 -0000      1.56
> +++ sys/sys/protosw.h 17 Sep 2022 19:06:10 -0000
> @@ -75,7 +75,7 @@ struct pr_usrreqs {
>       void    (*pru_rcvd)(struct socket *);
>       int     (*pru_send)(struct socket *, struct mbuf *, struct mbuf *,
>                   struct mbuf *);
> -     int     (*pru_abort)(struct socket *);
> +     void    (*pru_abort)(struct socket *);
>       int     (*pru_control)(struct socket *, u_long, caddr_t,
>                   struct ifnet *);
>       int     (*pru_sense)(struct socket *, struct stat *);
> @@ -349,10 +349,10 @@ pru_send(struct socket *so, struct mbuf 
>       return (*so->so_proto->pr_usrreqs->pru_send)(so, top, addr, control);
> }
> 
> -static inline int
> +static inline void
> pru_abort(struct socket *so)
> {
> -     return (*so->so_proto->pr_usrreqs->pru_abort)(so);
> +     (*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.41
> diff -u -p -r1.41 unpcb.h
> --- sys/sys/unpcb.h   13 Sep 2022 09:05:47 -0000      1.41
> +++ sys/sys/unpcb.h   17 Sep 2022 19:06:10 -0000
> @@ -123,7 +123,7 @@ int       uipc_shutdown(struct socket *);
> void  uipc_rcvd(struct socket *);
> int   uipc_send(struct socket *, struct mbuf *, struct mbuf *,
>           struct mbuf *);
> -int  uipc_abort(struct socket *);
> +void uipc_abort(struct socket *);
> int   uipc_sense(struct socket *, struct stat *);
> int   uipc_sockaddr(struct socket *, struct mbuf *);
> int   uipc_peeraddr(struct socket *, struct mbuf *);
> 

Reply via email to