PRU_SENDOOB request always consumes passed `top' and `control' mbufs. We don't want to have dummy m_freem(9) handlers for all protocols, so we release passed mbufs in the pru_sendoob() EOPNOTSUPP error path.
Also we had the `control' mbuf(9) leak in the tcp(4) PRU_SENDOOB error path, which was fixed in this diff. Index: sys/kern/uipc_usrreq.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_usrreq.c,v retrieving revision 1.179 diff -u -p -r1.179 uipc_usrreq.c --- sys/kern/uipc_usrreq.c 29 Aug 2022 08:08:17 -0000 1.179 +++ sys/kern/uipc_usrreq.c 29 Aug 2022 09:28:42 -0000 @@ -247,10 +247,6 @@ uipc_usrreq(struct socket *so, int req, } break; - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: uipc_setaddr(unp, nam); break; Index: sys/net/pfkeyv2.c =================================================================== RCS file: /cvs/src/sys/net/pfkeyv2.c,v retrieving revision 1.247 diff -u -p -r1.247 pfkeyv2.c --- sys/net/pfkeyv2.c 29 Aug 2022 08:08:17 -0000 1.247 +++ sys/net/pfkeyv2.c 29 Aug 2022 09:28:42 -0000 @@ -426,9 +426,6 @@ pfkeyv2_usrreq(struct socket *so, int re nam->m_len = pfkey_addr.sa_len; break; - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; default: panic("pfkeyv2_usrreq"); } Index: sys/net/rtsock.c =================================================================== RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.348 diff -u -p -r1.348 rtsock.c --- sys/net/rtsock.c 29 Aug 2022 08:08:17 -0000 1.348 +++ sys/net/rtsock.c 29 Aug 2022 09:28:42 -0000 @@ -251,9 +251,6 @@ route_usrreq(struct socket *so, int req, nam->m_len = route_src.sa_len; break; - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; default: panic("route_usrreq"); } Index: sys/netinet/ip_divert.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_divert.c,v retrieving revision 1.81 diff -u -p -r1.81 ip_divert.c --- sys/netinet/ip_divert.c 29 Aug 2022 08:08:17 -0000 1.81 +++ sys/netinet/ip_divert.c 29 Aug 2022 09:28:42 -0000 @@ -280,7 +280,6 @@ divert_usrreq(struct socket *so, int req break; case PRU_CONNECT2: - case PRU_SENDOOB: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: Index: sys/netinet/raw_ip.c =================================================================== RCS file: /cvs/src/sys/netinet/raw_ip.c,v retrieving revision 1.142 diff -u -p -r1.142 raw_ip.c --- sys/netinet/raw_ip.c 29 Aug 2022 08:08:17 -0000 1.142 +++ sys/netinet/raw_ip.c 29 Aug 2022 09:28:42 -0000 @@ -482,13 +482,6 @@ rip_usrreq(struct socket *so, int req, s error = EOPNOTSUPP; break; - /* - * Not supported. - */ - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: in_setsockaddr(inp, nam); break; Index: sys/netinet/tcp_usrreq.c =================================================================== RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v retrieving revision 1.199 diff -u -p -r1.199 tcp_usrreq.c --- sys/netinet/tcp_usrreq.c 29 Aug 2022 08:08:17 -0000 1.199 +++ sys/netinet/tcp_usrreq.c 29 Aug 2022 09:28:42 -0000 @@ -126,6 +126,7 @@ const struct pr_usrreqs tcp_usrreqs = { .pru_abort = tcp_abort, .pru_sense = tcp_sense, .pru_rcvoob = tcp_rcvoob, + .pru_sendoob = tcp_sendoob, }; static int pr_slowhz = PR_SLOWHZ; @@ -229,27 +230,6 @@ tcp_usrreq(struct socket *so, int req, s error = EOPNOTSUPP; break; - case PRU_SENDOOB: - if (sbspace(so, &so->so_snd) < -512) { - m_freem(m); - error = ENOBUFS; - break; - } - /* - * According to RFC961 (Assigned Protocols), - * the urgent pointer points to the last octet - * of urgent data. We continue, however, - * to consider it to indicate the first octet - * of data past the urgent section. - * Otherwise, snd_up should be one lower. - */ - sbappendstream(so, &so->so_snd, m); - tp->snd_up = tp->snd_una + so->so_snd.sb_cc; - tp->t_force = 1; - error = tcp_output(tp); - tp->t_force = 0; - break; - case PRU_SOCKADDR: #ifdef INET6 if (inp->inp_flags & INP_IPV6) @@ -1015,6 +995,60 @@ out: tcp_trace(TA_USER, tp->t_state, tp, tp, NULL, PRU_RCVOOB, 0); return (error); } + +int +tcp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *nam, + struct mbuf *control) +{ + struct inpcb *inp; + struct tcpcb *tp; + int error; + short ostate; + + soassertlocked(so); + + if (control && control->m_len) { + error = EINVAL; + goto release; + } + + if ((error = tcp_sogetpcb(so, &inp, &tp))) + goto release; + + if (so->so_options & SO_DEBUG) + ostate = tp->t_state; + + if (sbspace(so, &so->so_snd) < -512) { + error = ENOBUFS; + goto out; + } + + /* + * According to RFC961 (Assigned Protocols), + * the urgent pointer points to the last octet + * of urgent data. We continue, however, + * to consider it to indicate the first octet + * of data past the urgent section. + * Otherwise, snd_up should be one lower. + */ + sbappendstream(so, &so->so_snd, m); + m = NULL; + tp->snd_up = tp->snd_una + so->so_snd.sb_cc; + tp->t_force = 1; + error = tcp_output(tp); + tp->t_force = 0; + +out: + if (so->so_options & SO_DEBUG) + tcp_trace(TA_USER, ostate, tp, tp, NULL, PRU_SENDOOB, 0); + +release: + m_freem(control); + m_freem(m); + + return (error); +} + /* * Initiate (or continue) disconnect. Index: sys/netinet/tcp_var.h =================================================================== RCS file: /cvs/src/sys/netinet/tcp_var.h,v retrieving revision 1.152 diff -u -p -r1.152 tcp_var.h --- sys/netinet/tcp_var.h 29 Aug 2022 08:08:17 -0000 1.152 +++ sys/netinet/tcp_var.h 29 Aug 2022 09:28:42 -0000 @@ -727,6 +727,8 @@ int tcp_send(struct socket *, struct mb int tcp_abort(struct socket *); int tcp_sense(struct socket *, struct stat *); int tcp_rcvoob(struct socket *, struct mbuf *, int); +int tcp_sendoob(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); 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.294 diff -u -p -r1.294 udp_usrreq.c --- sys/netinet/udp_usrreq.c 29 Aug 2022 08:08:17 -0000 1.294 +++ sys/netinet/udp_usrreq.c 29 Aug 2022 09:28:42 -0000 @@ -1106,7 +1106,6 @@ udp_usrreq(struct socket *so, int req, s in_setpeeraddr(inp, addr); break; - case PRU_SENDOOB: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: Index: sys/netinet6/ip6_divert.c =================================================================== RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v retrieving revision 1.80 diff -u -p -r1.80 ip6_divert.c --- sys/netinet6/ip6_divert.c 29 Aug 2022 08:08:17 -0000 1.80 +++ sys/netinet6/ip6_divert.c 29 Aug 2022 09:28:42 -0000 @@ -286,7 +286,6 @@ divert6_usrreq(struct socket *so, int re break; case PRU_CONNECT2: - case PRU_SENDOOB: case PRU_FASTTIMO: case PRU_SLOWTIMO: case PRU_PROTORCV: Index: sys/netinet6/raw_ip6.c =================================================================== RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v retrieving revision 1.162 diff -u -p -r1.162 raw_ip6.c --- sys/netinet6/raw_ip6.c 29 Aug 2022 08:08:17 -0000 1.162 +++ sys/netinet6/raw_ip6.c 29 Aug 2022 09:28:43 -0000 @@ -597,13 +597,6 @@ rip6_usrreq(struct socket *so, int req, error = EOPNOTSUPP; break; - /* - * Not supported. - */ - case PRU_SENDOOB: - error = EOPNOTSUPP; - break; - case PRU_SOCKADDR: in6_setsockaddr(in6p, nam); break; Index: sys/sys/protosw.h =================================================================== RCS file: /cvs/src/sys/sys/protosw.h,v retrieving revision 1.49 diff -u -p -r1.49 protosw.h --- sys/sys/protosw.h 29 Aug 2022 08:08:17 -0000 1.49 +++ sys/sys/protosw.h 29 Aug 2022 09:28:43 -0000 @@ -79,6 +79,8 @@ struct pr_usrreqs { int (*pru_abort)(struct socket *); int (*pru_sense)(struct socket *, struct stat *); int (*pru_rcvoob)(struct socket *, struct mbuf *, int); + int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); }; struct protosw { @@ -242,6 +244,7 @@ char *prcorequests[] = { #ifdef _KERNEL +#include <sys/mbuf.h> #include <sys/socketvar.h> #include <sys/systm.h> @@ -367,8 +370,12 @@ static inline int pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr, struct mbuf *control) { - return (*so->so_proto->pr_usrreqs->pru_usrreq)(so, - PRU_SENDOOB, top, addr, control, curproc); + if (so->so_proto->pr_usrreqs->pru_sendoob) + return (*so->so_proto->pr_usrreqs->pru_sendoob)(so, + top, addr, control); + m_freem(top); + m_freem(control); + return (EOPNOTSUPP); } static inline int