From 5d8a69c49b590d39eb34a56f40ed145cc7da038c Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 16 Dec 2018 17:46:58 +0000 Subject: [PATCH] sbspace() does not return negative values anymore and that broke OOB data sending. Instead of depending on negative values, account for the 1024 bytes sosend() adds so that it can use all the space here in a separate function sbspace_oob(). Idea from mlelstv@ --- sys/netinet/dccp_usrreq.c | 6 +++--- sys/netinet/tcp_usrreq.c | 6 +++--- sys/sys/socketvar.h | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/sys/netinet/dccp_usrreq.c b/sys/netinet/dccp_usrreq.c index 3fd29ad5c5a5..fe32333553e6 100644 --- a/sys/netinet/dccp_usrreq.c +++ b/sys/netinet/dccp_usrreq.c @@ -1,5 +1,5 @@ /* $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $ */ -/* $NetBSD: dccp_usrreq.c,v 1.20 2018/09/14 05:09:51 maxv Exp $ */ +/* $NetBSD: dccp_usrreq.c,v 1.21 2018/12/16 17:46:58 christos Exp $ */ /* * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.20 2018/09/14 05:09:51 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.21 2018/12/16 17:46:58 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -2157,7 +2157,7 @@ dccp_send(struct socket *so, struct mbuf *m, struct sockaddr *addr, } } - if (sbspace(&so->so_snd) < -512) { + if (sbspace_oob(&so->so_snd) == 0) { INP_UNLOCK(inp); error = ENOBUFS; goto release; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 1daecacdae61..a05dde41eb70 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_usrreq.c,v 1.221 2018/11/24 17:05:54 maxv Exp $ */ +/* $NetBSD: tcp_usrreq.c,v 1.222 2018/12/16 17:46:58 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -99,7 +99,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.221 2018/11/24 17:05:54 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.222 2018/12/16 17:46:58 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1154,7 +1154,7 @@ tcp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control) 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; diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index cda50dd81b70..a7b0a0fbcb3b 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: socketvar.h,v 1.158 2018/08/01 23:35:32 rjs Exp $ */ +/* $NetBSD: socketvar.h,v 1.159 2018/12/16 17:46:58 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -412,6 +412,21 @@ sbspace(const struct sockbuf *sb) 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)