These changes represent a rewrite of retransmission policies to
[unix-history] / usr / src / sys / netiso / tp_subr2.c
index d80ab96..5c7bde9 100644 (file)
@@ -1,3 +1,12 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)tp_subr2.c  7.14 (Berkeley) %G%
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -29,26 +38,22 @@ SOFTWARE.
  *
  * $Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_subr2.c,v $
  *
  * $Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $
  * $Source: /usr/argo/sys/netiso/RCS/tp_subr2.c,v $
- *     @(#)tp_subr2.c  7.7 (Berkeley) %G%
  *
  * Some auxiliary routines:
  *
  * Some auxiliary routines:
- *             tp_protocol_error: required by xebec- called when a combo of state,
- *                     event, predicate isn't covered for by the transition file.
- *             tp_indicate: gives indications(signals) to the user process
- *             tp_getoptions: initializes variables that are affected by the options
- *          chosen.
+ *     tp_protocol_error: required by xebec- called when a combo of state,
+ *         event, predicate isn't covered for by the transition file.
+ *     tp_indicate: gives indications(signals) to the user process
+ *     tp_getoptions: initializes variables that are affected by the options
+ *         chosen.
  */
 
  */
 
-#ifndef lint
-static char *rcsid = "$Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $";
-#endif lint
-
 /* this def'n is to cause the expansion of this macro in the
  * routine tp_local_credit :
  */
 #define LOCAL_CREDIT_EXPAND
 
 #include "param.h"
 /* this def'n is to cause the expansion of this macro in the
  * routine tp_local_credit :
  */
 #define LOCAL_CREDIT_EXPAND
 
 #include "param.h"
+#include "systm.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "socketvar.h"
@@ -75,6 +80,7 @@ static char *rcsid = "$Header: tp_subr2.c,v 5.5 88/11/18 17:28:55 nhall Exp $";
 #include "cons.h"
 
 #include "../net/if.h"
 #include "cons.h"
 
 #include "../net/if.h"
+#include "../net/if_types.h"
 #ifdef TRUE
 #undef FALSE
 #undef TRUE
 #ifdef TRUE
 #undef FALSE
 #undef TRUE
@@ -267,7 +273,8 @@ struct tp_pcb *tpcb;
        tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1;
        tpcb->tp_dt_ticks =
                MAX(tpcb->tp_dt_ticks, (tpcb->tp_peer_acktime + 2));
        tpcb->tp_seqhalf = tpcb->tp_seqbit >> 1;
        tpcb->tp_dt_ticks =
                MAX(tpcb->tp_dt_ticks, (tpcb->tp_peer_acktime + 2));
-
+       (void) tp_rsyset(tpcb);
+       
 }
 
 /*
 }
 
 /*
@@ -336,11 +343,11 @@ tp_quench( tpcb, cmd )
        ENDDEBUG
        switch(cmd) {
                case PRC_QUENCH:
        ENDDEBUG
        switch(cmd) {
                case PRC_QUENCH:
-                       tpcb->tp_cong_win = 1;
+                       tpcb->tp_cong_win = tpcb->tp_l_tpdusize;
                        IncStat(ts_quench);
                        break;
                case PRC_QUENCH2:
                        IncStat(ts_quench);
                        break;
                case PRC_QUENCH2:
-                       tpcb->tp_cong_win = 1; /* might as well quench source also */
+                       tpcb->tp_cong_win = tpcb->tp_l_tpdusize; /* might as well quench source also */
                        tpcb->tp_decbit = TP_DECBIT_CLEAR_COUNT;
                        IncStat(ts_rcvdecbit);
                        break;
                        tpcb->tp_decbit = TP_DECBIT_CLEAR_COUNT;
                        IncStat(ts_rcvdecbit);
                        break;
@@ -377,10 +384,17 @@ tp_netcmd( tpcb, cmd )
 
        case CONN_CLOSE:
        case CONN_REFUSE:
 
        case CONN_CLOSE:
        case CONN_REFUSE:
-               if (isop->isop_refcnt == 1)
+               if (isop->isop_refcnt == 1) {
+                       /* This is really superfluous, since it would happen
+                          anyway in iso_pcbdetach, although it is a courtesy
+                          to free up the x.25 channel before the refwait timer
+                          expires. */
+                       lcp->lcd_upper = 0;
+                       lcp->lcd_upnext = 0;
                        pk_disconnect(lcp);
                        pk_disconnect(lcp);
-               isop->isop_chan = 0;
-               isop->isop_refcnt = 0;
+                       isop->isop_chan = 0;
+                       isop->isop_refcnt = 0;
+               }
                break;
 
        default:
                break;
 
        default:
@@ -469,8 +483,8 @@ tp_route_to( m, tpcb, channel)
 {
        register struct sockaddr_iso *siso;     /* NOTE: this may be a sockaddr_in */
        extern struct tp_conn_param tp_conn_param[];
 {
        register struct sockaddr_iso *siso;     /* NOTE: this may be a sockaddr_in */
        extern struct tp_conn_param tp_conn_param[];
-       struct pklcd *lcp = (struct pklcd *)channel;
-       int error = 0;
+       int error = 0, save_netservice = tpcb->tp_netservice;
+       register struct rtentry *rt = 0;
 
        siso = mtod(m, struct sockaddr_iso *);
        IFTRACE(D_CONN)
 
        siso = mtod(m, struct sockaddr_iso *);
        IFTRACE(D_CONN)
@@ -485,39 +499,65 @@ tp_route_to( m, tpcb, channel)
                printf("m->mlen x%x, m->m_data:\n", m->m_len);
                dump_buf(mtod(m, caddr_t), m->m_len);
        ENDDEBUG
                printf("m->mlen x%x, m->m_data:\n", m->m_len);
                dump_buf(mtod(m, caddr_t), m->m_len);
        ENDDEBUG
-       if (siso->siso_family != tpcb->tp_domain) {
-               error = EAFNOSUPPORT;
-               goto done;
-       }
-       IFDEBUG(D_CONN)
-               printf("tp_route_to  calling nlp_pcbconn, netserv %d\n",
-                       tpcb->tp_netservice);
-       ENDDEBUG
+       if (channel) {
 #ifdef TPCONS
 #ifdef TPCONS
-       if (lcp) {
+               struct pklcd *lcp = (struct pklcd *)channel;
                struct isopcb *isop = (struct isopcb *)lcp->lcd_upnext,
                struct isopcb *isop = (struct isopcb *)lcp->lcd_upnext,
-                       *isop_new = (struct isopcb *)tpcb->tp_sock->so_pcb;
+                       *isop_new = (struct isopcb *)tpcb->tp_npcb;
+               /* The next 2 lines believe that you haven't
+                  set any network level options or done a pcbconnect
+                  and XXXXXXX'edly apply to both inpcb's and isopcb's */
                remque(isop_new);
                free(isop_new, M_PCB);
                remque(isop_new);
                free(isop_new, M_PCB);
-               tpcb->tp_sock->so_pcb = (caddr_t)isop;
-               if (isop->isop_refcnt == 0) {
-                       extern struct isopcb tp_isopcb;
-                       remque(isop);
-                       insque(isop, &tp_isopcb);
-                       isop->isop_head = &tp_isopcb;
+               tpcb->tp_npcb = (caddr_t)isop;
+               tpcb->tp_netservice = ISO_CONS;
+               tpcb->tp_nlproto = nl_protosw + ISO_CONS;
+               isop->isop_socket = tpcb->tp_sock;
+               if (isop->isop_refcnt == 0)
                        iso_putsufx(isop, tpcb->tp_lsuffix, tpcb->tp_lsuffixlen, TP_LOCAL);
                        iso_putsufx(isop, tpcb->tp_lsuffix, tpcb->tp_lsuffixlen, TP_LOCAL);
-               }
-               /* else there are already connections sharing this */
+               else
+                       /* there are already connections sharing this */;
                isop->isop_refcnt++;
                isop->isop_refcnt++;
-       } else
 #endif
 #endif
-               error = (tpcb->tp_nlproto->nlp_pcbconn)(tpcb->tp_sock->so_pcb, m);
+       } else {
+               switch (siso->siso_family) {
+               default:
+                       error = EAFNOSUPPORT;
+                       goto done;
+#ifdef ISO
+               case AF_ISO:
+                       tpcb->tp_netservice = ISO_CLNS;
+                       if (rt = rtalloc1((struct sockaddr *)siso, 0)) {
+                               rt->rt_refcnt--;
+                               if (rt->rt_flags & RTF_PROTO1)
+                                       tpcb->tp_netservice = ISO_CONS;
+                       }
+                       break;
+#endif
+#ifdef INET
+               case AF_INET:
+                       tpcb->tp_netservice = IN_CLNS;
+               }
+#endif
+               if (tpcb->tp_nlproto->nlp_afamily != siso->siso_family) {
+                       IFDEBUG(D_CONN)
+                               printf("tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n", 
+                                               save_netservice, tpcb->tp_netservice);
+                       ENDDEBUG
+                       if (error = tp_set_npcb(tpcb))
+                               goto done;
+               }
+               IFDEBUG(D_CONN)
+                       printf("tp_route_to  calling nlp_pcbconn, netserv %d\n",
+                               tpcb->tp_netservice);
+               ENDDEBUG
+               tpcb->tp_nlproto = nl_protosw + tpcb->tp_netservice;
+               error = (tpcb->tp_nlproto->nlp_pcbconn)(tpcb->tp_npcb, m);
+       }
        if( error )
                goto done;
 
        {
        if( error )
                goto done;
 
        {
-               register int save_netservice = tpcb->tp_netservice;
-
                switch(tpcb->tp_netservice) {
                case ISO_COSNS:
                case ISO_CLNS:
                switch(tpcb->tp_netservice) {
                case ISO_COSNS:
                case ISO_CLNS:
@@ -525,8 +565,7 @@ tp_route_to( m, tpcb, channel)
                         * can get long enough timers. sigh.
                        if( siso->siso_addr.osinet_idi[1] == (u_char)IDI_OSINET )
                         */
                         * can get long enough timers. sigh.
                        if( siso->siso_addr.osinet_idi[1] == (u_char)IDI_OSINET )
                         */
-#define        IDI_OSINET      0x0004  /* bcd of "0004" */     
-                       if( siso->siso_addr.isoa_genaddr[2] == (char)IDI_OSINET ) {
+                       if (rt && rt->rt_ifp && rt->rt_ifp->if_type == IFT_X25) {
                                if( tpcb->tp_dont_change_params == 0) {
                                        copyQOSparms( &tp_conn_param[ISO_COSNS],
                                                        &tpcb->_tp_param);
                                if( tpcb->tp_dont_change_params == 0) {
                                        copyQOSparms( &tp_conn_param[ISO_COSNS],
                                                        &tpcb->_tp_param);
@@ -537,7 +576,7 @@ tp_route_to( m, tpcb, channel)
                case IN_CLNS:
                        if (iso_localifa(siso))
                                tpcb->tp_flags |= TPF_PEER_ON_SAMENET;
                case IN_CLNS:
                        if (iso_localifa(siso))
                                tpcb->tp_flags |= TPF_PEER_ON_SAMENET;
-                       if( (tpcb->tp_class & TP_CLASS_4)==0 ) {
+                       if((tpcb->tp_class & TP_CLASS_4) == 0) {
                                error = EPROTOTYPE;
                                break;
                        } 
                                error = EPROTOTYPE;
                                break;
                        } 
@@ -562,14 +601,6 @@ tp_route_to( m, tpcb, channel)
                        }
                        tpcb->tp_rx_strat =  TPRX_USE_CW;
 
                        }
                        tpcb->tp_rx_strat =  TPRX_USE_CW;
 
-                       if( (tpcb->tp_nlproto != &nl_protosw[ISO_CONS]) ) {
-                               IFDEBUG(D_CONN)
-                                       printf(
-                                       "tp_route_to( CHANGING nlproto old 0x%x new 0x%x)\n", 
-                                                       tpcb->tp_nlproto , &nl_protosw[ISO_CONS]);
-                               ENDDEBUG
-                               tpcb->tp_nlproto = &nl_protosw[ISO_CONS];
-                       }
                        /* class 4 doesn't need to open a vc now - may use one already 
                         * opened or may open one only when it sends a pkt.
                         */
                        /* class 4 doesn't need to open a vc now - may use one already 
                         * opened or may open one only when it sends a pkt.
                         */
@@ -581,7 +612,6 @@ tp_route_to( m, tpcb, channel)
                        error = EPROTOTYPE;
                }
 
                        error = EPROTOTYPE;
                }
 
-               ASSERT( save_netservice == tpcb->tp_netservice);
        }
        if (error) {
                tp_netcmd( tpcb, CONN_CLOSE);
        }
        if (error) {
                tp_netcmd( tpcb, CONN_CLOSE);
@@ -748,13 +778,13 @@ caddr_t   buf;
 int            len;
 {
        int             i,j;
 int            len;
 {
        int             i,j;
-
+#define Buf ((u_char *)buf)
        printf("Dump buf 0x%x len 0x%x\n", buf, len);
        for (i = 0; i < len; i += MAX_COLUMNS) {
                printf("+%d:\t", i);
                for (j = 0; j < MAX_COLUMNS; j++) {
                        if (i + j < len) {
        printf("Dump buf 0x%x len 0x%x\n", buf, len);
        for (i = 0; i < len; i += MAX_COLUMNS) {
                printf("+%d:\t", i);
                for (j = 0; j < MAX_COLUMNS; j++) {
                        if (i + j < len) {
-                               printf("%x/%d\t", buf[i+j]&0xff, buf[i+j]);
+                               printf("%x/%d\t", Buf[i+j], Buf[i+j]);
                        } else {
                                printf("        ");
                        }
                        } else {
                                printf("        ");
                        }
@@ -762,8 +792,8 @@ int         len;
 
                for (j = 0; j < MAX_COLUMNS; j++) {
                        if (i + j < len) {
 
                for (j = 0; j < MAX_COLUMNS; j++) {
                        if (i + j < len) {
-                               if (((buf[i+j]) > 31) && ((buf[i+j]) < 128))
-                                       printf("%c", buf[i+j]&0xff);
+                               if (((Buf[i+j]) > 31) && ((Buf[i+j]) < 128))
+                                       printf("%c", Buf[i+j]);
                                else
                                        printf(".");
                        }
                                else
                                        printf(".");
                        }