BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netiso / tp.trans
index b7f5375..9a9a1b7 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.trans    7.9 (Berkeley) 5/7/91
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -48,9 +83,8 @@ SOFTWARE.
 *PROTOCOL tp
 
 *INCLUDE
 *PROTOCOL tp
 
 *INCLUDE
-
 {
 {
-/*     @(#)tp.trans    7.5 (Berkeley) 6/6/90 */
+/* @(#)tp.trans        7.9 (Berkeley) 5/7/91 */
 #include "param.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "param.h"
 #include "socket.h"
 #include "socketvar.h"
@@ -315,7 +349,6 @@ TP_CONFIRMING               <==              TP_LISTENING                                                   CR_TPDU
                        /* n/a for class 0 */
                        ASSERT($P.tp_Xrcv.sb_cc == 0); 
                        sbappendrecord(&$P.tp_Xrcv, $$.e_data);
                        /* n/a for class 0 */
                        ASSERT($P.tp_Xrcv.sb_cc == 0); 
                        sbappendrecord(&$P.tp_Xrcv, $$.e_data);
-                       /*$P.tp_flags |= TPF_CONN_DATA_IN;*/
                        $$.e_data = MNULL; 
                } 
        }
                        $$.e_data = MNULL; 
                } 
        }
@@ -348,7 +381,7 @@ TP_AKWAIT           <==              TP_CONFIRMING                                                          T_ACPT_req
                        printf("Confirming connection: $P" );
                ENDDEBUG
                soisconnecting($P.tp_sock);
                        printf("Confirming connection: $P" );
                ENDDEBUG
                soisconnecting($P.tp_sock);
-               if($P.tp_rx_strat & TPRX_FASTSTART)
+               if (($P.tp_rx_strat & TPRX_FASTSTART) && ($P.tp_fcredit > 0))
                        $P.tp_cong_win = $P.tp_fcredit;
                $P.tp_retrans = $P.tp_Nretrans;
                tp_ctimeout($P.tp_refp, TM_retrans, (int)$P.tp_cc_ticks);
                        $P.tp_cong_win = $P.tp_fcredit;
                $P.tp_retrans = $P.tp_Nretrans;
                tp_ctimeout($P.tp_refp, TM_retrans, (int)$P.tp_cc_ticks);
@@ -406,14 +439,12 @@ TP_CRSENT         <==             TP_CLOSED                                                               T_CONN_req
 TP_REFWAIT             <==             [ TP_CRSENT, TP_AKWAIT, TP_OPEN ]                       DR_TPDU 
        DEFAULT
        {
 TP_REFWAIT             <==             [ TP_CRSENT, TP_AKWAIT, TP_OPEN ]                       DR_TPDU 
        DEFAULT
        {
-               if ($$.e_datalen > 0 && $P.tp_class != TP_CLASS_0) {
-                       /*sbdrop(&$P.tp_Xrcv, $P.tp_Xrcv.sb_cc); /* purge expedited data */
-                       sbflush(&$P.tp_Xrcv);
-                       $P.tp_flags |= TPF_DISC_DATA_IN;
+               sbflush(&$P.tp_Xrcv); /* purge non-delivered data data */
+               if ($$.e_datalen > 0) {
                        sbappendrecord(&$P.tp_Xrcv, $$.e_data);
                        $$.e_data = MNULL;
                } 
                        sbappendrecord(&$P.tp_Xrcv, $$.e_data);
                        $$.e_data = MNULL;
                } 
-               tp_indicate(T_DISCONNECT, $P, TP_ERROR_MASK | (u_short)$$.e_reason);
+               tp_indicate(T_DISCONNECT, $P, 0);
                tp_soisdisconnected($P);
                if ($P.tp_class != TP_CLASS_0) {
                        if ($P.tp_state == TP_OPEN ) {
                tp_soisdisconnected($P);
                if ($P.tp_class != TP_CLASS_0) {
                        if ($P.tp_state == TP_OPEN ) {
@@ -445,8 +476,7 @@ TP_REFWAIT          <==     TP_CRSENT                                                                       ER_TPDU
        DEFAULT
        {       
                tp_cuntimeout($P.tp_refp, TM_retrans);
        DEFAULT
        {       
                tp_cuntimeout($P.tp_refp, TM_retrans);
-               tp_indicate(T_DISCONNECT, $P, 
-                       TP_ERROR_MASK |(u_short)($$.e_reason | 0x40));
+               tp_indicate(ER_TPDU, $P, $$.e_reason);
                tp_soisdisconnected($P);
        }
 ;
                tp_soisdisconnected($P);
        }
 ;
@@ -455,7 +485,6 @@ TP_REFWAIT          <==     TP_CRSENT                                                                       ER_TPDU
 TP_REFWAIT             <==             TP_CLOSING                                                                      DR_TPDU
        DEFAULT
        {        
 TP_REFWAIT             <==             TP_CLOSING                                                                      DR_TPDU
        DEFAULT
        {        
-               $P.tp_sock->so_error = (u_short)$$.e_reason;
                tp_cuntimeout($P.tp_refp, TM_retrans);
                tp_soisdisconnected($P);
        }
                tp_cuntimeout($P.tp_refp, TM_retrans);
                tp_soisdisconnected($P);
        }
@@ -467,7 +496,7 @@ TP_REFWAIT          <==             TP_CLOSING                                                                      DR_TPDU
 TP_REFWAIT             <==             TP_CLOSING                                                                      ER_TPDU
        DEFAULT
        {        
 TP_REFWAIT             <==             TP_CLOSING                                                                      ER_TPDU
        DEFAULT
        {        
-               $P.tp_sock->so_error = (u_short)$$.e_reason;
+               tp_indicate(ER_TPDU, $P, $$.e_reason);
                tp_cuntimeout($P.tp_refp, TM_retrans);
                tp_soisdisconnected($P);
        }
                tp_cuntimeout($P.tp_refp, TM_retrans);
                tp_soisdisconnected($P);
        }
@@ -495,9 +524,7 @@ TP_REFWAIT          <==     TP_OPEN                                                                         ER_TPDU
        ($P.tp_class == TP_CLASS_0)
        {
                tp_soisdisconnecting($P.tp_sock);
        ($P.tp_class == TP_CLASS_0)
        {
                tp_soisdisconnecting($P.tp_sock);
-               tp_indicate(T_DISCONNECT, $P, 
-                       TP_ERROR_MASK |(u_short)($$.e_reason | 0x40));
-
+               tp_indicate(ER_TPDU, $P, $$.e_reason);
                tp_soisdisconnected($P);
                tp_netcmd( $P, CONN_CLOSE );
        }
                tp_soisdisconnected($P);
                tp_netcmd( $P, CONN_CLOSE );
        }
@@ -512,8 +539,7 @@ TP_CLOSING          <==     [ TP_AKWAIT, TP_OPEN ]                                          ER_TPDU
                        tp_cuntimeout($P.tp_refp, TM_sendack);
                }
                tp_soisdisconnecting($P.tp_sock);
                        tp_cuntimeout($P.tp_refp, TM_sendack);
                }
                tp_soisdisconnecting($P.tp_sock);
-               tp_indicate(T_DISCONNECT, $P, 
-                       TP_ERROR_MASK |(u_short)($$.e_reason | 0x40));
+               tp_indicate(ER_TPDU, $P, $$.e_reason);
                $P.tp_retrans = $P.tp_Nretrans;
                tp_ctimeout($P.tp_refp, TM_retrans, (int)$P.tp_dr_ticks);
                (void) tp_emit(DR_TPDU_type, $P, 0, E_TP_PROTO_ERR, MNULL);
                $P.tp_retrans = $P.tp_Nretrans;
                tp_ctimeout($P.tp_refp, TM_retrans, (int)$P.tp_dr_ticks);
                (void) tp_emit(DR_TPDU_type, $P, 0, E_TP_PROTO_ERR, MNULL);
@@ -541,7 +567,7 @@ TP_OPEN                     <==             TP_CRSENT                                                                       CC_TPDU
                $P.tp_fref = $$.e_sref;
                $P.tp_fcredit = $$.e_cdt;
                $P.tp_ackrcvd = 0;
                $P.tp_fref = $$.e_sref;
                $P.tp_fcredit = $$.e_cdt;
                $P.tp_ackrcvd = 0;
-               if($P.tp_rx_strat & TPRX_FASTSTART)
+               if (($P.tp_rx_strat & TPRX_FASTSTART) && ($$.e_cdt > 0))
                        $P.tp_cong_win = $$.e_cdt;
                tp_getoptions($P);
                tp_cuntimeout($P.tp_refp, TM_retrans);
                        $P.tp_cong_win = $$.e_cdt;
                tp_getoptions($P);
                tp_cuntimeout($P.tp_refp, TM_retrans);
@@ -557,7 +583,6 @@ TP_OPEN                     <==             TP_CRSENT                                                                       CC_TPDU
                if ($$.e_datalen > 0) {
                        ASSERT($P.tp_Xrcv.sb_cc == 0); /* should be empty */
                        sbappendrecord(&$P.tp_Xrcv, $$.e_data);
                if ($$.e_datalen > 0) {
                        ASSERT($P.tp_Xrcv.sb_cc == 0); /* should be empty */
                        sbappendrecord(&$P.tp_Xrcv, $$.e_data);
-                       $P.tp_flags |= TPF_CONN_DATA_IN;
                        $$.e_data = MNULL;
                }
 
                        $$.e_data = MNULL;
                }
 
@@ -756,7 +781,7 @@ TP_OPEN                     <==             TP_AKWAIT                                                                               AK_TPDU
 
 /* TP4 only */
 TP_OPEN                <==     [ TP_OPEN, TP_AKWAIT ]                                          XPD_TPDU
 
 /* TP4 only */
 TP_OPEN                <==     [ TP_OPEN, TP_AKWAIT ]                                          XPD_TPDU
-       ( $P.tp_Xrcvnxt == $$.e_seq  /* && $P.tp_Xrcv.sb_cc == 0*/)
+       ($P.tp_Xrcvnxt == $$.e_seq)
        {
                if( $P.tp_state == TP_AKWAIT ) {
                        if ($P.tp_ucddata) {
        {
                if( $P.tp_state == TP_AKWAIT ) {
                        if ($P.tp_ucddata) {
@@ -775,6 +800,7 @@ TP_OPEN             <==     [ TP_OPEN, TP_AKWAIT ]                                          XPD_TPDU
                ENDTRACE
 
                $P.tp_sock->so_state |= SS_RCVATMARK;
                ENDTRACE
 
                $P.tp_sock->so_state |= SS_RCVATMARK;
+               $$.e_data->m_flags |= M_EOR;
                sbinsertoob(&$P.tp_Xrcv, $$.e_data);
                IFDEBUG(D_XPD)
                        dump_mbuf($$.e_data, "XPD TPDU: tp_Xrcv");
                sbinsertoob(&$P.tp_Xrcv, $$.e_data);
                IFDEBUG(D_XPD)
                        dump_mbuf($$.e_data, "XPD TPDU: tp_Xrcv");
@@ -792,7 +818,6 @@ SAME                        <==             TP_OPEN                                                                         T_USR_Xrcvd
        DEFAULT
        {
                if( $P.tp_Xrcv.sb_cc == 0 ) {
        DEFAULT
        {
                if( $P.tp_Xrcv.sb_cc == 0 ) {
-                       /*$P.tp_flags &= ~TPF_XPD_PRESENT;*/
                        /* kludge for select(): */ 
                        /* $P.tp_sock->so_state &= ~SS_OOBAVAIL; */
                }
                        /* kludge for select(): */ 
                        /* $P.tp_sock->so_state &= ~SS_OOBAVAIL; */
                }
@@ -830,13 +855,6 @@ SAME                       <==     [ TP_AKWAIT, TP_OPEN ]                                                  XPD_TPDU
                if( $P.tp_Xrcvnxt != $$.e_seq )
                        IncStat(ts_xpd_niw);
                if( $P.tp_Xrcv.sb_cc ) {
                if( $P.tp_Xrcvnxt != $$.e_seq )
                        IncStat(ts_xpd_niw);
                if( $P.tp_Xrcv.sb_cc ) {
-#ifdef notdef
-                       if( $P.tp_flags & TPF_CONN_DATA_IN ) {
-                               /* user isn't reading the connection data; see note above */
-                               sbdrop(&$P.tp_Xrcv, $P.tp_Xrcv.sb_cc);
-                               $P.tp_flags &= ~TPF_CONN_DATA_IN;
-                       }
-#endif notdef
                        /* might as well kick 'em again */
                        tp_indicate(T_XDATA, $P, 0);
                        IncStat(ts_xpd_dup);
                        /* might as well kick 'em again */
                        tp_indicate(T_XDATA, $P, 0);
                        IncStat(ts_xpd_dup);
@@ -1319,7 +1337,10 @@ SAME                     <==             TP_OPEN                                                                 TM_sendack
 /* TP0 only */
 SAME                   <==             TP_OPEN                                                                         T_USR_rcvd
        ($P.tp_class == TP_CLASS_0)
 /* TP0 only */
 SAME                   <==             TP_OPEN                                                                         T_USR_rcvd
        ($P.tp_class == TP_CLASS_0)
-       NULLACTION
+       {
+               if (sbspace(&$P.tp_sock->so_rcv) > 0)
+                       tp0_openflow($P);
+       }
 ;
 
 /* TP4 only */
 ;
 
 /* TP4 only */