BSD 4_3_Tahoe release
[unix-history] / usr / src / sys / netinet / tcp_output.c
index 1b69eb5..38f3d17 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * Copyright (c) 1982, 1986 Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)tcp_output.c        7.18 (Berkeley) %G%
+ *     @(#)tcp_output.c        7.17 (Berkeley) 6/29/88
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "malloc.h"
 #include "mbuf.h"
 #include "protosw.h"
 #include "socket.h"
 #include "mbuf.h"
 #include "protosw.h"
 #include "socket.h"
@@ -73,7 +72,7 @@ tcp_output(tp)
 again:
        sendalot = 0;
        off = tp->snd_nxt - tp->snd_una;
 again:
        sendalot = 0;
        off = tp->snd_nxt - tp->snd_una;
-       win = min(tp->snd_wnd, tp->snd_cwnd);
+       win = MIN(tp->snd_wnd, tp->snd_cwnd);
 
        /*
         * If in persist timeout with window of 0, send 1 byte.
 
        /*
         * If in persist timeout with window of 0, send 1 byte.
@@ -90,7 +89,7 @@ again:
                }
        }
 
                }
        }
 
-       len = min(so->so_snd.sb_cc, win) - off;
+       len = MIN(so->so_snd.sb_cc, win) - off;
        flags = tcp_outflags[tp->t_state];
 
        if (len < 0) {
        flags = tcp_outflags[tp->t_state];
 
        if (len < 0) {
@@ -216,12 +215,13 @@ 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.
         */
-       MGETHDR(m, M_DONTWAIT, MT_HEADER);
+       MGET(m, M_DONTWAIT, MT_HEADER);
        if (m == NULL)
                return (ENOBUFS);
        if (m == NULL)
                return (ENOBUFS);
-       m->m_data += max_linkhdr;
+#define        MAXLINKHDR      32              /* belongs elsewhere */
+#define        DATASPACE  (MMAXOFF - (MMINOFF + MAXLINKHDR + sizeof (struct tcpiphdr)))
+       m->m_off = MMINOFF + MAXLINKHDR;
        m->m_len = sizeof (struct tcpiphdr);
        m->m_len = sizeof (struct tcpiphdr);
-       m->m_pkthdr.rcvif = (struct ifnet *)0;
        ti = mtod(m, struct tcpiphdr *);
        if (len) {
                if (tp->t_force && len == 1)
        ti = mtod(m, struct tcpiphdr *);
        if (len) {
                if (tp->t_force && len == 1)
@@ -233,7 +233,12 @@ send:
                        tcpstat.tcps_sndpack++;
                        tcpstat.tcps_sndbyte += len;
                }
                        tcpstat.tcps_sndpack++;
                        tcpstat.tcps_sndbyte += len;
                }
-               if (len <= MHLEN - sizeof (struct tcpiphdr) - max_linkhdr) {
+               if (len <= DATASPACE) {
+                       m_copydata(so->so_snd.sb_mb, off, (int) len,
+                           mtod(m, caddr_t) + sizeof(struct tcpiphdr));
+                       m->m_len += len;
+               } else {
+                       m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
                        if (m->m_next == 0)
                                len = 0;
                }
                        if (m->m_next == 0)
                                len = 0;
                }
@@ -268,7 +273,7 @@ send:
        if (flags & TH_SYN && (tp->t_flags & TF_NOOPT) == 0) {
                u_short mss;
 
        if (flags & TH_SYN && (tp->t_flags & TF_NOOPT) == 0) {
                u_short mss;
 
-               mss = min(so->so_rcv.sb_hiwat / 2, tcp_mss(tp));
+               mss = MIN(so->so_rcv.sb_hiwat / 2, tcp_mss(tp));
                if (mss > IP_MSS - sizeof(struct tcpiphdr)) {
                        opt = tcp_initopt;
                        optlen = sizeof (tcp_initopt);
                if (mss > IP_MSS - sizeof(struct tcpiphdr)) {
                        opt = tcp_initopt;
                        optlen = sizeof (tcp_initopt);
@@ -306,8 +311,6 @@ send:
                win = IP_MAXPACKET;
        if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
                win = (long)(tp->rcv_adv - tp->rcv_nxt);
                win = IP_MAXPACKET;
        if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
                win = (long)(tp->rcv_adv - tp->rcv_nxt);
-       if (win > IP_MAXPACKET)
-               win = IP_MAXPACKET;
        ti->ti_win = htons((u_short)win);
        if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
                ti->ti_urp = htons((u_short)(tp->snd_up - tp->snd_nxt));
        ti->ti_win = htons((u_short)win);
        if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
                ti->ti_urp = htons((u_short)(tp->snd_up - tp->snd_nxt));
@@ -399,16 +402,9 @@ send:
         * send to IP level.
         */
        ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + optlen + len;
         * send to IP level.
         */
        ((struct ip *)ti)->ip_len = sizeof (struct tcpiphdr) + optlen + len;
-       if (m->m_flags & M_PKTHDR)
-               m->m_pkthdr.len = ((struct ip *)ti)->ip_len;
        ((struct ip *)ti)->ip_ttl = TCP_TTL;
        ((struct ip *)ti)->ip_ttl = TCP_TTL;
-#if BSD>=43
        error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
            so->so_options & SO_DONTROUTE);
        error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
            so->so_options & SO_DONTROUTE);
-#else
-       error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route, 
-                         so->so_options & SO_DONTROUTE);
-#endif
        if (error) {
                if (error == ENOBUFS) {
                        tcp_quench(tp->t_inpcb);
        if (error) {
                if (error == ENOBUFS) {
                        tcp_quench(tp->t_inpcb);