]> git.proxmox.com Git - qemu.git/blobdiff - slirp/ip_output.c
rng-egd: remove redundant free
[qemu.git] / slirp / ip_output.c
index 5bce520612897b5fea9a6903ce905e921221c107..c82830fe7d299236b04090e2199d20c4602b95d8 100644 (file)
@@ -40,8 +40,6 @@
 
 #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
@@ -55,6 +53,7 @@ u_int16_t ip_id;
 int
 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 );
@@ -64,39 +63,21 @@ ip_output(struct socket *so, struct mbuf *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) {
-               ip->ip_len = htons((u_int16_t)ip->ip_len);
-               ip->ip_off = htons((u_int16_t)ip->ip_off);
+       if ((uint16_t)ip->ip_len <= IF_MTU) {
+               ip->ip_len = htons((uint16_t)ip->ip_len);
+               ip->ip_off = htons((uint16_t)ip->ip_off);
                ip->ip_sum = 0;
                ip->ip_sum = cksum(m, hlen);
 
@@ -110,7 +91,6 @@ ip_output(struct socket *so, struct mbuf *m0)
         */
        if (ip->ip_off & IP_DF) {
                error = -1;
-               STAT(ipstat.ips_cantfrag++);
                goto bad;
        }
 
@@ -130,54 +110,46 @@ ip_output(struct socket *so, struct mbuf *m0)
         */
        m0 = m;
        mhlen = sizeof (struct ip);
-       for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
+       for (off = hlen + len; off < (uint16_t)ip->ip_len; off += len) {
          register struct ip *mhip;
-         m = m_get();
+         m = m_get(slirp);
           if (m == NULL) {
            error = -1;
-           STAT(ipstat.ips_odropped++);
            goto sendorfree;
          }
          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)
            mhip->ip_off |= IP_MF;
-         if (off + len >= (u_int16_t)ip->ip_len)
-           len = (u_int16_t)ip->ip_len - off;
+         if (off + len >= (uint16_t)ip->ip_len)
+           len = (uint16_t)ip->ip_len - off;
          else
            mhip->ip_off |= IP_MF;
-         mhip->ip_len = htons((u_int16_t)(len + mhlen));
+         mhip->ip_len = htons((uint16_t)(len + mhlen));
 
          if (m_copy(m, m0, off, len) < 0) {
            error = -1;
            goto sendorfree;
          }
 
-         mhip->ip_off = htons((u_int16_t)mhip->ip_off);
+         mhip->ip_off = htons((uint16_t)mhip->ip_off);
          mhip->ip_sum = 0;
          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
         * and updating header, then send each fragment (in order).
         */
        m = m0;
-       m_adj(m, hlen + firstlen - (u_int16_t)ip->ip_len);
-       ip->ip_len = htons((u_int16_t)m->m_len);
-       ip->ip_off = htons((u_int16_t)(ip->ip_off | IP_MF));
+       m_adj(m, hlen + firstlen - (uint16_t)ip->ip_len);
+       ip->ip_len = htons((uint16_t)m->m_len);
+       ip->ip_off = htons((uint16_t)(ip->ip_off | IP_MF));
        ip->ip_sum = 0;
        ip->ip_sum = cksum(m, hlen);
 sendorfree:
@@ -187,17 +159,14 @@ sendorfree:
                if (error == 0)
                        if_output(so, m);
                else
-                       m_freem(m);
+                       m_free(m);
        }
-
-       if (error == 0)
-               STAT(ipstat.ips_fragmented++);
     }
 
 done:
        return (error);
 
 bad:
-       m_freem(m0);
+       m_free(m0);
        goto done;
 }