kvm: Improve upgrade notes when facing unsupported kernels
[qemu] / slirp / tcp_output.c
index b79bcf1..9ed50f5 100644 (file)
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -37,8 +33,8 @@
 /*
  * Changes and additions relating to SLiRP
  * Copyright (c) 1995 Danny Gasparovski.
- * 
- * Please read the file COPYRIGHT for the 
+ *
+ * Please read the file COPYRIGHT for the
  * terms and conditions of the copyright.
  */
 
  * Since this is only used in "stats socket", we give meaning
  * names instead of the REAL names
  */
-char *tcpstates[] = {
+const char * const tcpstates[] = {
 /*     "CLOSED",       "LISTEN",       "SYN_SENT",     "SYN_RCVD", */
        "REDIRECT",     "LISTEN",       "SYN_SENT",     "SYN_RCVD",
        "ESTABLISHED",  "CLOSE_WAIT",   "FIN_WAIT_1",   "CLOSING",
        "LAST_ACK",     "FIN_WAIT_2",   "TIME_WAIT",
 };
 
-u_char  tcp_outflags[TCP_NSTATES] = {
+static const 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_ACK,        TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK,
        TH_FIN|TH_ACK, TH_ACK, TH_ACK,
 };
 
@@ -68,8 +64,7 @@ u_char  tcp_outflags[TCP_NSTATES] = {
  * Tcp output routine: figure out what should be sent and send it.
  */
 int
-tcp_output(tp)
-       register struct tcpcb *tp;
+tcp_output(struct tcpcb *tp)
 {
        register struct socket *so = tp->t_socket;
        register long len, win;
@@ -79,10 +74,10 @@ tcp_output(tp)
        u_char opt[MAX_TCPOPTLEN];
        unsigned optlen, hdrlen;
        int idle, sendalot;
-       
+
        DEBUG_CALL("tcp_output");
        DEBUG_ARG("tp = %lx", (long )tp);
-       
+
        /*
         * Determine length of data that should be transmitted,
         * and flags that will be used.
@@ -103,9 +98,9 @@ again:
        win = min(tp->snd_wnd, tp->snd_cwnd);
 
        flags = tcp_outflags[tp->t_state];
-       
+
        DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
-       
+
        /*
         * If in persist timeout with window of 0, send 1 byte.
         * Otherwise, if window is small but nonzero
@@ -158,7 +153,7 @@ again:
                        tp->snd_nxt = tp->snd_una;
                }
        }
-       
+
        if (len > tp->t_maxseg) {
                len = tp->t_maxseg;
                sendalot = 1;
@@ -200,7 +195,7 @@ again:
         * window, then want to send a window update to peer.
         */
        if (win > 0) {
-               /* 
+               /*
                 * "adv" is the amount we can increase the window,
                 * taking into account that we are limited by
                 * TCP_MAXWIN << tp->rcv_scale.
@@ -263,8 +258,8 @@ again:
        /*
         * No reason to send a segment, just return.
         */
-       tcpstat.tcps_didnuttin++;
-       
+       STAT(tcpstat.tcps_didnuttin++);
+
        return (0);
 
 send:
@@ -302,9 +297,9 @@ send:
  */
                }
        }
+
        /*
-        * Send a timestamp and echo-reply if this is a SYN and our side 
+        * Send a timestamp and echo-reply if this is a SYN and our side
         * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
         * and our peer have sent timestamps in our SYN's.
         */
@@ -322,7 +317,7 @@ send:
  *     }
  */
        hdrlen += optlen;
+
        /*
         * Adjust data length if insertion of options will
         * bump the packet length beyond the t_maxseg length.
@@ -339,13 +334,13 @@ send:
         */
        if (len) {
                if (tp->t_force && len == 1)
-                       tcpstat.tcps_sndprobe++;
+                       STAT(tcpstat.tcps_sndprobe++);
                else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
-                       tcpstat.tcps_sndrexmitpack++;
-                       tcpstat.tcps_sndrexmitbyte += len;
+                       STAT(tcpstat.tcps_sndrexmitpack++);
+                       STAT(tcpstat.tcps_sndrexmitbyte += len);
                } else {
-                       tcpstat.tcps_sndpack++;
-                       tcpstat.tcps_sndbyte += len;
+                       STAT(tcpstat.tcps_sndpack++);
+                       STAT(tcpstat.tcps_sndbyte += len);
                }
 
                m = m_get();
@@ -354,10 +349,10 @@ send:
                        error = 1;
                        goto out;
                }
-               m->m_data += if_maxlinkhdr;
+               m->m_data += IF_MAXLINKHDR;
                m->m_len = hdrlen;
-               
-               /* 
+
+               /*
                 * This will always succeed, since we make sure our mbufs
                 * are big enough to hold one MSS packet + header + ... etc.
                 */
@@ -382,13 +377,13 @@ send:
                        flags |= TH_PUSH;
        } else {
                if (tp->t_flags & TF_ACKNOW)
-                       tcpstat.tcps_sndacks++;
+                       STAT(tcpstat.tcps_sndacks++);
                else if (flags & (TH_SYN|TH_FIN|TH_RST))
-                       tcpstat.tcps_sndctrl++;
+                       STAT(tcpstat.tcps_sndctrl++);
                else if (SEQ_GT(tp->snd_up, tp->snd_una))
-                       tcpstat.tcps_sndurg++;
+                       STAT(tcpstat.tcps_sndurg++);
                else
-                       tcpstat.tcps_sndwinup++;
+                       STAT(tcpstat.tcps_sndwinup++);
 
                m = m_get();
                if (m == NULL) {
@@ -396,12 +391,12 @@ send:
                        error = 1;
                        goto out;
                }
-               m->m_data += if_maxlinkhdr;
+               m->m_data += IF_MAXLINKHDR;
                m->m_len = hdrlen;
        }
 
        ti = mtod(m, struct tcpiphdr *);
-       
+
        memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr));
 
        /*
@@ -409,7 +404,7 @@ send:
         * window for use in delaying messages about window sizes.
         * If resending a FIN, be sure not to use a new sequence number.
         */
-       if (flags & TH_FIN && tp->t_flags & TF_SENTFIN && 
+       if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
            tp->snd_nxt == tp->snd_max)
                tp->snd_nxt--;
        /*
@@ -446,10 +441,10 @@ send:
        if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
                win = (long)(tp->rcv_adv - tp->rcv_nxt);
        ti->ti_win = htons((u_int16_t) (win>>tp->rcv_scale));
-       
+
        if (SEQ_GT(tp->snd_up, tp->snd_una)) {
                ti->ti_urp = htons((u_int16_t)(tp->snd_up - ntohl(ti->ti_seq)));
-#ifdef notdef          
+#ifdef notdef
        if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
                ti->ti_urp = htons((u_int16_t)(tp->snd_up - tp->snd_nxt));
 #endif
@@ -500,7 +495,7 @@ send:
                        if (tp->t_rtt == 0) {
                                tp->t_rtt = 1;
                                tp->t_rtseq = startseq;
-                               tcpstat.tcps_segstimed++;
+                               STAT(tcpstat.tcps_segstimed++);
                        }
                }
 
@@ -531,14 +526,14 @@ send:
         * the template, but need a way to checksum without them.
         */
        m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
-       
+
     {
-           
+
        ((struct ip *)ti)->ip_len = m->m_len;
 
-       ((struct ip *)ti)->ip_ttl = ip_defttl;
+       ((struct ip *)ti)->ip_ttl = IPDEFTTL;
        ((struct ip *)ti)->ip_tos = so->so_iptos;
-           
+
 /* #if BSD >= 43 */
        /* Don't do IP options... */
 /*     error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
@@ -547,7 +542,7 @@ send:
        error = ip_output(so, m);
 
 /* #else
- *     error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route, 
+ *     error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route,
  *         so->so_options & SO_DONTROUTE);
  * #endif
  */
@@ -567,7 +562,7 @@ out:
  */
                return (error);
        }
-       tcpstat.tcps_sndtotal++;
+       STAT(tcpstat.tcps_sndtotal++);
 
        /*
         * Data sent (as far as we can tell).
@@ -586,8 +581,7 @@ out:
 }
 
 void
-tcp_setpersist(tp)
-       register struct tcpcb *tp;
+tcp_setpersist(struct tcpcb *tp)
 {
     int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;