sun purge
[unix-history] / usr / src / sys / netinet / tcp_output.c
index 2b855d0..c89935d 100644 (file)
@@ -1,4 +1,4 @@
-/*     tcp_output.c    4.42    82/06/20        */
+/*     tcp_output.c    4.55    83/05/27        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -6,34 +6,28 @@
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/socketvar.h"
-#include "../net/in.h"
+#include "../h/errno.h"
+
 #include "../net/route.h"
 #include "../net/route.h"
-#include "../net/in_pcb.h"
-#include "../net/in_systm.h"
-#include "../net/ip.h"
-#include "../net/ip_var.h"
-#include "../net/tcp.h"
-#define        TCPOUTFLAGS
-#include "../net/tcp_fsm.h"
-#include "../net/tcp_seq.h"
-#include "../net/tcp_timer.h"
-#include "../net/tcp_var.h"
-#include "../net/tcpip.h"
-#include "../net/tcp_debug.h"
-#include <errno.h>
 
 
-char *tcpstates[]; /* XXX */
+#include "../netinet/in.h"
+#include "../netinet/in_pcb.h"
+#include "../netinet/in_systm.h"
+#include "../netinet/ip.h"
+#include "../netinet/ip_var.h"
+#include "../netinet/tcp.h"
+#define        TCPOUTFLAGS
+#include "../netinet/tcp_fsm.h"
+#include "../netinet/tcp_seq.h"
+#include "../netinet/tcp_timer.h"
+#include "../netinet/tcp_var.h"
+#include "../netinet/tcpip.h"
+#include "../netinet/tcp_debug.h"
 
 /*
 
 /*
- * Initial options: indicate max segment length 1/2 of space
- * allocated for receive; if TCPTRUEOOB is defined, indicate
- * willingness to do true out-of-band.
+ * Initial options.
  */
  */
-#ifndef TCPTRUEOOB
 u_char tcp_initopt[4] = { TCPOPT_MAXSEG, 4, 0x0, 0x0, };
 u_char tcp_initopt[4] = { TCPOPT_MAXSEG, 4, 0x0, 0x0, };
-#else
-u_char tcp_initopt[6] = { TCPOPT_MAXSEG, 4, 0x0, 0x0, TCPOPT_WILLOOB, 2 };
-#endif
 
 /*
  * Tcp output routine: figure out what should be sent and send it.
 
 /*
  * Tcp output routine: figure out what should be sent and send it.
@@ -51,7 +45,6 @@ tcp_output(tp)
        unsigned optlen = 0;
        int sendalot;
 
        unsigned optlen = 0;
        int sendalot;
 
-
        /*
         * Determine length of data that should be transmitted,
         * and flags that will be used.
        /*
         * Determine length of data that should be transmitted,
         * and flags that will be used.
@@ -97,13 +90,6 @@ again:
        if (tp->t_flags&TF_ACKNOW)
                goto send;
 
        if (tp->t_flags&TF_ACKNOW)
                goto send;
 
-#ifdef TCPTRUEOOB
-       /*
-        * Send if an out of band data or ack should be transmitted.
-        */
-       if (tp->t_oobflags&(TCPOOB_OWEACK|TCPOOB_NEEDACK)))
-               goto send;
-#endif
 
        /*
         * Calculate available window in i, and also amount
 
        /*
         * Calculate available window in i, and also amount
@@ -154,8 +140,8 @@ send:
         * be transmitted, and initialize the header from
         * the template for sends on this connection.
         */
         * be transmitted, and initialize the header from
         * the template for sends on this connection.
         */
-       MGET(m, 0);
-       if (m == 0)
+       MGET(m, M_DONTWAIT, MT_HEADER);
+       if (m == NULL)
                return (ENOBUFS);
        m->m_off = MMAXOFF - sizeof (struct tcpiphdr);
        m->m_len = sizeof (struct tcpiphdr);
                return (ENOBUFS);
        m->m_off = MMAXOFF - sizeof (struct tcpiphdr);
        m->m_len = sizeof (struct tcpiphdr);
@@ -175,10 +161,8 @@ send:
         */
        ti->ti_seq = tp->snd_nxt;
        ti->ti_ack = tp->rcv_nxt;
         */
        ti->ti_seq = tp->snd_nxt;
        ti->ti_ack = tp->rcv_nxt;
-#if vax
        ti->ti_seq = htonl(ti->ti_seq);
        ti->ti_ack = htonl(ti->ti_ack);
        ti->ti_seq = htonl(ti->ti_seq);
        ti->ti_ack = htonl(ti->ti_ack);
-#endif
        /*
         * Before ESTABLISHED, force sending of initial options
         * unless TCP set to not do any options.
        /*
         * Before ESTABLISHED, force sending of initial options
         * unless TCP set to not do any options.
@@ -188,24 +172,17 @@ send:
                        goto noopt;
                opt = tcp_initopt;
                optlen = sizeof (tcp_initopt);
                        goto noopt;
                opt = tcp_initopt;
                optlen = sizeof (tcp_initopt);
-               *(u_short *)(opt + 2) = so->so_rcv.sb_hiwat / 2;
-#if vax
+               *(u_short *)(opt + 2) = MIN(so->so_rcv.sb_hiwat / 2, 1024);
                *(u_short *)(opt + 2) = htons(*(u_short *)(opt + 2));
                *(u_short *)(opt + 2) = htons(*(u_short *)(opt + 2));
-#endif
        } else {
                if (tp->t_tcpopt == 0)
                        goto noopt;
                opt = mtod(tp->t_tcpopt, u_char *);
                optlen = tp->t_tcpopt->m_len;
        }
        } else {
                if (tp->t_tcpopt == 0)
                        goto noopt;
                opt = mtod(tp->t_tcpopt, u_char *);
                optlen = tp->t_tcpopt->m_len;
        }
-#ifndef TCPTRUEOOB
-       if (opt)
-#else
-       if (opt || (tp->t_oobflags&(TCPOOB_OWEACK|TCPOOB_NEEDACK)))
-#endif
-       {
+       if (opt) {
                m0 = m->m_next;
                m0 = m->m_next;
-               m->m_next = m_get(M_DONTWAIT);
+               m->m_next = m_get(M_DONTWAIT, MT_DATA);
                if (m->m_next == 0) {
                        (void) m_free(m);
                        m_freem(m0);
                if (m->m_next == 0) {
                        (void) m_free(m);
                        m_freem(m0);
@@ -213,35 +190,9 @@ send:
                }
                m->m_next->m_next = m0;
                m0 = m->m_next;
                }
                m->m_next->m_next = m0;
                m0 = m->m_next;
-               m0->m_off = MMINOFF;
                m0->m_len = optlen;
                bcopy((caddr_t)opt, mtod(m0, caddr_t), optlen);
                opt = (u_char *)(mtod(m0, caddr_t) + optlen);
                m0->m_len = optlen;
                bcopy((caddr_t)opt, mtod(m0, caddr_t), optlen);
                opt = (u_char *)(mtod(m0, caddr_t) + optlen);
-#ifdef TCPTRUEOOB
-               if (tp->t_oobflags&TCPOOB_OWEACK) {
-printf("tp %x send OOBACK for %x\n", tp->t_iobseq);
-                       *opt++ = TCPOPT_OOBACK;
-                       *opt++ = 3;
-                       *opt++ = tp->t_iobseq;
-                       m0->m_len += 3;
-                       tp->t_oobflags &= ~TCPOOB_OWEACK;
-                       /* sender should rexmt oob to force ack repeat */
-               }
-               if (tp->t_oobflags&TCPOOB_NEEDACK) {
-printf("tp %x send OOBDATA seq %x data %x\n", tp->t_oobseq, tp->t_oobc);
-                       *opt++ = TCPOPT_OOBDATA;
-                       *opt++ = 8;
-                       *opt++ = tp->t_oobseq;
-                       *opt++ = tp->t_oobc;
-                       *(tcp_seq *)opt = tp->t_oobmark - tp->snd_nxt;
-#ifdef vax
-                       *(tcp_seq *)opt = htonl((unsigned)*(tcp_seq *)opt);
-#endif
-                       m0->m_len += 8;
-                       TCPT_RANGESET(tp->t_timer[TCPT_OOBREXMT],
-                           tcp_beta * tp->t_srtt, TCPTV_MIN, TCPTV_MAX);
-               }
-#endif
                while (m0->m_len & 0x3) {
                        *opt++ = TCPOPT_EOL;
                        m0->m_len++;
                while (m0->m_len & 0x3) {
                        *opt++ = TCPOPT_EOL;
                        m0->m_len++;
@@ -255,16 +206,10 @@ noopt:
        if (win < so->so_rcv.sb_hiwat / 4)      /* avoid silly window */
                win = 0;
        if (win > 0)
        if (win < so->so_rcv.sb_hiwat / 4)      /* avoid silly window */
                win = 0;
        if (win > 0)
-#if vax
                ti->ti_win = htons((u_short)win);
                ti->ti_win = htons((u_short)win);
-#else
-               ti->ti_win = win;
-#endif
        if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
                ti->ti_urp = tp->snd_up - tp->snd_nxt;
        if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
                ti->ti_urp = tp->snd_up - tp->snd_nxt;
-#if vax
                ti->ti_urp = htons(ti->ti_urp);
                ti->ti_urp = htons(ti->ti_urp);
-#endif
                ti->ti_flags |= TH_URG;
        } else
                /*
                ti->ti_flags |= TH_URG;
        } else
                /*
@@ -274,7 +219,13 @@ noopt:
                 * number wraparound.
                 */
                tp->snd_up = tp->snd_una;               /* drag it along */
                 * number wraparound.
                 */
                tp->snd_up = tp->snd_una;               /* drag it along */
-       /* PUSH */
+       /*
+        * If anything to send and we can send it all, set PUSH.
+        * (This will keep happy those implementations which only
+        * give data to the user when a buffer fills or a PUSH comes in.)
+        */
+       if (len && off+len == so->so_snd.sb_cc)
+               ti->ti_flags |= TH_PUSH;
 
        /*
         * Put TCP length in extended header, and then
 
        /*
         * Put TCP length in extended header, and then
@@ -282,9 +233,7 @@ noopt:
         */
        if (len + optlen) {
                ti->ti_len = sizeof (struct tcphdr) + optlen + len;
         */
        if (len + optlen) {
                ti->ti_len = sizeof (struct tcphdr) + optlen + len;
-#if vax
                ti->ti_len = htons((u_short)ti->ti_len);
                ti->ti_len = htons((u_short)ti->ti_len);
-#endif
        }
        ti->ti_sum = in_cksum(m, sizeof (struct tcpiphdr) + (int)optlen + len);
 
        }
        ti->ti_sum = in_cksum(m, sizeof (struct tcpiphdr) + (int)optlen + len);
 
@@ -343,8 +292,12 @@ noopt:
         */
        ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + optlen + len;
        ((struct ip *)ti)->ip_ttl = TCP_TTL;
         */
        ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + optlen + len;
        ((struct ip *)ti)->ip_ttl = TCP_TTL;
-       if (error = ip_output(m, tp->t_ipopt, (so->so_options & SO_DONTROUTE) ?
-           &routetoif : &tp->t_inpcb->inp_route, 0))
+       if (so->so_options & SO_DONTROUTE)
+               error =
+                  ip_output(m, tp->t_ipopt, (struct route *)0, IP_ROUTETOIF);
+       else
+               error = ip_output(m, tp->t_ipopt, &tp->t_inpcb->inp_route, 0);
+       if (error)
                return (error);
 
        /*
                return (error);
 
        /*