linted
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 20 Nov 1981 16:48:02 +0000 (08:48 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 20 Nov 1981 16:48:02 +0000 (08:48 -0800)
SCCS-vsn: sys/kern/uipc_syscalls.c 4.5
SCCS-vsn: sys/kern/uipc_mbuf.c 1.12
SCCS-vsn: sys/kern/uipc_proto.c 4.6
SCCS-vsn: sys/kern/uipc_socket.c 4.7
SCCS-vsn: sys/net/if.c 4.2
SCCS-vsn: sys/net/if.h 4.2
SCCS-vsn: sys/netinet/in_pcb.c 4.4
SCCS-vsn: sys/netinet/in_systm.h 4.5
SCCS-vsn: sys/netinet/ip_input.c 1.16
SCCS-vsn: sys/netinet/ip_output.c 1.15
SCCS-vsn: sys/netinet/tcp_input.c 1.26
SCCS-vsn: sys/netinet/tcp_output.c 4.15
SCCS-vsn: sys/netinet/tcp_usrreq.c 1.31
SCCS-vsn: sys/netinet/udp_usrreq.c 4.7
SCCS-vsn: sys/sys/socketvar.h 4.6

15 files changed:
usr/src/sys/kern/uipc_mbuf.c
usr/src/sys/kern/uipc_proto.c
usr/src/sys/kern/uipc_socket.c
usr/src/sys/kern/uipc_syscalls.c
usr/src/sys/net/if.c
usr/src/sys/net/if.h
usr/src/sys/netinet/in_pcb.c
usr/src/sys/netinet/in_systm.h
usr/src/sys/netinet/ip_input.c
usr/src/sys/netinet/ip_output.c
usr/src/sys/netinet/tcp_input.c
usr/src/sys/netinet/tcp_output.c
usr/src/sys/netinet/tcp_usrreq.c
usr/src/sys/netinet/udp_usrreq.c
usr/src/sys/sys/socketvar.h

index ff67f53..35b2384 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_mbuf.c     1.11    81/11/18        */
+/*     uipc_mbuf.c     1.12    81/11/20        */
 
 #include "../h/param.h"
 #include "../h/dir.h"
 
 #include "../h/param.h"
 #include "../h/dir.h"
@@ -100,6 +100,7 @@ COUNT(M_FREEM);
        splx(s);
 }
 
        splx(s);
 }
 
+/*ARGSUSED*/
 m_pullup(m, len)
        struct mbuf *m;
        int len;
 m_pullup(m, len)
        struct mbuf *m;
        int len;
index 088a66a..8723d68 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_proto.c    4.5     81/11/18        */
+/*     uipc_proto.c    4.6     81/11/20        */
 
 #include "../h/param.h"
 #include "../h/socket.h"
 
 #include "../h/param.h"
 #include "../h/socket.h"
@@ -31,8 +31,8 @@ int   udp_init();
 int    tcp_input(),tcp_ctlinput();
 int    tcp_usrreq(),tcp_sense();
 int    tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain();
 int    tcp_input(),tcp_ctlinput();
 int    tcp_usrreq(),tcp_sense();
 int    tcp_init(),tcp_fasttimo(),tcp_slowtimo(),tcp_drain();
-int    ri_input(),ri_ctlinput();
-int    ri_usrreq(),ri_sense();
+int    rip_input(),rip_ctlinput();
+int    rip_usrreq(),rip_sense();
 
 struct protosw protosw[] = {
 { SOCK_STREAM, PF_LOCAL,       0,              PR_CONNREQUIRED,
 
 struct protosw protosw[] = {
 { SOCK_STREAM, PF_LOCAL,       0,              PR_CONNREQUIRED,
@@ -76,8 +76,8 @@ struct protosw protosw[] = {
   tcp_init,    tcp_fasttimo,   tcp_slowtimo,   tcp_drain,
 },
 { SOCK_RAW,    PF_INET,        IPPROTO_RAW,    PR_ATOMIC|PR_ADDR,
   tcp_init,    tcp_fasttimo,   tcp_slowtimo,   tcp_drain,
 },
 { SOCK_RAW,    PF_INET,        IPPROTO_RAW,    PR_ATOMIC|PR_ADDR,
-  ri_input,    0,              ri_ctlinput,    0,
-  ri_usrreq,   ri_sense,       MLEN,
+  rip_input,   0,              rip_ctlinput,   0,
+  rip_usrreq,  rip_sense,      MLEN,
   0,           0,              0,              0,
 }
 };
   0,           0,              0,              0,
 }
 };
index 3b650f0..5beb959 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_socket.c   4.6     81/11/18        */
+/*     uipc_socket.c   4.7     81/11/20        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -90,6 +90,10 @@ sofree(so)
 {
 
 COUNT(SOFREE);
 {
 
 COUNT(SOFREE);
+       if (so->so_pcb || (so->so_state & SS_USERGONE) == 0)
+               return;
+       sbrelease(&so->so_snd);
+       sbrelease(&so->so_rcv);
        m_free(dtom(so));
 }
 
        m_free(dtom(so));
 }
 
@@ -125,8 +129,8 @@ COUNT(SOCLOSE);
        }
        u.u_error = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, 0, 0);
 discard:
        }
        u.u_error = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, 0, 0);
 discard:
-       if (so->so_pcb == 0)
-               sofree(so);
+       so->so_state |= SS_USERGONE;
+       sofree(so);
        splx(s);
 }
 
        splx(s);
 }
 
index 4b09e0d..592771a 100644 (file)
@@ -1,4 +1,4 @@
-/*     uipc_syscalls.c 4.4     81/11/18        */
+/*     uipc_syscalls.c 4.5     81/11/20        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -59,7 +59,6 @@ COUNT(SPIPE);
        u.u_r.r_val1 = r;
        if (piconnect(rso, wso) == 0)
                goto free4;
        u.u_r.r_val1 = r;
        if (piconnect(rso, wso) == 0)
                goto free4;
-       rso->so_isfilerefd = wso->so_isfilerefd = 1;
        return;
 free4:
        wf->f_count = 0;
        return;
 free4:
        wf->f_count = 0;
@@ -68,8 +67,10 @@ free3:
        rf->f_count = 0;
        u.u_ofile[r] = 0;
 free2:
        rf->f_count = 0;
        u.u_ofile[r] = 0;
 free2:
+       wso->so_state |= SS_USERGONE;
        sofree(wso);
 free:
        sofree(wso);
 free:
+       rso->so_state |= SS_USERGONE;
        sofree(rso);
 }
 
        sofree(rso);
 }
 
@@ -144,7 +145,6 @@ COUNT(SSOCKET);
        if (u.u_error)
                goto bad;
        fp->f_socket = so;
        if (u.u_error)
                goto bad;
        fp->f_socket = so;
-       so->so_isfilerefd = 1;
        return;
 bad:
        u.u_ofile[u.u_r.r_val1] = 0;
        return;
 bad:
        u.u_ofile[u.u_r.r_val1] = 0;
index 68576c0..6b1ccaa 100644 (file)
@@ -1,4 +1,4 @@
-/*     if.c    4.1     81/11/18        */
+/*     if.c    4.2     81/11/20        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -6,11 +6,14 @@
 #include "../net/inet_systm.h"
 #include "../net/if.h"
 
 #include "../net/inet_systm.h"
 #include "../net/if.h"
 
+/*ARGSUSED*/
+struct ifnet *
 if_ifwithaddr(in)
        struct in_addr in;
 {
        register struct ifnet *ifp;
 
 if_ifwithaddr(in)
        struct in_addr in;
 {
        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)
 #if 0
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_addr.s_addr == in.s_addr)
@@ -21,6 +24,8 @@ if_ifwithaddr(in)
        return (ifp);
 }
 
        return (ifp);
 }
 
+/*ARGSUSED*/
+struct ifnet *
 if_ifonnetof(in)
        struct in_addr in;
 {
 if_ifonnetof(in)
        struct in_addr in;
 {
@@ -28,6 +33,7 @@ if_ifonnetof(in)
 #if 0
        int net;
 
 #if 0
        int net;
 
+COUNT(IF_IFONNETOF);
        net = 0;                        /* XXX */
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_net == net)
        net = 0;                        /* XXX */
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
                if (ifp->if_net == net)
@@ -38,5 +44,5 @@ if_ifonnetof(in)
        return (ifp);
 }
 
        return (ifp);
 }
 
-struct ifnet ifen = { 0, 0, 1024, 0, 0 };
+struct ifnet ifen;
 struct ifnet *ifnet = &ifen;
 struct ifnet *ifnet = &ifen;
index de55197..5e0c3ba 100644 (file)
@@ -1,4 +1,4 @@
-/*     if.h    4.1     81/11/18        */
+/*     if.h    4.2     81/11/20        */
 
 /*
  * Structure defining a network interface.
 
 /*
  * Structure defining a network interface.
@@ -21,6 +21,7 @@ struct ifnet {
                int     (*if_output)();         /* output routine */
                int     (*if_ubareset)();       /* uba reset routine */
        } *if_sw;
                int     (*if_output)();         /* output routine */
                int     (*if_ubareset)();       /* uba reset routine */
        } *if_sw;
+       struct  ifnet *if_next;
 };
 
 /* bits in if_flags */
 };
 
 /* bits in if_flags */
index 821d64f..5263cef 100644 (file)
@@ -1,37 +1,95 @@
-/* in_pcb.c 4.3 81/11/18 */
+/* in_pcb.c 4.4 81/11/20 */
 
 #include "../h/param.h"
 
 #include "../h/param.h"
+#include "../h/systm.h"
+#include "../h/dir.h"
+#include "../h/user.h"
 #include "../h/mbuf.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../net/inet.h"
 #include "../net/inet_systm.h"
 #include "../h/mbuf.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../net/inet.h"
 #include "../net/inet_systm.h"
-#include "../net/inet_host.h"
+#include "../net/if.h"
 #include "../net/inet_pcb.h"
 
 #include "../net/inet_pcb.h"
 
-struct inpcb *
-in_pcballoc()
+/*
+ * Allocate a protocol control block, space
+ * for send and receive data, and local host information.
+ * Return error.  If no error make socket point at pcb.
+ */
+in_pcballoc(so, head, sndcc, rcvcc, sin)
+       struct socket *so;
+       struct inpcb *head;
+       int sndcc, rcvcc;
+       struct sockaddr_in *sin;
 {
 {
-
        struct mbuf *m;
        struct mbuf *m;
+       register struct inpcb *inp;
+       struct ifnet *ifp;
+       u_long lport;
 
 
+       if (sin) {
+               if (sin->sin_family != AF_INET)
+                       return (EAFNOSUPPORT);
+               ifp = if_ifwithaddr(sin->sin_addr);
+               if (ifp == 0)
+                       return (EADDRNOTAVAIL);
+               lport = sin->sin_port;
+               if (lport) {
+                       inp = head->inp_next;
+                       for (; inp != head; inp = inp->inp_next) 
+                               if (inp->inp_laddr.s_addr ==
+                                   sin->sin_addr.s_addr &&
+                                   inp->inp_lport == lport &&
+                                   inp->inp_faddr.s_addr == 0)
+                                       return (EADDRINUSE);
+               }
+       } else {
+               ifp = if_ifwithaddr(ifnet->if_addr);
+               lport = 0;
+       }
        m = m_getclr(M_WAIT);
        m = m_getclr(M_WAIT);
-       m->m_off = MMINOFF;
-       return (mtod(m, struct inpcb *));
+       if (m == 0)
+               return (0);
+       if (sbreserve(&so->so_snd, sndcc) == 0)
+               goto bad;
+       if (sbreserve(&so->so_rcv, rcvcc) == 0)
+               goto bad2;
+       inp = mtod(m, struct inpcb *);
+       inp->inp_laddr = ifp->if_addr;
+       if (lport)
+               goto gotport;
+again:
+       if (head->inp_lport++ < 1024)
+               head->inp_lport = 1024;
+       for (inp = head->inp_next; inp != head; inp = inp->inp_next)
+               if (inp->inp_lport == head->inp_lport)
+                       goto again;
+       lport = head->inp_lport;
+gotport:
+       inp->inp_lport = lport;
+       insque(head, inp);
+       so->so_pcb = (caddr_t)inp;
+       return (0);
+bad2:
+       sbrelease(&so->so_snd);
+bad:
+       m_free(m);
+       return (ENOBUFS);
 }
 
 }
 
-in_pcbenter(head, new)
-       struct inpcb *head, *new;
+in_pcbsetpeer(inp, sin)
+       struct inpcb *inp;
+       struct sockaddr_in *sin;
 {
 {
-       register struct inpcb *inp;
 
 
-       for (inp = head->inp_next; inp != head; inp = inp->inp_next)
-               if (inp->inp_fhost->h_addr.s_addr == new->inp_fhost.s_addr &&
-                   inp->inp_fport == new->inp_fport &&
-                   inp->inp_lhost->h_addr.s_addr = new->inp_fhost.s_addr &&
-                   inp->inp_lport == new->inp_lport)
-                       return (EADDRINUSE);
-       insque(new, head);
+       if (sin->sin_family != AF_INET)
+               return (EAFNOSUPPORT);
+       if (sin->sin_addr.s_addr == 0 || sin->sin_port == 0)
+               return (EADDRNOTAVAIL);
+       /* should check not already in use... */
+       inp->inp_faddr = sin->sin_addr;
+       inp->inp_fport = sin->sin_port;
        return (0);
 }
 
        return (0);
 }
 
@@ -40,51 +98,33 @@ in_pcbfree(inp)
 {
        struct socket *so = inp->inp_socket;
 
 {
        struct socket *so = inp->inp_socket;
 
-       if (so->so_isfilerefd == 0)
+       if (so->so_state & SS_USERGONE)
                sofree(so);
        else
                so->so_pcb = 0;
                sofree(so);
        else
                so->so_pcb = 0;
-       if (inp->inp_lhost)
-               in_hostfree(inp->inp_lhost);
-       if (inp->inp_fhost)
-               in_hostfree(inp->inp_fhost);
        (void) m_free(dtom(inp));
 }
 
 struct inpcb *
        (void) m_free(dtom(inp));
 }
 
 struct inpcb *
-in_pcblookup(head, fhost, fport, lhost, lport)
+in_pcblookup(head, faddr, fport, laddr, lport)
        struct inpcb *head;
        struct inpcb *head;
-       struct in_addr *fhost, *lhost;
+       struct in_addr faddr, laddr;
        u_short fport, lport;
 {
        register struct inpcb *inp;
 
        for (inp = head->inp_next; inp != head; inp = inp->inp_next)
        u_short fport, lport;
 {
        register struct inpcb *inp;
 
        for (inp = head->inp_next; inp != head; inp = inp->inp_next)
-               if (inp->inp_fhost->h_addr.s_addr == fhost->s_addr &&
+               if (inp->inp_faddr.s_addr == faddr.s_addr &&
                    inp->inp_fport == fport &&
                    inp->inp_fport == fport &&
-                   inp->inp_lhost->h_addr.s_addr == lhost->s_addr &&
+                   inp->inp_laddr.s_addr == laddr.s_addr &&
                    inp->inp_lport == lport)
                        return (inp);
        for (inp = head->inp_next; inp != head; inp = inp->inp_next)
                    inp->inp_lport == lport)
                        return (inp);
        for (inp = head->inp_next; inp != head; inp = inp->inp_next)
-               if ((inp->inp_fhost->h_addr.s_addr == fhost->s_addr ||
-                    inp->inp_fhost == 0) &&
+               if ((inp->inp_faddr.s_addr == faddr.s_addr ||
+                    inp->inp_faddr.s_addr == 0) &&
                    (inp->inp_fport == fport || inp->inp_fport == 0) &&
                    (inp->inp_fport == fport || inp->inp_fport == 0) &&
-                    inp->inp_lhost->h_addr.s_addr == lhost->s_addr &&
+                    inp->inp_laddr.s_addr == laddr.s_addr &&
                    (inp->inp_lport == lport || inp->inp_lport == 0))
                        return (inp);
        return (0);
 }
                    (inp->inp_lport == lport || inp->inp_lport == 0))
                        return (inp);
        return (0);
 }
-
-in_pcbgenport(head)
-       struct inpcb *head;
-{
-       register struct inpcb *inp;
-
-again:
-       if (head->inp_lport++ < 1024)
-               head->inp_lport = 1024;
-       for (inp = head->inp_next; inp != head; inp = inp->inp_next)
-               if (inp->inp_lport == head->inp_lport)
-                       goto again;
-       return (head->inp_lport);
-}
index b518c16..e3aed64 100644 (file)
@@ -1,4 +1,4 @@
-/* in_systm.h 4.4 81/11/18 */
+/* in_systm.h 4.5 81/11/20 */
 
 /*
  * Miscellaneous internetwork
 
 /*
  * Miscellaneous internetwork
@@ -31,22 +31,6 @@ typedef      u_long  n_time;                 /* ms since 00:00 GMT, byte rev */
 #define        setsoftnet()    mtpr(SIRR, 12)
 /* splnet is defined in ../sys/asm.sed */
 
 #define        setsoftnet()    mtpr(SIRR, 12)
 /* splnet is defined in ../sys/asm.sed */
 
-/*
- * Network statistics record.
- *
- * SHOULD BE KEPT PER INTERFACE, AND WITH CNT, RATE, SUM.
- */
-struct net_stat {
-       int     imp_resets;             /* # times imp reset */
-       int     imp_flushes;            /* # packets flushed by imp */
-       int     imp_drops;              /* # msgs from imp no-one wants */
-       int     m_drops;                /* # mbuf drops from lack of bufs */
-       int     ip_badsum;              /* # bad ip checksums */
-       int     t_badsum;               /* # bad tcp checksums */
-       int     t_badsegs;              /* # bad tcp segments */
-       int     t_unack;                /* # tcp segs placed on rcv_unack */
-};
-
 #ifdef KERNEL
 n_time iptime();
 #endif
 #ifdef KERNEL
 n_time iptime();
 #endif
index 9808dc1..86b441b 100644 (file)
@@ -1,4 +1,4 @@
-/* ip_input.c 1.15 81/11/18 */
+/* ip_input.c 1.16 81/11/20 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -8,6 +8,7 @@
 #include "../h/socket.h"
 #include "../net/inet.h"
 #include "../net/inet_systm.h"
 #include "../h/socket.h"
 #include "../net/inet.h"
 #include "../net/inet_systm.h"
+#include "../net/if.h"
 #include "../net/imp.h"
 #include "../net/ip.h"                 /* belongs before inet.h */
 #include "../net/ip_var.h"
 #include "../net/imp.h"
 #include "../net/ip.h"                 /* belongs before inet.h */
 #include "../net/ip_var.h"
@@ -24,6 +25,7 @@ ip_init()
        register struct protosw *pr;
        register int i;
 
        register struct protosw *pr;
        register int i;
 
+COUNT(IP_INIT);
        pr = pffindproto(PF_INET, IPPROTO_RAW);
        if (pr == 0)
                panic("ip_init");
        pr = pffindproto(PF_INET, IPPROTO_RAW);
        if (pr == 0)
                panic("ip_init");
@@ -65,21 +67,21 @@ COUNT(IP_INPUT);
        ip = mtod(m, struct ip *);
        if ((hlen = ip->ip_hl << 2) > m->m_len) {
                printf("ip hdr ovflo\n");
        ip = mtod(m, struct ip *);
        if ((hlen = ip->ip_hl << 2) > m->m_len) {
                printf("ip hdr ovflo\n");
-               m_freem(m);
-               return;
+               goto bad;
        }
        }
-       ip->ip_sum = inet_cksum(m, hlen);
-       if (ip->ip_sum) {
-               printf("ip_sum %x\n", ip->ip_sum);
-               ipstat.ips_badsum++;
-               if (ipcksum) {
-                       m_freem(m);
-                       return;
+       if (ipcksum)
+               if (ip->ip_sum = inet_cksum(m, hlen)) {
+                       printf("ip_sum %x\n", ip->ip_sum);
+                       ipstat.ips_badsum++;
+                       goto bad;
                }
                }
-       }
+
+       /*
+        * Convert fields to host representation.
+        */
        ip->ip_len = ntohs((u_short)ip->ip_len);
        ip->ip_id = ntohs(ip->ip_id);
        ip->ip_len = ntohs((u_short)ip->ip_len);
        ip->ip_id = ntohs(ip->ip_id);
-       ip->ip_off = ntohs(ip->ip_off);
+       ip->ip_off = ntohs((u_short)ip->ip_off);
 
        /*
         * Check that the amount of data in the buffers
 
        /*
         * Check that the amount of data in the buffers
@@ -94,8 +96,7 @@ COUNT(IP_INPUT);
        if (i != ip->ip_len) {
                if (i < ip->ip_len) {
                        printf("ip_input: short packet\n");
        if (i != ip->ip_len) {
                if (i < ip->ip_len) {
                        printf("ip_input: short packet\n");
-                       m_freem(m);
-                       return;
+                       goto bad;
                }
                m_adj(m, ip->ip_len - i);
        }
                }
                m_adj(m, ip->ip_len - i);
        }
@@ -153,12 +154,19 @@ found:
        } else
                if (fp)
                        (void) ip_freef(fp);
        } else
                if (fp)
                        (void) ip_freef(fp);
+
+       /*
+        * Switch out to protocol's input routine.
+        */
        (*protosw[ip_protox[ip->ip_p]].pr_input)(m);
        (*protosw[ip_protox[ip->ip_p]].pr_input)(m);
+       return;
+bad:
+       m_freem(m);
 }
 
 /*
  * Take incoming datagram fragment and try to
 }
 
 /*
  * Take incoming datagram fragment and try to
- * reassamble it into whole datagram.  If a chain for
+ * reassemble it into whole datagram.  If a chain for
  * reassembly of this datagram already exists, then it
  * is given as fp; otherwise have to make a chain.
  */
  * reassembly of this datagram already exists, then it
  * is given as fp; otherwise have to make a chain.
  */
@@ -172,6 +180,7 @@ ip_reass(ip, fp)
        struct mbuf *t;
        int hlen = ip->ip_hl << 2;
        int i, next;
        struct mbuf *t;
        int hlen = ip->ip_hl << 2;
        int i, next;
+COUNT(IP_REASS);
 
        /*
         * Presence of header sizes in mbufs
 
        /*
         * Presence of header sizes in mbufs
@@ -293,6 +302,7 @@ ip_freef(fp)
 {
        register struct ipasfrag *q;
        struct mbuf *m;
 {
        register struct ipasfrag *q;
        struct mbuf *m;
+COUNT(IP_FREEF);
 
        for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next)
                m_freem(dtom(q));
 
        for (q = fp->ipq_next; q != (struct ipasfrag *)fp; q = q->ipf_next)
                m_freem(dtom(q));
@@ -310,8 +320,8 @@ ip_freef(fp)
 ip_enq(p, prev)
        register struct ipasfrag *p, *prev;
 {
 ip_enq(p, prev)
        register struct ipasfrag *p, *prev;
 {
-COUNT(IP_ENQ);
 
 
+COUNT(IP_ENQ);
        p->ipf_prev = prev;
        p->ipf_next = prev->ipf_next;
        prev->ipf_next->ipf_prev = p;
        p->ipf_prev = prev;
        p->ipf_next = prev->ipf_next;
        prev->ipf_next->ipf_prev = p;
@@ -324,8 +334,8 @@ COUNT(IP_ENQ);
 ip_deq(p)
        register struct ipasfrag *p;
 {
 ip_deq(p)
        register struct ipasfrag *p;
 {
-COUNT(IP_DEQ);
 
 
+COUNT(IP_DEQ);
        p->ipf_prev->ipf_next = p->ipf_next;
        p->ipf_next->ipf_prev = p->ipf_prev;
 }
        p->ipf_prev->ipf_next = p->ipf_next;
        p->ipf_next->ipf_prev = p->ipf_prev;
 }
@@ -339,8 +349,8 @@ ip_slowtimo()
 {
        register struct ipq *fp;
        int s = splnet();
 {
        register struct ipq *fp;
        int s = splnet();
-COUNT(IP_SLOWTIMO);
 
 
+COUNT(IP_SLOWTIMO);
        for (fp = ipq.next; fp != &ipq; )
                if (--fp->ipq_ttl == 0)
                        fp = ip_freef(fp);
        for (fp = ipq.next; fp != &ipq; )
                if (--fp->ipq_ttl == 0)
                        fp = ip_freef(fp);
@@ -349,9 +359,15 @@ COUNT(IP_SLOWTIMO);
        splx(s);
 }
 
        splx(s);
 }
 
+/*
+ * Drain off all datagram fragments.
+ */
 ip_drain()
 {
 
 ip_drain()
 {
 
+COUNT(IP_DRAIN);
+       while (ipq.next != &ipq)
+               (void) ip_freef(ipq.next);
 }
 
 /*
 }
 
 /*
@@ -366,7 +382,10 @@ ip_dooptions(ip)
        int opt, optlen, cnt;
        struct in_addr *sin;
        register struct ip_timestamp *ipt;
        int opt, optlen, cnt;
        struct in_addr *sin;
        register struct ip_timestamp *ipt;
+       register struct ifnet *ifp;
+       struct in_addr t;
 
 
+COUNT(IP_DOOPTIONS);
        cp = (u_char *)(ip + 1);
        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
        for (; cnt > 0; cnt -= optlen, cp += optlen) {
        cp = (u_char *)(ip + 1);
        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
        for (; cnt > 0; cnt -= optlen, cp += optlen) {
@@ -382,19 +401,32 @@ ip_dooptions(ip)
                default:
                        break;
 
                default:
                        break;
 
+               /*
+                * Source routing with record.
+                * Find interface with current destination address.
+                * If none on this machine then drop if strictly routed,
+                * or do nothing if loosely routed.
+                * Record interface address and bring up next address
+                * component.  If strictly routed make sure next
+                * address on directly accessible net.
+                */
                case IPOPT_LSRR:
                case IPOPT_LSRR:
-               case IPOPT_SSRR:
                        if (cp[2] < 4 || cp[2] > optlen - (sizeof (long) - 1))
                                break;
                        sin = (struct in_addr *)(cp + cp[2]);
                        if (cp[2] < 4 || cp[2] > optlen - (sizeof (long) - 1))
                                break;
                        sin = (struct in_addr *)(cp + cp[2]);
-                       if (n_lhost.s_addr == *(u_long *)sin) {
-                               if (opt == IPOPT_SSRR) {
-                                       /* MAKE SURE *SP DIRECTLY ACCESSIBLE */
-                               }
-                               ip->ip_dst = *sin;
-                               *sin = n_lhost;
-                               cp[2] += 4;
+                       ifp = if_ifwithaddr(*sin);
+                       if (ifp == 0) {
+                               if (opt == IPOPT_SSRR)
+                                       goto bad;
+                               break;
                        }
                        }
+                       t = ip->ip_dst; ip->ip_dst = *sin; *sin = t;
+                       cp[2] += 4;
+                       if (cp[2] > optlen - (sizeof (long) - 1))
+                               break;
+                       ip->ip_dst = sin[1];
+                       if (opt == IPOPT_SSRR && if_ifonnetof(ip->ip_dst)==0)
+                               goto bad;
                        break;
 
                case IPOPT_TS:
                        break;
 
                case IPOPT_TS:
@@ -415,12 +447,13 @@ ip_dooptions(ip)
                        case IPOPT_TS_TSANDADDR:
                                if (ipt->ipt_ptr + 8 > ipt->ipt_len)
                                        goto bad;
                        case IPOPT_TS_TSANDADDR:
                                if (ipt->ipt_ptr + 8 > ipt->ipt_len)
                                        goto bad;
-                               *(struct in_addr *)sin++ = n_lhost;
+                               /* stamp with ``first'' interface address */
+                               *sin++ = ifnet->if_addr;
                                break;
 
                        case IPOPT_TS_PRESPEC:
                                break;
 
                        case IPOPT_TS_PRESPEC:
-                               if (*(u_long *)sin != n_lhost.s_addr)
-                                       break;
+                               if (if_ifwithaddr(*sin) == 0)
+                                       continue;
                                if (ipt->ipt_ptr + 8 > ipt->ipt_len)
                                        goto bad;
                                ipt->ipt_ptr += 4;
                                if (ipt->ipt_ptr + 8 > ipt->ipt_len)
                                        goto bad;
                                ipt->ipt_ptr += 4;
@@ -440,19 +473,25 @@ bad:
 }
 
 /*
 }
 
 /*
- * Strip out IP options, e.g. before passing
- * to higher level protocol in the kernel.
+ * Strip out IP options, at higher
+ * level protocol in the kernel.
+ * Second argument is buffer to which options
+ * will be moved, and return value is their length.
  */
  */
-ip_stripoptions(ip)
+ip_stripoptions(ip, cp)
        struct ip *ip;
        struct ip *ip;
+       char *cp;
 {
        register int i;
        register struct mbuf *m;
        int olen;
 {
        register int i;
        register struct mbuf *m;
        int olen;
-COUNT(IP_OPT);
+COUNT(IP_STRIPOPTIONS);
 
        olen = (ip->ip_hl<<2) - sizeof (struct ip);
 
        olen = (ip->ip_hl<<2) - sizeof (struct ip);
-       m = dtom(++ip);
+       m = dtom(ip);
+       ip++;
+       if (cp)
+               bcopy((caddr_t)ip, cp, (unsigned)olen);
        i = m->m_len - (sizeof (struct ip) + olen);
        bcopy((caddr_t)ip+olen, (caddr_t)ip, (unsigned)i);
        m->m_len -= i;
        i = m->m_len - (sizeof (struct ip) + olen);
        bcopy((caddr_t)ip+olen, (caddr_t)ip, (unsigned)i);
        m->m_len -= i;
index a02b6b1..77d51c8 100644 (file)
@@ -1,4 +1,4 @@
-/*     ip_output.c     1.14    81/11/18        */
+/*     ip_output.c     1.15    81/11/20        */
 
 #include "../h/param.h"
 #include "../h/mbuf.h"
 
 #include "../h/param.h"
 #include "../h/mbuf.h"
@@ -8,7 +8,6 @@
 #include "../net/inet.h"
 #include "../net/inet_systm.h"
 #include "../net/imp.h"
 #include "../net/inet.h"
 #include "../net/inet_systm.h"
 #include "../net/imp.h"
-#include "../net/inet_host.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 
@@ -62,7 +61,7 @@ COUNT(IP_OUTPUT);
                mh->m_off = MMAXOFF - hlen;
                mhip = mtod(mh, struct ip *);
                *mhip = *ip;
                mh->m_off = MMAXOFF - hlen;
                mhip = mtod(mh, struct ip *);
                *mhip = *ip;
-               if (ip->ip_hl > sizeof (struct ip) >> 2) {
+               if (hlen > sizeof (struct ip)) {
                        int olen = ip_optcopy(ip, mhip, off);
                        mh->m_len = sizeof (struct ip) + olen;
                } else
                        int olen = ip_optcopy(ip, mhip, off);
                        mh->m_len = sizeof (struct ip) + olen;
                } else
@@ -79,7 +78,7 @@ COUNT(IP_OUTPUT);
                        m_free(mh);
                        goto bad;
                }
                        m_free(mh);
                        goto bad;
                }
-               ip_send(mh);
+               ip_send(mhip);
        }
 bad:
        m_freem(m);
        }
 bad:
        m_freem(m);
@@ -87,7 +86,7 @@ bad:
 
 /*
  * Copy options from ip to jp.
 
 /*
  * Copy options from ip to jp.
- * If off is 0 all options are copies
+ * If off is 0 all options are copied
  * otherwise copy selectively.
  */
 ip_optcopy(ip, jp, off)
  * otherwise copy selectively.
  */
 ip_optcopy(ip, jp, off)
@@ -97,6 +96,7 @@ ip_optcopy(ip, jp, off)
        register u_char *cp, *dp;
        int opt, optlen, cnt;
 
        register u_char *cp, *dp;
        int opt, optlen, cnt;
 
+COUNT(IP_OPTCOPY);
        cp = (u_char *)(ip + 1);
        dp = (u_char *)(jp + 1);
        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
        cp = (u_char *)(ip + 1);
        dp = (u_char *)(jp + 1);
        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
@@ -111,7 +111,7 @@ ip_optcopy(ip, jp, off)
                if (optlen > cnt)                       /* XXX */
                        optlen = cnt;                   /* XXX */
                if (off == 0 || IPOPT_COPIED(opt)) {
                if (optlen > cnt)                       /* XXX */
                        optlen = cnt;                   /* XXX */
                if (off == 0 || IPOPT_COPIED(opt)) {
-                       bcopy(cp, dp, optlen);
+                       bcopy((caddr_t)cp, (caddr_t)dp, (unsigned)optlen);
                        dp += optlen;
                }
        }
                        dp += optlen;
                }
        }
@@ -120,6 +120,8 @@ ip_optcopy(ip, jp, off)
        return (optlen);
 }
 
        return (optlen);
 }
 
+/* REST OF CODE HERE IS GARBAGE */
+
 ip_send(ip)
        register struct ip *ip;
 {
 ip_send(ip)
        register struct ip *ip;
 {
@@ -161,3 +163,5 @@ COUNT(IP_SEND);
        setsoftnet();
 #endif IMPLOOP
 }
        setsoftnet();
 #endif IMPLOOP
 }
+
+/* END GARBAGE */
index e5e6bd7..34964dd 100644 (file)
@@ -1,4 +1,4 @@
-/* tcp_input.c 1.25 81/11/18 */
+/* tcp_input.c 1.26 81/11/20 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -9,7 +9,6 @@
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/imp.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/imp.h"
-#include "../net/inet_host.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 #include "../net/tcp.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 #include "../net/tcp.h"
@@ -23,6 +22,7 @@ tcp_drain()
 {
        register struct inpcb *ip;
 
 {
        register struct inpcb *ip;
 
+COUNT(TCP_DRAIN);
        for (ip = tcb.inp_next; ip != &tcb; ip = ip->inp_next)
                tcp_drainunack(intotcpcb(ip));
 }
        for (ip = tcb.inp_next; ip != &tcb; ip = ip->inp_next)
                tcp_drainunack(intotcpcb(ip));
 }
@@ -32,6 +32,7 @@ tcp_drainunack(tp)
 {
        register struct mbuf *m;
 
 {
        register struct mbuf *m;
 
+COUNT(TCP_DRAINUNACK);
        for (m = tp->seg_unack; m; m = m->m_act)
                m_freem(m);
        tp->seg_unack = 0;
        for (m = tp->seg_unack; m; m = m->m_act)
                m_freem(m);
        tp->seg_unack = 0;
@@ -41,9 +42,12 @@ tcp_ctlinput(m)
        struct mbuf *m;
 {
 
        struct mbuf *m;
 {
 
+COUNT(TCP_CTLINPUT);
        m_freem(m);
 }
 
        m_freem(m);
 }
 
+struct sockaddr_in tcp_sockaddr = { AF_INET };
+
 tcp_input(m0)
        struct mbuf *m0;
 {
 tcp_input(m0)
        struct mbuf *m0;
 {
@@ -68,7 +72,7 @@ COUNT(TCP_INPUT);
        m = m0;
        ti = mtod(m, struct tcpiphdr *);
        if (ti->ti_len > sizeof (struct ip))
        m = m0;
        ti = mtod(m, struct tcpiphdr *);
        if (ti->ti_len > sizeof (struct ip))
-               ip_stripoptions((struct ip *)ti);
+               ip_stripoptions((struct ip *)ti, (char *)0);
        if (m->m_len < sizeof (struct tcpiphdr) &&
            m_pullup(m, sizeof (struct tcpiphdr)) == 0) {
                tcpstat.tcps_hdrops++;
        if (m->m_len < sizeof (struct tcpiphdr) &&
            m_pullup(m, sizeof (struct tcpiphdr)) == 0) {
                tcpstat.tcps_hdrops++;
@@ -83,7 +87,7 @@ COUNT(TCP_INPUT);
        if (tcpcksum) {
                ti->ti_next = ti->ti_prev = 0;
                ti->ti_x1 = 0;
        if (tcpcksum) {
                ti->ti_next = ti->ti_prev = 0;
                ti->ti_x1 = 0;
-               ti->ti_len = htons(tlen);
+               ti->ti_len = htons((u_short)tlen);
                if (ti->ti_sum = inet_cksum(m, len)) {
                        tcpstat.tcps_badsum++;
                        printf("tcp cksum %x\ti", ti->ti_sum);
                if (ti->ti_sum = inet_cksum(m, len)) {
                        tcpstat.tcps_badsum++;
                        printf("tcp cksum %x\ti", ti->ti_sum);
@@ -111,7 +115,7 @@ COUNT(TCP_INPUT);
        ti->ti_dst.s_addr = ntohl(ti->ti_dst.s_addr);
        ti->ti_sport = ntohs(ti->ti_sport);
        ti->ti_dport = ntohs(ti->ti_dport);
        ti->ti_dst.s_addr = ntohl(ti->ti_dst.s_addr);
        ti->ti_sport = ntohs(ti->ti_sport);
        ti->ti_dport = ntohs(ti->ti_dport);
-       inp = in_pcblookup(&tcb, &ti->ti_src, ti->ti_sport, &ti->ti_dst, ti->ti_dport);
+       inp = in_pcblookup(&tcb, ti->ti_src, ti->ti_sport, ti->ti_dst, ti->ti_dport);
        if (inp == 0)
                goto notwanted;
        tp = intotcpcb(inp);            /* ??? */
        if (inp == 0)
                goto notwanted;
        tp = intotcpcb(inp);            /* ??? */
@@ -167,8 +171,7 @@ COUNT(TCP_INPUT);
                        tp->t_rexmt = 0;
                        tp->t_rexmttl = 0;
                        tp->t_persist = 0;
                        tp->t_rexmt = 0;
                        tp->t_rexmttl = 0;
                        tp->t_persist = 0;
-                       in_hostfree(inp->inp_fhost);
-                       inp->inp_fhost = 0;
+                       inp->inp_faddr.s_addr = 0;
                        tp->t_state = LISTEN;
                        goto bad;
 
                        tp->t_state = LISTEN;
                        goto bad;
 
@@ -236,12 +239,12 @@ good:
        switch (tp->t_state) {
 
        case LISTEN:
        switch (tp->t_state) {
 
        case LISTEN:
-               if ((tiflags&TH_SYN) == 0 ||
-                   ((inp->inp_lhost = in_hostalloc(&ti->ti_src)) == 0)) {
+               tcp_sockaddr.sin_addr = ti->ti_src;
+               tcp_sockaddr.sin_port = ti->ti_sport;
+               if ((tiflags&TH_SYN) == 0 || in_pcbsetpeer(inp, &tcp_sockaddr)) {
                        nstate = EFAILEC;
                        goto done;
                }
                        nstate = EFAILEC;
                        goto done;
                }
-               inp->inp_fport = ti->ti_sport;
                tp->t_template = tcp_template(tp);
                tcp_ctldat(tp, ti, 1);
                if (tp->tc_flags&TC_FIN_RCVD) {
                tp->t_template = tcp_template(tp);
                tcp_ctldat(tp, ti, 1);
                if (tp->tc_flags&TC_FIN_RCVD) {
@@ -410,7 +413,7 @@ done:
                        register struct mbuf *n;
                        /* inline expansion of m_freem */
                        while (m) {
                        register struct mbuf *n;
                        /* inline expansion of m_freem */
                        while (m) {
-                               MFREE(n, m);
+                               MFREE(m, n);
                                m = n;
                        }
                }
                                m = n;
                        }
                }
@@ -433,7 +436,7 @@ notwanted:
        if (tiflags&TH_ACK)
                ti->ti_seq = ti->ti_ackno;
        else {
        if (tiflags&TH_ACK)
                ti->ti_seq = ti->ti_ackno;
        else {
-               ti->ti_ackno = htonl(ntohl(ti->ti_seq) + ti->ti_len);
+               ti->ti_ackno = htonl((unsigned)(ntohl(ti->ti_seq) + ti->ti_len));
                ti->ti_seq = 0;
        }
        ti->ti_flags = ((tiflags & TH_ACK) ? 0 : TH_ACK) | TH_RST;
                ti->ti_seq = 0;
        }
        ti->ti_flags = ((tiflags & TH_ACK) ? 0 : TH_ACK) | TH_RST;
index afbe28a..5189618 100644 (file)
@@ -1,4 +1,4 @@
-/* tcp_output.c 4.14 81/11/18 */
+/*     tcp_output.c    4.15    81/11/20        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -6,7 +6,6 @@
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../net/inet.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../net/inet.h"
-#include "../net/inet_host.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/imp.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/imp.h"
@@ -120,7 +119,7 @@ COUNT(TCP_SEND);
                        forced = 1;
                } else if (tp->snd_nxt >= tp->snd_lst && (tp->tc_flags&TC_SND_FIN) == 0)
                        return (0);
                        forced = 1;
                } else if (tp->snd_nxt >= tp->snd_lst && (tp->tc_flags&TC_SND_FIN) == 0)
                        return (0);
-               m = m_copy(&so->so_snd,
+               m = m_copy(so->so_snd.sb_mb,
                      (int)(MAX(tp->iss+1,tp->snd_nxt) - tp->snd_off),
                      (int)(tp->snd_lst - tp->snd_off));
                if (tp->snd_end > tp->iss && tp->snd_end <= tp->snd_lst)
                      (int)(MAX(tp->iss+1,tp->snd_nxt) - tp->snd_off),
                      (int)(tp->snd_lst - tp->snd_off));
                if (tp->snd_end > tp->iss && tp->snd_end <= tp->snd_lst)
@@ -168,12 +167,10 @@ tcp_template(tp)
        struct tcpcb *tp;
 {
        register struct inpcb *inp = tp->t_inpcb;
        struct tcpcb *tp;
 {
        register struct inpcb *inp = tp->t_inpcb;
-       register struct in_host *h = inp->inp_fhost;
        register struct mbuf *m;
        register struct tcpiphdr *n;
 
        register struct mbuf *m;
        register struct tcpiphdr *n;
 
-       if (h == 0)
-               return (0);
+COUNT(TCP_TEMPLATE);
        m = m_get(1);
        if (m == 0)
                return (0);
        m = m_get(1);
        if (m == 0)
                return (0);
@@ -184,8 +181,8 @@ tcp_template(tp)
        n->ti_x1 = 0;
        n->ti_pr = IPPROTO_TCP;
        n->ti_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip));
        n->ti_x1 = 0;
        n->ti_pr = IPPROTO_TCP;
        n->ti_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip));
-       n->ti_src.s_addr = n_lhost.s_addr;
-       n->ti_dst.s_addr = h->h_addr.s_addr;
+       n->ti_src = inp->inp_laddr;
+       n->ti_dst = inp->inp_faddr;
        n->ti_sport = htons(inp->inp_lport);
        n->ti_dport = htons(inp->inp_fport);
        n->ti_seq = 0;
        n->ti_sport = htons(inp->inp_lport);
        n->ti_dport = htons(inp->inp_fport);
        n->ti_seq = 0;
@@ -209,7 +206,6 @@ tcp_output(tp, flags, len, dat)
        register struct mbuf *m;
        struct socket *so = tp->t_inpcb->inp_socket;
        register struct ip *ip;
        register struct mbuf *m;
        struct socket *so = tp->t_inpcb->inp_socket;
        register struct ip *ip;
-       int i;
 #ifdef TCPDEBUG
        struct tcp_debug tdb;
 #endif
 #ifdef TCPDEBUG
        struct tcp_debug tdb;
 #endif
@@ -275,4 +271,6 @@ COUNT(TCP_OUTPUT);
 tcp_fasttimo()
 {
 
 tcp_fasttimo()
 {
 
+COUNT(TCP_FASTTIMO);
+       /* someday do delayed ack processing here */
 }
 }
index 8e7f55a..43722f0 100644 (file)
@@ -1,4 +1,4 @@
-/* tcp_usrreq.c 1.30 81/11/18 */
+/* tcp_usrreq.c 1.31 81/11/20 */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -7,9 +7,9 @@
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
 #include "../net/inet.h"
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
 #include "../net/inet.h"
-#include "../net/inet_host.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
+#include "../net/if.h"
 #include "../net/imp.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 #include "../net/imp.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
@@ -87,6 +87,7 @@ tcp_tcancel(tp)
                *tmp++ = 0;
 }
 
                *tmp++ = 0;
 }
 
+struct tcpcb *tcp_newtcpcb();
 /*
  * Process a TCP user request for tcp tb.  If this is a send request
  * then m is the mbuf chain of send data.  If this is a timer expiration
 /*
  * Process a TCP user request for tcp tb.  If this is a send request
  * then m is the mbuf chain of send data.  If this is a timer expiration
@@ -138,17 +139,26 @@ COUNT(TCP_USRREQ);
        switch (req) {
 
        case PRU_ATTACH:
        switch (req) {
 
        case PRU_ATTACH:
-               if (tp) {
+               if (inp) {
                        error = EISCONN;
                        break;
                }
                        error = EISCONN;
                        break;
                }
-               tcp_attach(so);
-               tp = sototcpcb(so);
-               if (so->so_options & SO_ACCEPTCONN) {
-                       inp->inp_lhost = in_hostalloc(&n_lhost);        /*XXX*/
-                       inp->inp_lport = in_pcbgenport(&tcb);
+               tp = tcp_newtcpcb();
+               if (tp == 0) {
+                       error = ENOBUFS;
+                       break;
+               }
+               error = in_pcballoc(so, &tcb, 2048, 2048, (struct sockaddr_in *)addr);
+               if (error) {
+                       m_free(dtom(tp));
+                       break;
+               }
+               inp = (struct inpcb *)so->so_pcb;
+               tp->t_inpcb = inp;
+               inp->inp_ppcb = (caddr_t)tp;
+               if (so->so_options & SO_ACCEPTCONN)
                        nstate = LISTEN;
                        nstate = LISTEN;
-               else
+               else
                        nstate = CLOSED;
                break;
 
                        nstate = CLOSED;
                break;
 
@@ -159,8 +169,8 @@ COUNT(TCP_USRREQ);
        case PRU_CONNECT:
                if (tp->t_state != 0 && tp->t_state != CLOSED)
                        goto bad;
        case PRU_CONNECT:
                if (tp->t_state != 0 && tp->t_state != CLOSED)
                        goto bad;
-               inp->inp_fhost = in_hosteval((struct sockaddr *)addr, &error);
-               if (inp->inp_fhost == 0)
+               error = in_pcbsetpeer(inp, (struct sockaddr_in *)addr);
+               if (error)
                        break;
                (void) tcp_sndctl(tp);
                nstate = SYN_SENT;
                        break;
                (void) tcp_sndctl(tp);
                nstate = SYN_SENT;
@@ -168,7 +178,8 @@ COUNT(TCP_USRREQ);
                break;
 
        case PRU_ACCEPT:
                break;
 
        case PRU_ACCEPT:
-               return (EOPNOTSUPP);            /* XXX */
+               soisconnected(so);
+               break;
 
        case PRU_DISCONNECT:
                if ((tp->tc_flags & TC_FIN_RCVD) == 0)
 
        case PRU_DISCONNECT:
                if ((tp->tc_flags & TC_FIN_RCVD) == 0)
@@ -297,11 +308,16 @@ abort:
        return (error);
 }
 
        return (error);
 }
 
-tcp_attach(so)
-       struct socket *so;
+struct tcpcb *
+tcp_newtcpcb()
 {
 {
-       register struct tcpcb *tp = sototcpcb(so);
-COUNT(TCP_ATTACH);
+       struct mbuf *m = m_getclr(0);
+       register struct tcpcb *tp;
+COUNT(TCP_NEWTCPCB);
+
+       if (m == 0)
+               return (0);
+       tp = mtod(m, struct tcpcb *);
 
        /*
         * Make empty reassembly queue.
 
        /*
         * Make empty reassembly queue.
@@ -316,6 +332,7 @@ COUNT(TCP_ATTACH);
            tp->iss = tcp_iss;
        tp->snd_off = tp->iss + 1;
        tcp_iss += (ISSINCR >> 1) + 1;
            tp->iss = tcp_iss;
        tp->snd_off = tp->iss + 1;
        tcp_iss += (ISSINCR >> 1) + 1;
+       return (tp);
 }
 
 tcp_detach(tp)
 }
 
 tcp_detach(tp)
@@ -332,6 +349,7 @@ tcp_disconnect(tp)
 {
        register struct tcpiphdr *t;
 
 {
        register struct tcpiphdr *t;
 
+COUNT(TCP_DISCONNECT);
        tcp_tcancel(tp);
        t = tp->seg_next;
        for (; t != (struct tcpiphdr *)tp; t = (struct tcpiphdr *)t->ti_next)
        tcp_tcancel(tp);
        t = tp->seg_next;
        for (; t != (struct tcpiphdr *)tp; t = (struct tcpiphdr *)t->ti_next)
@@ -348,6 +366,7 @@ tcp_abort(tp)
        register struct tcpcb *tp;
 {
 
        register struct tcpcb *tp;
 {
 
+COUNT(TCP_ABORT);
        switch (tp->t_state) {
 
        case SYN_RCVD:
        switch (tp->t_state) {
 
        case SYN_RCVD:
@@ -458,6 +477,7 @@ tcp_sense(m)
        struct mbuf *m;
 {
 
        struct mbuf *m;
 {
 
+COUNT(TCP_SENSE);
        return (EOPNOTSUPP);
 }
 
        return (EOPNOTSUPP);
 }
 
@@ -466,8 +486,8 @@ tcp_error(tp, errno)
        int errno;
 {
        struct socket *so = tp->t_inpcb->inp_socket;
        int errno;
 {
        struct socket *so = tp->t_inpcb->inp_socket;
-COUNT(TCP_ERROR);
 
 
+COUNT(TCP_ERROR);
        so->so_error = errno;
        sorwakeup(so);
        sowwakeup(so);
        so->so_error = errno;
        sorwakeup(so);
        sowwakeup(so);
index 0674bbe..85ef543 100644 (file)
@@ -1,4 +1,4 @@
-/*     udp_usrreq.c    4.6     81/11/18        */
+/*     udp_usrreq.c    4.7     81/11/20        */
 
 #include "../h/param.h"
 #include "../h/dir.h"
 
 #include "../h/param.h"
 #include "../h/dir.h"
@@ -8,7 +8,6 @@
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../net/inet.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../net/inet.h"
-#include "../net/inet_host.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/ip.h"
 #include "../net/inet_pcb.h"
 #include "../net/inet_systm.h"
 #include "../net/ip.h"
@@ -43,7 +42,7 @@ udp_input(m0)
        m = m0;
        ui = mtod(m, struct udpiphdr *);
        if (ui->ui_len > sizeof (struct ip))
        m = m0;
        ui = mtod(m, struct udpiphdr *);
        if (ui->ui_len > sizeof (struct ip))
-               ip_stripoptions((struct ip *)ui);
+               ip_stripoptions((struct ip *)ui, (char *)0);
        if (m->m_len < sizeof (struct udpiphdr) &&
            m_pullup(m, sizeof (struct udpiphdr)) == 0) {
                udpstat.udps_hdrops++;
        if (m->m_len < sizeof (struct udpiphdr) &&
            m_pullup(m, sizeof (struct udpiphdr)) == 0) {
                udpstat.udps_hdrops++;
@@ -54,7 +53,7 @@ udp_input(m0)
         * Make mbuf data length reflect udp length.
         * If not enough data to reflect udp length, drop.
         */
         * Make mbuf data length reflect udp length.
         * If not enough data to reflect udp length, drop.
         */
-       ulen = ntohs(ui->ui_ulen);
+       ulen = ntohs((u_short)ui->ui_ulen);
        len = sizeof (struct udpiphdr) + ulen;
        if (((struct ip *)ui)->ip_len != len) {
                if (len > ((struct ip *)ui)->ip_len) {
        len = sizeof (struct udpiphdr) + ulen;
        if (((struct ip *)ui)->ip_len != len) {
                if (len > ((struct ip *)ui)->ip_len) {
@@ -71,7 +70,7 @@ udp_input(m0)
        if (udpcksum) {
                ui->ui_next = ui->ui_prev = 0;
                ui->ui_x1 = 0;
        if (udpcksum) {
                ui->ui_next = ui->ui_prev = 0;
                ui->ui_x1 = 0;
-               ui->ui_len = htons(sizeof (struct udpiphdr) + ulen);
+               ui->ui_len = htons((u_short)(sizeof (struct udpiphdr) + ulen));
                if (ui->ui_sum = inet_cksum(m, len)) {
                        udpstat.udps_badsum++;
                        printf("udp cksum %x\n", ui->ui_sum);
                if (ui->ui_sum = inet_cksum(m, len)) {
                        udpstat.udps_badsum++;
                        printf("udp cksum %x\n", ui->ui_sum);
@@ -99,7 +98,7 @@ udp_input(m0)
         */
        udp_in.sin_port = ui->ui_sport;
        udp_in.sin_addr = ui->ui_src;
         */
        udp_in.sin_port = ui->ui_sport;
        udp_in.sin_addr = ui->ui_src;
-       if (sbappendaddr(inp->inp_socket, &udp_in, m) == 0)
+       if (sbappendaddr(&inp->inp_socket->so_snd, (struct sockaddr *)&udp_in, m) == 0)
                goto bad;
        return;
 bad:
                goto bad;
        return;
 bad:
@@ -114,10 +113,8 @@ udp_ctlinput(m)
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
-udp_output(inp, raddr, rport, m0)
+udp_output(inp, m0)
        struct inpcb *inp;
        struct inpcb *inp;
-       struct in_addr *raddr;
-       u_short rport;
        struct mbuf *m0;
 {
        register struct mbuf *m;
        struct mbuf *m0;
 {
        register struct mbuf *m;
@@ -145,12 +142,12 @@ udp_output(inp, raddr, rport, m0)
        ui->ui_next = ui->ui_prev = 0;
        ui->ui_x1 = 0;
        ui->ui_pr = IPPROTO_UDP;
        ui->ui_next = ui->ui_prev = 0;
        ui->ui_x1 = 0;
        ui->ui_pr = IPPROTO_UDP;
-       ui->ui_len = htons(sizeof (struct udphdr) + len);
-       ui->ui_src.s_addr = htonl(inp->inp_lhost);
-       ui->ui_dst.s_addr = htonl(raddr->s_addr);
+       ui->ui_len = htons((u_short)(sizeof (struct udphdr) + len));
+       ui->ui_src.s_addr = htonl(inp->inp_laddr.s_addr);
+       ui->ui_dst.s_addr = htonl(inp->inp_faddr.s_addr);
        ui->ui_sport = htons(inp->inp_lport);
        ui->ui_dport = htons(inp->inp_fport);
        ui->ui_sport = htons(inp->inp_lport);
        ui->ui_dport = htons(inp->inp_fport);
-       ui->ui_ulen = htons(len);
+       ui->ui_ulen = htons((u_short)len);
 
        /*
         * Stuff checksum and output datagram.
 
        /*
         * Stuff checksum and output datagram.
@@ -171,7 +168,6 @@ udp_usrreq(so, req, m, addr)
        caddr_t addr;
 {
        struct inpcb *inp = sotoinpcb(so);
        caddr_t addr;
 {
        struct inpcb *inp = sotoinpcb(so);
-       struct sockaddr_in *sin;
        int error;
 
        switch (req) {
        int error;
 
        switch (req) {
@@ -179,9 +175,9 @@ udp_usrreq(so, req, m, addr)
        case PRU_ATTACH:
                if (inp != 0)
                        return (EINVAL);
        case PRU_ATTACH:
                if (inp != 0)
                        return (EINVAL);
-               inp = in_pcballoc();
-               if (inp == NULL)
-                       return (ENOBUFS);
+               error = in_pcballoc(so, &udb, 2048, 2048, (struct sockaddr_in *)addr);
+               if (error)
+                       return (error);
                so->so_pcb = (caddr_t)inp;
                break;
 
                so->so_pcb = (caddr_t)inp;
                break;
 
@@ -192,10 +188,10 @@ udp_usrreq(so, req, m, addr)
                break;
 
        case PRU_CONNECT:
                break;
 
        case PRU_CONNECT:
-               if (inp->inp_fhost)
+               if (inp->inp_faddr.s_addr)
                        return (EISCONN);
                        return (EISCONN);
-               in_hosteval(inp, (struct sockaddr *)addr, &error);
-               if (inp->inp_fhost == 0)
+               error = in_pcbsetpeer(inp, (struct sockaddr_in *)addr);
+               if (error)
                        return (error);
                soisconnected(so);
                break;
                        return (error);
                soisconnected(so);
                break;
@@ -204,10 +200,9 @@ udp_usrreq(so, req, m, addr)
                return (EOPNOTSUPP);
 
        case PRU_DISCONNECT:
                return (EOPNOTSUPP);
 
        case PRU_DISCONNECT:
-               if (inp->inp_fhost == 0)
+               if (inp->inp_faddr.s_addr == 0)
                        return (ENOTCONN);
                        return (ENOTCONN);
-               in_hostfree(inp->inp_fhost);
-               inp->inp_fhost = 0;
+               inp->inp_faddr.s_addr = 0;
                soisdisconnected(so);
                break;
 
                soisdisconnected(so);
                break;
 
@@ -217,15 +212,18 @@ udp_usrreq(so, req, m, addr)
 
        case PRU_SEND:
                if (addr) {
 
        case PRU_SEND:
                if (addr) {
-                       if (inp->inp_fhost)
+                       if (inp->inp_faddr.s_addr)
                                return (EISCONN);
                                return (EISCONN);
-                       sin = (struct sockaddr_in *)addr;
-                       if (sin->sin_family != AF_INET)
-                               return (EAFNOSUPPORT);
-                       udp_output(inp, sin->sin_addr, sin->sin_port, m);
-               } else
-                       udp_output(inp,
-                           inp->inp_fhost->h_addr, inp->inp_fport, m);
+                       error = in_pcbsetpeer(inp, (struct sockaddr_in *)addr);
+                       if (error)
+                               return (error);
+               } else {
+                       if (inp->inp_faddr.s_addr == 0)
+                               return (ENOTCONN);
+               }
+               udp_output(inp, m);
+               if (addr)
+                       inp->inp_faddr.s_addr = 0;
                break;
 
        case PRU_ABORT:
                break;
 
        case PRU_ABORT:
@@ -243,9 +241,10 @@ udp_usrreq(so, req, m, addr)
        return (0);
 }
 
        return (0);
 }
 
+/*ARGSUSED*/
 udp_sense(m)
        struct mbuf *m;
 {
 udp_sense(m)
        struct mbuf *m;
 {
-       return (EOPNOTSUPP);
 
 
+       return (EOPNOTSUPP);
 }
 }
index 52c7e8b..b290fa0 100644 (file)
@@ -1,4 +1,4 @@
-/* socketvar.h 4.5 81/11/18 */
+/* socketvar.h 4.6 81/11/20 */
 
 /*
  * Kernel structure per socket.
 
 /*
  * Kernel structure per socket.
@@ -10,7 +10,6 @@ struct socket {
        short   so_type;                /* generic type, see socket.h */
        short   so_options;             /* from socket call, see socket.h */
        short   so_state;               /* internal state flags SS_*, below */
        short   so_type;                /* generic type, see socket.h */
        short   so_options;             /* from socket call, see socket.h */
        short   so_state;               /* internal state flags SS_*, below */
-       short   so_isfilerefd;          /* no file table reference */
        caddr_t so_pcb;                 /* protocol control block */
        struct  protosw *so_proto;      /* protocol handle */
        struct  sockbuf {
        caddr_t so_pcb;                 /* protocol control block */
        struct  protosw *so_proto;      /* protocol handle */
        struct  sockbuf {
@@ -39,11 +38,11 @@ struct socket {
  */
 #define        SS_USERGONE             0x01    /* no file table ref any more */
 #define        SS_ISCONNECTED          0x02    /* socket connected to a peer */
  */
 #define        SS_USERGONE             0x01    /* no file table ref any more */
 #define        SS_ISCONNECTED          0x02    /* socket connected to a peer */
-#define        SS_ISCONNECTING         0x03    /* in process of connecting to peer */
-#define        SS_ISDISCONNECTING      0x04    /* in process of disconnecting */
-#define        SS_CANTSENDMORE         0x08    /* can't send more data to peer */
-#define        SS_CANTRCVMORE          0x10    /* can't receive more data from peer */
-#define        SS_CONNAWAITING         0x20    /* connections awaiting acceptance */
+#define        SS_ISCONNECTING         0x04    /* in process of connecting to peer */
+#define        SS_ISDISCONNECTING      0x08    /* in process of disconnecting */
+#define        SS_CANTSENDMORE         0x10    /* can't send more data to peer */
+#define        SS_CANTRCVMORE          0x20    /* can't receive more data from peer */
+#define        SS_CONNAWAITING         0x40    /* connections awaiting acceptance */
 
 /*
  * Macros for sockets and socket buffering.
 
 /*
  * Macros for sockets and socket buffering.
@@ -101,7 +100,3 @@ struct socket {
 
 #define        sorwakeup(so)   sbwakeup(&(so)->so_rcv)
 #define        sowwakeup(so)   sbwakeup(&(so)->so_snd)
 
 #define        sorwakeup(so)   sbwakeup(&(so)->so_rcv)
 #define        sowwakeup(so)   sbwakeup(&(so)->so_snd)
-
-#ifdef KERNEL
-struct mbuf *sbcopy();
-#endif