summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2018-12-16 17:46:58 +0000
committerchristos <christos@NetBSD.org>2018-12-16 17:46:58 +0000
commit65093efef762d730bf3f84c6bdf79dcf2f7f0cb2 (patch)
tree4d00059c846fb4ae0d472b4dd920e78973f40715
parent7f9882455050f075df8b1c111c72ccc23f9280a8 (diff)
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@
-rw-r--r--sys/netinet/dccp_usrreq.c6
-rw-r--r--sys/netinet/tcp_usrreq.c6
-rw-r--r--sys/sys/socketvar.h17
3 files changed, 22 insertions, 7 deletions
diff --git a/sys/netinet/dccp_usrreq.c b/sys/netinet/dccp_usrreq.c
index 3fd29ad5c5a..fe32333553e 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 <sys/cdefs.h>
-__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 1daecacdae6..a05dde41eb7 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 <sys/cdefs.h>
-__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 cda50dd81b7..a7b0a0fbcb3 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)