Skip to contentSkip to conversation

[7207] net: Prevent multiple slirp instances (Jan Kiszka)

Qemu-devel Anthony Liguori 1 participant 1 message Apr 21, 2009

lore
Share & tools
lore
#0 lore raw

Revision: 7207

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7207
Author:   aliguori
Date:     2009-04-21 20:47:59 +0000 (Tue, 21 Apr 2009)

Log Message:
-----------
net: Prevent multiple slirp instances (Jan Kiszka)

The slirp stack is full of global variables which prevents instantiating it more than once. Catch this during net_slirp_init to prevent more harm later on.

Modified Paths:
--------------

    branches/stable_0_10/net.c

Modified: branches/stable_0_10/net.c
===================================================================

stable_0_10/net.c +13 -1
@@ -515,15 +515,27 @@
     slirp_input(buf, size);
 }
 
+static int slirp_in_use;
+
+static void net_slirp_cleanup(VLANClientState *vc)
+{
+    slirp_in_use = 0;
+}
+
 static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
 {
+    if (slirp_in_use) {
+        /* slirp only supports a single instance so far */
+        return -1;
+    }
     if (!slirp_inited) {
         slirp_inited = 1;
         slirp_init(slirp_restrict, slirp_ip);
     }
     slirp_vc = qemu_new_vlan_client(vlan, model, name,
-                                    slirp_receive, NULL, NULL, NULL);
+                                    slirp_receive, NULL, net_slirp_cleanup, NULL);
     slirp_vc->info_str[0] = '\0';
+    slirp_in_use = 1;
     return 0;
 }