ram: Remove SaveVM Version 2 support
[qemu] / slirp / ip_output.c
index b41d062..dba2784 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.
  *
@@ -44,7 +40,9 @@
 
 #include <slirp.h>
 
-u_int16_t ip_id;
+/* Number of packets queued before we start sending
+ * (to prevent allocing too many mbufs) */
+#define IF_THRESH 10
 
 /*
  * IP output.  The packet in mbuf chain m contains a skeletal IP
@@ -53,10 +51,9 @@ u_int16_t ip_id;
  * The mbuf opt, if present, will not be freed.
  */
 int
-ip_output(so, m0)
-       struct socket *so;
-       struct mbuf *m0;
+ip_output(struct socket *so, struct mbuf *m0)
 {
+       Slirp *slirp = m0->slirp;
        register struct ip *ip;
        register struct mbuf *m = m0;
        register int hlen = sizeof(struct ip );
@@ -66,37 +63,19 @@ ip_output(so, m0)
        DEBUG_ARG("so = %lx", (long)so);
        DEBUG_ARG("m0 = %lx", (long)m0);
 
-       /* We do no options */
-/*     if (opt) {
- *             m = ip_insertoptions(m, opt, &len);
- *             hlen = len;
- *     }
- */
        ip = mtod(m, struct ip *);
        /*
         * Fill in IP header.
         */
        ip->ip_v = IPVERSION;
        ip->ip_off &= IP_DF;
-       ip->ip_id = htons(ip_id++);
+       ip->ip_id = htons(slirp->ip_id++);
        ip->ip_hl = hlen >> 2;
-       STAT(ipstat.ips_localout++);
-
-       /*
-        * Verify that we have any chance at all of being able to queue
-        *      the packet or packet fragments
-        */
-       /* XXX Hmmm... */
-/*     if (if_queued > if_thresh && towrite <= 0) {
- *             error = ENOBUFS;
- *             goto bad;
- *     }
- */
 
        /*
         * If small enough for interface, can just send directly.
         */
-       if ((u_int16_t)ip->ip_len <= if_mtu) {
+       if ((u_int16_t)ip->ip_len <= IF_MTU) {
                ip->ip_len = htons((u_int16_t)ip->ip_len);
                ip->ip_off = htons((u_int16_t)ip->ip_off);
                ip->ip_sum = 0;
@@ -112,11 +91,10 @@ ip_output(so, m0)
         */
        if (ip->ip_off & IP_DF) {
                error = -1;
-               STAT(ipstat.ips_cantfrag++);
                goto bad;
        }
 
-       len = (if_mtu - hlen) &~ 7;       /* ip databytes per packet */
+       len = (IF_MTU - hlen) &~ 7;       /* ip databytes per packet */
        if (len < 8) {
                error = -1;
                goto bad;
@@ -134,22 +112,15 @@ ip_output(so, m0)
        mhlen = sizeof (struct ip);
        for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
          register struct ip *mhip;
-         m = m_get();
-         if (m == 0) {
+         m = m_get(slirp);
+          if (m == NULL) {
            error = -1;
-           STAT(ipstat.ips_odropped++);
            goto sendorfree;
          }
-         m->m_data += if_maxlinkhdr;
+         m->m_data += IF_MAXLINKHDR;
          mhip = mtod(m, struct ip *);
          *mhip = *ip;
 
-               /* No options */
-/*             if (hlen > sizeof (struct ip)) {
- *                     mhlen = ip_optcopy(ip, mhip) + sizeof (struct ip);
- *                     mhip->ip_hl = mhlen >> 2;
- *             }
- */
          m->m_len = mhlen;
          mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF);
          if (ip->ip_off & IP_MF)
@@ -170,7 +141,6 @@ ip_output(so, m0)
          mhip->ip_sum = cksum(m, mhlen);
          *mnext = m;
          mnext = &m->m_nextpkt;
-         STAT(ipstat.ips_ofragments++);
        }
        /*
         * Update first fragment by trimming what's been copied out
@@ -185,15 +155,12 @@ ip_output(so, m0)
 sendorfree:
        for (m = m0; m; m = m0) {
                m0 = m->m_nextpkt;
-               m->m_nextpkt = 0;
+                m->m_nextpkt = NULL;
                if (error == 0)
                        if_output(so, m);
                else
                        m_freem(m);
        }
-
-       if (error == 0)
-               STAT(ipstat.ips_fragmented++);
     }
 
 done: