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@
This commit is contained in:
christos 2018-12-16 17:46:58 +00:00
parent 3aa82d61be
commit 5d8a69c49b
3 changed files with 22 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)