BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netiso / tp_usrreq.c
index 65709d9..e085ad2 100644 (file)
@@ -1,3 +1,38 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ *     @(#)tp_usrreq.c 7.17 (Berkeley) 6/27/91
+ */
+
 /***********************************************************
                                Copyright IBM Corporation 1987
 
 /***********************************************************
                                Copyright IBM Corporation 1987
 
@@ -29,7 +64,6 @@ SOFTWARE.
  *
  * $Header: tp_usrreq.c,v 5.4 88/11/18 17:29:18 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_usrreq.c,v $
  *
  * $Header: tp_usrreq.c,v 5.4 88/11/18 17:29:18 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_usrreq.c,v $
- *     @(#)tp_usrreq.c 7.13 (Berkeley) 6/29/90
  *
  * tp_usrreq(), the fellow that gets called from most of the socket code.
  * Pretty straighforward.
  *
  * tp_usrreq(), the fellow that gets called from most of the socket code.
  * Pretty straighforward.
@@ -38,19 +72,15 @@ SOFTWARE.
  * tp_rcvoob() and tp_sendoob() are contained here and called by tp_usrreq().
  */
 
  * tp_rcvoob() and tp_sendoob() are contained here and called by tp_usrreq().
  */
 
-#ifndef lint
-static char *rcsid = "$Header: tp_usrreq.c,v 5.4 88/11/18 17:29:18 nhall Exp $";
-#endif lint
-
 #include "param.h"
 #include "systm.h"
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "domain.h"
 #include "protosw.h"
 #include "errno.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "domain.h"
 #include "protosw.h"
 #include "errno.h"
+#include "time.h"
 
 #include "tp_param.h"
 #include "tp_timer.h"
 
 #include "tp_param.h"
 #include "tp_timer.h"
@@ -184,7 +214,6 @@ restart:
                        break;
 
        if (n == 0) {
                        break;
 
        if (n == 0) {
-               ASSERT((tpcb->tp_flags & TPF_DISC_DATA_IN) == 0);
                IFDEBUG(D_XPD)
                        printf("RCVOOB: empty queue!\n");
                ENDDEBUG
                IFDEBUG(D_XPD)
                        printf("RCVOOB: empty queue!\n");
                ENDDEBUG
@@ -588,26 +617,25 @@ tp_usrreq(so, req, m, nam, controlp)
                        if (error)
                                break;
                }
                        if (error)
                                break;
                }
-               if (so->so_state & SS_ISCONFIRMING) {
-                       if (tpcb->tp_state == TP_CONFIRMING)
-                               error = tp_confirm(tpcb);
-                       if (m) {
-                               if (error == 0 && m->m_len != 0)
-                                       error =  ENOTCONN;
-                               m_freem(m);
-                               m = 0;
-                       }
+               if ((so->so_state & SS_ISCONFIRMING) &&
+                   (tpcb->tp_state == TP_CONFIRMING) &&
+                   (error = tp_confirm(tpcb)))
+                           break;
+               if (req == PRU_SENDOOB) {
+                       error = (tpcb->tp_xpd_service == 0) ?
+                                               EOPNOTSUPP : tp_sendoob(tpcb, so, m, outflags);
                        break;
                }
                if (m == 0)
                        break;
                        break;
                }
                if (m == 0)
                        break;
-
-               if (req == PRU_SENDOOB) {
-                       if (tpcb->tp_xpd_service == 0) {
-                               error = EOPNOTSUPP;
-                               break;
-                       }
-                       error = tp_sendoob(tpcb, so, m, outflags);
+               if (m->m_flags & M_EOR) {
+                       eotsdu = 1;
+                       m->m_flags &= ~M_EOR;
+               }
+               if (eotsdu == 0 && m->m_pkthdr.len == 0)
+                       break;
+               if (tpcb->tp_state != TP_AKWAIT && tpcb->tp_state != TP_OPEN) {
+                       error = ENOTCONN;
                        break;
                }
                /*
                        break;
                }
                /*
@@ -634,10 +662,6 @@ tp_usrreq(so, req, m, nam, controlp)
                         * Could have eotsdu and no data.(presently MUST have
                         * an mbuf though, even if its length == 0) 
                         */
                         * Could have eotsdu and no data.(presently MUST have
                         * an mbuf though, even if its length == 0) 
                         */
-                       if (n->m_flags & M_EOR) {
-                               eotsdu = 1;
-                               n->m_flags &= ~M_EOR;
-                       }
                        IFPERF(tpcb)
                           PStat(tpcb, Nb_from_sess) += totlen;
                           tpmeas(tpcb->tp_lref, TPtime_from_session, 0, 0, 
                        IFPERF(tpcb)
                           PStat(tpcb, Nb_from_sess) += totlen;
                           tpmeas(tpcb->tp_lref, TPtime_from_session, 0, 0, 
@@ -711,7 +735,8 @@ tp_usrreq(so, req, m, nam, controlp)
                                        eotsdu, n, mbufcnt);
                                dump_mbuf(sb->sb_mb, "so_snd.sb_mb");
                        ENDDEBUG
                                        eotsdu, n, mbufcnt);
                                dump_mbuf(sb->sb_mb, "so_snd.sb_mb");
                        ENDDEBUG
-                       error = DoEvent(T_DATA_req); 
+                       if (tpcb->tp_state == TP_OPEN)
+                               error = DoEvent(T_DATA_req); 
                        IFDEBUG(D_SYSCALL)
                                printf("PRU_SEND: after driver error 0x%x \n",error);
                                printf("so_snd 0x%x cc 0t%d mbcnt 0t%d\n",
                        IFDEBUG(D_SYSCALL)
                                printf("PRU_SEND: after driver error 0x%x \n",error);
                                printf("so_snd 0x%x cc 0t%d mbcnt 0t%d\n",