trailing comment after #else or #endif
[unix-history] / usr / src / sys / netiso / tp_inet.c
index 07d5f20..6b45f81 100644 (file)
@@ -1,3 +1,12 @@
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)tp_inet.c   7.12 (Berkeley) %G%
+ */
+
 /***********************************************************
                Copyright IBM Corporation 1987
 
 /***********************************************************
                Copyright IBM Corporation 1987
 
@@ -35,42 +44,41 @@ SOFTWARE.
  * through a switch table (struct nl_protosw *) tpcb->tp_nlproto 
  * (see tp_pcb.c). 
  * The routines here are:
  * through a switch table (struct nl_protosw *) tpcb->tp_nlproto 
  * (see tp_pcb.c). 
  * The routines here are:
- *             in_getsufx: gets transport suffix out of an inpcb structure.
- *             in_putsufx: put transport suffix into an inpcb structure.
- *             in_putnetaddr: put a whole net addr into an inpcb.
- *             in_getnetaddr: get a whole net addr from an inpcb.
- *             in_recycle_suffix: clear suffix for reuse in inpcb
- *             tpip_mtu: figure out what size tpdu to use
- *             tpip_input: take a pkt from ip, strip off its ip header, give to tp
- *             tpip_output_dg: package a pkt for ip given 2 addresses & some data
- *             tpip_output: package a pkt for ip given an inpcb & some data
+ *     in_getsufx: gets transport suffix out of an inpcb structure.
+ *     in_putsufx: put transport suffix into an inpcb structure.
+ *     in_putnetaddr: put a whole net addr into an inpcb.
+ *     in_getnetaddr: get a whole net addr from an inpcb.
+ *     in_cmpnetaddr: compare a whole net addr from an isopcb.
+ *     in_recycle_suffix: clear suffix for reuse in inpcb
+ *     tpip_mtu: figure out what size tpdu to use
+ *     tpip_input: take a pkt from ip, strip off its ip header, give to tp
+ *     tpip_output_dg: package a pkt for ip given 2 addresses & some data
+ *     tpip_output: package a pkt for ip given an inpcb & some data
  */
 
  */
 
-#ifndef lint
-static char *rcsid = "$Header: tp_inet.c,v 5.3 88/11/18 17:27:29 nhall Exp $";
-#endif lint
-
 #ifdef INET
 
 #ifdef INET
 
-#include "param.h"
-#include "socket.h"
-#include "socketvar.h"
-#include "mbuf.h"
-#include "errno.h"
-#include "time.h"
-#include "../net/if.h"
-#include "tp_param.h"
-#include "argo_debug.h"
-#include "tp_stat.h"
-#include "tp_ip.h"
-#include "tp_pcb.h"
-#include "tp_trace.h"
-#include "tp_stat.h"
-#include "tp_tpdu.h"
-#include "../netinet/in_var.h"
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/mbuf.h>
+#include <sys/errno.h>
+#include <sys/time.h>
+
+#include <net/if.h>
+
+#include <netiso/tp_param.h>
+#include <netiso/argo_debug.h>
+#include <netiso/tp_stat.h>
+#include <netiso/tp_ip.h>
+#include <netiso/tp_pcb.h>
+#include <netiso/tp_trace.h>
+#include <netiso/tp_stat.h>
+#include <netiso/tp_tpdu.h>
+#include <netinet/in_var.h>
 
 #ifndef ISO
 
 #ifndef ISO
-#include "iso_chksum.c"
+#include <netiso/iso_chksum.c>
 #endif
 
 /*
 #endif
 
 /*
@@ -200,6 +208,39 @@ in_putnetaddr(inp, name, which)
        }
 }
 
        }
 }
 
+/*
+ * NAME:       in_putnetaddr()
+ *
+ * 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 inpcb (inp).
+ *     The argument (which) takes values TP_LOCAL or TP_FOREIGN
+ *
+ * RETURNS:            Nada
+ *
+ * SIDE EFFECTS:       
+ *
+ * NOTES:                      
+ */ 
+in_cmpnetaddr(inp, name, which)
+       register struct inpcb   *inp;
+       register struct sockaddr_in     *name;
+       int which;
+{
+       if (which == TP_LOCAL) {
+               if (name->sin_port && name->sin_port != inp->inp_lport)
+                       return 0;
+               return (name->sin_addr.s_addr == inp->inp_laddr.s_addr);
+       }
+       if (name->sin_port && name->sin_port != inp->inp_fport)
+               return 0;
+       return (name->sin_addr.s_addr == inp->inp_faddr.s_addr);
+}
+
 /*
  * NAME:       in_getnetaddr()
  *
 /*
  * NAME:       in_getnetaddr()
  *
@@ -245,102 +286,32 @@ in_getnetaddr( inp, name, which)
  * NAME:       tpip_mtu()
  *
  * CALLED FROM:
  * NAME:       tpip_mtu()
  *
  * CALLED FROM:
- *  tp_input() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT
+ *  tp_route_to() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT
  *
  * FUNCTION, ARGUMENTS, and RETURN VALUE:
  *
  *
  * FUNCTION, ARGUMENTS, 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 (inp),
- * b) the max size negotiated so far (negot)
- * c) the window size used by the tp connection (found in so),
- *
- * The result is put in the integer *size in its integer form and in
- * *negot in its logarithmic form.  
- * 
- * 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.
+ * 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.
  * 
  * SIDE EFFECTS:
  * 
  * SIDE EFFECTS:
- *     changes the values addressed by the arguments (size) and (negot)
- *  and
- *  when the peer is not on one of our directly connected subnets, it
- *  looks up a route, leaving the route in the inpcb addressed by (inp)
+ * Sets tp_routep pointer in pcb.
  *
  * NOTES:
  */
 
  *
  * NOTES:
  */
 
-void
-tpip_mtu(so, inp, size, negot)
-       struct socket *so;
-       struct inpcb *inp;
-       int *size;
-       u_char *negot;
+tpip_mtu(tpcb)
+register struct tp_pcb *tpcb;
 {
 {
-       register struct ifnet   *ifp;
-       struct ifnet                    *tpip_route();
-       struct in_ifaddr                *ia;
-       register int                    i;
-       int                                             windowsize = so->so_rcv.sb_hiwat;
-
-       IFDEBUG(D_CONN)
-               printf("tpip_mtu(0x%x,0x%x,0x%x,0x%x)\n",
-                       so, inp, size, negot);
-               printf("tpip_mtu routing to addr 0x%x\n", inp->inp_faddr);
-       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;
-       }
-
-       ia = in_iaonnetof(in_netof(inp->inp_faddr));
-       if ( ia == (struct in_ifaddr *)0 ) {
-               ifp = tpip_route(&inp->inp_faddr);
-               if( ifp == (struct ifnet *)0 )
-                       return ;
-       } else
-               ifp = ia->ia_ifp;
-
-
-       /****************************************************************
-        * TODO - make this indirect off the socket structure to the
-        * network layer to get headersize
-        * After all, who knows what lies below the IP layer?
-        * Who knows how big the NL header will be?
-        ***************************************************************/
-
-       if( *size > ifp->if_mtu - sizeof(struct ip)) {
-               *size = ifp->if_mtu - sizeof(struct ip);
-       }
-       for(i=TP_MIN_TPDUSIZE; (i<TP_MAX_TPDUSIZE && ((1<<i)<*size)) ; i++)
-               ;
-       i--;
-
-       if (in_netof(inp->inp_laddr) != in_netof(inp->inp_faddr)) {
-               i++;
-       } else {
-               *size = 1<<i;
-       }
-       *negot = i;
+       struct inpcb                    *inp = (struct inpcb *)tpcb->tp_npcb;
 
        IFDEBUG(D_CONN)
 
        IFDEBUG(D_CONN)
-               printf("GET MTU RETURNS: ifp %s size 0x%x negot 0x%x\n",
-               ifp->if_name,   *size, *negot);
+               printf("tpip_mtu(tpcb)\n", tpcb);
+               printf("tpip_mtu routing to addr 0x%x\n", inp->inp_faddr.s_addr);
        ENDDEBUG
        ENDDEBUG
-       IFTRACE(D_CONN)
-               tptrace(TPPTmisc, "EXIT GET MTU: tpcb size negot \n",
-               *size, *negot, 0, 0);
-       ENDTRACE
+       tpcb->tp_routep = &(inp->inp_route.ro_rt);
+       return (sizeof (struct ip));
 
 }
 
 
 }
 
@@ -534,8 +505,7 @@ tpip_input(m, iplen)
        dst.sin_len  = sizeof(dst);
 
        (void) tp_input(m, (struct sockaddr *)&src, (struct sockaddr *)&dst,
        dst.sin_len  = sizeof(dst);
 
        (void) tp_input(m, (struct sockaddr *)&src, (struct sockaddr *)&dst,
-                               0, tpip_output_dg);
-       splx(s);
+                               0, tpip_output_dg, 0);
        return 0;
 
 discard:
        return 0;
 
 discard:
@@ -552,8 +522,8 @@ discard:
 }
 
 
 }
 
 
-#include "protosw.h"
-#include "../netinet/ip_icmp.h"
+#include <sys/protosw.h>
+#include <netinet/ip_icmp.h>
 
 extern void tp_quench();
 /*
 
 extern void tp_quench();
 /*
@@ -574,7 +544,7 @@ void
 tpin_quench(inp)
        struct inpcb *inp;
 {
 tpin_quench(inp)
        struct inpcb *inp;
 {
-       tp_quench((struct tp_pcb *)inp->inp_socket->so_tpcb, PRC_QUENCH);
+       tp_quench((struct tp_pcb *)inp->inp_socket->so_pcb, PRC_QUENCH);
 }
 
 /*
 }
 
 /*
@@ -605,6 +575,7 @@ tpip_ctlinput(cmd, sin)
        extern u_char inetctlerrmap[];
        extern ProtoHook tpin_abort();
        extern ProtoHook in_rtchange();
        extern u_char inetctlerrmap[];
        extern ProtoHook tpin_abort();
        extern ProtoHook in_rtchange();
+       extern struct in_addr zeroin_addr;
 
        if (sin->sin_family != AF_INET && sin->sin_family != AF_IMPLINK)
                return 0;
 
        if (sin->sin_family != AF_INET && sin->sin_family != AF_IMPLINK)
                return 0;
@@ -615,8 +586,8 @@ tpip_ctlinput(cmd, sin)
        switch (cmd) {
 
                case    PRC_QUENCH:
        switch (cmd) {
 
                case    PRC_QUENCH:
-                       in_pcbnotify(&tp_inpcb, &sin->sin_addr, 
-                                               0, (int (*)())tp_quench);
+                       in_pcbnotify(&tp_inpcb, sin, 0,
+                               zeroin_addr, 0, cmd, (int (*)())tp_quench);
                        break;
 
                case    PRC_ROUTEDEAD:
                        break;
 
                case    PRC_ROUTEDEAD:
@@ -624,8 +595,8 @@ tpip_ctlinput(cmd, sin)
                case    PRC_UNREACH_NET:
                case    PRC_IFDOWN:
                case    PRC_HOSTDEAD:
                case    PRC_UNREACH_NET:
                case    PRC_IFDOWN:
                case    PRC_HOSTDEAD:
-                       in_pcbnotify(&tp_inpcb, &sin->sin_addr, 
-                                       (int)inetctlerrmap[cmd], in_rtchange);
+                       in_pcbnotify(&tp_inpcb, sin, 0,
+                               zeroin_addr, 0, cmd, in_rtchange);
                        break;
 
                default:
                        break;
 
                default:
@@ -644,8 +615,8 @@ tpip_ctlinput(cmd, sin)
                case    PRC_TIMXCEED_REASS:
                case    PRC_PARAMPROB:
                */
                case    PRC_TIMXCEED_REASS:
                case    PRC_PARAMPROB:
                */
-               in_pcbnotify(&tp_inpcb, &sin->sin_addr,
-                               (int)inetctlerrmap[cmd], tpin_abort);
+               in_pcbnotify(&tp_inpcb, sin, 0, zeroin_addr, 0,
+                               cmd, tpin_abort);
        }
        return 0;
 }
        }
        return 0;
 }
@@ -687,66 +658,5 @@ dump_inaddr(addr)
 {
        printf("INET: port 0x%x; addr 0x%x\n", addr->sin_port, addr->sin_addr);
 }
 {
        printf("INET: port 0x%x; addr 0x%x\n", addr->sin_port, addr->sin_addr);
 }
-#endif ARGO_DEBUG
-
-/*
- * NAME:       tpip_route()
- *
- * CALLED FROM: tpip_mtu()
- *
- * FUNCTION and ARGUMENTS:     given a destination addresss,
- *     find the interface that would be used to send something to this address.
- *
- * RETURNS:     pointer to an ifnet structure
- *
- * SIDE EFFECTS:
- *
- * NOTES:                      
- */
-struct ifnet *
-tpip_route(dst)
-       struct in_addr *dst;
-{
-       struct ifnet            *ifp = (struct ifnet *)0;
-       struct sockaddr_in      insock;
-       struct sockaddr_in      *sin = &insock;
-       struct rtentry          *rt;
-       struct ifaddr   *ia;
-
-       IFDEBUG(D_CONN)
-               printf("tpip_route: dst is x%x\n", *dst);
-       ENDDEBUG
-
-       bzero((caddr_t)sin, sizeof (*sin));
-       sin->sin_family = AF_INET;
-       sin->sin_len = sizeof(*sin);
-       sin->sin_addr = *dst;
-
-       ia = ifa_ifwithdstaddr((struct sockaddr *)sin);
-       if (ia == 0)
-               ia = ifa_ifwithnet((struct sockaddr *)sin);
-       if (ia != 0) {
-               ifp = ia->ifa_ifp;
-               IFDEBUG(D_CONN)
-                       printf("tpip_route: ifp from ia:0x%x\n", ia);
-               ENDDEBUG
-       } else {
-               rt = rtalloc1((struct sockaddr *)sin, 0);
-               if (rt != 0) {
-                       ifp = rt->rt_ifp;
-                       IFDEBUG(D_CONN)
-                               printf("tpip_route: ifp from rentry: 0x%x\n", rt);
-                       ENDDEBUG
-                       rtfree(rt);
-               }
-       }
-       IFDEBUG(D_CONN)
-               printf("tpip_route: returning 0x%x\n", ifp);
-               if (ifp)
-                       printf("tpip_route: if name %s unit 0x%x, mtu 0x%x\n", 
-                               ifp->if_name, ifp->if_unit, ifp->if_mtu);
-       ENDDEBUG
-       return ifp;
-}
-
-#endif INET
+#endif /* ARGO_DEBUG */
+#endif /* INET */