Index: sys/socketvar.h =================================================================== RCS file: /cvsroot/src/sys/sys/socketvar.h,v retrieving revision 1.158 diff -u -u -r1.158 socketvar.h --- sys/socketvar.h 1 Aug 2018 23:35:32 -0000 1.158 +++ sys/socketvar.h 16 Dec 2018 16:32:50 -0000 @@ -68,6 +68,7 @@ #include #include #include +#include #if !defined(_KERNEL) struct uio; @@ -412,6 +413,21 @@ return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt); } +static __inline u_long +sbspace_oob(const struct sockbuf *sb) +{ + u_long hiwat = sb->sb_hiwat; + + if (hiwat < ULONG_MAX - 1024) + hiwat += 1024; + + KASSERT(solocked(sb->sb_so)); + + if (hiwat <= sb->sb_cc || sb->sb_mbmax <= sb->sb_mbcnt) + return 0; + return lmin(hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt); +} + /* do we have to send all at once on a socket? */ static __inline int sosendallatonce(const struct socket *so) Index: netinet/dccp_usrreq.c =================================================================== RCS file: /cvsroot/src/sys/netinet/dccp_usrreq.c,v retrieving revision 1.20 diff -u -u -r1.20 dccp_usrreq.c --- netinet/dccp_usrreq.c 14 Sep 2018 05:09:51 -0000 1.20 +++ netinet/dccp_usrreq.c 16 Dec 2018 16:32:51 -0000 @@ -2157,7 +2157,7 @@ } } - if (sbspace(&so->so_snd) < -512) { + if (sbspace_oob(&so->so_snd) == 0) { INP_UNLOCK(inp); error = ENOBUFS; goto release; Index: netinet/tcp_usrreq.c =================================================================== RCS file: /cvsroot/src/sys/netinet/tcp_usrreq.c,v retrieving revision 1.221 diff -u -u -r1.221 tcp_usrreq.c --- netinet/tcp_usrreq.c 24 Nov 2018 17:05:54 -0000 1.221 +++ netinet/tcp_usrreq.c 16 Dec 2018 16:32:51 -0000 @@ -1154,7 +1154,7 @@ ostate = tcp_debug_capture(tp, PRU_SENDOOB); s = splsoftnet(); - if (sbspace(&so->so_snd) < -512) { + if (sbspace_oob(&so->so_snd) == 0) { m_freem(m); splx(s); return ENOBUFS;