add crontab entry
[unix-history] / usr / src / sys / netinet / tcp_input.c
index fc59db7..a54439c 100644 (file)
  * 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_input.c 7.19 (Berkeley) %G%
+ *     @(#)tcp_input.c 7.20 (Berkeley) %G%
  */
 
 #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"
@@ -42,7 +43,6 @@
 #include "tcp_debug.h"
 
 int    tcpprintfs = 0;
 #include "tcp_debug.h"
 
 int    tcpprintfs = 0;
-int    tcpcksum = 1;
 int    tcprexmtthresh = 3;
 struct tcpiphdr tcp_saveti;
 
 int    tcprexmtthresh = 3;
 struct tcpiphdr tcp_saveti;
 
@@ -183,12 +183,12 @@ drop:
  * TCP input routine, follows pages 65-76 of the
  * protocol specification dated September, 1981 very closely.
  */
  * TCP input routine, follows pages 65-76 of the
  * protocol specification dated September, 1981 very closely.
  */
-tcp_input(m0)
-       struct mbuf *m0;
+tcp_input(m, iphlen)
+       register struct mbuf *m;
+       int iphlen;
 {
        register struct tcpiphdr *ti;
        struct inpcb *inp;
 {
        register struct tcpiphdr *ti;
        struct inpcb *inp;
-       register struct mbuf *m;
        struct mbuf *om = 0;
        int len, tlen, off;
        register struct tcpcb *tp = 0;
        struct mbuf *om = 0;
        int len, tlen, off;
        register struct tcpcb *tp = 0;
@@ -205,11 +205,10 @@ tcp_input(m0)
         * Get IP and TCP header together in first mbuf.
         * Note: IP leaves IP header in first mbuf.
         */
         * Get IP and TCP header together in first mbuf.
         * Note: IP leaves IP header in first mbuf.
         */
-       m = m0;
        ti = mtod(m, struct tcpiphdr *);
        ti = mtod(m, struct tcpiphdr *);
-       if (((struct ip *)ti)->ip_hl > (sizeof (struct ip) >> 2))
-               ip_stripoptions((struct ip *)ti, (struct mbuf *)0);
-       if (m->m_off > MMAXOFF || m->m_len < sizeof (struct tcpiphdr)) {
+       if (iphlen > sizeof (struct ip))
+               ip_stripoptions(m, (struct mbuf *)0);
+       if (m->m_flags & M_EXT || m->m_len < sizeof (struct tcpiphdr)) {
                if ((m = m_pullup(m, sizeof (struct tcpiphdr))) == 0) {
                        tcpstat.tcps_rcvshort++;
                        return;
                if ((m = m_pullup(m, sizeof (struct tcpiphdr))) == 0) {
                        tcpstat.tcps_rcvshort++;
                        return;
@@ -222,17 +221,15 @@ tcp_input(m0)
         */
        tlen = ((struct ip *)ti)->ip_len;
        len = sizeof (struct ip) + tlen;
         */
        tlen = ((struct ip *)ti)->ip_len;
        len = sizeof (struct ip) + tlen;
-       if (tcpcksum) {
-               ti->ti_next = ti->ti_prev = 0;
-               ti->ti_x1 = 0;
-               ti->ti_len = (u_short)tlen;
-               ti->ti_len = htons((u_short)ti->ti_len);
-               if (ti->ti_sum = in_cksum(m, len)) {
-                       if (tcpprintfs)
-                               printf("tcp sum: src %x\n", ti->ti_src);
-                       tcpstat.tcps_rcvbadsum++;
-                       goto drop;
-               }
+       ti->ti_next = ti->ti_prev = 0;
+       ti->ti_x1 = 0;
+       ti->ti_len = (u_short)tlen;
+       ti->ti_len = htons((u_short)ti->ti_len);
+       if (ti->ti_sum = in_cksum(m, len)) {
+               if (tcpprintfs)
+                       printf("tcp sum: src %x\n", ti->ti_src);
+               tcpstat.tcps_rcvbadsum++;
+               goto drop;
        }
 
        /*
        }
 
        /*
@@ -263,6 +260,7 @@ tcp_input(m0)
                { caddr_t op = mtod(m, caddr_t) + sizeof (struct tcpiphdr);
                  bcopy(op, mtod(om, caddr_t), (unsigned)om->m_len);
                  m->m_len -= om->m_len;
                { caddr_t op = mtod(m, caddr_t) + sizeof (struct tcpiphdr);
                  bcopy(op, mtod(om, caddr_t), (unsigned)om->m_len);
                  m->m_len -= om->m_len;
+                 m->m_pkthdr.len -= om->m_len;
                  bcopy(op+om->m_len, op,
                   (unsigned)(m->m_len-sizeof (struct tcpiphdr)));
                }
                  bcopy(op+om->m_len, op,
                   (unsigned)(m->m_len-sizeof (struct tcpiphdr)));
                }
@@ -272,8 +270,9 @@ tcp_input(m0)
        /*
         * Drop TCP and IP headers; TCP options were dropped above.
         */
        /*
         * Drop TCP and IP headers; TCP options were dropped above.
         */
-       m->m_off += sizeof(struct tcpiphdr);
+       m->m_data += sizeof(struct tcpiphdr);
        m->m_len -= sizeof(struct tcpiphdr);
        m->m_len -= sizeof(struct tcpiphdr);
+       m->m_pkthdr.len -= sizeof(struct tcpiphdr);
 
        /*
         * Convert TCP protocol specific fields to host format.
 
        /*
         * Convert TCP protocol specific fields to host format.
@@ -362,7 +361,7 @@ findpcb:
        win = sbspace(&so->so_rcv);
        if (win < 0)
                win = 0;
        win = sbspace(&so->so_rcv);
        if (win < 0)
                win = 0;
-       tp->rcv_wnd = MAX(win, (int)(tp->rcv_adv - tp->rcv_nxt));
+       tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt));
        }
 
        switch (tp->t_state) {
        }
 
        switch (tp->t_state) {
@@ -390,7 +389,7 @@ findpcb:
                        goto dropwithreset;
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
                        goto dropwithreset;
                if ((tiflags & TH_SYN) == 0)
                        goto drop;
-               if (in_broadcast(ti->ti_dst))
+               if (m->m_flags & M_BCAST)
                        goto drop;
                am = m_get(M_DONTWAIT, MT_SONAME);
                if (am == NULL)
                        goto drop;
                am = m_get(M_DONTWAIT, MT_SONAME);
                if (am == NULL)
@@ -472,7 +471,7 @@ findpcb:
                        tcpstat.tcps_connects++;
                        soisconnected(so);
                        tp->t_state = TCPS_ESTABLISHED;
                        tcpstat.tcps_connects++;
                        soisconnected(so);
                        tp->t_state = TCPS_ESTABLISHED;
-                       tp->t_maxseg = MIN(tp->t_maxseg, tcp_mss(tp));
+                       tp->t_maxseg = min(tp->t_maxseg, tcp_mss(tp));
                        (void) tcp_reass(tp, (struct tcpiphdr *)0);
                        /*
                         * if we didn't have to retransmit the SYN,
                        (void) tcp_reass(tp, (struct tcpiphdr *)0);
                        /*
                         * if we didn't have to retransmit the SYN,
@@ -703,7 +702,7 @@ trimthenstep6:
                tcpstat.tcps_connects++;
                soisconnected(so);
                tp->t_state = TCPS_ESTABLISHED;
                tcpstat.tcps_connects++;
                soisconnected(so);
                tp->t_state = TCPS_ESTABLISHED;
-               tp->t_maxseg = MIN(tp->t_maxseg, tcp_mss(tp));
+               tp->t_maxseg = min(tp->t_maxseg, tcp_mss(tp));
                (void) tcp_reass(tp, (struct tcpiphdr *)0);
                tp->snd_wl1 = ti->ti_seq - 1;
                /* fall into ... */
                (void) tcp_reass(tp, (struct tcpiphdr *)0);
                tp->snd_wl1 = ti->ti_seq - 1;
                /* fall into ... */
@@ -757,7 +756,7 @@ trimthenstep6:
                                else if (++tp->t_dupacks == tcprexmtthresh) {
                                        tcp_seq onxt = tp->snd_nxt;
                                        u_int win =
                                else if (++tp->t_dupacks == tcprexmtthresh) {
                                        tcp_seq onxt = tp->snd_nxt;
                                        u_int win =
-                                           MIN(tp->snd_wnd, tp->snd_cwnd) / 2 /
+                                           min(tp->snd_wnd, tp->snd_cwnd) / 2 /
                                                tp->t_maxseg;
 
                                        if (win < 2)
                                                tp->t_maxseg;
 
                                        if (win < 2)
@@ -867,9 +866,9 @@ trimthenstep6:
                u_int incr = tp->t_maxseg;
 
                if (tp->snd_cwnd > tp->snd_ssthresh)
                u_int incr = tp->t_maxseg;
 
                if (tp->snd_cwnd > tp->snd_ssthresh)
-                       incr = MAX(incr * incr / tp->snd_cwnd, 1);
+                       incr = max(incr * incr / tp->snd_cwnd, 1);
 
 
-               tp->snd_cwnd = MIN(tp->snd_cwnd + incr, IP_MAXPACKET); /* XXX */
+               tp->snd_cwnd = min(tp->snd_cwnd + incr, USHRT_MAX); /* XXX */
                }
                if (acked > so->so_snd.sb_cc) {
                        tp->snd_wnd -= so->so_snd.sb_cc;
                }
                if (acked > so->so_snd.sb_cc) {
                        tp->snd_wnd -= so->so_snd.sb_cc;
@@ -880,8 +879,7 @@ trimthenstep6:
                        tp->snd_wnd -= acked;
                        ourfinisacked = 0;
                }
                        tp->snd_wnd -= acked;
                        ourfinisacked = 0;
                }
-               if ((so->so_snd.sb_flags & SB_WAIT) || so->so_snd.sb_sel)
-                       sowwakeup(so);
+               sowwakeup(so);
                tp->snd_una = ti->ti_ack;
                if (SEQ_LT(tp->snd_nxt, tp->snd_una))
                        tp->snd_nxt = tp->snd_una;
                tp->snd_una = ti->ti_ack;
                if (SEQ_LT(tp->snd_nxt, tp->snd_una))
                        tp->snd_nxt = tp->snd_una;
@@ -1136,14 +1134,14 @@ dropwithreset:
         * Make ACK acceptable to originator of segment.
         * Don't bother to respond if destination was broadcast.
         */
         * Make ACK acceptable to originator of segment.
         * Don't bother to respond if destination was broadcast.
         */
-       if ((tiflags & TH_RST) || in_broadcast(ti->ti_dst))
+       if ((tiflags & TH_RST) || m->m_flags & M_BCAST)
                goto drop;
        if (tiflags & TH_ACK)
                goto drop;
        if (tiflags & TH_ACK)
-               tcp_respond(tp, ti, (tcp_seq)0, ti->ti_ack, TH_RST);
+               tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
        else {
                if (tiflags & TH_SYN)
                        ti->ti_len++;
        else {
                if (tiflags & TH_SYN)
                        ti->ti_len++;
-               tcp_respond(tp, ti, ti->ti_seq+ti->ti_len, (tcp_seq)0,
+               tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
                    TH_RST|TH_ACK);
        }
        /* destroy temporarily created socket */
                    TH_RST|TH_ACK);
        }
        /* destroy temporarily created socket */
@@ -1199,7 +1197,7 @@ tcp_dooptions(tp, om, ti)
                                continue;
                        tp->t_maxseg = *(u_short *)(cp + 2);
                        tp->t_maxseg = ntohs((u_short)tp->t_maxseg);
                                continue;
                        tp->t_maxseg = *(u_short *)(cp + 2);
                        tp->t_maxseg = ntohs((u_short)tp->t_maxseg);
-                       tp->t_maxseg = MIN(tp->t_maxseg, tcp_mss(tp));
+                       tp->t_maxseg = min(tp->t_maxseg, tcp_mss(tp));
                        break;
                }
        }
                        break;
                }
        }
@@ -1289,7 +1287,7 @@ tcp_mss(tp)
        if (in_localaddr(inp->inp_faddr))
                return (mss);
 
        if (in_localaddr(inp->inp_faddr))
                return (mss);
 
-       mss = MIN(mss, TCP_MSS);
+       mss = min(mss, TCP_MSS);
        tp->snd_cwnd = mss;
        return (mss);
 }
        tp->snd_cwnd = mss;
        return (mss);
 }