Source-Changes-HG archive

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

[src/trunk]: src/sys * split PRU_ACCEPT function out of pr_generic() usrreq s...



details:   https://anonhg.NetBSD.org/src/rev/8108aa337e0e
branches:  trunk
changeset: 330457:8108aa337e0e
user:      rtr <rtr%NetBSD.org@localhost>
date:      Wed Jul 09 14:41:42 2014 +0000

description:
* split PRU_ACCEPT function out of pr_generic() usrreq switches and put
  into a separate function xxx_accept(struct socket *, struct mbuf *)

note: future cleanup will take place to remove struct mbuf parameter
type and replace it with a more appropriate type.

patch reviewed by rmind

diffstat:

 sys/kern/uipc_socket.c              |    7 +-
 sys/kern/uipc_usrreq.c              |  119 ++++++++++++++++++++---------------
 sys/net/if_mpls.c                   |    8 +-
 sys/net/raw_usrreq.c                |    5 +-
 sys/net/rtsock.c                    |   16 ++++-
 sys/netatalk/ddp_usrreq.c           |   16 +++-
 sys/netbt/hci_socket.c              |   16 +++-
 sys/netbt/l2cap_socket.c            |   30 ++++++--
 sys/netbt/rfcomm_socket.c           |   30 ++++++--
 sys/netbt/sco_socket.c              |   30 ++++++--
 sys/netinet/raw_ip.c                |   17 ++++-
 sys/netinet/tcp_usrreq.c            |   97 +++++++++++++++++++++++-----
 sys/netinet/udp_usrreq.c            |   17 ++++-
 sys/netinet6/raw_ip6.c              |   16 +++-
 sys/netinet6/udp6_usrreq.c          |   16 +++-
 sys/netipsec/keysock.c              |   17 ++++-
 sys/netmpls/mpls_proto.c            |   18 ++++-
 sys/netnatm/natm.c                  |   16 +++-
 sys/rump/net/lib/libsockin/sockin.c |   20 ++++-
 sys/sys/protosw.h                   |   12 +++-
 20 files changed, 385 insertions(+), 138 deletions(-)

diffs (truncated from 1355 to 300 lines):

diff -r 80f10ac56cfb -r 8108aa337e0e sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Wed Jul 09 13:50:48 2014 +0000
+++ b/sys/kern/uipc_socket.c    Wed Jul 09 14:41:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.224 2014/05/19 02:51:24 rmind Exp $  */
+/*     $NetBSD: uipc_socket.c,v 1.225 2014/07/09 14:41:42 rtr 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.224 2014/05/19 02:51:24 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.225 2014/07/09 14:41:42 rtr Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_sock_counters.h"
@@ -802,8 +802,7 @@
        so->so_state &= ~SS_NOFDREF;
        if ((so->so_state & SS_ISDISCONNECTED) == 0 ||
            (so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0)
-               error = (*so->so_proto->pr_usrreqs->pr_generic)(so,
-                   PRU_ACCEPT, NULL, nam, NULL, NULL);
+               error = (*so->so_proto->pr_usrreqs->pr_accept)(so, nam);
        else
                error = ECONNABORTED;
 
diff -r 80f10ac56cfb -r 8108aa337e0e sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Wed Jul 09 13:50:48 2014 +0000
+++ b/sys/kern/uipc_usrreq.c    Wed Jul 09 14:41:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.158 2014/07/09 04:54:03 rtr Exp $    */
+/*     $NetBSD: uipc_usrreq.c,v 1.159 2014/07/09 14:41:42 rtr 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.158 2014/07/09 04:54:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.159 2014/07/09 14:41:42 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -376,6 +376,7 @@
 
        KASSERT(req != PRU_ATTACH);
        KASSERT(req != PRU_DETACH);
+       KASSERT(req != PRU_ACCEPT);
        KASSERT(req != PRU_CONTROL);
        KASSERT(req != PRU_SENSE);
        KASSERT(req != PRU_PEERADDR);
@@ -419,56 +420,6 @@
                unp_disconnect(unp);
                break;
 
-       case PRU_ACCEPT:
-               KASSERT(so->so_lock == uipc_lock);
-               /*
-                * Mark the initiating STREAM socket as connected *ONLY*
-                * after it's been accepted.  This prevents a client from
-                * overrunning a server and receiving ECONNREFUSED.
-                */
-               if (unp->unp_conn == NULL) {
-                       /*
-                        * This will use the empty socket and will not
-                        * allocate.
-                        */
-                       unp_setaddr(so, nam, true);
-                       break;
-               }
-               so2 = unp->unp_conn->unp_socket;
-               if (so2->so_state & SS_ISCONNECTING) {
-                       KASSERT(solocked2(so, so->so_head));
-                       KASSERT(solocked2(so2, so->so_head));
-                       soisconnected(so2);
-               }
-               /*
-                * If the connection is fully established, break the
-                * association with uipc_lock and give the connected
-                * pair a separate lock to share.
-                * There is a race here: sotounpcb(so2)->unp_streamlock
-                * is not locked, so when changing so2->so_lock
-                * another thread can grab it while so->so_lock is still
-                * pointing to the (locked) uipc_lock.
-                * this should be harmless, except that this makes
-                * solocked2() and solocked() unreliable.
-                * Another problem is that unp_setaddr() expects the
-                * the socket locked. Grabing sotounpcb(so2)->unp_streamlock
-                * fixes both issues.
-                */
-               mutex_enter(sotounpcb(so2)->unp_streamlock);
-               unp_setpeerlocks(so2, so);
-               /*
-                * Only now return peer's address, as we may need to
-                * block in order to allocate memory.
-                *
-                * XXX Minor race: connection can be broken while
-                * lock is dropped in unp_setaddr().  We will return
-                * error == 0 and sun_noname as the peer address.
-                */
-               unp_setaddr(so, nam, true);
-               /* so_lock now points to unp_streamlock */
-               mutex_exit(so2->so_lock);
-               break;
-
        case PRU_SHUTDOWN:
                socantsendmore(so);
                unp_shutdown(unp);
@@ -837,6 +788,69 @@
 }
 
 static int
+unp_accept(struct socket *so, struct mbuf *nam)
+{
+       struct unpcb *unp = sotounpcb(so);
+       struct socket *so2;
+
+       KASSERT(solocked(so));
+       KASSERT(nam != NULL);
+
+       /* XXX code review required to determine if unp can ever be NULL */
+       if (unp == NULL)
+               return EINVAL;
+
+       KASSERT(so->so_lock == uipc_lock);
+       /*
+        * Mark the initiating STREAM socket as connected *ONLY*
+        * after it's been accepted.  This prevents a client from
+        * overrunning a server and receiving ECONNREFUSED.
+        */
+       if (unp->unp_conn == NULL) {
+               /*
+                * This will use the empty socket and will not
+                * allocate.
+                */
+               unp_setaddr(so, nam, true);
+               return 0;
+       }
+       so2 = unp->unp_conn->unp_socket;
+       if (so2->so_state & SS_ISCONNECTING) {
+               KASSERT(solocked2(so, so->so_head));
+               KASSERT(solocked2(so2, so->so_head));
+               soisconnected(so2);
+       }
+       /*
+        * If the connection is fully established, break the
+        * association with uipc_lock and give the connected
+        * pair a separate lock to share.
+        * There is a race here: sotounpcb(so2)->unp_streamlock
+        * is not locked, so when changing so2->so_lock
+        * another thread can grab it while so->so_lock is still
+        * pointing to the (locked) uipc_lock.
+        * this should be harmless, except that this makes
+        * solocked2() and solocked() unreliable.
+        * Another problem is that unp_setaddr() expects the
+        * the socket locked. Grabing sotounpcb(so2)->unp_streamlock
+        * fixes both issues.
+        */
+       mutex_enter(sotounpcb(so2)->unp_streamlock);
+       unp_setpeerlocks(so2, so);
+       /*
+        * Only now return peer's address, as we may need to
+        * block in order to allocate memory.
+        *
+        * XXX Minor race: connection can be broken while
+        * lock is dropped in unp_setaddr().  We will return
+        * error == 0 and sun_noname as the peer address.
+        */
+       unp_setaddr(so, nam, true);
+       /* so_lock now points to unp_streamlock */
+       mutex_exit(so2->so_lock);
+       return 0;
+}
+
+static int
 unp_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
 {
        return EOPNOTSUPP;
@@ -1843,6 +1857,7 @@
 const struct pr_usrreqs unp_usrreqs = {
        .pr_attach      = unp_attach,
        .pr_detach      = unp_detach,
+       .pr_accept      = unp_accept,
        .pr_ioctl       = unp_ioctl,
        .pr_stat        = unp_stat,
        .pr_peeraddr    = unp_peeraddr,
diff -r 80f10ac56cfb -r 8108aa337e0e sys/net/if_mpls.c
--- a/sys/net/if_mpls.c Wed Jul 09 13:50:48 2014 +0000
+++ b/sys/net/if_mpls.c Wed Jul 09 14:41:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_mpls.c,v 1.14 2014/06/06 01:02:47 rmind Exp $ */
+/*     $NetBSD: if_mpls.c,v 1.15 2014/07/09 14:41:42 rtr Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.14 2014/06/06 01:02:47 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.15 2014/07/09 14:41:42 rtr Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -104,7 +104,7 @@
 static struct mbuf *mpls_prepend_shim(struct mbuf *, union mpls_shim *);
 
 extern int mpls_defttl, mpls_mapttl_inet, mpls_mapttl_inet6, mpls_icmp_respond,
-       mpls_forwarding, mpls_accept, mpls_mapprec_inet, mpls_mapclass_inet6,
+       mpls_forwarding, mpls_frame_accept, mpls_mapprec_inet, mpls_mapclass_inet6,
        mpls_rfc4182;
 
 /* ARGSUSED */
@@ -329,7 +329,7 @@
 
        /* Check if we're accepting MPLS Frames */
        error = EINVAL;
-       if (!mpls_accept)
+       if (!mpls_frame_accept)
                goto done;
 
        /* TTL decrement */
diff -r 80f10ac56cfb -r 8108aa337e0e sys/net/raw_usrreq.c
--- a/sys/net/raw_usrreq.c      Wed Jul 09 13:50:48 2014 +0000
+++ b/sys/net/raw_usrreq.c      Wed Jul 09 14:41:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: raw_usrreq.c,v 1.42 2014/07/09 04:54:03 rtr Exp $      */
+/*     $NetBSD: raw_usrreq.c,v 1.43 2014/07/09 14:41:42 rtr Exp $      */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.42 2014/07/09 04:54:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.43 2014/07/09 14:41:42 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -162,6 +162,7 @@
 
        KASSERT(req != PRU_ATTACH);
        KASSERT(req != PRU_DETACH);
+       KASSERT(req != PRU_ACCEPT);
        KASSERT(req != PRU_CONTROL);
        KASSERT(req != PRU_SENSE);
        KASSERT(req != PRU_PEERADDR);
diff -r 80f10ac56cfb -r 8108aa337e0e sys/net/rtsock.c
--- a/sys/net/rtsock.c  Wed Jul 09 13:50:48 2014 +0000
+++ b/sys/net/rtsock.c  Wed Jul 09 14:41:42 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.154 2014/07/09 04:54:03 rtr Exp $ */
+/*     $NetBSD: rtsock.c,v 1.155 2014/07/09 14:41:42 rtr 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.154 2014/07/09 04:54:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.155 2014/07/09 14:41:42 rtr Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -224,6 +224,16 @@
 }
 
 static int
+COMPATNAME(route_accept)(struct socket *so, struct mbuf *nam)
+{
+       KASSERT(solocked(so));
+
+       panic("route_accept");
+       /* NOT REACHED */
+       return EOPNOTSUPP;
+}
+
+static int
 COMPATNAME(route_ioctl)(struct socket *so, u_long cmd, void *nam,
     struct ifnet * ifp)
 {
@@ -278,6 +288,7 @@
 
        KASSERT(req != PRU_ATTACH);
        KASSERT(req != PRU_DETACH);
+       KASSERT(req != PRU_ACCEPT);
        KASSERT(req != PRU_CONTROL);
        KASSERT(req != PRU_SENSE);
        KASSERT(req != PRU_PEERADDR);
@@ -1378,6 +1389,7 @@
 static const struct pr_usrreqs route_usrreqs = {
        .pr_attach      = COMPATNAME(route_attach_wrapper),
        .pr_detach      = COMPATNAME(route_detach_wrapper),
+       .pr_accept      = COMPATNAME(route_accept_wrapper),
        .pr_ioctl       = COMPATNAME(route_ioctl_wrapper),



Home | Main Index | Thread Index | Old Index