aboutsummaryrefslogtreecommitdiff
path: root/slirp
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2009-06-24 14:42:31 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-29 08:52:49 -0500
commitad0d8c4c326c87ee3f193f90f31ec4af0fce5598 (patch)
tree8cf29f6a524c52cdf7cc1b482060ade9e4a485e7 /slirp
parent9f8bd0421dc03b2640ac2d0a4d702354a218b2ab (diff)
slirp: Allocate/free stack instance dynamically
Allocate the internal slirp state dynamically and provide and call slirp_cleanup to properly release it after use. This patch finally unbreaks slirp release and re-instantiation via host_net_* monitor commands. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'slirp')
-rw-r--r--slirp/libslirp.h1
-rw-r--r--slirp/main.h1
-rw-r--r--slirp/slirp.c32
-rw-r--r--slirp/slirp.h2
4 files changed, 21 insertions, 15 deletions
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 521de3e026..3bcc3923f3 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -13,6 +13,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
const char *vhostname, const char *tftp_path,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, void *opaque);
+void slirp_cleanup(Slirp *slirp);
void slirp_select_fill(int *pnfds,
fd_set *readfds, fd_set *writefds, fd_set *xfds);
diff --git a/slirp/main.h b/slirp/main.h
index 90deb58b27..28d92d8866 100644
--- a/slirp/main.h
+++ b/slirp/main.h
@@ -11,7 +11,6 @@
#define TOWRITEMAX 512
-extern int link_up;
extern int slirp_socket;
extern int slirp_socket_unit;
extern int slirp_socket_port;
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 7e86124df1..43aba3d152 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -40,8 +40,6 @@ static const uint8_t special_ethaddr[6] = {
static const uint8_t zero_ethaddr[6] = { 0, 0, 0, 0, 0, 0 };
-int link_up; // FIXME: kill this
-
/* XXX: suppress those select globals */
fd_set *global_readfds, *global_writefds, *global_xfds;
@@ -49,7 +47,7 @@ u_int curtime;
static u_int time_fasttimo, last_slowtimo;
static int do_slowtimo;
-Slirp slirp_instance;
+Slirp *slirp_instance;
#ifdef _WIN32
@@ -193,11 +191,10 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
const char *bootfile, struct in_addr vdhcp_start,
struct in_addr vnameserver, void *opaque)
{
- Slirp *slirp = &slirp_instance;
+ Slirp *slirp = qemu_mallocz(sizeof(Slirp));
slirp_init_once();
- link_up = 1;
slirp->restricted = restricted;
if_init(slirp);
@@ -213,13 +210,9 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
vhostname);
}
- qemu_free(slirp->tftp_prefix);
- slirp->tftp_prefix = NULL;
if (tftp_path) {
slirp->tftp_prefix = qemu_strdup(tftp_path);
}
- qemu_free(slirp->bootp_filename);
- slirp->bootp_filename = NULL;
if (bootfile) {
slirp->bootp_filename = qemu_strdup(bootfile);
}
@@ -230,9 +223,22 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
register_savevm("slirp", 0, 2, slirp_state_save, slirp_state_load, slirp);
+ slirp_instance = slirp;
+
return slirp;
}
+void slirp_cleanup(Slirp *slirp)
+{
+ unregister_savevm("slirp", slirp);
+
+ qemu_free(slirp->tftp_prefix);
+ qemu_free(slirp->bootp_filename);
+ qemu_free(slirp);
+
+ slirp_instance = NULL;
+}
+
#define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
#define CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
#define UPD_NFDS(x) if (nfds < (x)) nfds = (x)
@@ -263,11 +269,11 @@ static void updtime(void)
void slirp_select_fill(int *pnfds,
fd_set *readfds, fd_set *writefds, fd_set *xfds)
{
- Slirp *slirp = &slirp_instance;
+ Slirp *slirp = slirp_instance;
struct socket *so, *so_next;
int nfds;
- if (!link_up) {
+ if (!slirp_instance) {
return;
}
@@ -384,11 +390,11 @@ void slirp_select_fill(int *pnfds,
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
int select_error)
{
- Slirp *slirp = &slirp_instance;
+ Slirp *slirp = slirp_instance;
struct socket *so, *so_next;
int ret;
- if (!link_up) {
+ if (!slirp_instance) {
return;
}
diff --git a/slirp/slirp.h b/slirp/slirp.h
index cb1a746b39..5d8861ceb5 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -259,7 +259,7 @@ struct Slirp {
void *opaque;
};
-extern Slirp slirp_instance;
+extern Slirp *slirp_instance;
#ifndef NULL
#define NULL (void *)0