before carry to ARPAVAX
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 27 Nov 1981 03:57:04 +0000 (19:57 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 27 Nov 1981 03:57:04 +0000 (19:57 -0800)
SCCS-vsn: sys/net/if.c 4.3
SCCS-vsn: sys/net/if.h 4.3
SCCS-vsn: sys/vax/if/if_en.c 4.14
SCCS-vsn: sys/vax/if/if_uba.c 4.2
SCCS-vsn: sys/vax/if/if_uba.h 4.2
SCCS-vsn: sys/netinet/in.h 4.5
SCCS-vsn: sys/vax/vax/in_cksum.c 1.11
SCCS-vsn: sys/netinet/in_pcb.c 4.9
SCCS-vsn: sys/netinet/in_systm.h 4.6
SCCS-vsn: sys/netinet/ip_icmp.c 4.8
SCCS-vsn: sys/netinet/ip_input.c 1.19
SCCS-vsn: sys/netinet/ip_output.c 1.20
SCCS-vsn: sys/netinet/ip_var.h 4.4
SCCS-vsn: sys/netinet/tcp.h 1.19
SCCS-vsn: sys/netinet/tcp_fsm.h 4.9
SCCS-vsn: sys/netinet/tcp_input.c 1.32

16 files changed:
usr/src/sys/net/if.c
usr/src/sys/net/if.h
usr/src/sys/netinet/in.h
usr/src/sys/netinet/in_pcb.c
usr/src/sys/netinet/in_systm.h
usr/src/sys/netinet/ip_icmp.c
usr/src/sys/netinet/ip_input.c
usr/src/sys/netinet/ip_output.c
usr/src/sys/netinet/ip_var.h
usr/src/sys/netinet/tcp.h
usr/src/sys/netinet/tcp_fsm.h
usr/src/sys/netinet/tcp_input.c
usr/src/sys/vax/if/if_en.c
usr/src/sys/vax/if/if_uba.c
usr/src/sys/vax/if/if_uba.h
usr/src/sys/vax/vax/in_cksum.c

index 6b1ccaa..c09068a 100644 (file)
@@ -1,9 +1,9 @@
-/*     if.c    4.2     81/11/20        */
+/*     if.c    4.3     81/11/26        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 #include "../net/if.h"
 
 /*ARGSUSED*/
 #include "../net/if.h"
 
 /*ARGSUSED*/
@@ -14,13 +14,9 @@ if_ifwithaddr(in)
        register struct ifnet *ifp;
 
 COUNT(IF_IFWITHADDR);
        register struct ifnet *ifp;
 
 COUNT(IF_IFWITHADDR);
-#if 0
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_addr.s_addr == in.s_addr)
                        break;
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_addr.s_addr == in.s_addr)
                        break;
-#else
-       ifp = ifnet;
-#endif
        return (ifp);
 }
 
        return (ifp);
 }
 
@@ -30,19 +26,21 @@ if_ifonnetof(in)
        struct in_addr in;
 {
        register struct ifnet *ifp;
        struct in_addr in;
 {
        register struct ifnet *ifp;
-#if 0
        int net;
 
 COUNT(IF_IFONNETOF);
        int net;
 
 COUNT(IF_IFONNETOF);
-       net = 0;                        /* XXX */
+       net = in.s_net;                 /* XXX */
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_net == net)
                        break;
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_net == net)
                        break;
-#else
-       ifp = ifnet;
-#endif
        return (ifp);
 }
 
        return (ifp);
 }
 
-struct ifnet ifen;
-struct ifnet *ifnet = &ifen;
+struct ifnet *
+if_gatewayfor(addr)
+       struct in_addr addr;
+{
+
+COUNT(IF_GATEWAYFOR);
+       return (0);
+}
index 5e0c3ba..70cb7c6 100644 (file)
@@ -1,33 +1,53 @@
-/*     if.h    4.2     81/11/20        */
+/*     if.h    4.3     81/11/26        */
 
 /*
 
 /*
- * Structure defining a network interface.
+ * Definitions for network interfaces.
+ */
+struct ifqueue {
+       struct  mbuf *ifq_head;
+       struct  mbuf *ifq_tail;
+};
+
+/*
+ * Structure defining a queue for a network interface.
  *
  * (Would like to call this struct ``if'', but C isn't PL/1.)
  */
 struct ifnet {
        short   if_unit;                /* sub-unit for lower level driver */
  *
  * (Would like to call this struct ``if'', but C isn't PL/1.)
  */
 struct ifnet {
        short   if_unit;                /* sub-unit for lower level driver */
-       short   if_flags;               /* state flags */
        short   if_mtu;                 /* maximum transmission unit */
        short   if_net;                 /* network number of interface */
        short   if_mtu;                 /* maximum transmission unit */
        short   if_net;                 /* network number of interface */
+       int     if_host[2];             /* local net host number */
        struct  in_addr if_addr;        /* internet address of interface */
        struct  in_addr if_addr;        /* internet address of interface */
-       struct ifbuf {
-               short   ib_mbcnt;       /* mbufs on chain */
-               short   ib_mbhiwat;     /* mbufs permitted on chain */
-               struct  mbuf *ib_hd;    /* head of chain */
-               struct  mbuf *ib_tl;    /* tail of chain */
-       } if_snd, if_rcv;
-       struct ifsw {
-               int     (*if_output)();         /* output routine */
-               int     (*if_ubareset)();       /* uba reset routine */
-       } *if_sw;
+       struct  ifqueue if_snd;         /* output queue */
+       int     (*if_output)();         /* output routine */
+       int     (*if_ubareset)();       /* uba reset routine */
+       int     if_collisions;
+       int     if_ierrors;
+       int     if_oerrors;
        struct  ifnet *if_next;
 };
 
        struct  ifnet *if_next;
 };
 
-/* bits in if_flags */
-#define        IF_OACTIVE      1               /* output in progress */
+#define        IF_ENQUEUE(ifq, m) { \
+       (m)->m_act = 0; \
+       if ((ifq)->ifq_tail == 0) \
+               (ifq)->ifq_head = (ifq)->ifq_tail =  m; \
+       else \
+               (ifq)->ifq_tail->m_act = m; \
+}
+#define        IF_DEQUEUE(ifq, m) { \
+       (m) = (ifq)->ifq_head; \
+       if (m) { \
+               if (((ifq)->ifq_head = (m)->m_act) == 0) \
+                       (ifq)->ifq_tail = 0; \
+               (m)->m_act = 0; \
+       } \
+}
 
 #ifdef KERNEL
 
 #ifdef KERNEL
+#ifdef INET
+struct ifqueue ipintrq;                /* ip packet input queue */
+#endif
 struct ifnet *ifnet;
 struct ifnet *ifnet;
-struct ifnet *if_ifwithaddr(), *if_ifonnetof();
+struct ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor();
 #endif
 #endif
index 87ea700..5c0b7fd 100644 (file)
@@ -1,4 +1,4 @@
-/* in.h 4.4 81/11/18 */
+/* in.h 4.5 81/11/26 */
 
 /*
  * Constants and structures defined by the internet system,
 
 /*
  * Constants and structures defined by the internet system,
index 87f6979..c9f1585 100644 (file)
@@ -1,4 +1,4 @@
-/* in_pcb.c 4.8 81/11/21 */
+/* in_pcb.c 4.9 81/11/26 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -7,10 +7,10 @@
 #include "../h/mbuf.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/mbuf.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../net/if.h"
-#include "../net/inet_pcb.h"
+#include "../net/in_pcb.h"
 
 /*
  * Allocate a protocol control block, space
 
 /*
  * Allocate a protocol control block, space
index e3aed64..167f207 100644 (file)
@@ -1,4 +1,4 @@
-/* in_systm.h 4.5 81/11/20 */
+/* in_systm.h 4.6 81/11/26 */
 
 /*
  * Miscellaneous internetwork
 
 /*
  * Miscellaneous internetwork
  */
 typedef u_short n_short;               /* short as received from the net */
 typedef u_long n_long;                 /* long as received from the net */
  */
 typedef u_short n_short;               /* short as received from the net */
 typedef u_long n_long;                 /* long as received from the net */
-typedef u_long seq_t;                  /* sequence number */
 
 typedef        u_long  n_time;                 /* ms since 00:00 GMT, byte rev */
 
 /*
 
 typedef        u_long  n_time;                 /* ms since 00:00 GMT, byte rev */
 
 /*
- * The network runs as a software interrupt process.
+ * The internet code runs off software interrupts.
+ * There is one software interrupt level for each IP layer protocol
+ * (e.g. IP, PUP, etc), and each such interrupt traps to the lowest
+ * level routine for that protocol.
+ *
  * You can switch into the network by doing splnet() and return by splx().
  * The software interrupt level for the network is higher than the software
  * level for the clock (so you can enter the network in routines called
  * You can switch into the network by doing splnet() and return by splx().
  * The software interrupt level for the network is higher than the software
  * level for the clock (so you can enter the network in routines called
@@ -28,7 +31,7 @@ typedef       u_long  n_time;                 /* ms since 00:00 GMT, byte rev */
  * While manipulating the mbuf buffer pool you have to block imps.
  */
 #define        splimp          spl5
  * While manipulating the mbuf buffer pool you have to block imps.
  */
 #define        splimp          spl5
-#define        setsoftnet()    mtpr(SIRR, 12)
+#define        setipintr()     mtpr(SIRR, 12)
 /* splnet is defined in ../sys/asm.sed */
 
 #ifdef KERNEL
 /* splnet is defined in ../sys/asm.sed */
 
 #ifdef KERNEL
index 830f8d8..51656bc 100644 (file)
@@ -1,12 +1,12 @@
-/*     ip_icmp.c       4.7     81/11/23        */
+/*     ip_icmp.c       4.8     81/11/26        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/clock.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/clock.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 #include "../net/ip.h"
 #include "../net/ip_icmp.h"
 
 #include "../net/ip.h"
 #include "../net/ip_icmp.h"
 
@@ -27,6 +27,7 @@ icmp_error(oip, type, code)
        struct icmp *icp = (struct icmp *)((int)oip + oiplen);
        struct mbuf *m;
        struct ip *nip;
        struct icmp *icp = (struct icmp *)((int)oip + oiplen);
        struct mbuf *m;
        struct ip *nip;
+COUNT(ICMP_ERROR);
 
        /*
         * Make sure that the old IP packet had 8 bytes of data to return;
 
        /*
         * Make sure that the old IP packet had 8 bytes of data to return;
@@ -81,6 +82,7 @@ icmp_input(m)
        int hlen = ip->ip_hl << 2;
        int icmplen = ip->ip_len - hlen;
        int i;
        int hlen = ip->ip_hl << 2;
        int icmplen = ip->ip_len - hlen;
        int i;
+COUNT(ICMP_INPUT);
 
        /*
         * Locate icmp structure in mbuf, and check
 
        /*
         * Locate icmp structure in mbuf, and check
@@ -92,7 +94,7 @@ icmp_input(m)
        icp = (struct icmp *)mtod(m, struct icmp *);
        i = icp->icmp_cksum;
        icp->icmp_cksum = 0;
        icp = (struct icmp *)mtod(m, struct icmp *);
        i = icp->icmp_cksum;
        icp->icmp_cksum = 0;
-       if (i != inet_cksum(m, icmplen) || icmplen < ICMP_MINLEN)
+       if (i != in_cksum(m, icmplen) || icmplen < ICMP_MINLEN)
                goto free;
 
        /*
                goto free;
 
        /*
@@ -154,6 +156,7 @@ icmp_reflect(ip)
        struct ip *ip;
 {
        struct in_addr t;
        struct ip *ip;
 {
        struct in_addr t;
+COUNT(ICMP_REFLECT);
 
        t = ip->ip_src; ip->ip_dst = ip->ip_src; ip->ip_src = t;
        /*
 
        t = ip->ip_src; ip->ip_dst = ip->ip_src; ip->ip_src = t;
        /*
@@ -171,11 +174,12 @@ icmp_send(ip)
        struct ip *ip;
 {
        struct icmp *icp = 0;                                   /* XXX */
        struct ip *ip;
 {
        struct icmp *icp = 0;                                   /* XXX */
+COUNT(ICMP_SEND);
 
        icp->icmp_cksum = 0;
 
        icp->icmp_cksum = 0;
-       icp->icmp_cksum = inet_cksum(dtom(ip), 0);              /* XXX */
+       icp->icmp_cksum = in_cksum(dtom(ip), 0);                /* XXX */
        ip->ip_ttl = MAXTTL;
        ip->ip_ttl = MAXTTL;
-       ip_output(dtom(ip));
+       ip_output(dtom(ip), (struct mbuf *)0);
 }
 
 /*
 }
 
 /*
@@ -186,6 +190,7 @@ icmp_ctlinput(ip)
        struct ip *ip;
 {
        extern u_char ip_protox[];              /* XXX */
        struct ip *ip;
 {
        extern u_char ip_protox[];              /* XXX */
+COUNT(ICMP_CTLINPUT);
 
        (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)(ip);
 }
 
        (*protosw[ip_protox[ip->ip_p]].pr_ctlinput)(ip);
 }
@@ -199,11 +204,13 @@ icmp_gotreply(icp)
        struct icmp *icp;
 {
 
        struct icmp *icp;
 {
 
+COUNT(ICMP_GOTREPLY);
 }
 
 icmp_drain()
 {
 
 }
 
 icmp_drain()
 {
 
+COUNT(ICMP_DRAIN);
 }
 
 n_time
 }
 
 n_time
@@ -212,6 +219,7 @@ iptime()
        int s = spl6();
        u_long t;
 
        int s = spl6();
        u_long t;
 
+COUNT(IPTIME);
        t = (time % SECDAY) * 1000 + lbolt * hz;
        splx(s);
        return (htonl(t));
        t = (time % SECDAY) * 1000 + lbolt * hz;
        splx(s);
        return (htonl(t));
index 8dd3ca7..014e589 100644 (file)
@@ -1,4 +1,4 @@
-/* ip_input.c 1.18 81/11/23 */
+/* ip_input.c 1.19 81/11/26 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -6,11 +6,10 @@
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/mbuf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../net/if.h"
-#include "../net/imp.h"
-#include "../net/ip.h"                 /* belongs before inet.h */
+#include "../net/ip.h"                 /* belongs before in.h */
 #include "../net/ip_var.h"
 #include "../net/ip_icmp.h"
 #include "../net/tcp.h"
 #include "../net/ip_var.h"
 #include "../net/ip_icmp.h"
 #include "../net/tcp.h"
@@ -51,19 +50,26 @@ struct      ip *ip_reass();
  * try to reassamble.  If complete and fragment queue exists, discard.
  * Process options.  Pass to next level.
  */
  * try to reassamble.  If complete and fragment queue exists, discard.
  * Process options.  Pass to next level.
  */
-ip_input(m0)
-       struct mbuf *m0;
+ipintr()
 {
        register struct ip *ip;
 {
        register struct ip *ip;
-       register struct mbuf *m = m0;
+       register struct mbuf *m;
+       struct mbuf *m0;
        register int i;
        register struct ipq *fp;
        register int i;
        register struct ipq *fp;
-       int hlen;
+       int hlen, s;
 
 
-COUNT(IP_INPUT);
+COUNT(IPINTR);
+next:
        /*
        /*
-        * Check header and byteswap.
+        * Get next datagram off input queue and get IP header
+        * in first mbuf.
         */
         */
+       s = splimp();
+       IF_DEQUEUE(&ipintrq, m);
+       splx(s);
+       if (m == 0)
+               return;
        if (m->m_len < sizeof (struct ip) &&
            m_pullup(m, sizeof (struct ip)) == 0)
                goto bad;
        if (m->m_len < sizeof (struct ip) &&
            m_pullup(m, sizeof (struct ip)) == 0)
                goto bad;
@@ -72,7 +78,7 @@ COUNT(IP_INPUT);
            m_pullup(m, hlen) == 0)
                goto bad;
        if (ipcksum)
            m_pullup(m, hlen) == 0)
                goto bad;
        if (ipcksum)
-               if ((ip->ip_sum = inet_cksum(m, hlen)) != 0xffff) {
+               if ((ip->ip_sum = in_cksum(m, hlen)) != 0xffff) {
                        printf("ip_sum %x\n", ip->ip_sum);
                        ipstat.ips_badsum++;
                        goto bad;
                        printf("ip_sum %x\n", ip->ip_sum);
                        ipstat.ips_badsum++;
                        goto bad;
@@ -92,7 +98,7 @@ COUNT(IP_INPUT);
         * Drop packet if shorter than we expect.
         */
        i = 0;
         * Drop packet if shorter than we expect.
         */
        i = 0;
-       for (; m != NULL; m = m->m_next)
+       for (m0 = m; m != NULL; m = m->m_next)
                i += m->m_len;
        m = m0;
        if (i != ip->ip_len) {
                i += m->m_len;
        m = m0;
        if (i != ip->ip_len) {
@@ -107,14 +113,14 @@ COUNT(IP_INPUT);
         */
        if (hlen > sizeof (struct ip))
                ip_dooptions(ip);
         */
        if (hlen > sizeof (struct ip))
                ip_dooptions(ip);
-       if (ip->ip_dst.s_addr != n_lhost.s_addr &&
+       if (ifnet && ip->ip_dst.s_addr != ifnet->if_addr.s_addr &&
            if_ifwithaddr(ip->ip_dst) == 0) {
                if (--ip->ip_ttl == 0) {
                        icmp_error(ip, ICMP_TIMXCEED, 0);
            if_ifwithaddr(ip->ip_dst) == 0) {
                if (--ip->ip_ttl == 0) {
                        icmp_error(ip, ICMP_TIMXCEED, 0);
-                       return;
+                       goto next;
                }
                }
-               ip_output(dtom(ip));
-               return;
+               ip_output(dtom(ip), (struct mbuf *)0);
+               goto next;
        }
 
        /*
        }
 
        /*
@@ -149,7 +155,7 @@ found:
        if (((struct ipasfrag *)ip)->ipf_mff || ip->ip_off) {
                ip = ip_reass((struct ipasfrag *)ip, fp);
                if (ip == 0)
        if (((struct ipasfrag *)ip)->ipf_mff || ip->ip_off) {
                ip = ip_reass((struct ipasfrag *)ip, fp);
                if (ip == 0)
-                       return;
+                       goto next;
                hlen = ip->ip_hl << 2;
                m = dtom(ip);
        } else
                hlen = ip->ip_hl << 2;
                m = dtom(ip);
        } else
@@ -160,9 +166,10 @@ found:
         * Switch out to protocol's input routine.
         */
        (*protosw[ip_protox[ip->ip_p]].pr_input)(m);
         * Switch out to protocol's input routine.
         */
        (*protosw[ip_protox[ip->ip_p]].pr_input)(m);
-       return;
+       goto next;
 bad:
        m_freem(m);
 bad:
        m_freem(m);
+       goto next;
 }
 
 /*
 }
 
 /*
index e36ad83..70bac4c 100644 (file)
@@ -1,21 +1,22 @@
-#define IMPLOOP
-/*     ip_output.c     1.19    81/11/24        */
+/*     ip_output.c     1.20    81/11/26        */
 
 #include "../h/param.h"
 #include "../h/mbuf.h"
 #include "../h/mtpr.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 
 #include "../h/param.h"
 #include "../h/mbuf.h"
 #include "../h/mtpr.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
-#include "../net/imp.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
+#include "../net/if.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 
-ip_output(m)
+ip_output(m, opt)
        struct mbuf *m;
        struct mbuf *m;
+       struct mbuf *opt;
 {
        register struct ip *ip = mtod(m, struct ip *);
 {
        register struct ip *ip = mtod(m, struct ip *);
+       register struct ifnet *ifp;
        int len, hlen = ip->ip_hl << 2, off;
 
 COUNT(IP_OUTPUT);
        int len, hlen = ip->ip_hl << 2, off;
 
 COUNT(IP_OUTPUT);
@@ -25,14 +26,27 @@ COUNT(IP_OUTPUT);
        ip->ip_v = IPVERSION;
        ip->ip_hl = hlen >> 2;
        ip->ip_off &= IP_DF;
        ip->ip_v = IPVERSION;
        ip->ip_hl = hlen >> 2;
        ip->ip_off &= IP_DF;
-       ip->ip_id = ip_id++;
+       ip->ip_id = htons(ip_id++);
+
+       /*
+        * Find interface for this packet.
+        */
+       ifp = if_ifonnetof(ip->ip_dst);
+       if (ifp == 0) {
+               ifp = if_gatewayfor(ip->ip_dst);
+               if (ifp == 0)
+                       goto bad;
+       }
 
        /*
         * If small enough for interface, can just send directly.
         */
 
        /*
         * If small enough for interface, can just send directly.
         */
-       if (ip->ip_len <= MTU) {
-               ip_send(ip);
-               return;
+       if (ip->ip_len <= ifp->if_mtu) {
+               ip->ip_len = htons((u_short)ip->ip_len);
+               ip->ip_off = htons((u_short)ip->ip_off);
+               ip->ip_sum = 0;
+               ip->ip_sum = in_cksum(m, hlen);
+               return ((*ifp->if_output)(ifp, m, PF_INET));
        }
 
        /*
        }
 
        /*
@@ -41,7 +55,7 @@ COUNT(IP_OUTPUT);
         */
        if (ip->ip_off & IP_DF)
                goto bad;
         */
        if (ip->ip_off & IP_DF)
                goto bad;
-       len = (MTU-hlen) &~ 7;
+       len = (ifp->if_mtu - hlen) &~ 7;
        if (len < 8)
                goto bad;
 
        if (len < 8)
                goto bad;
 
@@ -73,16 +87,23 @@ COUNT(IP_OUTPUT);
                        mhip->ip_len = len;
                        mhip->ip_off |= IP_MF;
                }
                        mhip->ip_len = len;
                        mhip->ip_off |= IP_MF;
                }
-               mhip->ip_len += sizeof (struct ip);
+               mhip->ip_len = htons((u_short)(mhip->ip_len + sizeof (struct ip)));
                mh->m_next = m_copy(m, off, len);
                if (mh->m_next == 0) {
                        (void) m_free(mh);
                        goto bad;
                }
                mh->m_next = m_copy(m, off, len);
                if (mh->m_next == 0) {
                        (void) m_free(mh);
                        goto bad;
                }
-               ip_send(mhip);
+               ip->ip_off = htons((u_short)ip->ip_off);
+               ip->ip_sum = 0;
+               ip->ip_sum = in_cksum(m, hlen);
+               if ((*ifp->if_output)(ifp, mh, PF_INET) == 0)
+                       goto bad;
        }
        }
+       m_freem(m);
+       return (1);
 bad:
        m_freem(m);
 bad:
        m_freem(m);
+       return (0);
 }
 
 /*
 }
 
 /*
@@ -120,49 +141,3 @@ COUNT(IP_OPTCOPY);
                *dp++ = IPOPT_EOL;
        return (optlen);
 }
                *dp++ = IPOPT_EOL;
        return (optlen);
 }
-
-/* REST OF CODE HERE IS GARBAGE */
-
-ip_send(ip)
-       register struct ip *ip;
-{
-       register struct mbuf *m;
-       register struct imp *l;
-       int hlen = ip->ip_hl << 2;
-       int s;
-COUNT(IP_SEND);
-
-       m = dtom(ip);
-       l = (struct imp *)(mtod(m, caddr_t) - L1822);
-       l->i_shost = ip->ip_src.s_host;
-       l->i_dhost = ip->ip_dst.s_host;
-       l->i_type = IPTYPE;
-       ip->ip_sum = 0;
-       ip->ip_len = htons((u_short)ip->ip_len);
-       ip->ip_id = htons(ip->ip_id);
-       ip->ip_off = htons((u_short)ip->ip_off);
-       ip->ip_sum = inet_cksum(m, hlen);
-       m->m_off -= L1822;
-       m->m_len += L1822;
-       m->m_act = NULL;
-#ifndef IMPLOOP
-       s = splimp();
-       if (imp_stat.outq_head != NULL)
-               imp_stat.outq_tail->m_act = m;
-       else
-               imp_stat.outq_head = m;
-       imp_stat.outq_tail = m;
-       splx(s);
-       if (!imp_stat.outactive)
-               enstart(0);
-#else
-       if (imp_stat.inq_head != NULL)
-               imp_stat.inq_tail->m_act = m;
-       else
-               imp_stat.inq_head = m;
-       imp_stat.inq_tail = m;
-       setsoftnet();
-#endif IMPLOOP
-}
-
-/* END GARBAGE */
index 9b6e6b5..2d419e1 100644 (file)
@@ -1,4 +1,4 @@
-/*     ip_var.h        4.3     81/11/18        */
+/*     ip_var.h        4.4     81/11/26        */
 
 /*
  * Overlay for ip header used by other protocols (tcp, udp).
 
 /*
  * Overlay for ip header used by other protocols (tcp, udp).
index ae22aea..25d2f96 100644 (file)
@@ -1,5 +1,6 @@
-/* tcp.h 1.18 81/11/24 */
+/* tcp.h 1.19 81/11/26 */
 
 
+typedef        u_long  tcp_seq;
 /*
  * TCP header.
  * Per RFC 793, September, 1981.
 /*
  * TCP header.
  * Per RFC 793, September, 1981.
@@ -7,8 +8,8 @@
 struct tcphdr {
        u_short th_sport;               /* source port */
        u_short th_dport;               /* destination port */
 struct tcphdr {
        u_short th_sport;               /* source port */
        u_short th_dport;               /* destination port */
-       seq_t   th_seq;                 /* sequence number */
-       seq_t   th_ackno;               /* acknowledgement number */
+       tcp_seq th_seq;                 /* sequence number */
+       tcp_seq th_ack;                 /* acknowledgement number */
        u_char
                th_x2:4,                /* (unused) */
                th_off:4;               /* data offset */
        u_char
                th_x2:4,                /* (unused) */
                th_off:4;               /* data offset */
index dbf5f90..b298078 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_fsm.h       4.8     81/11/25        */
+/*     tcp_fsm.h       4.9     81/11/26        */
 
 /*
  * TCP FSM state definitions.
 
 /*
  * TCP FSM state definitions.
 #define        TCPS_CLOSED             0       /* closed */
 #define        TCPS_LISTEN             1       /* listening for connection */
 #define        TCPS_SYN_SENT           2       /* active, have sent syn */
 #define        TCPS_CLOSED             0       /* closed */
 #define        TCPS_LISTEN             1       /* listening for connection */
 #define        TCPS_SYN_SENT           2       /* active, have sent syn */
-#define        TCPS_SYN_RCVD           3       /* have send and received syn */
+#define        TCPS_SYN_RECEIVED       3       /* have send and received syn */
 /* states < TCPS_ESTABLISHED are those where connections not established */
 #define        TCPS_ESTABLISHED        4       /* established */
 /* states < TCPS_ESTABLISHED are those where connections not established */
 #define        TCPS_ESTABLISHED        4       /* established */
-#define        TCPS_CLOSE_WAIT         8       /* rcvd fin, waiting for close */
+#define        TCPS_CLOSE_WAIT         5       /* rcvd fin, waiting for close */
 /* states > TCPS_CLOSE_WAIT are those where user has closed */
 /* states > TCPS_CLOSE_WAIT are those where user has closed */
-#define        TCPS_FIN_WAIT_1         5       /* have closed, sent fin */
-#define        TCPS_FIN_WAIT_2         6       /* have closed, fin is acked */
-#define        TCPS_TIME_WAIT          7       /* in 2*msl quiet wait after close */
-#define        TCPS_CLOSING            9       /* closed xchd FIN; await FIN ACK */
-#define        TCPS_LAST_ACK           10      /* had fin and close; await FIN ACK */
+#define        TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
+#define        TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
+#define        TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
+/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
+#define        TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
+#define        TCPS_TIME_WAIT          10      /* in 2*msl quiet wait after close */
 
 
-#define        TCPS_HAVERCVDSYN(s)     ((s) >= TCPS_SYN_RCVD)
+#define        TCPS_HAVERCVDSYN(s)     ((s) >= TCPS_SYN_RECEIVED)
 #define        TCPS_HAVERCVDFIN(s)     ((s) >= TCPS_TIME_WAIT)
 #define        TCPS_HAVERCVDFIN(s)     ((s) >= TCPS_TIME_WAIT)
+#define        TCPS_OURFINNOTACKED(s)  ((s) > TCPS_CLOSE_WAIT && (s) < TCPS_FIN_WAIT_2)
+
+#ifdef TCPOUTFLAGS
+/*
+ * Flags used when sending segments in tcp_output.
+ * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally
+ * determined by state.
+ */
+u_char tcp_outflags[TCP_NSTATES] = {
+    TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
+    TH_ACK, TH_ACK,
+    TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK,
+};
+#endif
 
 #ifdef KPROF
 int    tcp_acounts[TCP_NSTATES][PRU_NREQ];
 #endif
 
 
 #ifdef KPROF
 int    tcp_acounts[TCP_NSTATES][PRU_NREQ];
 #endif
 
-#ifdef TCPSTATES
+#ifdef TCPSTATES
 char *tcpstates[] = {
        "CLOSED",       "LISTEN",       "SYN_SENT",     "SYN_RCVD",
 char *tcpstates[] = {
        "CLOSED",       "LISTEN",       "SYN_SENT",     "SYN_RCVD",
-       "ESTABLISHED",  "FIN_WAIT1",    "FIN_WAIT2",    "TIME_WAIT",
-       "CLOSE_WAIT",   "CLOSING",      "LAST_ACK",
+       "ESTABLISHED",  "CLOSE_WAIT",   "FIN_WAIT_1",   "FIN_WAIT_2",
+       "TIME_WAIT",    "CLOSING",      "LAST_ACK",
 };
 #endif
 };
 #endif
index 91acf5e..5c5b308 100644 (file)
@@ -1,19 +1,23 @@
-/*     tcp_input.c     1.31    81/11/25        */
+/*     tcp_input.c     1.32    81/11/26        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
+#include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
-#include "../net/inet.h"
-#include "../net/inet_pcb.h"
-#include "../net/inet_systm.h"
-#include "../net/imp.h"
+#include "../net/in.h"
+#include "../net/in_pcb.h"
+#include "../net/in_systm.h"
+#include "../net/if.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 #include "../net/tcp.h"
 #include "../net/tcp_fsm.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 #include "../net/tcp.h"
 #include "../net/tcp_fsm.h"
+#include "../net/tcp_seq.h"
+#include "../net/tcp_timer.h"
 #include "../net/tcp_var.h"
 #include "../net/tcp_var.h"
+#include "../net/tcpip.h"
 #include "/usr/include/errno.h"
 
 int    tcpcksum = 1;
 #include "/usr/include/errno.h"
 
 int    tcpcksum = 1;
@@ -34,22 +38,24 @@ tcp_input(m0)
        register struct tcpcb *tp;
        register int tiflags;
        struct socket *so;
        register struct tcpcb *tp;
        register int tiflags;
        struct socket *so;
-       seq_t segend;
        int acceptable;
        int acceptable;
+       tcp_seq todrop, acked;
 
 COUNT(TCP_INPUT);
        /*
         * Get ip and tcp header together in first mbuf.
         */
        m = m0;
 
 COUNT(TCP_INPUT);
        /*
         * Get ip and tcp header together in first mbuf.
         */
        m = m0;
-       if (m->m_len < sizeof (struct tcpiphdr) &&
-           m_pullup(m, sizeof (struct tcpiphdr)) == 0) {
-               tcpstat.tcps_hdrops++;
-               goto bad;
-       }
        ti = mtod(m, struct tcpiphdr *);
        if (ti->ti_len > sizeof (struct ip))
                ip_stripoptions((struct ip *)ti, (char *)0);
        ti = mtod(m, struct tcpiphdr *);
        if (ti->ti_len > sizeof (struct ip))
                ip_stripoptions((struct ip *)ti, (char *)0);
+       if (m->m_len < sizeof (struct tcpiphdr)) {
+               if (m_pullup(m, sizeof (struct tcpiphdr)) == 0) {
+                       tcpstat.tcps_hdrops++;
+                       goto drop;
+               }
+               ti = mtod(m, struct tcpiphdr *);
+       }
 
        /*
         * Checksum extended tcp header and data.
 
        /*
         * Checksum extended tcp header and data.
@@ -60,10 +66,10 @@ COUNT(TCP_INPUT);
                ti->ti_next = ti->ti_prev = 0;
                ti->ti_x1 = 0;
                ti->ti_len = htons((u_short)tlen);
                ti->ti_next = ti->ti_prev = 0;
                ti->ti_x1 = 0;
                ti->ti_len = htons((u_short)tlen);
-               if ((ti->ti_sum = inet_cksum(m, len)) != 0xffff) {
+               if ((ti->ti_sum = in_cksum(m, len)) != 0xffff) {
                        tcpstat.tcps_badsum++;
                        printf("tcp cksum %x\n", ti->ti_sum);
                        tcpstat.tcps_badsum++;
                        printf("tcp cksum %x\n", ti->ti_sum);
-                       goto bad;
+                       goto drop;
                }
        }
 
                }
        }
 
@@ -74,12 +80,23 @@ COUNT(TCP_INPUT);
        off = ti->ti_off << 2;
        if (off < sizeof (struct tcphdr) || off > ti->ti_len) {
                tcpstat.tcps_badoff++;
        off = ti->ti_off << 2;
        if (off < sizeof (struct tcphdr) || off > ti->ti_len) {
                tcpstat.tcps_badoff++;
-               goto bad;
+               goto drop;
        }
        ti->ti_len = tlen - off;
        }
        ti->ti_len = tlen - off;
-       /* PROCESS OPTIONS */
+#if 0
+       if (off > sizeof (struct tcphdr) >> 2)
+               tcp_options(ti);
+#endif
        tiflags = ti->ti_flags;
 
        tiflags = ti->ti_flags;
 
+       /*
+        * Convert tcp protocol specific fields to host format.
+        */
+       ti->ti_seq = ntohl(ti->ti_seq);
+       ti->ti_ack = ntohl(ti->ti_ack);
+       ti->ti_win = ntohs(ti->ti_win);
+       ti->ti_urp = ntohs(ti->ti_urp);
+
        /*
         * Locate pcb for segment.
         */
        /*
         * Locate pcb for segment.
         */
@@ -91,25 +108,16 @@ COUNT(TCP_INPUT);
         * all data in the incoming segment is discarded.  (p. 65).
         */
        if (inp == 0)
         * all data in the incoming segment is discarded.  (p. 65).
         */
        if (inp == 0)
-               goto sendreset;
+               goto dropwithreset;
        tp = intotcpcb(inp);
        if (tp == 0)
        tp = intotcpcb(inp);
        if (tp == 0)
-               goto sendreset;
+               goto dropwithreset;
 
        /*
 
        /*
-        * Convert tcp protocol specific fields to host format.
+        * Calculate amount of space in receive window,
+        * and then do TCP input processing.
         */
         */
-       ti->ti_seq = ntohl(ti->ti_seq);
-       ti->ti_ackno = ntohl((n_long)ti->ti_ackno);
-       ti->ti_win = ntohs(ti->ti_win);
-       ti->ti_urp = ntohs(ti->ti_urp);
-
-       /*
-        * Discard ip header, and do tcp input processing.
-        */
-       off += sizeof (struct ip);
-       m->m_off += off;
-       m->m_len -= off;
+       tp->rcv_wnd = sbspace(&so->so_rcv);
 
        switch (tp->t_state) {
 
 
        switch (tp->t_state) {
 
@@ -117,9 +125,9 @@ COUNT(TCP_INPUT);
         * If the state is LISTEN then ignore segment if it contains an RST.
         * If the segment contains an ACK then it is bad and send a RST.
         * If it does not contain a SYN then it is not interesting; drop it.
         * If the state is LISTEN then ignore segment if it contains an RST.
         * If the segment contains an ACK then it is bad and send a RST.
         * If it does not contain a SYN then it is not interesting; drop it.
-        * Otherwise initialize tp->rcv_next, and tp->irs, select an initial
+        * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
         * tp->iss, and send a segment:
         * tp->iss, and send a segment:
-        *     <SEQ=ISS><ACK=RCV>NXT><CTL=SYN,ACK>
+        *     <SEQ=ISS><ACK=RCV_NXT><CTL=SYN,ACK>
         * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
         * Fill in remote peer address fields if not previously specified.
         * Enter SYN_RECEIVED state, and process any other fields of this
         * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
         * Fill in remote peer address fields if not previously specified.
         * Enter SYN_RECEIVED state, and process any other fields of this
@@ -129,20 +137,19 @@ COUNT(TCP_INPUT);
                if (tiflags & TH_RST)
                        goto drop;
                if (tiflags & TH_ACK)
                if (tiflags & TH_RST)
                        goto drop;
                if (tiflags & TH_ACK)
-                       goto sendrst;
+                       goto dropwithreset;
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
-               tp->rcv_nxt = ti->ti_seq + 1;
+               tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2;
                tp->irs = ti->ti_seq;
                tp->irs = ti->ti_seq;
-               tp->iss = tcp_selectiss();
-               tcp_reflect(ti, tp->iss, tp->rcv_next, TH_SYN|TH_ACK);
+               tcp_sendseqinit(tp);
+               tcp_rcvseqinit(tp);
                tp->t_state = TCPS_SYN_RECEIVED;
                tp->t_state = TCPS_SYN_RECEIVED;
-               tiflags &= ~TH_SYN; tiflags |= TH_RST;
                if (inp->inp_faddr.s_addr == 0) {
                        inp->inp_faddr = ti->ti_src;
                        inp->inp_fport = ti->ti_sport;
                }
                if (inp->inp_faddr.s_addr == 0) {
                        inp->inp_faddr = ti->ti_src;
                        inp->inp_fport = ti->ti_sport;
                }
-               break;
+               goto trimthenstep6;
 
        /*
         * If the state is SYN_SENT:
 
        /*
         * If the state is SYN_SENT:
@@ -159,28 +166,45 @@ COUNT(TCP_INPUT);
        case TCPS_SYN_SENT:
                if ((tiflags & TH_ACK) &&
                    (SEQ_LEQ(ti->ti_ack, tp->iss) ||
        case TCPS_SYN_SENT:
                if ((tiflags & TH_ACK) &&
                    (SEQ_LEQ(ti->ti_ack, tp->iss) ||
-                    SEQ_GT(ti->ti_ack, tp->snd.nxt))) {
-                       tcp_reflect(ti, ti->ti_ack, 0, TH_RST);
-                       goto drop;
-               }
+                    SEQ_GT(ti->ti_ack, tp->snd_nxt)))
+                       goto dropwithreset;
                if (tiflags & TH_RST) {
                        if (tiflags & TH_ACK)
                if (tiflags & TH_RST) {
                        if (tiflags & TH_ACK)
-                               tcp_drop(tp, ENETRESET);
+                               tcp_drop(tp, ECONNRESET);
                        goto drop;
                }
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
                        goto drop;
                }
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
-               tp->rcv_nxt = ti->ti_seq + 1;
+               tp->iss = ti->ti_ack;
+               tcp_sendseqinit(tp);
                tp->irs = ti->ti_seq;
                tp->irs = ti->ti_seq;
-               tp->snd_una = ti->ti_seq;
-               if (SEQ_GT(tp->snd_una, tp->iss)) {
+               tcp_rcvseqinit(tp);
+               tp->t_flags |= TF_ACKNOW;
+               if (SEQ_GT(tp->snd_una, tp->iss))
                        tp->t_state = TCPS_ESTABLISHED;
                        tp->t_state = TCPS_ESTABLISHED;
-                       tp->t_flags |= TF_OWEACK;
-                       goto step6;
+               else
+                       tp->t_state = TCPS_SYN_RECEIVED;
+               goto trimthenstep6;
+
+trimthenstep6:
+               /*
+                * If had syn, advance ti->ti_seq to correspond
+                * to first data byte.
+                */
+               if (tiflags & TH_SYN)
+                       ti->ti_seq++;
+
+               /*
+                * If data, trim to stay within window,
+                * dropping FIN if necessary.
+                */
+               if (ti->ti_len > tp->rcv_wnd) {
+                       todrop = ti->ti_len - tp->rcv_wnd;
+                       m_adj(m, -todrop);
+                       ti->ti_len = tp->rcv_wnd;
+                       ti->ti_flags &= ~TH_FIN;
                }
                }
-               tp->t_state = TCPS_SYN_RECEIVED;
-               tcp_reflect(ti, tp->iss, tp->rcv_nxt, TH_SYN|TH_ACK);
-               break;
+               goto step6;
        }
 
        /*
        }
 
        /*
@@ -196,9 +220,9 @@ COUNT(TCP_INPUT);
                 */
                if (tp->rcv_nxt != ti->ti_seq)
                        goto dropafterack;
                 */
                if (tp->rcv_nxt != ti->ti_seq)
                        goto dropafterack;
-               if (tp->ti_len > 0) {
-                       tp->ti_len = 0;
-                       tp->ti_flags &= ~(TH_EOL|TH_FIN);
+               if (ti->ti_len > 0) {
+                       ti->ti_len = 0;
+                       ti->ti_flags &= ~(TH_PUSH|TH_FIN);
                }
        } else {
                /*
                }
        } else {
                /*
@@ -206,26 +230,42 @@ COUNT(TCP_INPUT);
                 * data (and SYN); if nothing left, just ack.
                 */
                if (SEQ_GT(tp->rcv_nxt, ti->ti_seq)) {
                 * data (and SYN); if nothing left, just ack.
                 */
                if (SEQ_GT(tp->rcv_nxt, ti->ti_seq)) {
-                       tcpseq_t todrop = tp->rcv_nxt - ti->ti_seq;
+                       todrop = tp->rcv_nxt - ti->ti_seq;
+                       if (tiflags & TH_SYN) {
+                               ti->ti_seq++;
+                               if (ti->ti_urp > 1) 
+                                       ti->ti_urp--;
+                               else
+                                       tiflags &= ~TH_URG;
+                               todrop--;
+                       }
                        if (todrop > ti->ti_len)
                                goto dropafterack;
                        m_adj(m, todrop);
                        ti->ti_seq += todrop;
                        ti->ti_len -= todrop;
                        if (todrop > ti->ti_len)
                                goto dropafterack;
                        m_adj(m, todrop);
                        ti->ti_seq += todrop;
                        ti->ti_len -= todrop;
-                       ti->ti_flags &= ~TH_SYN;
+                       if (ti->ti_urp > todrop)
+                               ti->ti_urp -= todrop;
+                       else {
+                               tiflags &= ~TH_URG;
+                               /* ti->ti_flags &= ~TH_URG; */
+                               /* ti->ti_urp = 0; */
+                       }
+                       /* tiflags &= ~TH_SYN; */
+                       /* ti->ti_flags &= ~TH_SYN; */
                }
                /*
                 * If segment ends after window, drop trailing data
                }
                /*
                 * If segment ends after window, drop trailing data
-                * (and EOL and FIN); if there would be nothing left, just ack.
+                * (and PUSH and FIN); if nothing left, just ACK.
                 */
                if (SEQ_GT(ti->ti_seq+ti->ti_len, tp->rcv_nxt+tp->rcv_wnd)) {
                 */
                if (SEQ_GT(ti->ti_seq+ti->ti_len, tp->rcv_nxt+tp->rcv_wnd)) {
-                       tcpseq_t todrop =
+                       todrop =
                             ti->ti_seq+ti->ti_len - (tp->rcv_nxt+tp->rcv_wnd);
                        if (todrop > ti->ti_len)
                                goto dropafterack;
                        m_adj(m, -todrop);
                        ti->ti_len -= todrop;
                             ti->ti_seq+ti->ti_len - (tp->rcv_nxt+tp->rcv_wnd);
                        if (todrop > ti->ti_len)
                                goto dropafterack;
                        m_adj(m, -todrop);
                        ti->ti_len -= todrop;
-                       ti->ti_flags &= ~(TH_EOL|TH_FIN);
+                       ti->ti_flags &= ~(TH_PUSH|TH_FIN);
                }
        }
 
                }
        }
 
@@ -243,11 +283,11 @@ COUNT(TCP_INPUT);
                
        case TCPS_SYN_RECEIVED:
                if (inp->inp_socket->so_options & SO_ACCEPTCONN) {
                
        case TCPS_SYN_RECEIVED:
                if (inp->inp_socket->so_options & SO_ACCEPTCONN) {
-                       tp->t_state = LISTEN;
-                       inp->inp_fhost->s_addr = 0;
+                       tp->t_state = TCPS_LISTEN;
+                       inp->inp_faddr.s_addr = 0;
                        goto drop;
                }
                        goto drop;
                }
-               tcp_drop(tp, EREFUSED);
+               tcp_drop(tp, ECONNREFUSED);
                goto drop;
 
        case TCPS_ESTABLISHED:
                goto drop;
 
        case TCPS_ESTABLISHED:
@@ -269,14 +309,14 @@ COUNT(TCP_INPUT);
         * error and we send an RST and drop the connection.
         */
        if (tiflags & TH_SYN) {
         * error and we send an RST and drop the connection.
         */
        if (tiflags & TH_SYN) {
-               tcp_drop(tp, ECONNRESET);
-               goto sendreset;
+               tcp_drop(tp, ECONNABORTED);
+               goto dropwithreset;
        }
 
        /*
         * If the ACK bit is off we drop the segment and return.
         */
        }
 
        /*
         * If the ACK bit is off we drop the segment and return.
         */
-       if ((tiflags & TI_ACK) == 0)
+       if ((tiflags & TH_ACK) == 0)
                goto drop;
        
        /*
                goto drop;
        
        /*
@@ -290,12 +330,12 @@ COUNT(TCP_INPUT);
         * send an RST.
         */
        case TCPS_SYN_RECEIVED:
         * send an RST.
         */
        case TCPS_SYN_RECEIVED:
-               if (SEQ_LEQ(tp->snd_una, ti->ti_ack) &&
-                   SEQ_LEQ(ti->ti_ack, tp->snd_nxt))
-                       tp->t_state = TCPS_ESTABLISHED;
-               else
-                       goto sendreset;
-               /* fall into next case, below... */
+               if (SEQ_GT(tp->snd_una, ti->ti_ack) ||
+                   SEQ_GT(ti->ti_ack, tp->snd_nxt))
+                       goto dropwithreset;
+               soisconnected(so);
+               tp->t_state = TCPS_ESTABLISHED;
+               /* fall into ... */
 
        /*
         * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
 
        /*
         * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
@@ -310,14 +350,28 @@ COUNT(TCP_INPUT);
        case TCPS_FIN_WAIT_2:
        case TCPS_CLOSE_WAIT:
        case TCPS_CLOSING:
        case TCPS_FIN_WAIT_2:
        case TCPS_CLOSE_WAIT:
        case TCPS_CLOSING:
+#define        ourfinisacked   (acked > 0)
+
                if (SEQ_LT(ti->ti_ack, tp->snd_una))
                        break;
                if (SEQ_GT(ti->ti_ack, tp->snd_nxt))
                        goto dropafterack;
                if (SEQ_LT(ti->ti_ack, tp->snd_una))
                        break;
                if (SEQ_GT(ti->ti_ack, tp->snd_nxt))
                        goto dropafterack;
-               sbdrop(&so->so_snd, ti->ti_ack - tp->snd_una);
+               acked = ti->ti_ack - tp->snd_una;
+               if (acked > so->so_snd.sb_cc) {
+                       sbflush(&so->so_snd);
+                       acked -= so->so_snd.sb_cc;
+               } else {
+                       sbdrop(&so->so_snd, acked);
+                       acked = 0;
+               }
+               /* if acked our FIN is acked */
                tp->snd_una = ti->ti_ack;
                tp->snd_una = ti->ti_ack;
+
+               /*
+                * Update window information.
+                */
                if (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
                if (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
-                   tp->snd_wl1==ti-ti_seq && SEQ_LEQ(tp->snd_wl2,ti->ti_seq)) {
+                   tp->snd_wl1==ti->ti_seq && SEQ_LEQ(tp->snd_wl2,ti->ti_seq)) {
                        tp->snd_wnd = ti->ti_win;
                        tp->snd_wl1 = ti->ti_seq;
                        tp->snd_wl2 = ti->ti_ack;
                        tp->snd_wnd = ti->ti_win;
                        tp->snd_wl1 = ti->ti_seq;
                        tp->snd_wl2 = ti->ti_ack;
@@ -328,21 +382,11 @@ COUNT(TCP_INPUT);
                /*
                 * In FIN_WAIT_1 STATE in addition to the processing
                 * for the ESTABLISHED state if our FIN is now acknowledged
                /*
                 * In FIN_WAIT_1 STATE in addition to the processing
                 * for the ESTABLISHED state if our FIN is now acknowledged
-                * then enter FIN_WAIT_2 and continue processing in that state.
+                * then enter FIN_WAIT_2.
                 */
                case TCPS_FIN_WAIT_1:
                 */
                case TCPS_FIN_WAIT_1:
-                       if (tcp_finisacked(tp) == 0)
-                               break;
-                       tp->t_state = TCPS_FIN_WAIT_2;
-                       /* fall into ... */
-
-               /*
-                * In FIN_WAIT_2 STATE in addition to the processing for
-                * the ESTABLISHED state allow the user to close when
-                * the data has drained.
-                */
-               case TCPS_FIN_WAIT_2:
-                       tcp_usrcanclose(tp);
+                       if (ourfinisacked)
+                               tp->t_state = TCPS_FIN_WAIT_2;
                        break;
 
                /*
                        break;
 
                /*
@@ -352,17 +396,18 @@ COUNT(TCP_INPUT);
                 * the segment.
                 */
                case TCPS_CLOSING:
                 * the segment.
                 */
                case TCPS_CLOSING:
-                       if (tcp_finisacked(tp))
+                       if (ourfinisacked)
                                tp->t_state = TCPS_TIME_WAIT;
                                tp->t_state = TCPS_TIME_WAIT;
-                       break;
+                       goto drop;
 
                /*
 
                /*
-                * In LAST_ACK state if our FIN is now acknowledged
-                * then enter the TIME_WAIT state, otherwise ignore the
-                * segment.
+                * The only thing that can arrive in  LAST_ACK state
+                * is an acknowledgment of our FIN.  If our FIN is now
+                * acknowledged, delete the TCB, enter the closed state
+                * and return.
                 */
                case TCPS_LAST_ACK:
                 */
                case TCPS_LAST_ACK:
-                       if (tcp_finisacked(tp))
+                       if (ourfinisacked)
                                tcp_close(tp);
                        goto drop;
 
                                tcp_close(tp);
                        goto drop;
 
@@ -372,9 +417,11 @@ COUNT(TCP_INPUT);
                 * it and restart the finack timer.
                 */
                case TCPS_TIME_WAIT:
                 * it and restart the finack timer.
                 */
                case TCPS_TIME_WAIT:
-                       tp->t_finack = 2 * TCP_MSL;
+                       tp->t_timer[TCPT_2MSL] = 2 * TCPSC_MSL;
                        goto dropafterack;
                }
                        goto dropafterack;
                }
+#undef ourfinisacked
+       }
 
 step6:
        /*
 
 step6:
        /*
@@ -385,12 +432,13 @@ step6:
         * a FIN has been received from the remote side.  In these states
         * we ignore the URG.
         */
         * a FIN has been received from the remote side.  In these states
         * we ignore the URG.
         */
-       if ((tiflags & TH_URG) == 0 && (TCPS_RCVDFIN(tp->t_state) == 0) {
-               if (SEQ_GT(ti->ti_urp, tp->rcv_up) {
+       if ((tiflags & TH_URG) == 0 && TCPS_HAVERCVDFIN(tp->t_state) == 0)
+               if (SEQ_GT(ti->ti_urp, tp->rcv_up)) {
                        tp->rcv_up = ti->ti_urp;
                        tp->rcv_up = ti->ti_urp;
+#if 0
                        soisurgendata(so);              /* XXX */
                        soisurgendata(so);              /* XXX */
+#endif
                }
                }
-       }
 
        /*
         * Process the segment text, merging it into the TCP sequencing queue,
 
        /*
         * Process the segment text, merging it into the TCP sequencing queue,
@@ -401,10 +449,14 @@ step6:
         * connection then we just ignore the text.
         */
        if (ti->ti_len) {
         * connection then we just ignore the text.
         */
        if (ti->ti_len) {
-               if (TCPS_RCVDFIN(tp->t_state))
+               if (TCPS_HAVERCVDFIN(tp->t_state))
                        goto drop;
                        goto drop;
+               off += sizeof (struct ip);              /* drop IP header */
+               m->m_off += off;
+               m->m_len -= off;
                tiflags = tcp_reass(tp, ti);
                tiflags = tcp_reass(tp, ti);
-       else
+               tp->t_flags |= TF_ACKNOW;               /* XXX TF_DELACK */
+       } else
                m_freem(m);
 
        /*
                m_freem(m);
 
        /*
@@ -412,7 +464,7 @@ step6:
         * therefore can't validate drop the segment.  Otherwise ACK
         * the FIN and let the user know that the connection is closing.
         */
         * therefore can't validate drop the segment.  Otherwise ACK
         * the FIN and let the user know that the connection is closing.
         */
-       if (tiflags & TH_FIN) {
+       if ((tiflags & TH_FIN)) {
                if (TCPS_HAVERCVDSYN(tp->t_state) == 0)
                        goto drop;
                socantrcvmore(so);
                if (TCPS_HAVERCVDSYN(tp->t_state) == 0)
                        goto drop;
                socantrcvmore(so);
@@ -430,20 +482,12 @@ step6:
                        break;
 
                /*
                        break;
 
                /*
-                * In FIN_WAIT_1 STATE if our FIN has been acked then
-                * enter TIME_WAIT state, starting the associated timer
-                * and turning off all other standard timers.
-                * If FIN has not been acked enter the CLOSING state.
+                * If still in FIN_WAIT_1 STATE FIN has not been acked so
+                * enter the CLOSING state.
                 */
                case TCPS_FIN_WAIT_1:
                 */
                case TCPS_FIN_WAIT_1:
-                       if (tcp_finisacked(tp)) {
-                               tp->t_state = TCPS_TIME_WAIT;
-                               tcp_canceltimers(tp, 0);
-                               tp->t_timer[TCPT_FINACK] = TCPSC_2MSL;
-                       } else
-                               tp->t_state = TCPS_CLOSING;
+                       tp->t_state = TCPS_CLOSING;
                        break;
                        break;
-               }
 
                /*
                 * In FIN_WAIT_2 state enter the TIME_WAIT state,
 
                /*
                 * In FIN_WAIT_2 state enter the TIME_WAIT state,
@@ -451,25 +495,57 @@ step6:
                 * standard timers.
                 */
                case TCPS_FIN_WAIT_2:
                 * standard timers.
                 */
                case TCPS_FIN_WAIT_2:
-                       tp->t_state = TCPS_FIN_WAIT_2;
+                       tp->t_state = TCPS_TIME_WAIT;;
                        tcp_canceltimers(tp);
                        tcp_canceltimers(tp);
-                       tp->t_timer[TCPT_FINACK] = TCPSC_2MSL;
+                       tp->t_timer[TCPT_2MSL] = TCPSC_2MSL;
                        break;
 
                /*
                 * In TIME_WAIT state restart the 2 MSL time_wait timer.
                 */
                case TCPS_TIME_WAIT:
                        break;
 
                /*
                 * In TIME_WAIT state restart the 2 MSL time_wait timer.
                 */
                case TCPS_TIME_WAIT:
-                       tp->t_timer[TCPT_FINACK] = TCPSC_2MSL;
+                       tp->t_timer[TCPT_2MSL] = TCPSC_2MSL;
                        break;
                        break;
+               }
        }
        }
+
+       /*
+        * Return any desired output.
+        */
+       tcp_output(tp);
        return;
        return;
+
 dropafterack:
 dropafterack:
-       if ((tiflags & TH_RST) == 0)
-               tcp_reflect(ti, tp->rcv_nxt, tp->snd_nxt, TH_ACK);
+       /*
+        * Generate an ACK, then drop incoming segment.
+        * Make ACK reflect our state.
+        */
+       if (tiflags & TH_RST)
+               goto drop;
+       tcp_respond(ti, tp->rcv_nxt, tp->snd_nxt, TH_ACK);
+       goto drop;
+
+dropwithreset:
+       /*
+        * Generate a RST, then drop incoming segment.
+        * Make ACK acceptable to originator of segment.
+        */
+       if (tiflags & TH_RST)
+               goto drop;
+       if (tiflags & TH_ACK)
+               tcp_respond(ti, 0, ti->ti_ack, TH_RST);
+       else {
+               if (tiflags & TH_SYN)
+                       ti->ti_len++;
+               tcp_respond(ti, ti->ti_seq+ti->ti_len, 0, TH_RST|TH_ACK);
+       }
+       goto drop;
+
 drop:
 drop:
+       /*
+        * Drop space held by incoming segment and return.
+        */
        m_freem(m);
        m_freem(m);
-       return;
 }
 
 /*
 }
 
 /*
@@ -483,8 +559,10 @@ tcp_reass(tp, ti, endp)
        int *endp;
 {
        register struct tcpiphdr *q;
        int *endp;
 {
        register struct tcpiphdr *q;
+       struct socket *so = tp->t_inpcb->inp_socket;
        int flags = 0;          /* no FIN */
        int overage;
        int flags = 0;          /* no FIN */
        int overage;
+COUNT(TCP_REASS);
 
        /*
         * If no data in this segment may want
 
        /*
         * If no data in this segment may want
@@ -545,20 +623,20 @@ tcp_reass(tp, ti, endp)
         * Stick new segment in its place.
         */
        insque(ti, q->ti_prev);
         * Stick new segment in its place.
         */
        insque(ti, q->ti_prev);
-       tp->seqcnt += ti->ti_len;
+       tp->t_seqcnt += ti->ti_len;
 
        /*
         * Calculate available space and discard segments for
         * which there is too much.
         */
        overage = 
 
        /*
         * Calculate available space and discard segments for
         * which there is too much.
         */
        overage = 
-           (so->so_rcv.sb_cc + tp->seqcnt) - so->so_rcv.sb_hiwat;
+           (so->so_rcv.sb_cc + tp->t_seqcnt) - so->so_rcv.sb_hiwat;
        if (overage > 0) {
                q = tp->seg_prev;
                for (;;) {
                        register int i = MIN(q->ti_len, overage);
                        overage -= i;
        if (overage > 0) {
                q = tp->seg_prev;
                for (;;) {
                        register int i = MIN(q->ti_len, overage);
                        overage -= i;
-                       tp->seqcnt -= i;
+                       tp->t_seqcnt -= i;
                        q->ti_len -= i;
                        m_adj(dtom(q), -i);
                        if (q->ti_len)
                        q->ti_len -= i;
                        m_adj(dtom(q), -i);
                        if (q->ti_len)
@@ -585,14 +663,14 @@ present:
        /*
         * Present data to user.
         */
        /*
         * Present data to user.
         */
-       if (tp->t_state < ESTAB)
+       if (tp->t_state < TCPS_ESTABLISHED)
                return (flags);
        ti = tp->seg_next;
        while (ti != (struct tcpiphdr *)tp && ti->ti_seq < tp->rcv_nxt) {
                remque(ti);
                sbappend(&so->so_rcv, dtom(ti));
                return (flags);
        ti = tp->seg_next;
        while (ti != (struct tcpiphdr *)tp && ti->ti_seq < tp->rcv_nxt) {
                remque(ti);
                sbappend(&so->so_rcv, dtom(ti));
-               tp->seqcnt -= ti->ti_len;
-               if (tp->seqcnt < 0)
+               tp->t_seqcnt -= ti->ti_len;
+               if (tp->t_seqcnt < 0)
                        panic("tcp_reass");
                ti = (struct tcpiphdr *)ti->ti_next;
        }
                        panic("tcp_reass");
                ti = (struct tcpiphdr *)ti->ti_next;
        }
index 3dfc1e4..188a16f 100644 (file)
@@ -1,4 +1,4 @@
-/* if_en.c 4.13 81/11/24 */
+/*     if_en.c 4.14    81/11/26        */
 
 #include "en.h"
 /*
 
 #include "en.h"
 /*
@@ -8,50 +8,43 @@
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
-#include "../net/inet.h"
-#include "../net/inet_pcb.h"
-#include "../net/if.h"
-#include "../net/inet_systm.h"
-#include "../net/imp.h"
-#include "../net/ip.h"
-#include "../net/ip_var.h"
-#include "../net/tcp.h"                        /* XXX */
-#include "../net/tcp_var.h"
-#include "../h/map.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
+#include "../h/protosw.h"
+#include "../h/socket.h"
 #include "../h/ubareg.h"
 #include "../h/ubavar.h"
 #include "../h/ubareg.h"
 #include "../h/ubavar.h"
-#include "../h/conf.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/proc.h"
 #include "../h/enreg.h"
 #include "../h/enreg.h"
-#include "../h/mtpr.h"
 #include "../h/cpu.h"
 #include "../h/cpu.h"
-#include "../h/cmap.h"
+#include "../h/mtpr.h"
+#include "../h/vmmac.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
+#include "../net/if.h"
+#include "../net/if_en.h"
+#include "../net/if_uba.h"
+#include "../net/ip.h"
+#include "../net/ip_var.h"
+
+#define        ENMTU   1024
 
 
-int    enrswaps;
-/* int enwswaps; */
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 u_short enstd[] = { 0 };
 struct uba_driver endriver =
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 u_short enstd[] = { 0 };
 struct uba_driver endriver =
-       { enprobe, 0, enattach, 0, enstd, "en", eninfo };
-
+       { enprobe, 0, enattach, 0, enstd, "es", eninfo };
 #define        ENUNIT(x)       minor(x)
 
 #define        ENUNIT(x)       minor(x)
 
-struct en_packet *xpkt, *rpkt;
-struct en_prefix {
-       struct en_header enp_h;
-       struct tcpiphdr enp_th;
-};
-struct uba_regs *enuba;
-struct pte *enrmr, *enxmr;
-int    enrbdp, enwbdp;
-int    enrproto, enwproto;
-struct pte enxmap[2];
-int    enxswapd;
+struct en_softc {
+       struct  ifnet *es_if;
+       struct  ifuba *es_ifuba;
+       short   es_delay;
+       short   es_mask;
+       u_char  es_addr;
+       u_char  es_lastx;
+       short   es_oactive;
+       short   es_olen;
+} en_softc[NEN];
 
 enprobe(reg)
        caddr_t reg;
 
 enprobe(reg)
        caddr_t reg;
@@ -59,19 +52,17 @@ enprobe(reg)
        register int br, cvec;
        register struct endevice *addr = (struct endevice *)reg;
 
        register int br, cvec;
        register struct endevice *addr = (struct endevice *)reg;
 
+COUNT(ENPROBE);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        enrint(0); enxint(0); encollide(0);
 #endif
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        enrint(0); enxint(0); encollide(0);
 #endif
-
        addr->en_istat = 0;
        addr->en_istat = 0;
-       addr->en_ostat = 0;
        addr->en_owc = -1;
        addr->en_oba = 0;
        addr->en_ostat = EN_IEN|EN_GO;
        DELAY(100000);
        addr->en_ostat = 0;
        addr->en_owc = -1;
        addr->en_oba = 0;
        addr->en_ostat = EN_IEN|EN_GO;
        DELAY(100000);
        addr->en_ostat = 0;
-       printf("ethernet address %d\n", ~addr->en_addr&0xff);
        return (1);
 }
 
        return (1);
 }
 
@@ -79,393 +70,253 @@ enprobe(reg)
 enattach(ui)
        struct uba_device *ui;
 {
 enattach(ui)
        struct uba_device *ui;
 {
-       extern struct ifnet ifen;
 
 
-       ifen.if_mtu = 1024;
-       ifen.if_net = 10;
-       ifen.if_addr.s_host = LOCALHST;
-       ifen.if_addr.s_net = LOCALNET;
-       ifen.if_addr.s_imp = LOCALIMP;
-       n_lhost = ifen.if_addr;
+COUNT(ENATTACH);
+       eninit(ui->ui_unit);
+       /* net initialization, based on ui->ui_flags?!? */
 }
 
 eninit(unit)
        int unit;
 }
 
 eninit(unit)
        int unit;
-{      
-       register struct endevice *addr;
+{
        register struct uba_device *ui;
        register struct uba_device *ui;
-       int uban, x;
-       static reenter;
+       register struct endevice *addr;
+       register struct en_softc *es;
 
 
+COUNT(ENINIT);
        if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0) {
        if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0) {
-               printf("en%d: not alive\n", unit);
+               printf("es%d: not alive\n", unit);
                return;
        }
                return;
        }
-       x = splimp();
-       if (reenter == 0) {
-               int n, j, i, k; char *cp;
-               reenter = 1;
-               n = 10;
-               k = n<<1;
-               i = rmalloc(mbmap, n*2);
-               if (i == 0)
-                       panic("eninit");
-               j = i << 1;
-               cp = (char *)pftom(i);
-               if (memall(&Mbmap[j], k, proc, CSYS) == 0)
-                       panic("eninit");
-               vmaccess(&Mbmap[j], (caddr_t)cp, k);
-               rpkt = (struct en_packet *)
-                   (cp + 1024 - sizeof (struct en_prefix));
-               xpkt = (struct en_packet *)
-                   (cp + 5 * 1024 + 1024 - sizeof (struct en_prefix));
-               for (j = 0; j < n; j++)
-                       mprefcnt[i+j] = 1;
+       es = &en_softc[unit];
+       if (if_ubainit(es->es_ifuba, ui->ui_ubanum,
+           sizeof (struct en_header), btop(ENMTU)) == 0) { 
+               printf("es%d: can't initialize\n", unit);
+               return;
        }
        }
-       uban = ui->ui_ubanum;
        addr = (struct endevice *)ui->ui_addr;
        addr = (struct endevice *)ui->ui_addr;
-       addr->en_istat = 0;
-       addr->en_ostat = 0;
-       imp_stat.iaddr =
-           uballoc(uban, (caddr_t)rpkt, 1024+512, UBA_NEED16|UBA_NEEDBDP);
-       imp_stat.oaddr =
-           uballoc(uban, (caddr_t)xpkt, 1024+512, UBA_NEED16|UBA_NEEDBDP);
-       enuba = ui->ui_hd->uh_uba;
-       enrbdp = (imp_stat.iaddr >> 28) & 0xf;
-       enwbdp = (imp_stat.oaddr >> 28) & 0xf;
-       enrproto = UBAMR_MRV | (enrbdp << 21);
-       enwproto = UBAMR_MRV | (enwbdp << 21);
-       enrmr = &enuba->uba_map[((imp_stat.iaddr>>9)&0x1ff) + 1];
-       enxmr = &enuba->uba_map[((imp_stat.oaddr>>9)&0x1ff) + 1];
-       enxmap[0] = enxmr[0];
-       enxmap[1] = enxmr[1];
-       enxswapd = 0;
-       printf("enrbdp %x enrproto %x enrmr %x imp_stat.iaddr %x\n",
-           enrbdp, enrproto, enrmr, imp_stat.iaddr);
-       imp_stat.impopen = 1;
-       imp_stat.flush = 0;
-       splx(x);
-#ifdef IMPDEBUG
-       printf("eninit(%d): iaddr = %x, oaddr = %x\n",
-               unit, imp_stat.iaddr, imp_stat.oaddr);
-#endif
+       addr->en_istat = addr->en_ostat = 0;
 }
 
 }
 
-#if 0
 enreset(uban)
        int uban;
 {
        register int unit;
        struct uba_device *ui;
 
 enreset(uban)
        int uban;
 {
        register int unit;
        struct uba_device *ui;
 
+COUNT(ENRESET);
        for (unit = 0; unit < NEN; unit++) {
                ui = eninfo[unit];
                if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
                        continue;
        for (unit = 0; unit < NEN; unit++) {
                ui = eninfo[unit];
                if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
                        continue;
-               if (imp_stat.iaddr)
-                       ubarelse(uban, &imp_stat.iaddr);
-               if (imp_stat.oaddr)
-                       ubarelse(uban, &imp_stat.oaddr);
                eninit(unit);
                eninit(unit);
-               printf("en%d ", unit);
+               printf("es%d ", unit);
        }
 }
        }
 }
-#endif
 
 int    enlastdel = 25;
 
 int    enlastdel = 25;
-int    enlastx = 0;
+
 enstart(dev)
        dev_t dev;
 {
 enstart(dev)
        dev_t dev;
 {
-       register struct mbuf *m, *mp;
-       register struct endevice *addr;
-       register caddr_t cp, top;
         int unit;
         int unit;
-        register int len;
        struct uba_device *ui;
        struct uba_device *ui;
-       int enxswapnow = 0;
+       register struct endevice *addr;
+       register struct en_softc *es;
+       register struct ifuba *ifu;
+       struct mbuf *m;
+       int dest;
 COUNT(ENSTART);
 
        unit = ENUNIT(dev);
        ui = eninfo[unit];
 COUNT(ENSTART);
 
        unit = ENUNIT(dev);
        ui = eninfo[unit];
-       if (ui == 0 || ui->ui_alive == 0) {
-               printf("en%d (imp_output): not alive\n", unit);
+       es = &en_softc[unit];
+       if (es->es_oactive)
+               goto restart;
+       IF_DEQUEUE(&es->es_if->if_snd, m);
+       if (m == 0) {
+               es->es_oactive = 0;
                return;
        }
                return;
        }
+       dest = mtod(m, struct en_header *)->en_dhost;
+       es->es_olen = if_wubaput(&es->es_ifuba, m);
+       if (es->es_lastx && es->es_lastx == dest)
+               es->es_delay = enlastdel;
+       else
+               es->es_lastx = dest;
+restart:
+       ifu = es->es_ifuba;
+       UBAPURGE(ifu->ifu_uba, ifu->ifu_w.ifrw_bdp);
        addr = (struct endevice *)ui->ui_addr;
        addr = (struct endevice *)ui->ui_addr;
-       if (!imp_stat.outactive) {
-               if ((m = imp_stat.outq_head) == NULL)
-                       return;
-               imp_stat.outactive = 1;      /* set myself active */
-               imp_stat.outq_head = m->m_act;  /* -> next packet chain */
-               /*
-                * Pack mbufs into ethernet packet.
-                */
-               cp = (caddr_t)xpkt;
-               top = (caddr_t)xpkt + sizeof(struct en_packet);
-               while (m != NULL) {
-                       char *dp;
-                       if (cp + m->m_len > top) {
-                               printf("imp_snd: my packet runneth over\n");
-                               m_freem(m);
-                               return;
-                       }
-                       dp = mtod(m, char *);
-                       if (((int)cp&0x3ff)==0 && ((int)dp&0x3ff)==0) {
-                               struct pte *pte = &Mbmap[mtopf(dp)*2];
-                               *(int *)enxmr = enwproto | pte++->pg_pfnum;
-                               *(int *)(enxmr+1) = enwproto | pte->pg_pfnum;
-                               enxswapd = enxswapnow = 1;
-                       } else
-                               bcopy(mtod(m, caddr_t), cp,
-                                   (unsigned)m->m_len);
-                       cp += m->m_len;
-                       /* too soon! */
-                       MFREE(m, mp);
-                       m = mp;
-               }
-               if (enxswapnow == 0 && enxswapd) {
-                       enxmr[0] = enxmap[0];
-                       enxmr[1] = enxmap[1];
-               }
-               if (enlastx && enlastx == xpkt->Header.en_dhost)
-                       imp_stat.endelay = enlastdel;
-               else
-                       enlastx = xpkt->Header.en_dhost;
-       }
-       len = ntohs((u_short)(((struct ip *)((int)xpkt + L1822))->ip_len)) +
-           L1822;
-       if (len > sizeof(struct en_packet)) {
-               printf("imp_output: ridiculous IP length %d\n", len);
-               return;
-       }
-#if defined(VAX780) || defined(VAX750)
-       switch (cpu) {
-#if defined(VAX780)
-       case VAX_780:
-               UBA_PURGE780(enuba, enwbdp);
-               break;
-#endif
-#if defined(VAX750)
-       case VAX_750:
-               UBA_PURGE750(enuba, enwbdp);
-               break;
-#endif
-       }
-#endif
-       addr->en_oba = imp_stat.oaddr;
-       addr->en_odelay = imp_stat.endelay;
-       addr->en_owc = -((len + 1) >> 1);
-#ifdef IMPDEBUG
-       printf("en%d: sending packet (%d bytes)\n", unit, len);
-       prt_byte(xpkt, len);
-#endif
+       addr->en_oba = (int)ifu->ifu_w.ifrw_addr;
+       addr->en_odelay = es->es_delay;
+       addr->en_owc = -((es->es_olen + 1) >> 1);
        addr->en_ostat = EN_IEN|EN_GO;
        addr->en_ostat = EN_IEN|EN_GO;
+       es->es_oactive = 1;
 }
 
 }
 
-/*
- * Output interrupt handler.
- */
 enxint(unit)
        int unit;
 {
        register struct endevice *addr;
        register struct uba_device *ui;
 enxint(unit)
        int unit;
 {
        register struct endevice *addr;
        register struct uba_device *ui;
+       register struct en_softc *es;
 COUNT(ENXINT);
 
        ui = eninfo[unit];
 COUNT(ENXINT);
 
        ui = eninfo[unit];
+       es = &en_softc[unit];
+       if (es->es_oactive == 0)
+               return;
        addr = (struct endevice *)ui->ui_addr;
        addr = (struct endevice *)ui->ui_addr;
-
-#ifdef IMPDEBUG
-       printf("en%d: enxint ostat=%b\n", unit, addr->en_ostat, EN_BITS);
-#endif
-       if (!imp_stat.outactive) {
-               printf("en%d: phantom output intr ostat=%b\n",
-                       unit, addr->en_ostat, EN_BITS);
+       es = &en_softc[unit];
+       es->es_oactive = 0;
+       es->es_delay = 0;
+       es->es_mask = ~0;
+       if (addr->en_ostat&EN_OERROR)
+               printf("es%d: output error\n", unit);
+       if (es->es_if->if_snd.ifq_head == 0) {
+               es->es_lastx = 0;
                return;
        }
                return;
        }
-       imp_stat.endelay = 0;
-       imp_stat.enmask = ~0;
-       if (addr->en_ostat&EN_OERROR)
-               printf("en%d: output error ostat=%b\n", unit,
-                       addr->en_ostat, EN_BITS);
-       imp_stat.outactive = 0;
-       if (imp_stat.outq_head)
-               enstart(unit);
-       else
-               enlastx = 0;
+       enstart(unit);
 }
 
 }
 
-int collisions;
 encollide(unit)
        int unit;
 {
 encollide(unit)
        int unit;
 {
-       register struct endevice *addr;
-       register struct uba_device *ui;
+       register struct en_softc *es;
 COUNT(ENCOLLIDE);
 
 COUNT(ENCOLLIDE);
 
-       collisions++;
-       ui = eninfo[unit];
-       addr = (struct endevice *)ui->ui_addr;
-
-#ifdef IMPDEBUG
-       printf("en%d: collision ostat=%b\n", unit, addr->en_ostat, EN_BITS);
-#endif
-       if (!imp_stat.outactive) {
-               printf("en%d: phantom collision intr ostat=%b\n",
-                       unit, addr->en_ostat, EN_BITS);
+       es = &en_softc[unit];
+       es->es_if->if_collisions++;
+       if (es->es_oactive == 0)
                return;
                return;
-       }
-       if (imp_stat.enmask == 0) {
-               printf("en%d: output error ostat=%b\n", unit,
-                       addr->en_ostat, EN_BITS);
+       if (es->es_mask == 0) {
+               printf("es%d: send error\n", unit);
+               enxint(unit);
        } else {
        } else {
-               imp_stat.enmask <<= 1;
-               imp_stat.endelay = mfpr(ICR) & ~imp_stat.enmask;
+               es->es_mask <<= 1;
+               es->es_delay = mfpr(ICR) &~ es->es_mask;
+               enstart(unit);
        }
        }
-       enstart(unit);
 }
 
 enrint(unit)
        int unit;
 {
 }
 
 enrint(unit)
        int unit;
 {
-       register struct mbuf *m;
-       struct mbuf *mp;
-       register struct endevice *addr;
-       register struct uba_device *ui;
+       struct endevice *addr;
+       register struct en_softc *es;
+       register struct ifuba *ifu;
+       struct en_header *en;
+       struct mbuf *m;
+       struct ifqueue *inq;
        register int len;
        register int len;
-       register caddr_t cp;
-       struct mbuf *p, *top = 0;
-       struct ip *ip;
-       u_int hlen;
+       int off;
 COUNT(ENRINT);
 
 COUNT(ENRINT);
 
-       ui = eninfo[unit];
-       addr = (struct endevice *)ui->ui_addr;
-#ifdef IMPDEBUG
-       printf("en%d: enrint istat=%b\n", unit, addr->en_istat, EN_BITS);
-#endif
-       if (imp_stat.flush)
-               goto flush;
+       addr = (struct endevice *)eninfo[unit]->ui_addr;
        if (addr->en_istat&EN_IERROR) {
        if (addr->en_istat&EN_IERROR) {
-#ifdef notdef
-               printf("en%d: input error istat=%b\n", unit,
-                       addr->en_istat, EN_BITS);
-#endif
-               goto flush;
+               es->es_if->if_ierrors++;
+               printf("es%d: input error\n", unit);
+               goto setup;
        }
        }
-#if defined(VAX780) || defined(VAX750)
-       switch (cpu) {
-#if defined(VAX780)
-       case VAX_780:
-               UBA_PURGE780(enuba, enrbdp);
-               break;
-#endif
-#if defined(VAX750)
-       case VAX_750:
-               UBA_PURGE750(enuba, enrbdp);
+       ifu = en_softc[unit].es_ifuba;
+       UBAPURGE(ifu->ifu_uba, ifu->ifu_r.ifrw_bdp);
+       en = (struct en_header *)(ifu->ifu_r.ifrw_addr);
+#define        endataaddr(en, off, type)       ((type)(((caddr_t)((en)+1)+(off))))
+       if (en->en_type >= ENPUP_TRAIL &&
+           en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
+               off = (en->en_type - ENPUP_TRAIL) * 512;
+               en->en_type = *endataaddr(en, off, u_short *);
+               off += 2;
+       } else
+               off = 0;
+       switch (en->en_type) {
+
+#ifdef INET
+       case ENPUP_IPTYPE:
+               len = endataaddr(en, off, struct ip *)->ip_len;
+               setipintr();
+               inq = &ipintrq;
                break;
 #endif
                break;
 #endif
-       }
-#endif
-       ip = (struct ip *)((int)rpkt + L1822);
-       len = ntohs((u_short *)ip->ip_len) + L1822;
-       if (len > sizeof(struct en_packet) || len < sizeof (struct ip)) {
-               printf("enrint: bad ip length %d\n", len);
-               goto flush;
-       }
-       hlen = L1822 + sizeof (struct ip);
-       switch (ip->ip_p) {
 
 
-       case IPPROTO_TCP:
-               hlen += ((struct tcpiphdr *)ip)->ti_off << 2;
-               break;
-       }
-       MGET(m, 0);
-       if (m == 0)
-               goto flush;
-       top = m;
-       m->m_off = MMINOFF;
-       m->m_len = hlen;
-       bcopy((caddr_t)rpkt, mtod(m, caddr_t), hlen);
-       len -= hlen;
-       cp = (caddr_t)rpkt + hlen;
-       mp = m;
-       while (len > 0) {
-               MGET(m, 0);
-               if (m == NULL)
-                       goto flush;
-               if (len >= PGSIZE) {
-                       MPGET(p, 1);
-                       if (p == 0)
-                               goto nopage;
-                       m->m_len = PGSIZE;
-                       m->m_off = (int)p - (int)m;
-                       if (((int)cp & 0x3ff) == 0) {
-                               struct pte *cpte = &Mbmap[mtopf(cp)*2];
-                               struct pte *ppte = &Mbmap[mtopf(p)*2];
-                               struct pte t;
-                               enrswaps++;
-                               t = *ppte; *ppte++ = *cpte; *cpte++ = t;
-                               t = *ppte; *ppte = *cpte; *cpte = t;
-                               mtpr(TBIS, (caddr_t)cp);
-                               mtpr(TBIS, (caddr_t)cp+512);
-                               mtpr(TBIS, (caddr_t)p);
-                               mtpr(TBIS, (caddr_t)p+512);
-                               *(int *)(enrmr+1) =
-                                   cpte[0].pg_pfnum | enrproto;
-                               *(int *)(enrmr) =
-                                   cpte[-1].pg_pfnum | enrproto;
-                               goto nocopy;
-                       }
-               } else {
-nopage:
-                       m->m_len = MIN(MLEN, len);
-                       m->m_off = MMINOFF;
-               }
-               bcopy(cp, mtod(m, caddr_t), (unsigned)m->m_len);
-nocopy:
-               cp += m->m_len;
-               len -= m->m_len;
-               mp->m_next = m;
-               mp = m;
+       default:
+               printf("en%d: unknow pkt type 0x%x\n", en->en_type);
+               goto setup;
        }
        }
-       m = top;
-       if (imp_stat.inq_head != NULL)
-               imp_stat.inq_tail->m_act = m;
-       else
-               imp_stat.inq_head = m;
-       imp_stat.inq_tail = m;
-#ifdef IMPDEBUG
-       printf("en%d: received packet (%d bytes)\n", unit, len);
-       prt_byte(rpkt, len);
-#endif
-       setsoftnet();
-       goto setup;
-flush:
-       m_freem(top);
-#ifdef IMPDEBUG
-       printf("en%d: flushing packet %x\n", unit, top);
-#endif
+       if (len == 0)
+               goto setup;
+       m = if_rubaget(&ifu->ifu_r, len, off);
+       IF_ENQUEUE(inq, m);
 setup:
 setup:
-       addr->en_iba = imp_stat.iaddr;
-       addr->en_iwc = -600;
+       addr->en_iba = es->es_ifuba->ifu_r.ifrw_info;
+       addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
        addr->en_istat = EN_IEN|EN_GO;
 }
 
        addr->en_istat = EN_IEN|EN_GO;
 }
 
-#ifdef IMPDEBUG
-prt_byte(s, ct)
-       register char *s;
-       int ct;
+/*
+ * Ethernet output routine.
+ * Encapsulate a packet of type family for the local net.
+ */
+enoutput(ifp, m0, pf)
+       struct ifnet *ifp;
+       struct mbuf *m0;
+       int pf;
 {
 {
-       register i, j, c;
+       int type, dest;
+       register struct mbuf *m;
+       register struct en_header *en;
+       int s;
+
+       switch (pf) {
 
 
-       for (i=0; i<ct; i++) {
-               c = *s++;
-               for (j=0; j<2 ; j++)
-                       putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]);
-               putchar(' ');
+#ifdef INET
+       case PF_INET: {
+               register struct ip *ip = mtod(m0, struct ip *);
+               int off;
+
+               off = ip->ip_len - (ip->ip_hl << 2);
+               if (off && off % 512 == 0 && m0->m_off >= MMINOFF + 2) {
+                       type = ENPUP_TRAIL + (off>>9);
+                       m0->m_off -= 2;
+                       m0->m_len += 2;
+                       *mtod(m0, u_short *) = ENPUP_IPTYPE;
+               } else {
+                       type = ENPUP_IPTYPE;
+                       off = 0;
+               }
+               dest = ip->ip_dst.s_addr >> 24;
+               }
+               break;
+#endif
+
+       default:
+               printf("en%d: can't encapsulate pf%d\n", ifp->if_unit, pf);
+               m_freem(m0);
+               return (0);
+       }
+       if (MMINOFF + sizeof (struct en_header) > m0->m_off) {
+               m = m_get(0);
+               if (m == 0) {
+                       m_freem(m0);
+                       return (0);
+               }
+               m->m_next = m0;
+               m->m_off = MMINOFF;
+               m->m_len = sizeof (struct en_header);
+       } else {
+               m = m0;
+               m->m_off -= sizeof (struct en_header);
+               m->m_len += sizeof (struct en_header);
        }
        }
-       putchar('\n');
+       en = mtod(m, struct en_header *);
+       en->en_shost = ifp->if_host[0];
+       en->en_dhost = dest;
+       en->en_type = type;
+       s = splimp();
+       IF_ENQUEUE(&ifp->if_snd, m);
+       splx(s);
+       if (en_softc[ifp->if_unit].es_oactive == 0)
+               enstart(ifp->if_unit);
 }
 }
-#endif IMPDEBUG
index 6396e92..5d99b97 100644 (file)
@@ -1,14 +1,19 @@
-/*     if_uba.c        4.1     81/11/25        */
+/*     if_uba.c        4.2     81/11/26        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/map.h"
 #include "../h/pte.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/map.h"
 #include "../h/pte.h"
+#include "../h/buf.h"
 #include "../h/ubareg.h"
 #include "../h/ubavar.h"
 #include "../h/cmap.h"
 #include "../h/mtpr.h"
 #include "../h/ubareg.h"
 #include "../h/ubavar.h"
 #include "../h/cmap.h"
 #include "../h/mtpr.h"
+#include "../h/vmmac.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
+#include "../net/if.h"
 #include "../net/if_uba.h"
 
 /*
 #include "../net/if_uba.h"
 
 /*
@@ -29,24 +34,26 @@ if_ubainit(ifu, uban, hlen, nmr)
        register struct ifuba *ifu;
        int uban, hlen, nmr;
 {
        register struct ifuba *ifu;
        int uban, hlen, nmr;
 {
-       register caddr_t cp = m_pgalloc(2 * (nmr + 1));
+       register caddr_t cp = (caddr_t)m_pgalloc(2 * (nmr + 1));
+       int i;
 
 
+COUNT(IF_UBAINIT);
        if (cp == 0)
                return (0);
        if (cp == 0)
                return (0);
-       ifu->if_uban = uban;
-       ifu->if_uba = &uba_hd[uban]->uh_uba;
-       ifu->if_r.if_addr = cp + NMBPG - hlen;
-       ifu->if_w.if_addr = ifu->if_r.if_addr + (nmr + 1) * NMBPG;
-       if (if_ubaalloc(ifu, &ifu->if_r) == 0)
+       ifu->ifu_uban = uban;
+       ifu->ifu_uba = uba_hd[uban].uh_uba;
+       ifu->ifu_r.ifrw_addr = cp + NBPG - hlen;
+       ifu->ifu_w.ifrw_addr = ifu->ifu_r.ifrw_addr + (nmr + 1) * NBPG;
+       if (if_ubaalloc(ifu, &ifu->ifu_r) == 0)
                goto bad;
                goto bad;
-       if (if_ubaalloc(ifu, &ifu->if_w) == 0)
+       if (if_ubaalloc(ifu, &ifu->ifu_w) == 0)
                goto bad2;
        for (i = 0; i < IF_NUBAMR; i++)
                goto bad2;
        for (i = 0; i < IF_NUBAMR; i++)
-               ifu->if_xmap[i] = ifu->if_w.if_map[i+1];
-       ifu->if_xswapd = 0;
+               ifu->ifu_wmap[i] = ifu->ifu_w.ifrw_mr[i+1];
+       ifu->ifu_xswapd = 0;
        return (1);
 bad2:
        return (1);
 bad2:
-       ubafree(ifu->ifu_uban, ifu->if_r.ifrw_info);
+       ubarelse(ifu->ifu_uban, &ifu->ifu_r.ifrw_info);
 bad:
        m_pgfree(cp, 2 * (nmr + 1));
        return (0);
 bad:
        m_pgfree(cp, 2 * (nmr + 1));
        return (0);
@@ -64,15 +71,17 @@ if_ubaalloc(ifu, ifrw)
 {
        register int info;
 
 {
        register int info;
 
+COUNT(IF_UBAALLOC);
        info =
        info =
-           uballoc(ifu->ifu_uban, ifrw->ifrw_addr, IF_NUBAMR*NMBPG + hlen,
+           uballoc(ifu->ifu_uban, ifrw->ifrw_addr, IF_NUBAMR*NBPG + ifu->ifu_hlen,
                UBA_NEED16|UBA_NEEDBDP);
        if (info == 0)
                UBA_NEED16|UBA_NEEDBDP);
        if (info == 0)
-               goto bad;
+               return (0);
        ifrw->ifrw_info = info;
        ifrw->ifrw_bdp = UBAI_BDP(info);
        ifrw->ifrw_info = info;
        ifrw->ifrw_bdp = UBAI_BDP(info);
-       ifrw->ifrw_proto = UBAMR_MRV | UBAI_DPDF(info);
-       ifrw->ifrw_mr = &ifu->if_uba[UBAI_MR(info) + 1];
+       ifrw->ifrw_proto = UBAMR_MRV | (UBAI_MR(info) << UBAMR_DPSHIFT);
+       ifrw->ifrw_mr = &ifu->ifu_uba->uba_map[UBAI_MR(info) + 1];
+       return (1);
 }
 
 /*
 }
 
 /*
@@ -91,6 +100,7 @@ if_rubaget(ifu, len)
        register caddr_t cp;
        struct mbuf *mp, *p, *top;
 
        register caddr_t cp;
        struct mbuf *mp, *p, *top;
 
+COUNT(IF_RUBAGET);
        /*
         * First pull local net header off into a mbuf.
         */
        /*
         * First pull local net header off into a mbuf.
         */
@@ -98,12 +108,12 @@ if_rubaget(ifu, len)
        if (m == 0)
                return (0);
        m->m_off = MMINOFF;
        if (m == 0)
                return (0);
        m->m_off = MMINOFF;
-       m->m_len = ifu->if_hlen;
+       m->m_len = ifu->ifu_hlen;
        top = m;
        cp = ifu->ifu_r.ifrw_addr;
        top = m;
        cp = ifu->ifu_r.ifrw_addr;
-       bcopy(cp, mtod(m, caddr_t), ifu->if_hlen);
-       len -= hlen;
-       cp += hlen;
+       bcopy(cp, mtod(m, caddr_t), ifu->ifu_hlen);
+       len -= ifu->ifu_hlen;
+       cp += ifu->ifu_hlen;
 
        /*
         * Now pull data off.  If whole pages
 
        /*
         * Now pull data off.  If whole pages
@@ -114,7 +124,7 @@ if_rubaget(ifu, len)
        while (len > 0) {
                MGET(m, 0);
                if (m == 0)
        while (len > 0) {
                MGET(m, 0);
                if (m == 0)
-                       goto flush;
+                       goto bad;
                if (len >= CLSIZE) {
                        struct pte *cpte, *ppte;
                        int i, x, *ip;
                if (len >= CLSIZE) {
                        struct pte *cpte, *ppte;
                        int i, x, *ip;
@@ -150,17 +160,17 @@ if_rubaget(ifu, len)
                         */
                        cpte = &Mbmap[mtocl(cp)];
                        ppte = &Mbmap[mtocl(p)];
                         */
                        cpte = &Mbmap[mtocl(cp)];
                        ppte = &Mbmap[mtocl(p)];
-                       x = btop(cp - ifu->if_r.ifrw_addr);
+                       x = btop(cp - ifu->ifu_r.ifrw_addr);
                        ip = (int *)&ifu->ifu_r.ifrw_mr[x+1];
                        for (i = 0; i < CLSIZE; i++) {
                                struct pte t;
                                t = *ppte; *ppte = *cpte; *cpte = t;
                                *ip++ =
                        ip = (int *)&ifu->ifu_r.ifrw_mr[x+1];
                        for (i = 0; i < CLSIZE; i++) {
                                struct pte t;
                                t = *ppte; *ppte = *cpte; *cpte = t;
                                *ip++ =
-                                   *cpte++->pg_pfnum|ifu->if_r.ifrw_proto;
+                                   cpte++->pg_pfnum|ifu->ifu_r.ifrw_proto;
                                mtpr(TBIS, cp);
                                mtpr(TBIS, cp);
-                               cp += NMBPG;
+                               cp += NBPG;
                                mtpr(TBIS, (caddr_t)p);
                                mtpr(TBIS, (caddr_t)p);
-                               p += NMBPG / sizeof (*p);
+                               p += NBPG / sizeof (*p);
                        }
                        goto nocopy;
                }
                        }
                        goto nocopy;
                }
@@ -198,6 +208,7 @@ if_wubaput(ifu, m)
        int xswapd = ifu->ifu_xswapd;
        int x;
 
        int xswapd = ifu->ifu_xswapd;
        int x;
 
+COUNT(IF_WUBAPUT);
        ifu->ifu_xswapd = 0;
        cp = ifu->ifu_w.ifrw_addr;
        while (m) {
        ifu->ifu_xswapd = 0;
        cp = ifu->ifu_w.ifrw_addr;
        while (m) {
@@ -206,7 +217,7 @@ if_wubaput(ifu, m)
                        struct pte *pte; int *ip;
                        pte = &Mbmap[mtocl(dp)];
                        x = btop(cp - ifu->ifu_w.ifrw_addr);
                        struct pte *pte; int *ip;
                        pte = &Mbmap[mtocl(dp)];
                        x = btop(cp - ifu->ifu_w.ifrw_addr);
-                       ip = &ifu->ifu_w.ifrw_mr[x + 1];
+                       ip = (int *)&ifu->ifu_w.ifrw_mr[x + 1];
                        for (i = 0; i < CLSIZE; i++)
                                *ip++ =
                                    ifu->ifu_w.ifrw_proto | pte++->pg_pfnum;
                        for (i = 0; i < CLSIZE; i++)
                                *ip++ =
                                    ifu->ifu_w.ifrw_proto | pte++->pg_pfnum;
@@ -224,7 +235,7 @@ if_wubaput(ifu, m)
                        xswapd &= ~(1<<i);
                        i <<= CLSHIFT;
                        for (x = 0; x < CLSIZE; x++) {
                        xswapd &= ~(1<<i);
                        i <<= CLSHIFT;
                        for (x = 0; x < CLSIZE; x++) {
-                               ifu->ifu_rw.ifrw_mr[i] = ifu->ifu_xmap[i];
+                               ifu->ifu_w.ifrw_mr[i] = ifu->ifu_wmap[i];
                                i++;
                        }
                }
                                i++;
                        }
                }
index 16df9b0..549fa69 100644 (file)
@@ -1,4 +1,4 @@
-/*     if_uba.h        4.1     81/11/25        */
+/*     if_uba.h        4.2     81/11/26        */
 
 /*
  * Structure and routine definitions
 
 /*
  * Structure and routine definitions
@@ -38,7 +38,15 @@ struct       ifuba {
                caddr_t ifrw_addr;              /* virt addr of header */
        } ifu_r, ifu_w;
        struct  pte ifu_wmap[IF_NUBAMR];        /* base pages for output */
                caddr_t ifrw_addr;              /* virt addr of header */
        } ifu_r, ifu_w;
        struct  pte ifu_wmap[IF_NUBAMR];        /* base pages for output */
+       short   ifu_hlen;
 /* ifu_xswapd is set when we have swapped write pte's to do direct output */
 /* ifu_xswapd is set when we have swapped write pte's to do direct output */
-/* bit i of ifu_xswapd 
+/* bit i of ifu_xswapd */
        short   ifu_xswapd;                     /* bit map of pages swapped */
        short   ifu_xswapd;                     /* bit map of pages swapped */
+       int     ifu_ierrors;
+       int     ifu_oerrors;
+       int     ifu_collisions;
 };
 };
+
+#ifdef         KERNEL
+struct mbuf *if_rubaget();
+#endif
index 205afac..2b81da1 100644 (file)
@@ -1,9 +1,9 @@
-/* in_cksum.c 1.10 81/11/18 */
+/* in_cksum.c 1.11 81/11/26 */
 
 #include <sys/types.h>
 #include "../h/mbuf.h"
 
 #include <sys/types.h>
 #include "../h/mbuf.h"
-#include "../net/inet.h"
-#include "../net/inet_systm.h"
+#include "../net/in.h"
+#include "../net/in_systm.h"
 
 /*
  * Checksum routine for Internet Protocol family headers.
 
 /*
  * Checksum routine for Internet Protocol family headers.
  */
 
 #if vax
  */
 
 #if vax
-inet_cksum(m, len)
+in_cksum(m, len)
        register struct mbuf *m;
        register int len;
 {
        register u_short *w;            /* known to be r9 */
        register int sum = 0;           /* known to be r8 */
        register int mlen = 0;
        register struct mbuf *m;
        register int len;
 {
        register u_short *w;            /* known to be r9 */
        register int sum = 0;           /* known to be r8 */
        register int mlen = 0;
-COUNT(INET_CKSUM);
+COUNT(IN_CKSUM);
 
        for (;;) {
                /*
 
        for (;;) {
                /*