BSD 4_4_Lite2 release
[unix-history] / usr / src / sys / netns / spp_usrreq.c
index 502eac6..7ce6723 100644 (file)
@@ -1,47 +1,61 @@
 /*
 /*
- * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1984, 1985, 1986, 1987, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)spp_usrreq.c        7.9 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)spp_usrreq.c        8.2 (Berkeley) 1/9/95
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "dir.h"
-#include "user.h"
-#include "malloc.h"
-#include "mbuf.h"
-#include "protosw.h"
-#include "socket.h"
-#include "socketvar.h"
-#include "errno.h"
-
-#include "../net/if.h"
-#include "../net/route.h"
-#include "../netinet/tcp_fsm.h"
-
-#include "ns.h"
-#include "ns_pcb.h"
-#include "idp.h"
-#include "idp_var.h"
-#include "ns_error.h"
-#include "sp.h"
-#include "spidp.h"
-#include "spp_timer.h"
-#include "spp_var.h"
-#include "spp_debug.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/errno.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <netinet/tcp_fsm.h>
+
+#include <netns/ns.h>
+#include <netns/ns_pcb.h>
+#include <netns/idp.h>
+#include <netns/idp_var.h>
+#include <netns/ns_error.h>
+#include <netns/sp.h>
+#include <netns/spidp.h>
+#include <netns/spp_timer.h>
+#include <netns/spp_var.h>
+#include <netns/spp_debug.h>
 
 /*
  * SP protocol implementation.
 
 /*
  * SP protocol implementation.
@@ -98,7 +112,7 @@ spp_input(m, nsp)
        if (so->so_options & SO_ACCEPTCONN) {
                struct sppcb *ocb = cb;
 
        if (so->so_options & SO_ACCEPTCONN) {
                struct sppcb *ocb = cb;
 
-               so = sonewconn(so);
+               so = sonewconn(so, 0);
                if (so == 0) {
                        goto drop;
                }
                if (so == 0) {
                        goto drop;
                }
@@ -151,6 +165,7 @@ spp_input(m, nsp)
                        goto drop;
                am->m_len = sizeof (struct sockaddr_ns);
                sns = mtod(am, struct sockaddr_ns *);
                        goto drop;
                am->m_len = sizeof (struct sockaddr_ns);
                sns = mtod(am, struct sockaddr_ns *);
+               sns->sns_len = sizeof(*sns);
                sns->sns_family = AF_NS;
                sns->sns_addr = si->si_sna;
                laddr = nsp->nsp_laddr;
                sns->sns_family = AF_NS;
                sns->sns_addr = si->si_sna;
                laddr = nsp->nsp_laddr;
@@ -722,11 +737,12 @@ spp_output(cb, m0)
 
                                cb->s_cc &= ~SP_EM;
                                while (len > mtu) {
 
                                cb->s_cc &= ~SP_EM;
                                while (len > mtu) {
-                                       m = m_copy(m0, 0, mtu);
-                                       if (m == NULL) {
-                                               error = ENOBUFS;
-                                               goto bad_copy;
-                                       }
+                                       /*
+                                        * Here we are only being called
+                                        * from usrreq(), so it is OK to
+                                        * block.
+                                        */
+                                       m = m_copym(m0, 0, mtu, M_WAIT);
                                        if (cb->s_flags & SF_NEWCALL) {
                                            struct mbuf *mm = m;
                                            spp_newchecks[7]++;
                                        if (cb->s_flags & SF_NEWCALL) {
                                            struct mbuf *mm = m;
                                            spp_newchecks[7]++;
@@ -737,7 +753,6 @@ spp_output(cb, m0)
                                        }
                                        error = spp_output(cb, m);
                                        if (error) {
                                        }
                                        error = spp_output(cb, m);
                                        if (error) {
-                                       bad_copy:
                                                cb->s_cc |= oldEM;
                                                m_freem(m0);
                                                return(error);
                                                cb->s_cc |= oldEM;
                                                m_freem(m0);
                                                return(error);
@@ -1239,10 +1254,10 @@ spp_ctloutput(req, so, level, name, value)
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
-spp_usrreq(so, req, m, nam, rights, controlp)
+spp_usrreq(so, req, m, nam, controlp)
        struct socket *so;
        int req;
        struct socket *so;
        int req;
-       struct mbuf *m, *nam, *rights, *controlp;
+       struct mbuf *m, *nam, *controlp;
 {
        struct nspcb *nsp = sotonspcb(so);
        register struct sppcb *cb;
 {
        struct nspcb *nsp = sotonspcb(so);
        register struct sppcb *cb;
@@ -1252,12 +1267,8 @@ spp_usrreq(so, req, m, nam, rights, controlp)
        register struct sockbuf *sb;
 
        if (req == PRU_CONTROL)
        register struct sockbuf *sb;
 
        if (req == PRU_CONTROL)
-                return (ns_control(so, (int)m, (caddr_t)nam,
-                       (struct ifnet *)rights));
-       if (rights && rights->m_len) {
-               error = EINVAL;
-               goto release;
-       }
+                return (ns_control(so, m, (caddr_t)nam,
+                       (struct ifnet *)controlp));
        if (nsp == NULL) {
                if (req != PRU_ATTACH) {
                        error = EINVAL;
        if (nsp == NULL) {
                if (req != PRU_ATTACH) {
                        error = EINVAL;
@@ -1449,13 +1460,15 @@ spp_usrreq(so, req, m, nam, rights, controlp)
                /* fall into */
        case PRU_SEND:
                if (controlp) {
                /* fall into */
        case PRU_SEND:
                if (controlp) {
-                       u_short *s = mtod(controlp, u_short *);
+                       u_short *p = mtod(controlp, u_short *);
                        spp_newchecks[2]++;
                        spp_newchecks[2]++;
-                       if ((s[0] == 5) && s[1] == 1 ) { /* XXXX, for testing */
-                               cb->s_shdr.sp_dt = *(u_char *)(&s[2]);
+                       if ((p[0] == 5) && p[1] == 1) { /* XXXX, for testing */
+                               cb->s_shdr.sp_dt = *(u_char *)(&p[2]);
                                spp_newchecks[3]++;
                        }
                                spp_newchecks[3]++;
                        }
+                       m_freem(controlp);
                }
                }
+               controlp = NULL;
                error = spp_output(cb, m);
                m = NULL;
                break;
                error = spp_output(cb, m);
                m = NULL;
                break;
@@ -1485,18 +1498,20 @@ spp_usrreq(so, req, m, nam, rights, controlp)
        if (cb && (so->so_options & SO_DEBUG || traceallspps))
                spp_trace(SA_USER, (u_char)ostate, cb, (struct spidp *)0, req);
 release:
        if (cb && (so->so_options & SO_DEBUG || traceallspps))
                spp_trace(SA_USER, (u_char)ostate, cb, (struct spidp *)0, req);
 release:
+       if (controlp != NULL)
+               m_freem(controlp);
        if (m != NULL)
                m_freem(m);
        splx(s);
        return (error);
 }
 
        if (m != NULL)
                m_freem(m);
        splx(s);
        return (error);
 }
 
-spp_usrreq_sp(so, req, m, nam, rights, controlp)
+spp_usrreq_sp(so, req, m, nam, controlp)
        struct socket *so;
        int req;
        struct socket *so;
        int req;
-       struct mbuf *m, *nam, *rights, *controlp;
+       struct mbuf *m, *nam, *controlp;
 {
 {
-       int error = spp_usrreq(so, req, m, nam, rights, controlp);
+       int error = spp_usrreq(so, req, m, nam, controlp);
 
        if (req == PRU_ATTACH && error == 0) {
                struct nspcb *nsp = sotonspcb(so);
 
        if (req == PRU_ATTACH && error == 0) {
                struct nspcb *nsp = sotonspcb(so);
@@ -1666,7 +1681,8 @@ spp_slowtimo()
                        if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
                                (void) spp_usrreq(cb->s_nspcb->nsp_socket,
                                    PRU_SLOWTIMO, (struct mbuf *)0,
                        if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
                                (void) spp_usrreq(cb->s_nspcb->nsp_socket,
                                    PRU_SLOWTIMO, (struct mbuf *)0,
-                                   (struct mbuf *)i, (struct mbuf *)0);
+                                   (struct mbuf *)i, (struct mbuf *)0,
+                                   (struct mbuf *)0);
                                if (ipnxt->nsp_prev != ip)
                                        goto tpgone;
                        }
                                if (ipnxt->nsp_prev != ip)
                                        goto tpgone;
                        }
@@ -1785,4 +1801,4 @@ spp_timers(cb, timer)
 #ifndef lint
 int SppcbSize = sizeof (struct sppcb);
 int NspcbSize = sizeof (struct nspcb);
 #ifndef lint
 int SppcbSize = sizeof (struct sppcb);
 int NspcbSize = sizeof (struct nspcb);
-#endif lint
+#endif /* lint */