Source-Changes-HG archive

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

src: Pull up following revision(s) (requested by roy in ticket #...



details:   https://anonhg.NetBSD.org/src/rev/8f3256aa3819
branches:  netbsd-8
changeset: 317945:8f3256aa3819
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Mon Apr 09 13:34:10 2018 +0000
description:
Pull up following revision(s) (requested by roy in ticket #724):
        tests/net/icmp/t_ping.c: revision 1.19
        sys/netinet6/raw_ip6.c: revision 1.166
        sys/netinet6/ip6_input.c: revision 1.195
        sys/net/raw_usrreq.c: revision 1.59
        sys/sys/socketvar.h: revision 1.151
        sys/kern/uipc_socket2.c: revision 1.128
        tests/lib/libc/sys/t_recvmmsg.c: revision 1.2
        lib/libc/sys/recv.2: revision 1.38
        sys/net/rtsock.c: revision 1.239
        sys/netinet/udp_usrreq.c: revision 1.246
        sys/netinet6/icmp6.c: revision 1.224
        tests/net/icmp/t_ping.c: revision 1.20
        sys/netipsec/keysock.c: revision 1.63
        sys/netinet/raw_ip.c: revision 1.172
        sys/kern/uipc_socket.c: revision 1.260
        tests/net/icmp/t_ping.c: revision 1.22
        sys/kern/uipc_socket.c: revision 1.261
        tests/net/icmp/t_ping.c: revision 1.23
        sys/netinet/ip_mroute.c: revision 1.155
        sbin/route/route.c: revision 1.159
        sys/netinet6/ip6_mroute.c: revision 1.123
        sys/netatalk/ddp_input.c: revision 1.31
        sys/netcan/can.c: revision 1.3
        sys/kern/uipc_usrreq.c: revision 1.184
        sys/netinet6/udp6_usrreq.c: revision 1.138
        tests/net/icmp/t_ping.c: revision 1.18
socket: report receive buffer overflows
Add soroverflow() which increments the overflow counter, sets so_error
to ENOBUFS and wakes the receive socket up.
Replace all code that manually increments this counter with soroverflow().
Add soroverflow() to raw_input().
This allows userland to detect route(4) overflows so it can re-sync
with the current state.
socket: clear error even when peeking
The error has already been reported and it's pointless requiring another
recv(2) call just to clear it.
socket: remove now incorrect comment that so_error is only udp
As it can be affected by route(4) sockets which are raw.
rtsock: log dropped messages that we cannot report to userland
Handle ENOBUFS when receiving messages.
Don't send messages if the receiver has died.
Sprinkle more soroverflow().
Handle ENOBUFS in recv
Handle ENOBUFS in sendto
Note value received. Harden another sendto for ENOBUFS.
Handle the routing socket overflowing gracefully.
Allow a valid sendto .... duh
Handle errors better.
Fix test for checking we sent all the data we asked to.

diffstat:

 lib/libc/sys/recv.2             |   6 ++++--
 sbin/route/route.c              |  19 ++++++++++++++-----
 sys/kern/uipc_socket.c          |  11 +++++------
 sys/kern/uipc_socket2.c         |  18 ++++++++++++++++--
 sys/kern/uipc_usrreq.c          |   6 +++---
 sys/net/raw_usrreq.c            |  31 ++++++++++++++++++-------------
 sys/net/rtsock.c                |   5 +++--
 sys/netatalk/ddp_input.c        |   5 +++--
 sys/netcan/can.c                |   5 +++--
 sys/netinet/ip_mroute.c         |   5 +++--
 sys/netinet/raw_ip.c            |   6 +++---
 sys/netinet/udp_usrreq.c        |   6 +++---
 sys/netinet6/icmp6.c            |   7 ++++---
 sys/netinet6/ip6_input.c        |   6 +++---
 sys/netinet6/ip6_mroute.c       |   5 +++--
 sys/netinet6/raw_ip6.c          |   7 ++++---
 sys/netinet6/udp6_usrreq.c      |   6 +++---
 sys/netipsec/keysock.c          |  11 ++++++-----
 sys/sys/socketvar.h             |   3 ++-
 tests/lib/libc/sys/t_recvmmsg.c |  40 ++++++++++++++++++++++++++++++++++------
 tests/net/icmp/t_ping.c         |  32 +++++++++++++++++++++++---------
 21 files changed, 160 insertions(+), 80 deletions(-)

diffs (truncated from 798 to 300 lines):

diff -r cc5b00c28874 -r 8f3256aa3819 lib/libc/sys/recv.2
--- a/lib/libc/sys/recv.2       Mon Apr 09 13:29:01 2018 +0000
+++ b/lib/libc/sys/recv.2       Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: recv.2,v 1.36 2013/07/14 14:29:09 njoly Exp $
+.\"    $NetBSD: recv.2,v 1.36.20.1 2018/04/09 13:34:10 bouyer Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)recv.2     8.3 (Berkeley) 2/21/94
 .\"
-.Dd June 22, 2012
+.Dd March 19, 2018
 .Dt RECV 2
 .Os
 .Sh NAME
@@ -321,6 +321,8 @@
 .It Bq Er EINVAL
 The total length of the I/O is more than can be expressed by the ssize_t
 return value.
+.It Bq Er ENOBUFS
+A message was not delivered because it would have overflowed the buffer.
 .It Bq Er ENOTCONN
 The socket is associated with a connection-oriented protocol
 and has not been connected (see
diff -r cc5b00c28874 -r 8f3256aa3819 sbin/route/route.c
--- a/sbin/route/route.c        Mon Apr 09 13:29:01 2018 +0000
+++ b/sbin/route/route.c        Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.155.4.2 2017/12/21 21:33:31 snj Exp $      */
+/*     $NetBSD: route.c,v 1.155.4.3 2018/04/09 13:34:11 bouyer Exp $   */
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)route.c    8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.155.4.2 2017/12/21 21:33:31 snj Exp $");
+__RCSID("$NetBSD: route.c,v 1.155.4.3 2018/04/09 13:34:11 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -340,8 +340,10 @@
                        continue;
                rtm->rtm_type = RTM_DELETE;
                rtm->rtm_seq = seqno;
-               if ((rlen = prog_write(sock, next,
-                   rtm->rtm_msglen)) < 0) {
+               do {
+                       rlen = prog_write(sock, next, rtm->rtm_msglen);
+               } while (rlen == -1 && errno == ENOBUFS);
+               if (rlen == -1) {
                        warnx("writing to routing socket: %s",
                            route_strerror(errno));
                        return 1;
@@ -1138,6 +1140,10 @@
        for(i = 0; count == 0 || i < count; i++) {
                time_t now;
                n = prog_read(sock, &u, sizeof(u));
+               if (n == -1) {
+                       warn("read");
+                       continue;
+               }
                now = time(NULL);
                (void)printf("got message of size %d on %s", n, ctime(&now));
                print_rtmsg(&u.hdr, n);
@@ -1213,7 +1219,10 @@
        }
        if (debugonly)
                return 0;
-       if ((rlen = prog_write(sock, (char *)&m_rtmsg, l)) < 0) {
+       do {
+               rlen = prog_write(sock, (char *)&m_rtmsg, l);
+       } while (rlen == -1 && errno == ENOBUFS);
+       if (rlen == -1) {
                warnx("writing to routing socket: %s", route_strerror(errno));
                return -1;
        }
diff -r cc5b00c28874 -r 8f3256aa3819 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Mon Apr 09 13:29:01 2018 +0000
+++ b/sys/kern/uipc_socket.c    Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.255.2.1 2018/03/18 10:57:01 martin Exp $     */
+/*     $NetBSD: uipc_socket.c,v 1.255.2.2 2018/04/09 13:34:10 bouyer Exp $     */
 
 /*-
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.255.2.1 2018/03/18 10:57:01 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.255.2.2 2018/04/09 13:34:10 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1244,8 +1244,7 @@
                        if (m != NULL)
                                goto dontblock;
                        error = so->so_error;
-                       if ((flags & MSG_PEEK) == 0)
-                               so->so_error = 0;
+                       so->so_error = 0;
                        goto release;
                }
                if (so->so_state & SS_CANTRCVMORE) {
@@ -2251,7 +2250,7 @@
                kn->kn_flags |= EV_EOF;
                kn->kn_fflags = so->so_error;
                rv = 1;
-       } else if (so->so_error)        /* temporary udp error */
+       } else if (so->so_error)
                rv = 1;
        else if (kn->kn_sfflags & NOTE_LOWAT)
                rv = (kn->kn_data >= kn->kn_sdata);
@@ -2290,7 +2289,7 @@
                kn->kn_flags |= EV_EOF;
                kn->kn_fflags = so->so_error;
                rv = 1;
-       } else if (so->so_error)        /* temporary udp error */
+       } else if (so->so_error)
                rv = 1;
        else if (((so->so_state & SS_ISCONNECTED) == 0) &&
            (so->so_proto->pr_flags & PR_CONNREQUIRED))
diff -r cc5b00c28874 -r 8f3256aa3819 sys/kern/uipc_socket2.c
--- a/sys/kern/uipc_socket2.c   Mon Apr 09 13:29:01 2018 +0000
+++ b/sys/kern/uipc_socket2.c   Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket2.c,v 1.124 2016/10/02 19:26:46 christos Exp $      */
+/*     $NetBSD: uipc_socket2.c,v 1.124.8.1 2018/04/09 13:34:10 bouyer Exp $    */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.124 2016/10/02 19:26:46 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.124.8.1 2018/04/09 13:34:10 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mbuftrace.h"
@@ -495,6 +495,20 @@
 }
 
 /*
+ * soroverflow(): indicates that data was attempted to be sent
+ * but the receiving buffer overflowed.
+ */
+void
+soroverflow(struct socket *so)
+{
+       KASSERT(solocked(so));
+
+       so->so_rcv.sb_overflowed++;
+       so->so_error = ENOBUFS;
+       sorwakeup(so);
+}
+
+/*
  * Wait for data to arrive at/drain from a socket buffer.
  */
 int
diff -r cc5b00c28874 -r 8f3256aa3819 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Mon Apr 09 13:29:01 2018 +0000
+++ b/sys/kern/uipc_usrreq.c    Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.181 2016/10/31 15:05:05 maxv Exp $   */
+/*     $NetBSD: uipc_usrreq.c,v 1.181.8.1 2018/04/09 13:34:10 bouyer Exp $     */
 
 /*-
  * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.181 2016/10/31 15:05:05 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.181.8.1 2018/04/09 13:34:10 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -329,10 +329,10 @@
 #endif
        if (sbappendaddr(&so2->so_rcv, (const struct sockaddr *)sun, m,
            control) == 0) {
-               so2->so_rcv.sb_overflowed++;
                unp_dispose(control);
                m_freem(control);
                m_freem(m);
+               soroverflow(so2);
                return (ENOBUFS);
        } else {
                sorwakeup(so2);
diff -r cc5b00c28874 -r 8f3256aa3819 sys/net/raw_usrreq.c
--- a/sys/net/raw_usrreq.c      Mon Apr 09 13:29:01 2018 +0000
+++ b/sys/net/raw_usrreq.c      Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: raw_usrreq.c,v 1.56.4.1 2017/10/21 19:43:54 snj Exp $  */
+/*     $NetBSD: raw_usrreq.c,v 1.56.4.2 2018/04/09 13:34:10 bouyer Exp $       */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.56.4.1 2017/10/21 19:43:54 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.56.4.2 2018/04/09 13:34:10 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -106,21 +106,26 @@
                        continue;
                if (last != NULL) {
                        struct mbuf *n;
-                       if ((n = m_copy(m, 0, M_COPYALL)) == NULL)
-                               ;
-                       else if (sbappendaddr(&last->so_rcv, src, n, NULL) == 0)
-                               /* should notify about lost packet */
-                               m_freem(n);
-                       else {
+
+                       if ((n = m_copy(m, 0, M_COPYALL)) == NULL ||
+                           sbappendaddr(&last->so_rcv, src, n, NULL) == 0)
+                       {
+                               if (n != NULL)
+                                       m_freem(n);
+                               soroverflow(last);
+                       } else
                                sorwakeup(last);
-                       }
                }
                last = rp->rcb_socket;
        }
-       if (last == NULL || sbappendaddr(&last->so_rcv, src, m, NULL) == 0)
-               m_freem(m);
-       else {
-               sorwakeup(last);
+       if (last != NULL) {
+               if (sbappendaddr(&last->so_rcv, src, m, NULL) == 0) {
+                       m_free(m);
+                       soroverflow(last);
+               } else
+                       sorwakeup(last);
+       } else {
+               m_free(m);
        }
 }
 
diff -r cc5b00c28874 -r 8f3256aa3819 sys/net/rtsock.c
--- a/sys/net/rtsock.c  Mon Apr 09 13:29:01 2018 +0000
+++ b/sys/net/rtsock.c  Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.213.2.7 2018/02/28 18:54:43 martin Exp $  */
+/*     $NetBSD: rtsock.c,v 1.213.2.8 2018/04/09 13:34:10 bouyer Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.7 2018/02/28 18:54:43 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.8 2018/04/09 13:34:10 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2114,6 +2114,7 @@
 
        IFQ_LOCK(&ri->ri_intrq);
        if (IF_QFULL(&ri->ri_intrq)) {
+               printf("%s: queue full, dropped message\n", __func__);
                IF_DROP(&ri->ri_intrq);
                IFQ_UNLOCK(&ri->ri_intrq);
                m_freem(m);
diff -r cc5b00c28874 -r 8f3256aa3819 sys/netatalk/ddp_input.c
--- a/sys/netatalk/ddp_input.c  Mon Apr 09 13:29:01 2018 +0000
+++ b/sys/netatalk/ddp_input.c  Mon Apr 09 13:34:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ddp_input.c,v 1.29 2016/12/08 05:16:33 ozaki-r Exp $    */
+/*     $NetBSD: ddp_input.c,v 1.29.8.1 2018/04/09 13:34:11 bouyer Exp $         */
 
 /*
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ddp_input.c,v 1.29 2016/12/08 05:16:33 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ddp_input.c,v 1.29.8.1 2018/04/09 13:34:11 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -315,6 +315,7 @@
        if (sbappendaddr(&ddp->ddp_socket->so_rcv, (struct sockaddr *) & from,
                         m, (struct mbuf *) 0) == 0) {
                DDP_STATINC(DDP_STAT_NOSOCKSPACE);



Home | Main Index | Thread Index | Old Index