minor fixes & improvements: swab not in kernel; make sure NSEL is
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Sat, 21 Nov 1992 14:45:25 +0000 (06:45 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Sat, 21 Nov 1992 14:45:25 +0000 (06:45 -0800)
6 when connecting; don't bother to save extra 2 cksum fudges; change convention
on who moves pointer past CLNP header; on input, if you have to pull up TCP
header, do it directly into aligned header.

SCCS-vsn: sys/netiso/tuba_subr.c 7.10
SCCS-vsn: sys/netiso/tuba_table.c 7.8
SCCS-vsn: sys/netiso/tuba_table.h 7.8
SCCS-vsn: sys/netiso/tuba_usrreq.c 7.7

usr/src/sys/netiso/tuba_subr.c
usr/src/sys/netiso/tuba_table.c
usr/src/sys/netiso/tuba_table.h
usr/src/sys/netiso/tuba_usrreq.c

index e4a0b63..1deb326 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)tuba_subr.c 7.9 (Berkeley) %G%
+ *     @(#)tuba_subr.c 7.10 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -72,6 +72,11 @@ struct addr_arg {
        u_long  sum;
 };
 
        u_long  sum;
 };
 
+/*
+ * Calculate contribution to fudge factor for TCP checksum,
+ * and coincidentally set pointer for convenience of clnp_output
+ * if we are are responding when there is no isopcb around.
+ */
 static void
 tuba_getaddr(arg, siso, index)
        register struct addr_arg *arg;
 static void
 tuba_getaddr(arg, siso, index)
        register struct addr_arg *arg;
@@ -82,7 +87,8 @@ tuba_getaddr(arg, siso, index)
        if (index <= tuba_table_size && (tc = tuba_table[index])) {
                if (siso)
                        *siso = &tc->tc_siso;
        if (index <= tuba_table_size && (tc = tuba_table[index])) {
                if (siso)
                        *siso = &tc->tc_siso;
-               arg->sum += (arg->offset & 1 ? tc->tc_ssum_d : tc->tc_sum_d);
+               arg->sum += (arg->offset & 1 ? tc->tc_ssum : tc->tc_sum)
+                               + (0xffff ^ index);
                arg->offset += tc->tc_siso.siso_nlen + 1;
        } else
                arg->error = 1;
                arg->offset += tc->tc_siso.siso_nlen + 1;
        } else
                arg->error = 1;
@@ -191,10 +197,9 @@ tuba_pcbconnect(inp, nam)
  * and do tcp input processing.
  * No return value.  
  */
  * and do tcp input processing.
  * No return value.  
  */
-tuba_tcpinput(m, src, dst, clnp_len, ce_bit)
+tuba_tcpinput(m, src, dst)
        register struct mbuf *m;
        struct sockaddr_iso *src, *dst;
        register struct mbuf *m;
        struct sockaddr_iso *src, *dst;
-       int clnp_len, ce_bit;
 {
        unsigned long sum, lindex, findex;
        register struct tcpiphdr *ti;
 {
        unsigned long sum, lindex, findex;
        register struct tcpiphdr *ti;
@@ -209,17 +214,8 @@ tuba_tcpinput(m, src, dst, clnp_len, ce_bit)
        struct in_addr laddr;
        int dropsocket = 0, iss = 0;
 
        struct in_addr laddr;
        int dropsocket = 0, iss = 0;
 
-       if ((m->m_flags & M_PKTHDR) == 0) {
-               om = m_gethdr(M_DONTWAIT, MT_DATA);
-               if (om == 0)
-                       goto drop;
-               om->m_next = m;
-               for (len = 0; m; m = m->m_next)
-                       len += m->m_len;
-               m = om;
-               m->m_pkthdr.len = len;
-       }
-       om = 0;
+       if ((m->m_flags & M_PKTHDR) == 0)
+               panic("tuba_tcpinput");
        /*
         * Do some housekeeping looking up CLNP addresses.
         * If we are out of space might as well drop the packet now.
        /*
         * Do some housekeeping looking up CLNP addresses.
         * If we are out of space might as well drop the packet now.
@@ -230,24 +226,11 @@ tuba_tcpinput(m, src, dst, clnp_len, ce_bit)
        if (lindex == 0 || findex == 0)
                goto drop;
        /*
        if (lindex == 0 || findex == 0)
                goto drop;
        /*
-        * Get CLNP and TCP header together in first mbuf.
         * CLNP gave us an mbuf chain WITH the clnp header pulled up,
         * CLNP gave us an mbuf chain WITH the clnp header pulled up,
-        * and the length of the clnp header.
+        * but the data pointer pushed past it.
         */
         */
-       len = clnp_len + sizeof(struct tcphdr);
-       if (m->m_len < len) {
-               if ((m = m_pullup(m, len)) == 0) {
-                       tcpstat.tcps_rcvshort++;
-                       return;
-               }
-       }
-       /*
-        * Calculate checksum of extended TCP header and data,
-        * by adjusting the checksum for missing parts of the header.
-        */
-       m->m_data += clnp_len;
-       m->m_len -= clnp_len;
-       tlen = m->m_pkthdr.len -= clnp_len;
+       len = m->m_len;
+       tlen = m->m_pkthdr.len;
        m->m_data -= sizeof(struct ip);
        m->m_len += sizeof(struct ip);
        m->m_pkthdr.len += sizeof(struct ip);
        m->m_data -= sizeof(struct ip);
        m->m_len += sizeof(struct ip);
        m->m_pkthdr.len += sizeof(struct ip);
@@ -262,23 +245,37 @@ tuba_tcpinput(m, src, dst, clnp_len, ce_bit)
         */
        off = ((sizeof (long) - 1) & ((m->m_flags & M_EXT) ?
                (m->m_data - m->m_ext.ext_buf) :  (m->m_data - m->m_pktdat)));
         */
        off = ((sizeof (long) - 1) & ((m->m_flags & M_EXT) ?
                (m->m_data - m->m_ext.ext_buf) :  (m->m_data - m->m_pktdat)));
-       if (off) {
-               struct mbuf *m0 = m_gethdr(M_DONTWAIT, MT_DATA);
-               if (m0 == 0) {
+       if (off || len < sizeof(struct tcphdr)) {
+               struct mbuf *m0 = m;
+
+               MGETHDR(m, M_DONTWAIT, MT_DATA);
+               if (m == 0) { 
+                       m = m0;
                        goto drop;
                }
                        goto drop;
                }
-               m0->m_data += max_linkhdr;
-               bcopy(mtod(m, caddr_t) + sizeof(struct ip),
-                     mtod(m0, caddr_t) + sizeof(struct ip),
-                     sizeof(struct tcphdr));
-               m->m_data += sizeof(struct tcpiphdr);
-               m->m_len -= sizeof(struct tcpiphdr);
-               m0->m_next = m;
-               m0->m_pkthdr = m->m_pkthdr;
-               m0->m_flags = m->m_flags & M_COPYFLAGS;
-               m0->m_len = sizeof(struct tcpiphdr);
-               m = m0;
+               m->m_next = m0;
+               m->m_data += max_linkhdr;
+               m->m_pkthdr = m->m_pkthdr;
+               m->m_flags = m->m_flags & M_COPYFLAGS;
+               if (len < sizeof(struct tcphdr)) {
+                       if ((m = m_pullup(m, sizeof(struct tcpiphdr))) == 0) {
+                               tcpstat.tcps_rcvshort++;
+                               return;
+                       }
+               } else {
+                       bcopy(mtod(m, caddr_t) + sizeof(struct ip),
+                             mtod(m0, caddr_t) + sizeof(struct ip),
+                             sizeof(struct tcphdr));
+                       m0->m_len -= sizeof(struct tcpiphdr);
+                       m0->m_data += sizeof(struct tcpiphdr);
+                       m->m_len = sizeof(struct tcpiphdr);
+               }
        }
        }
+       /*
+        * Calculate checksum of extended TCP header and data,
+        * replacing what would have been IP addresses by
+        * the IP checksum of the CLNP addresses.
+        */
        ti = mtod(m, struct tcpiphdr *);
        ti->ti_dst.s_addr = tuba_table[lindex]->tc_sum;
        if (dst->siso_nlen & 1)
        ti = mtod(m, struct tcpiphdr *);
        ti->ti_dst.s_addr = tuba_table[lindex]->tc_sum;
        if (dst->siso_nlen & 1)
@@ -307,4 +304,5 @@ tuba_tcpinput(m, src, dst, clnp_len, ce_bit)
 
 #define tcp_slowtimo   tuba_slowtimo
 #define tcp_fasttimo   tuba_fasttimo
 
 #define tcp_slowtimo   tuba_slowtimo
 #define tcp_fasttimo   tuba_fasttimo
+
 #include <netinet/tcp_timer.c>
 #include <netinet/tcp_timer.c>
index 66a8e79..a25b573 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)tuba_table.c        7.7 (Berkeley) %G%
+ *     @(#)tuba_table.c        7.8 (Berkeley) %G%
  */
 #include <sys/param.h>
 #include <sys/systm.h>
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -88,7 +88,7 @@ tuba_lookup(isoa, wait)
                (i & 1 ? sum_a : sum_b) += tc->tc_siso.siso_data[i];
        REDUCE(tc->tc_sum, (sum_a << 8) + sum_b);
        HTONS(tc->tc_sum);
                (i & 1 ? sum_a : sum_b) += tc->tc_siso.siso_data[i];
        REDUCE(tc->tc_sum, (sum_a << 8) + sum_b);
        HTONS(tc->tc_sum);
-       tc->tc_ssum = swab(tc->tc_sum);
+       SWAB(tc->tc_ssum, tc->tc_sum);
        for (i = tuba_table_size; i > 0; i--)
                if (tuba_table[i] == 0)
                        goto fixup;
        for (i = tuba_table_size; i > 0; i--)
                if (tuba_table[i] == 0)
                        goto fixup;
@@ -117,8 +117,5 @@ tuba_lookup(isoa, wait)
 fixup:
        tuba_table[i] = tc;
        tc->tc_index = i;
 fixup:
        tuba_table[i] = tc;
        tc->tc_index = i;
-       i ^= 0xffff;
-       REDUCE(tc->tc_sum_d, tc->tc_sum + i);
-       REDUCE(tc->tc_ssum_d, tc->tc_ssum + i);
        return (tc->tc_index);
 }
        return (tc->tc_index);
 }
index b38ca94..d83c1ff 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)tuba_table.h        7.7 (Berkeley) %G%
+ *     @(#)tuba_table.h        7.8 (Berkeley) %G%
  */
 
 struct tuba_cache {
  */
 
 struct tuba_cache {
@@ -16,8 +16,6 @@ struct tuba_cache {
        int     tc_index;
        u_short tc_sum;                         /* cksum of nsap inc. length */
        u_short tc_ssum;                        /* swab(tc_sum) */
        int     tc_index;
        u_short tc_sum;                         /* cksum of nsap inc. length */
        u_short tc_ssum;                        /* swab(tc_sum) */
-       u_short tc_sum_d;                       /* o.c. diff sum - index */
-       u_short tc_ssum_d;                      /* o.c. diff ssum - index */
        struct  sockaddr_iso tc_siso;           /* for responding */
 };
 
        struct  sockaddr_iso tc_siso;           /* for responding */
 };
 
@@ -25,6 +23,8 @@ struct tuba_cache {
 #define REDUCE(a, b) { union { u_short s[2]; long l;} l_util; long x; \
        l_util.l = (b); x = l_util.s[0] + l_util.s[1]; ADDCARRY(x); \
        if (x == 0) x = 0xffff; a = x;}
 #define REDUCE(a, b) { union { u_short s[2]; long l;} l_util; long x; \
        l_util.l = (b); x = l_util.s[0] + l_util.s[1]; ADDCARRY(x); \
        if (x == 0) x = 0xffff; a = x;}
+#define SWAB(a, b) { union { u_char c[2]; u_short s;} s_util; u_short x; \
+       u_char t; s_util.s = b; t = c[0]; c[0] = c[1]; c[1] = t; }
 
 #ifdef KERNEL
 extern int     tuba_table_size;
 
 #ifdef KERNEL
 extern int     tuba_table_size;
index c16ecb8..b46faac 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)tuba_usrreq.c       7.6 (Berkeley) %G%
+ *     @(#)tuba_usrreq.c       7.7 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -176,6 +176,10 @@ tuba_usrreq(so, req, m, nam, control)
        /* case PRU_CONNECT: */
                if (error = iso_pcbconnect(isop, nam))
                        break;
        /* case PRU_CONNECT: */
                if (error = iso_pcbconnect(isop, nam))
                        break;
+               if ((siso = isop->isop_laddr) && siso->siso_nlen > 1)
+                       siso->siso_data[siso->siso_nlen - 1] = ISOPROTO_TCP;
+               else
+                       panic("tuba_usrreq: connect");
                siso = mtod(nam, struct sockaddr_iso *);
                if (!(inp->inp_faddr.s_addr = tuba_lookup(&siso->siso_addr, M_WAITOK))) {
                unconnect:
                siso = mtod(nam, struct sockaddr_iso *);
                if (!(inp->inp_faddr.s_addr = tuba_lookup(&siso->siso_addr, M_WAITOK))) {
                unconnect: