]> Git Repo - qemu.git/commitdiff
slirp: Cleanup resources on instance removal
authorJan Kiszka <[email protected]>
Wed, 29 Feb 2012 18:14:23 +0000 (19:14 +0100)
committerJan Kiszka <[email protected]>
Tue, 13 Mar 2012 13:05:49 +0000 (14:05 +0100)
Close & free sockets when shutting down a slirp instance, also release
all buffers.

CC: Michael S. Tsirkin <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
slirp/ip_icmp.c
slirp/ip_icmp.h
slirp/ip_input.c
slirp/mbuf.c
slirp/mbuf.h
slirp/slirp.c
slirp/slirp.h
slirp/tcp_subr.c
slirp/udp.c
slirp/udp.h

index 5dbf21da9d7dc82e3d2325a731ad4d603cce0a08..d571fd0b767aa3ba7869b2a166c3159851d624df 100644 (file)
@@ -66,6 +66,13 @@ void icmp_init(Slirp *slirp)
     slirp->icmp_last_so = &slirp->icmp;
 }
 
+void icmp_cleanup(Slirp *slirp)
+{
+    while (slirp->icmp.so_next != &slirp->icmp) {
+        icmp_detach(slirp->icmp.so_next);
+    }
+}
+
 static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
 {
     struct ip *ip = mtod(m, struct ip *);
index b3da1f26977255e3fba7ec452b225b5cfc59fd4c..1a1af91e1e40241836532893079ee7ec2cdacbbb 100644 (file)
@@ -154,6 +154,7 @@ struct icmp {
        (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
 
 void icmp_init(Slirp *slirp);
+void icmp_cleanup(Slirp *slirp);
 void icmp_input(struct mbuf *, int);
 void icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
                 const char *message);
index c7b3eb48069d70bf5b749242b1cc93b3ac798383..ce24faf165f650e7ecb5c12c0fa965a284db1808 100644 (file)
@@ -61,6 +61,13 @@ ip_init(Slirp *slirp)
     icmp_init(slirp);
 }
 
+void ip_cleanup(Slirp *slirp)
+{
+    udp_cleanup(slirp);
+    tcp_cleanup(slirp);
+    icmp_cleanup(slirp);
+}
+
 /*
  * Ip input routine.  Checksum and byte swap header.  If fragmented
  * try to reassemble.  Process options.  Pass to next level.
index c699c750962b9533fd148a486d4228b6b1ba8c33..4fefb043bf882979ff2396e5bc1b4f5bbeb20aa4 100644 (file)
@@ -32,6 +32,27 @@ m_init(Slirp *slirp)
     slirp->m_usedlist.m_next = slirp->m_usedlist.m_prev = &slirp->m_usedlist;
 }
 
+void m_cleanup(Slirp *slirp)
+{
+    struct mbuf *m, *next;
+
+    m = slirp->m_usedlist.m_next;
+    while (m != &slirp->m_usedlist) {
+        next = m->m_next;
+        if (m->m_flags & M_EXT) {
+            free(m->m_ext);
+        }
+        free(m);
+        m = next;
+    }
+    m = slirp->m_freelist.m_next;
+    while (m != &slirp->m_freelist) {
+        next = m->m_next;
+        free(m);
+        m = next;
+    }
+}
+
 /*
  * Get an mbuf from the free list, if there are none
  * malloc one
index 8d7951fb42334868f4dff15ea9b9abb713fe71da..3f3ab095b1030eb61d5e9f14116bd6179440d08c 100644 (file)
@@ -116,6 +116,7 @@ struct mbuf {
                                         * it rather than putting it on the free list */
 
 void m_init(Slirp *);
+void m_cleanup(Slirp *slirp);
 struct mbuf * m_get(Slirp *);
 void m_free(struct mbuf *);
 void m_cat(register struct mbuf *, register struct mbuf *);
index bcffc3414fb2a8fb32ee308e7298b055a33cd080..150283097807b209c1181dd616c4b6341f9ff72b 100644 (file)
@@ -246,6 +246,9 @@ void slirp_cleanup(Slirp *slirp)
 
     unregister_savevm(NULL, "slirp", slirp);
 
+    ip_cleanup(slirp);
+    m_cleanup(slirp);
+
     g_free(slirp->tftp_prefix);
     g_free(slirp->bootp_filename);
     g_free(slirp);
index cbe8a3cd4dccca6fa0c57cc84edc59bd67644fe4..5033ee3118ac7702c6f1484ec0bfc3b795ddfb97 100644 (file)
@@ -315,6 +315,7 @@ void if_output(struct socket *, struct mbuf *);
 
 /* ip_input.c */
 void ip_init(Slirp *);
+void ip_cleanup(Slirp *);
 void ip_input(struct mbuf *);
 void ip_slowtimo(Slirp *);
 void ip_stripoptions(register struct mbuf *, struct mbuf *);
@@ -332,6 +333,7 @@ void tcp_setpersist(register struct tcpcb *);
 
 /* tcp_subr.c */
 void tcp_init(Slirp *);
+void tcp_cleanup(Slirp *);
 void tcp_template(struct tcpcb *);
 void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
 struct tcpcb * tcp_newtcpcb(struct socket *);
index 143a2383c8570b9d6f971629a098eec917366ab0..6f6585a10ff6a11d1296b3ac18c44719f8fd2e6a 100644 (file)
@@ -55,6 +55,13 @@ tcp_init(Slirp *slirp)
     slirp->tcp_last_so = &slirp->tcb;
 }
 
+void tcp_cleanup(Slirp *slirp)
+{
+    while (slirp->tcb.so_next != &slirp->tcb) {
+        tcp_close(sototcpcb(slirp->tcb.so_next));
+    }
+}
+
 /*
  * Create template to be used to send tcp packets on a connection.
  * Call after host entry created, fills
index 5b060f397bbb25b88e39f0557b265a11969ed406..ced509656d63362678285738b48d43d65d976fb4 100644 (file)
@@ -49,6 +49,14 @@ udp_init(Slirp *slirp)
     slirp->udb.so_next = slirp->udb.so_prev = &slirp->udb;
     slirp->udp_last_so = &slirp->udb;
 }
+
+void udp_cleanup(Slirp *slirp)
+{
+    while (slirp->udb.so_next != &slirp->udb) {
+        udp_detach(slirp->udb.so_next);
+    }
+}
+
 /* m->m_data  points at ip packet header
  * m->m_len   length ip packet
  * ip->ip_len length data (IPDU)
index 9b5c3cf56a42ab12e3a6e96b31071e1ebb6bf2c4..9bf31fe7be41a7ad631b84b0db1a0c56d2054313 100644 (file)
@@ -74,6 +74,7 @@ struct udpiphdr {
 struct mbuf;
 
 void udp_init(Slirp *);
+void udp_cleanup(Slirp *);
 void udp_input(register struct mbuf *, int);
 int udp_output(struct socket *, struct mbuf *, struct sockaddr_in *);
 int udp_attach(struct socket *);
This page took 0.036587 seconds and 4 git commands to generate.