Source-Changes-HG archive

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

[src/trunk]: src/sys split PRU_SEND function out of pr_generic() usrreq switc...



details:   https://anonhg.NetBSD.org/src/rev/02aadf70e79c
branches:  trunk
changeset: 331193:02aadf70e79c
user:      rtr <rtr%NetBSD.org@localhost>
date:      Tue Aug 05 07:55:31 2014 +0000

description:
split PRU_SEND function out of pr_generic() usrreq switches and put into
separate functions

   xxx_send(struct socket *, struct mbuf *, struct mbuf *,
       struct mbuf *, struct lwp *)

  - always KASSERT(solocked(so)) even if not implemented

  - replace calls to pr_generic() with req = PRU_SEND with calls to
    pr_send()

rename existing functions that operate on PCB for consistency (and to
free up their names for xxx_send() PRUs

  - l2cap_send() -> l2cap_send_pcb()
  - sco_send() -> sco_send_pcb()
  - rfcomm_send() -> rfcomm_send_pcb()

patch reviewed by rmind

diffstat:

 sys/dev/bluetooth/bthidev.c         |    6 +-
 sys/dev/bluetooth/btmagic.c         |    6 +-
 sys/dev/bluetooth/btsco.c           |    8 +-
 sys/dev/kttcp.c                     |    8 +-
 sys/kern/uipc_socket.c              |    8 +-
 sys/kern/uipc_usrreq.c              |  250 +++++++++++++++++++----------------
 sys/net/if_gre.c                    |    8 +-
 sys/net/link_proto.c                |   17 ++-
 sys/net/raw_cb.h                    |    4 +-
 sys/net/raw_usrreq.c                |   82 ++++++-----
 sys/net/rtsock.c                    |   22 ++-
 sys/netatalk/ddp_usrreq.c           |   73 +++++----
 sys/netbt/hci_socket.c              |   68 ++++++---
 sys/netbt/l2cap.h                   |    6 +-
 sys/netbt/l2cap_lower.c             |    6 +-
 sys/netbt/l2cap_socket.c            |   73 ++++++---
 sys/netbt/l2cap_upper.c             |    8 +-
 sys/netbt/rfcomm.h                  |    6 +-
 sys/netbt/rfcomm_session.c          |    8 +-
 sys/netbt/rfcomm_socket.c           |   57 +++++--
 sys/netbt/rfcomm_upper.c            |    8 +-
 sys/netbt/sco.h                     |    4 +-
 sys/netbt/sco_socket.c              |   71 ++++++---
 sys/netbt/sco_upper.c               |    8 +-
 sys/netinet/raw_ip.c                |   93 +++++++-----
 sys/netinet/tcp_usrreq.c            |   61 ++++++--
 sys/netinet/udp_usrreq.c            |  100 ++++++++------
 sys/netinet6/raw_ip6.c              |  104 ++++++++------
 sys/netinet6/udp6_usrreq.c          |   34 +++-
 sys/netipsec/keysock.c              |   23 +++-
 sys/netmpls/mpls_proto.c            |   16 ++-
 sys/netnatm/natm.c                  |   69 +++++----
 sys/nfs/nfs_socket.c                |   12 +-
 sys/rump/net/lib/libsockin/sockin.c |  124 +++++++++--------
 sys/sys/protosw.h                   |   14 +-
 35 files changed, 884 insertions(+), 581 deletions(-)

diffs (truncated from 2745 to 300 lines):

diff -r 4e8a7e4c4064 -r 02aadf70e79c sys/dev/bluetooth/bthidev.c
--- a/sys/dev/bluetooth/bthidev.c       Tue Aug 05 07:34:52 2014 +0000
+++ b/sys/dev/bluetooth/bthidev.c       Tue Aug 05 07:55:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bthidev.c,v 1.28 2014/07/31 03:39:35 rtr Exp $ */
+/*     $NetBSD: bthidev.c,v 1.29 2014/08/05 07:55:31 rtr Exp $ */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.28 2014/07/31 03:39:35 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.29 2014/08/05 07:55:31 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -1017,7 +1017,7 @@
        m->m_pkthdr.len = m->m_len = rlen + 2;
 
        mutex_enter(bt_lock);
-       err = l2cap_send(sc->sc_int, m);
+       err = l2cap_send_pcb(sc->sc_int, m);
        mutex_exit(bt_lock);
 
        return err;
diff -r 4e8a7e4c4064 -r 02aadf70e79c sys/dev/bluetooth/btmagic.c
--- a/sys/dev/bluetooth/btmagic.c       Tue Aug 05 07:34:52 2014 +0000
+++ b/sys/dev/bluetooth/btmagic.c       Tue Aug 05 07:55:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btmagic.c,v 1.10 2014/07/31 03:39:35 rtr Exp $ */
+/*     $NetBSD: btmagic.c,v 1.11 2014/08/05 07:55:31 rtr Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
  *****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.10 2014/07/31 03:39:35 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.11 2014/08/05 07:55:31 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -723,7 +723,7 @@
 
        memcpy(mtod(m, uint8_t *), data, len);
        m->m_pkthdr.len = m->m_len = len;
-       return l2cap_send(sc->sc_ctl, m);
+       return l2cap_send_pcb(sc->sc_ctl, m);
 }
 
 /*
diff -r 4e8a7e4c4064 -r 02aadf70e79c sys/dev/bluetooth/btsco.c
--- a/sys/dev/bluetooth/btsco.c Tue Aug 05 07:34:52 2014 +0000
+++ b/sys/dev/bluetooth/btsco.c Tue Aug 05 07:55:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btsco.c,v 1.32 2014/07/31 03:39:35 rtr Exp $   */
+/*     $NetBSD: btsco.c,v 1.33 2014/08/05 07:55:31 rtr Exp $   */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: btsco.c,v 1.32 2014/07/31 03:39:35 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: btsco.c,v 1.33 2014/08/05 07:55:31 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/audioio.h>
@@ -1123,7 +1123,7 @@
 /*
  * Our transmit interrupt. This is triggered when a new block is to be
  * sent.  We send mtu sized chunks of the block as mbufs with external
- * storage to sco_send()
+ * storage to sco_send_pcb()
  */
 static void
 btsco_intr(void *arg)
@@ -1163,7 +1163,7 @@
                m->m_pkthdr.len = m->m_len = mlen;
                sc->sc_tx_pending++;
 
-               if (sco_send(sc->sc_sco, m) > 0) {
+               if (sco_send_pcb(sc->sc_sco, m) > 0) {
                        sc->sc_tx_pending--;
                        break;
                }
diff -r 4e8a7e4c4064 -r 02aadf70e79c sys/dev/kttcp.c
--- a/sys/dev/kttcp.c   Tue Aug 05 07:34:52 2014 +0000
+++ b/sys/dev/kttcp.c   Tue Aug 05 07:55:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kttcp.c,v 1.35 2014/07/25 08:10:35 dholland Exp $      */
+/*     $NetBSD: kttcp.c,v 1.36 2014/08/05 07:55:31 rtr Exp $   */
 
 /*
  * Copyright (c) 2002 Wasabi Systems, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kttcp.c,v 1.35 2014/07/25 08:10:35 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kttcp.c,v 1.36 2014/08/05 07:55:31 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -324,8 +324,8 @@
                                error = (*so->so_proto->pr_usrreqs->pr_sendoob)(so,
                                    top, NULL);
                        else
-                               error = (*so->so_proto->pr_usrreqs->pr_generic)(so,
-                                   PRU_SEND, top, NULL, NULL, l);
+                               error = (*so->so_proto->pr_usrreqs->pr_send)(so,
+                                   top, NULL, NULL, l);
                        if (dontroute)
                                so->so_options &= ~SO_DONTROUTE;
                        if (resid > 0)
diff -r 4e8a7e4c4064 -r 02aadf70e79c sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Tue Aug 05 07:34:52 2014 +0000
+++ b/sys/kern/uipc_socket.c    Tue Aug 05 07:55:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.231 2014/08/05 05:24:26 rtr Exp $    */
+/*     $NetBSD: uipc_socket.c,v 1.232 2014/08/05 07:55:31 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.231 2014/08/05 05:24:26 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.232 2014/08/05 07:55:31 rtr Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_sock_counters.h"
@@ -1052,8 +1052,8 @@
                                error = (*so->so_proto->pr_usrreqs->pr_sendoob)(so,
                                    top, control);
                        else
-                               error = (*so->so_proto->pr_usrreqs->pr_generic)(so,
-                                   PRU_SEND, top, addr, control, curlwp);
+                               error = (*so->so_proto->pr_usrreqs->pr_send)(so,
+                                   top, addr, control, l);
                        if (dontroute)
                                so->so_options &= ~SO_DONTROUTE;
                        if (resid > 0)
diff -r 4e8a7e4c4064 -r 02aadf70e79c sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Tue Aug 05 07:34:52 2014 +0000
+++ b/sys/kern/uipc_usrreq.c    Tue Aug 05 07:55:31 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.165 2014/08/05 05:24:26 rtr Exp $    */
+/*     $NetBSD: uipc_usrreq.c,v 1.166 2014/08/05 07:55:31 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.165 2014/08/05 05:24:26 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.166 2014/08/05 07:55:31 rtr Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -377,6 +377,134 @@
 }
 
 static int
+unp_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
+    struct mbuf *control, struct lwp *l)
+{
+       struct unpcb *unp = sotounpcb(so);
+       int error = 0;
+       u_int newhiwat;
+       struct socket *so2;
+
+       KASSERT(solocked(so));
+       KASSERT(unp != NULL);
+       KASSERT(m != NULL);
+
+       /*
+        * Note: unp_internalize() rejects any control message
+        * other than SCM_RIGHTS, and only allows one.  This
+        * has the side-effect of preventing a caller from
+        * forging SCM_CREDS.
+        */
+       if (control) {
+               sounlock(so);
+               error = unp_internalize(&control);
+               solock(so);
+               if (error != 0) {
+                       m_freem(control);
+                       m_freem(m);
+                       return error;
+               }
+       }
+
+       switch (so->so_type) {
+
+       case SOCK_DGRAM: {
+               KASSERT(so->so_lock == uipc_lock);
+               if (nam) {
+                       if ((so->so_state & SS_ISCONNECTED) != 0)
+                               error = EISCONN;
+                       else {
+                               /*
+                                * Note: once connected, the
+                                * socket's lock must not be
+                                * dropped until we have sent
+                                * the message and disconnected.
+                                * This is necessary to prevent
+                                * intervening control ops, like
+                                * another connection.
+                                */
+                               error = unp_connect(so, nam, l);
+                       }
+               } else {
+                       if ((so->so_state & SS_ISCONNECTED) == 0)
+                               error = ENOTCONN;
+               }
+               if (error) {
+                       unp_dispose(control);
+                       m_freem(control);
+                       m_freem(m);
+                       return error;
+               }
+               error = unp_output(m, control, unp);
+               if (nam)
+                       unp_disconnect1(unp);
+               break;
+       }
+
+       case SOCK_SEQPACKET: /* FALLTHROUGH */
+       case SOCK_STREAM:
+#define        rcv (&so2->so_rcv)
+#define        snd (&so->so_snd)
+               if (unp->unp_conn == NULL) {
+                       error = ENOTCONN;
+                       break;
+               }
+               so2 = unp->unp_conn->unp_socket;
+               KASSERT(solocked2(so, so2));
+               if (unp->unp_conn->unp_flags & UNP_WANTCRED) {
+                       /*
+                        * Credentials are passed only once on
+                        * SOCK_STREAM and SOCK_SEQPACKET.
+                        */
+                       unp->unp_conn->unp_flags &= ~UNP_WANTCRED;
+                       control = unp_addsockcred(l, control);
+               }
+               /*
+                * Send to paired receive port, and then reduce
+                * send buffer hiwater marks to maintain backpressure.
+                * Wake up readers.
+                */
+               if (control) {
+                       if (sbappendcontrol(rcv, m, control) != 0)
+                               control = NULL;
+               } else {
+                       switch(so->so_type) {
+                       case SOCK_SEQPACKET:
+                               sbappendrecord(rcv, m);
+                               break;
+                       case SOCK_STREAM:
+                               sbappend(rcv, m);
+                               break;
+                       default:
+                               panic("uipc_usrreq");
+                               break;
+                       }
+               }
+               snd->sb_mbmax -=
+                   rcv->sb_mbcnt - unp->unp_conn->unp_mbcnt;
+               unp->unp_conn->unp_mbcnt = rcv->sb_mbcnt;
+               newhiwat = snd->sb_hiwat -
+                   (rcv->sb_cc - unp->unp_conn->unp_cc);
+               (void)chgsbsize(so->so_uidinfo,
+                   &snd->sb_hiwat, newhiwat, RLIM_INFINITY);
+               unp->unp_conn->unp_cc = rcv->sb_cc;
+               sorwakeup(so2);
+#undef snd
+#undef rcv
+               if (control != NULL) {
+                       unp_dispose(control);
+                       m_freem(control);
+               }
+               break;
+
+       default:
+               panic("uipc 4");
+       }
+
+       return error;
+}
+
+static int
 unp_sendoob(struct socket *so, struct mbuf *m, struct mbuf * control)
 {



Home | Main Index | Thread Index | Old Index