trailing comment after #else or #endif
[unix-history] / usr / src / sys / netiso / tp_iso.c
index d15bbe9..ce93b6d 100644 (file)
@@ -1,3 +1,12 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)tp_iso.c    7.16 (Berkeley) %G%
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -28,7 +37,6 @@ SOFTWARE.
  * ARGO TP
  * $Header: /var/src/sys/netiso/RCS/tp_iso.c,v 5.1 89/02/09 16:20:51 hagens Exp $
  * $Source: /var/src/sys/netiso/RCS/tp_iso.c,v $
  * ARGO TP
  * $Header: /var/src/sys/netiso/RCS/tp_iso.c,v 5.1 89/02/09 16:20:51 hagens Exp $
  * $Source: /var/src/sys/netiso/RCS/tp_iso.c,v $
- *     @(#)tp_iso.c    7.3 (Berkeley) %G% *
  *
  * Here is where you find the iso-dependent code.  We've tried
  * keep all net-level and (primarily) address-family-dependent stuff
  *
  * Here is where you find the iso-dependent code.  We've tried
  * keep all net-level and (primarily) address-family-dependent stuff
@@ -40,6 +48,7 @@ SOFTWARE.
  *             iso_putsufx: put transport suffix into an isopcb structure.
  *             iso_putnetaddr: put a whole net addr into an isopcb.
  *             iso_getnetaddr: get a whole net addr from an isopcb.
  *             iso_putsufx: put transport suffix into an isopcb structure.
  *             iso_putnetaddr: put a whole net addr into an isopcb.
  *             iso_getnetaddr: get a whole net addr from an isopcb.
+ *             iso_cmpnetaddr: compare a whole net addr from an isopcb.
  *             iso_recycle_suffix: clear suffix for reuse in isopcb
  *             tpclnp_ctlinput: handle ER CNLPdu : icmp-like stuff
  *             tpclnp_mtu: figure out what size tpdu to use
  *             iso_recycle_suffix: clear suffix for reuse in isopcb
  *             tpclnp_ctlinput: handle ER CNLPdu : icmp-like stuff
  *             tpclnp_mtu: figure out what size tpdu to use
@@ -49,33 +58,30 @@ SOFTWARE.
  *             tpclnp_output: package a pkt for clnp given an isopcb & some data
  */
 
  *             tpclnp_output: package a pkt for clnp given an isopcb & some data
  */
 
-#ifndef lint
-static char *rcsid = "$Header: /var/src/sys/netiso/RCS/tp_iso.c,v 5.1 89/02/09 16:20:51 hagens Exp $";
-#endif lint
-
 #ifdef ISO
 
 #ifdef ISO
 
-#include "param.h"
-#include "socket.h"
-#include "socketvar.h"
-#include "domain.h"
-#include "malloc.h"
-#include "mbuf.h"
-#include "errno.h"
-#include "time.h"
-#include "protosw.h"
-
-#include "../net/if.h"
-#include "../net/route.h"
-
-#include "argo_debug.h"
-#include "tp_param.h"
-#include "tp_stat.h"
-#include "tp_pcb.h"
-#include "tp_trace.h"
-#include "tp_stat.h"
-#include "tp_tpdu.h"
-#include "tp_clnp.h"
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/domain.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/errno.h>
+#include <sys/time.h>
+#include <sys/protosw.h>
+
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netiso/argo_debug.h>
+#include <netiso/tp_param.h>
+#include <netiso/tp_stat.h>
+#include <netiso/tp_pcb.h>
+#include <netiso/tp_trace.h>
+#include <netiso/tp_stat.h>
+#include <netiso/tp_tpdu.h>
+#include <netiso/tp_clnp.h>
+#include <netiso/cltp_var.h>
 
 /*
  * CALLED FROM:
 
 /*
  * CALLED FROM:
@@ -198,6 +204,9 @@ iso_putnetaddr(isop, name, which)
        register struct sockaddr_iso *siso;
 
        switch (which) {
        register struct sockaddr_iso *siso;
 
        switch (which) {
+       default:
+               printf("iso_putnetaddr: should panic\n");
+               return;
        case TP_LOCAL:
                sisop = &isop->isop_laddr;
                backup = &isop->isop_sladdr;
        case TP_LOCAL:
                sisop = &isop->isop_laddr;
                backup = &isop->isop_sladdr;
@@ -214,6 +223,47 @@ iso_putnetaddr(isop, name, which)
        siso->siso_addr = name->siso_addr;
 }
 
        siso->siso_addr = name->siso_addr;
 }
 
+/*
+ * CALLED FROM:
+ *     tp_input() when a connection is being established by an
+ *     incoming CR_TPDU, and considered for interception.
+ *
+ * FUNCTION and ARGUMENTS:
+ *     compare a whole net addr from a struct sockaddr (name),
+ *     with that implicitly stored in an isopcb (isop).
+ *     The argument (which) takes values TP_LOCAL or TP_FOREIGN.
+ */ 
+iso_cmpnetaddr(isop, name, which)
+       register struct isopcb  *isop;
+       register struct sockaddr_iso    *name;
+       int which;
+{
+       struct sockaddr_iso **sisop, *backup;
+       register struct sockaddr_iso *siso;
+
+       switch (which) {
+       default:
+               printf("iso_cmpnetaddr: should panic\n");
+               return 0;
+       case TP_LOCAL:
+               sisop = &isop->isop_laddr;
+               backup = &isop->isop_sladdr;
+               break;
+       case TP_FOREIGN:
+               sisop = &isop->isop_faddr;
+               backup = &isop->isop_sfaddr;
+       }
+       siso = ((*sisop == 0) ? (*sisop = backup) : *sisop);
+       IFDEBUG(D_TPISO)
+               printf("ISO_CMPNETADDR\n");
+               dump_isoaddr(siso);
+       ENDDEBUG
+       if (name->siso_tlen && bcmp(TSEL(name), TSEL(siso), name->siso_tlen))
+               return (0);
+       return (bcmp((caddr_t)name->siso_data,
+                        (caddr_t)siso->siso_data, name->siso_nlen) == 0);
+}
+
 /*
  * CALLED FROM:
  *  pr_usrreq() PRU_SOCKADDR, PRU_ACCEPT, PRU_PEERADDR
 /*
  * CALLED FROM:
  *  pr_usrreq() PRU_SOCKADDR, PRU_ACCEPT, PRU_PEERADDR
@@ -237,105 +287,41 @@ iso_getnetaddr( isop, name, which)
        else
                name->m_len = 0;
 }
        else
                name->m_len = 0;
 }
-
 /*
 /*
+ * NAME:       tpclnp_mtu()
+ *
  * CALLED FROM:
  * CALLED FROM:
- *  tp_input() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT
- * FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE:
- * Determine the proper maximum transmission unit, i.e., MTU, to use, given
- * a) the header size for the network protocol and the max transmission
- *       unit on the subnet interface, determined from the information in (isop),
- * b) the max size negotiated so far (negot)
- * c) the window size used by the tp connection (found in so),
+ *  tp_route_to() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT
+ *
+ * FUNCTION, ARGUMENTS, and RETURN VALUE:
  *
  *
- * The result is put in the integer *size in its integer form and in
- * *negot in its logarithmic form.  
+ * Perform subnetwork dependent part of determining MTU information.
+ * It appears that setting a double pointer to the rtentry associated with
+ * the destination, and returning the header size for the network protocol
+ * suffices.
  * 
  * 
- * The rules are:
- * a) can only negotiate down from the value found in *negot.
- * b) the MTU must be < the windowsize,
- * c) If src and dest are on the same net,
- *       we will negotiate the closest size larger than  MTU but really USE 
- *    the actual device mtu - ll hdr sizes.
- *   otherwise we negotiate the closest size smaller than MTU - ll hdr sizes.
+ * SIDE EFFECTS:
+ * Sets tp_routep pointer in pcb.
+ *
+ * NOTES:
  */
  */
-
-void
-tpclnp_mtu(so, isop, size, negot )
-       struct socket *so;
-       struct isopcb *isop;
-       int *size;
-       u_char *negot;
+tpclnp_mtu(tpcb)
+register struct tp_pcb *tpcb;
 {
 {
-       struct ifnet *ifp;
-       struct iso_ifaddr *ia;
-       register int i;
-       int windowsize = so->so_rcv.sb_hiwat;
-       int clnp_size;
-       int sizeismtu = 0;
-
-       struct iso_ifaddr       *iso_routeifa();
+       struct isopcb                   *isop = (struct isopcb *)tpcb->tp_npcb;
 
        IFDEBUG(D_CONN)
 
        IFDEBUG(D_CONN)
-               printf("tpclnp_mtu(0x%x,0x%x,0x%x,0x%x)\n", so, isop, size, negot);
+               printf("tpclnp_mtu(tpcb)\n", tpcb);
        ENDDEBUG
        ENDDEBUG
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "ENTER GET MTU: size negot \n",*size, *negot, 0, 0);
-       ENDTRACE
-
-       *size = 1 << *negot;
-
-       if( *size > windowsize ) {
-               *size = windowsize;
-       }
-
-       if  (((ia = iso_routeifa(isop->isop_faddr)) == 0)
-             || (ifp = ia->ia_ifp) == 0)
-               return;
-
-       /* TODO - make this indirect off the socket structure to the
-        * network layer to get headersize
-        */
-       if (isop->isop_laddr)
-               clnp_size = clnp_hdrsize(isop->isop_laddr->siso_addr.isoa_len);
+       tpcb->tp_routep = &(isop->isop_route.ro_rt);
+       if (tpcb->tp_netservice == ISO_CONS)
+               return 0;
        else
        else
-               clnp_size = 20;
-
-       if(*size > ifp->if_mtu - clnp_size) {
-               *size = ifp->if_mtu - clnp_size;
-               sizeismtu = 1;
-       }
-       /* have to transform size to the log2 of size */
-       for(i=TP_MIN_TPDUSIZE; (i<TP_MAX_TPDUSIZE && ((1<<i) <= *size)) ; i++)
-               ;
-       i--;
-
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "GET MTU MID: tpcb size negot i \n",
-               *size, *negot, i, 0);
-       ENDTRACE
-
-       /* are we on the same LAN? if so, negotiate one tpdu size larger,
-        * and actually send the real mtu size
-        */
-       if (iso_localifa(isop->isop_faddr)) {
-               i++;
-       } else {
-               *size = 1<<i;
-       }
-       *negot = i;
+               return (sizeof(struct clnp_fixed) + sizeof(struct clnp_segment) +
+                       2 * sizeof(struct iso_addr));
 
 
-       IFDEBUG(D_CONN)
-               printf("GET MTU RETURNS: ifp %s size 0x%x negot 0x%x\n",
-               ifp->if_name,   *size, *negot);
-       ENDDEBUG
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "EXIT GET MTU: tpcb size negot \n",
-               *size, *negot, 0, 0);
-       ENDTRACE
 }
 
 }
 
-
 /*
  * CALLED FROM:
  *  tp_emit()
 /*
  * CALLED FROM:
  *  tp_emit()
@@ -343,7 +329,7 @@ tpclnp_mtu(so, isop, size, negot )
  *  Take a packet(m0) from tp and package it so that clnp will accept it.
  *  This means prepending space for the clnp header and filling in a few
  *  of the fields.
  *  Take a packet(m0) from tp and package it so that clnp will accept it.
  *  This means prepending space for the clnp header and filling in a few
  *  of the fields.
- *  inp is the isopcb structure; datalen is the length of the data in the
+ *  isop is the isopcb structure; datalen is the length of the data in the
  *  mbuf string m0.
  * RETURN VALUE:
  *  whatever (E*) is returned form the net layer output routine.
  *  mbuf string m0.
  * RETURN VALUE:
  *  whatever (E*) is returned form the net layer output routine.
@@ -440,7 +426,6 @@ tpclnp_output_dg(laddr, faddr, m0, datalen, ro, nochksum)
        
        return(err);
 }
        
        return(err);
 }
-extern struct sockaddr_iso blank_siso;
 /*
  * CALLED FROM:
  *     clnp's input routine, indirectly through the protosw.
 /*
  * CALLED FROM:
  *     clnp's input routine, indirectly through the protosw.
@@ -449,14 +434,13 @@ extern struct sockaddr_iso blank_siso;
  * No return value.  
  */
 ProtoHook
  * No return value.  
  */
 ProtoHook
-tpclnp_input(m, faddr, laddr, clnp_len)
-       struct mbuf *m;
-       struct iso_addr *faddr, *laddr;
-       int clnp_len;
+tpclnp_input(m, src, dst, clnp_len, ce_bit)
+       register struct mbuf *m;
+       struct sockaddr_iso *src, *dst;
+       int clnp_len, ce_bit;
 {
 {
-       struct sockaddr_iso src, dst;
-       int s = splnet();
        struct mbuf *tp_inputprep();
        struct mbuf *tp_inputprep();
+       int tp_input(), cltp_input(), (*input)() = tp_input;
 
        IncStat(ts_pkt_rcvd);
 
 
        IncStat(ts_pkt_rcvd);
 
@@ -470,30 +454,41 @@ tpclnp_input(m, faddr, laddr, clnp_len)
         * First, strip off the Clnp header. leave the mbuf there for the
         * pullup that follows.
         */
         * First, strip off the Clnp header. leave the mbuf there for the
         * pullup that follows.
         */
-
        m->m_len -= clnp_len;
        m->m_data += clnp_len;
        m->m_len -= clnp_len;
        m->m_data += clnp_len;
-
+       m->m_pkthdr.len -= clnp_len;
+       /* XXXX: should probably be in clnp_input */
+       switch (dst->siso_data[dst->siso_nlen - 1]) {
+#ifdef TUBA
+       case ISOPROTO_TCP:
+               return (tuba_tcpinput(m, src, dst));
+#endif
+       case 0:
+               if (m->m_len == 0 && (m = m_pullup(m, 1)) == 0)
+                       return 0;
+               if (*(mtod(m, u_char *)) == ISO10747_IDRP)
+                       return (idrp_input(m, src, dst));
+       }
        m = tp_inputprep(m);
        m = tp_inputprep(m);
+       if (m == 0)
+               return 0;
+       if (mtod(m, u_char *)[1] == UD_TPDU_type)
+               input = cltp_input;
 
        IFDEBUG(D_TPINPUT)
                dump_mbuf(m, "after tpclnp_input both pullups");
        ENDDEBUG
 
 
        IFDEBUG(D_TPINPUT)
                dump_mbuf(m, "after tpclnp_input both pullups");
        ENDDEBUG
 
-       src = blank_siso; dst = blank_siso;
-       bcopy((caddr_t)faddr, (caddr_t)&src.siso_addr, 1 + faddr->isoa_len);
-       bcopy((caddr_t)laddr, (caddr_t)&dst.siso_addr, 1 + laddr->isoa_len);
-
        IFDEBUG(D_TPISO)
        IFDEBUG(D_TPISO)
-               printf("calling tp_input: &src 0x%x  &dst 0x%x, src addr:\n", 
-                       &src, &dst);
+               printf("calling %sinput : src 0x%x, dst 0x%x, src addr:\n", 
+                       (input == tp_input ? "tp_" : "clts_"), src, dst);
+               dump_isoaddr(src);
                printf(" dst addr:\n");
                printf(" dst addr:\n");
-               dump_isoaddr(&src);
-               dump_isoaddr(&dst);
+               dump_isoaddr(dst);
        ENDDEBUG
 
        ENDDEBUG
 
-       (void) tp_input(m, (struct sockaddr *)&src, (struct sockaddr *)&dst,
-                               0, tpclnp_output_dg);
+       (void) (*input)(m, (struct sockaddr *)src, (struct sockaddr *)dst,
+                               0, tpclnp_output_dg, ce_bit);
 
        IFDEBUG(D_QUENCH)
                { 
 
        IFDEBUG(D_QUENCH)
                { 
@@ -509,7 +504,6 @@ tpclnp_input(m, faddr, laddr, clnp_len)
                }
        ENDDEBUG
 
                }
        ENDDEBUG
 
-       splx(s);
        return 0;
 }
 
        return 0;
 }
 
@@ -529,7 +523,7 @@ void
 tpiso_decbit(isop)
        struct isopcb *isop;
 {
 tpiso_decbit(isop)
        struct isopcb *isop;
 {
-       tp_quench((struct tp_pcb *)isop->isop_socket->so_tpcb, PRC_QUENCH2);
+       tp_quench((struct tp_pcb *)isop->isop_socket->so_pcb, PRC_QUENCH2);
 }
 /*
  * CALLED FROM:
 }
 /*
  * CALLED FROM:
@@ -541,7 +535,7 @@ void
 tpiso_quench(isop)
        struct isopcb *isop;
 {
 tpiso_quench(isop)
        struct isopcb *isop;
 {
-       tp_quench((struct tp_pcb *)isop->isop_socket->so_tpcb, PRC_QUENCH);
+       tp_quench((struct tp_pcb *)isop->isop_socket->so_pcb, PRC_QUENCH);
 }
 
 /*
 }
 
 /*
@@ -559,17 +553,6 @@ ProtoHook
 tpclnp_ctlinput(cmd, siso)
        int cmd;
        struct sockaddr_iso *siso;
 tpclnp_ctlinput(cmd, siso)
        int cmd;
        struct sockaddr_iso *siso;
-{
-       return tpclnp_ctlinput1(cmd, &siso->siso_addr);
-}
-
-/*
- *     Entry to ctlinput with argument of an iso_addr rather than a sockaddr
- */
-ProtoHook
-tpclnp_ctlinput1(cmd, isoa)
-       int cmd;
-       struct iso_addr *isoa;
 {
        extern u_char inetctlerrmap[];
        extern ProtoHook tpiso_abort();
 {
        extern u_char inetctlerrmap[];
        extern ProtoHook tpiso_abort();
@@ -578,32 +561,34 @@ tpclnp_ctlinput1(cmd, isoa)
        void iso_pcbnotify();
 
        IFDEBUG(D_TPINPUT)
        void iso_pcbnotify();
 
        IFDEBUG(D_TPINPUT)
-               printf("tpclnp_ctlinput1: cmd 0x%x addr: %s\n", cmd, 
-                       clnp_iso_addrp(isoa));
+               printf("tpclnp_ctlinput1: cmd 0x%x addr: \n", cmd);
+               dump_isoaddr(siso);
        ENDDEBUG
 
        if (cmd < 0 || cmd > PRC_NCMDS)
                return 0;
        ENDDEBUG
 
        if (cmd < 0 || cmd > PRC_NCMDS)
                return 0;
+       if (siso->siso_family != AF_ISO)
+               return 0;
        switch (cmd) {
 
                case    PRC_QUENCH2:
        switch (cmd) {
 
                case    PRC_QUENCH2:
-                       iso_pcbnotify(&tp_isopcb, isoa, 0, (int (*)())tpiso_decbit);
+                       iso_pcbnotify(&tp_isopcb, siso, 0, (int (*)())tpiso_decbit);
                        break;
 
                case    PRC_QUENCH:
                        break;
 
                case    PRC_QUENCH:
-                       iso_pcbnotify(&tp_isopcb, isoa, 0, (int (*)())tpiso_quench);
+                       iso_pcbnotify(&tp_isopcb, siso, 0, (int (*)())tpiso_quench);
                        break;
 
                case    PRC_TIMXCEED_REASS:
                case    PRC_ROUTEDEAD:
                        break;
 
                case    PRC_TIMXCEED_REASS:
                case    PRC_ROUTEDEAD:
-                       iso_pcbnotify(&tp_isopcb, isoa, 0, tpiso_reset);
+                       iso_pcbnotify(&tp_isopcb, siso, 0, tpiso_reset);
                        break;
 
                case    PRC_HOSTUNREACH:
                case    PRC_UNREACH_NET:
                case    PRC_IFDOWN:
                case    PRC_HOSTDEAD:
                        break;
 
                case    PRC_HOSTUNREACH:
                case    PRC_UNREACH_NET:
                case    PRC_IFDOWN:
                case    PRC_HOSTDEAD:
-                       iso_pcbnotify(&tp_isopcb, isoa,
+                       iso_pcbnotify(&tp_isopcb, siso,
                                        (int)inetctlerrmap[cmd], iso_rtchange);
                        break;
 
                                        (int)inetctlerrmap[cmd], iso_rtchange);
                        break;
 
@@ -622,11 +607,25 @@ tpclnp_ctlinput1(cmd, isoa)
                case    PRC_TIMXCEED_INTRANS:
                case    PRC_PARAMPROB:
                */
                case    PRC_TIMXCEED_INTRANS:
                case    PRC_PARAMPROB:
                */
-               iso_pcbnotify(&tp_isopcb, isoa, (int)inetctlerrmap[cmd], tpiso_abort);
+               iso_pcbnotify(&tp_isopcb, siso, (int)inetctlerrmap[cmd], tpiso_abort);
                break;
        }
        return 0;
 }
                break;
        }
        return 0;
 }
+/*
+ * XXX - Variant which is called by clnp_er.c with an isoaddr rather
+ * than a sockaddr_iso.
+ */
+
+static struct sockaddr_iso siso = {sizeof(siso), AF_ISO};
+tpclnp_ctlinput1(cmd, isoa)
+       int cmd;
+       struct iso_addr *isoa;
+{
+       bzero((caddr_t)&siso.siso_addr, sizeof(siso.siso_addr));
+       bcopy((caddr_t)isoa, (caddr_t)&siso.siso_addr, isoa->isoa_len);
+       tpclnp_ctlinput(cmd, &siso);
+}
 
 /*
  * These next 2 routines are
 
 /*
  * These next 2 routines are
@@ -651,7 +650,7 @@ tpiso_abort(isop)
        ENDDEBUG
        e.ev_number = ER_TPDU;
        e.ATTR(ER_TPDU).e_reason = ECONNABORTED;
        ENDDEBUG
        e.ev_number = ER_TPDU;
        e.ATTR(ER_TPDU).e_reason = ECONNABORTED;
-       return  tp_driver((struct tp_pcb *)isop->isop_socket->so_tpcb, &e);
+       return  tp_driver((struct tp_pcb *)isop->isop_socket->so_pcb, &e);
 }
 
 ProtoHook
 }
 
 ProtoHook
@@ -661,8 +660,8 @@ tpiso_reset(isop)
        struct tp_event e;
 
        e.ev_number = T_NETRESET;
        struct tp_event e;
 
        e.ev_number = T_NETRESET;
-       return tp_driver((struct tp_pcb *)isop->isop_socket->so_tpcb, &e);
+       return tp_driver((struct tp_pcb *)isop->isop_socket->so_pcb, &e);
 
 }
 
 
 }
 
-#endif ISO
+#endif /* ISO */