mirror of
https://git.proxmox.com/git/qemu
synced 2025-07-09 13:18:26 +00:00
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>
This commit is contained in:
parent
9f8bd0421d
commit
ad0d8c4c32
18
net.c
18
net.c
@ -729,11 +729,13 @@ static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t siz
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int slirp_in_use;
|
|
||||||
|
|
||||||
static void net_slirp_cleanup(VLANClientState *vc)
|
static void net_slirp_cleanup(VLANClientState *vc)
|
||||||
{
|
{
|
||||||
slirp_in_use = 0;
|
SlirpState *s = vc->opaque;
|
||||||
|
|
||||||
|
slirp_cleanup(s->slirp);
|
||||||
|
slirp_state = NULL;
|
||||||
|
qemu_free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
|
static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
|
||||||
@ -744,13 +746,6 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
|
|||||||
const char *vnameserver, const char *smb_export,
|
const char *vnameserver, const char *smb_export,
|
||||||
const char *vsmbserver)
|
const char *vsmbserver)
|
||||||
{
|
{
|
||||||
SlirpState *s = slirp_state;
|
|
||||||
|
|
||||||
if (slirp_in_use) {
|
|
||||||
/* slirp only supports a single instance so far */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!s) {
|
|
||||||
/* default settings according to historic slirp */
|
/* default settings according to historic slirp */
|
||||||
struct in_addr net = { .s_addr = htonl(0x0a000000) }; /* 10.0.0.0 */
|
struct in_addr net = { .s_addr = htonl(0x0a000000) }; /* 10.0.0.0 */
|
||||||
struct in_addr mask = { .s_addr = htonl(0xff000000) }; /* 255.0.0.0 */
|
struct in_addr mask = { .s_addr = htonl(0xff000000) }; /* 255.0.0.0 */
|
||||||
@ -760,6 +755,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
struct in_addr smbsrv = { .s_addr = 0 };
|
struct in_addr smbsrv = { .s_addr = 0 };
|
||||||
#endif
|
#endif
|
||||||
|
SlirpState *s;
|
||||||
char buf[20];
|
char buf[20];
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
int shift;
|
int shift;
|
||||||
@ -869,12 +865,10 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
|
|||||||
slirp_smb(s, smb_export, smbsrv);
|
slirp_smb(s, smb_export, smbsrv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
s->vc = qemu_new_vlan_client(vlan, model, name, NULL, slirp_receive, NULL,
|
s->vc = qemu_new_vlan_client(vlan, model, name, NULL, slirp_receive, NULL,
|
||||||
net_slirp_cleanup, s);
|
net_slirp_cleanup, s);
|
||||||
s->vc->info_str[0] = '\0';
|
s->vc->info_str[0] = '\0';
|
||||||
slirp_in_use = 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
|
|||||||
const char *vhostname, const char *tftp_path,
|
const char *vhostname, const char *tftp_path,
|
||||||
const char *bootfile, struct in_addr vdhcp_start,
|
const char *bootfile, struct in_addr vdhcp_start,
|
||||||
struct in_addr vnameserver, void *opaque);
|
struct in_addr vnameserver, void *opaque);
|
||||||
|
void slirp_cleanup(Slirp *slirp);
|
||||||
|
|
||||||
void slirp_select_fill(int *pnfds,
|
void slirp_select_fill(int *pnfds,
|
||||||
fd_set *readfds, fd_set *writefds, fd_set *xfds);
|
fd_set *readfds, fd_set *writefds, fd_set *xfds);
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#define TOWRITEMAX 512
|
#define TOWRITEMAX 512
|
||||||
|
|
||||||
extern int link_up;
|
|
||||||
extern int slirp_socket;
|
extern int slirp_socket;
|
||||||
extern int slirp_socket_unit;
|
extern int slirp_socket_unit;
|
||||||
extern int slirp_socket_port;
|
extern int slirp_socket_port;
|
||||||
|
@ -40,8 +40,6 @@ static const uint8_t special_ethaddr[6] = {
|
|||||||
|
|
||||||
static const uint8_t zero_ethaddr[6] = { 0, 0, 0, 0, 0, 0 };
|
static const uint8_t zero_ethaddr[6] = { 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
int link_up; // FIXME: kill this
|
|
||||||
|
|
||||||
/* XXX: suppress those select globals */
|
/* XXX: suppress those select globals */
|
||||||
fd_set *global_readfds, *global_writefds, *global_xfds;
|
fd_set *global_readfds, *global_writefds, *global_xfds;
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ u_int curtime;
|
|||||||
static u_int time_fasttimo, last_slowtimo;
|
static u_int time_fasttimo, last_slowtimo;
|
||||||
static int do_slowtimo;
|
static int do_slowtimo;
|
||||||
|
|
||||||
Slirp slirp_instance;
|
Slirp *slirp_instance;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
@ -193,11 +191,10 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
|
|||||||
const char *bootfile, struct in_addr vdhcp_start,
|
const char *bootfile, struct in_addr vdhcp_start,
|
||||||
struct in_addr vnameserver, void *opaque)
|
struct in_addr vnameserver, void *opaque)
|
||||||
{
|
{
|
||||||
Slirp *slirp = &slirp_instance;
|
Slirp *slirp = qemu_mallocz(sizeof(Slirp));
|
||||||
|
|
||||||
slirp_init_once();
|
slirp_init_once();
|
||||||
|
|
||||||
link_up = 1;
|
|
||||||
slirp->restricted = restricted;
|
slirp->restricted = restricted;
|
||||||
|
|
||||||
if_init(slirp);
|
if_init(slirp);
|
||||||
@ -213,13 +210,9 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
|
|||||||
pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
|
pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
|
||||||
vhostname);
|
vhostname);
|
||||||
}
|
}
|
||||||
qemu_free(slirp->tftp_prefix);
|
|
||||||
slirp->tftp_prefix = NULL;
|
|
||||||
if (tftp_path) {
|
if (tftp_path) {
|
||||||
slirp->tftp_prefix = qemu_strdup(tftp_path);
|
slirp->tftp_prefix = qemu_strdup(tftp_path);
|
||||||
}
|
}
|
||||||
qemu_free(slirp->bootp_filename);
|
|
||||||
slirp->bootp_filename = NULL;
|
|
||||||
if (bootfile) {
|
if (bootfile) {
|
||||||
slirp->bootp_filename = qemu_strdup(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);
|
register_savevm("slirp", 0, 2, slirp_state_save, slirp_state_load, slirp);
|
||||||
|
|
||||||
|
slirp_instance = slirp;
|
||||||
|
|
||||||
return 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_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 CONN_CANFRCV(so) (((so)->so_state & (SS_FCANTRCVMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
|
||||||
#define UPD_NFDS(x) if (nfds < (x)) nfds = (x)
|
#define UPD_NFDS(x) if (nfds < (x)) nfds = (x)
|
||||||
@ -263,11 +269,11 @@ static void updtime(void)
|
|||||||
void slirp_select_fill(int *pnfds,
|
void slirp_select_fill(int *pnfds,
|
||||||
fd_set *readfds, fd_set *writefds, fd_set *xfds)
|
fd_set *readfds, fd_set *writefds, fd_set *xfds)
|
||||||
{
|
{
|
||||||
Slirp *slirp = &slirp_instance;
|
Slirp *slirp = slirp_instance;
|
||||||
struct socket *so, *so_next;
|
struct socket *so, *so_next;
|
||||||
int nfds;
|
int nfds;
|
||||||
|
|
||||||
if (!link_up) {
|
if (!slirp_instance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,11 +390,11 @@ void slirp_select_fill(int *pnfds,
|
|||||||
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
|
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
|
||||||
int select_error)
|
int select_error)
|
||||||
{
|
{
|
||||||
Slirp *slirp = &slirp_instance;
|
Slirp *slirp = slirp_instance;
|
||||||
struct socket *so, *so_next;
|
struct socket *so, *so_next;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!link_up) {
|
if (!slirp_instance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ struct Slirp {
|
|||||||
void *opaque;
|
void *opaque;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Slirp slirp_instance;
|
extern Slirp *slirp_instance;
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL (void *)0
|
#define NULL (void *)0
|
||||||
|
Loading…
Reference in New Issue
Block a user