Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys sbspace() does not return negative values anymore and th...



details:   https://anonhg.NetBSD.org/src/rev/96af18d12faa
branches:  trunk
changeset: 446748:96af18d12faa
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Dec 16 17:46:58 2018 +0000

description:
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@

diffstat:

 sys/netinet/dccp_usrreq.c |   6 +++---
 sys/netinet/tcp_usrreq.c  |   6 +++---
 sys/sys/socketvar.h       |  17 ++++++++++++++++-
 3 files changed, 22 insertions(+), 7 deletions(-)

diffs (86 lines):

diff -r 544870bd2f67 -r 96af18d12faa sys/netinet/dccp_usrreq.c
--- a/sys/netinet/dccp_usrreq.c Sun Dec 16 17:30:57 2018 +0000
+++ b/sys/netinet/dccp_usrreq.c Sun Dec 16 17:46:58 2018 +0000
@@ -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 @@
                }
        }
 
-       if (sbspace(&so->so_snd) < -512) {
+       if (sbspace_oob(&so->so_snd) == 0) {
                INP_UNLOCK(inp);
                error = ENOBUFS;
                goto release;
diff -r 544870bd2f67 -r 96af18d12faa sys/netinet/tcp_usrreq.c
--- a/sys/netinet/tcp_usrreq.c  Sun Dec 16 17:30:57 2018 +0000
+++ b/sys/netinet/tcp_usrreq.c  Sun Dec 16 17:46:58 2018 +0000
@@ -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 @@
        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 -r 544870bd2f67 -r 96af18d12faa sys/sys/socketvar.h
--- a/sys/sys/socketvar.h       Sun Dec 16 17:30:57 2018 +0000
+++ b/sys/sys/socketvar.h       Sun Dec 16 17:46:58 2018 +0000
@@ -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 @@
        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)



Home | Main Index | Thread Index | Old Index