mirror of
https://github.com/xemu-project/xemu.git
synced 2025-01-31 09:02:37 +00:00
convert net_init_slirp() to NetClientOptions
Signed-off-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
This commit is contained in:
parent
848040d174
commit
094f15c5c8
95
net/slirp.c
95
net/slirp.c
@ -686,89 +686,46 @@ void do_info_usernet(Monitor *mon)
|
||||
}
|
||||
}
|
||||
|
||||
static int net_init_slirp_configs(const char *name, const char *value, void *opaque)
|
||||
static void
|
||||
net_init_slirp_configs(const StringList *fwd, int flags)
|
||||
{
|
||||
struct slirp_config_str *config;
|
||||
while (fwd) {
|
||||
struct slirp_config_str *config;
|
||||
|
||||
if (strcmp(name, "hostfwd") != 0 && strcmp(name, "guestfwd") != 0) {
|
||||
return 0;
|
||||
config = g_malloc0(sizeof(*config));
|
||||
pstrcpy(config->str, sizeof(config->str), fwd->value->str);
|
||||
config->flags = flags;
|
||||
config->next = slirp_configs;
|
||||
slirp_configs = config;
|
||||
|
||||
fwd = fwd->next;
|
||||
}
|
||||
|
||||
config = g_malloc0(sizeof(*config));
|
||||
|
||||
pstrcpy(config->str, sizeof(config->str), value);
|
||||
|
||||
if (!strcmp(name, "hostfwd")) {
|
||||
config->flags = SLIRP_CFG_HOSTFWD;
|
||||
}
|
||||
|
||||
config->next = slirp_configs;
|
||||
slirp_configs = config;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int net_init_slirp(QemuOpts *opts, const NetClientOptions *new_opts,
|
||||
int net_init_slirp(QemuOpts *old_opts, const NetClientOptions *opts,
|
||||
const char *name, VLANState *vlan)
|
||||
{
|
||||
struct slirp_config_str *config;
|
||||
const char *vhost;
|
||||
const char *vhostname;
|
||||
const char *vdhcp_start;
|
||||
const char *vnamesrv;
|
||||
const char *tftp_export;
|
||||
const char *bootfile;
|
||||
const char *smb_export;
|
||||
const char *vsmbsrv;
|
||||
const char *restrict_opt;
|
||||
char *vnet = NULL;
|
||||
int restricted = 0;
|
||||
char *vnet;
|
||||
int ret;
|
||||
const NetdevUserOptions *user;
|
||||
|
||||
vhost = qemu_opt_get(opts, "host");
|
||||
vhostname = qemu_opt_get(opts, "hostname");
|
||||
vdhcp_start = qemu_opt_get(opts, "dhcpstart");
|
||||
vnamesrv = qemu_opt_get(opts, "dns");
|
||||
tftp_export = qemu_opt_get(opts, "tftp");
|
||||
bootfile = qemu_opt_get(opts, "bootfile");
|
||||
smb_export = qemu_opt_get(opts, "smb");
|
||||
vsmbsrv = qemu_opt_get(opts, "smbserver");
|
||||
assert(opts->kind == NET_CLIENT_OPTIONS_KIND_USER);
|
||||
user = opts->user;
|
||||
|
||||
restrict_opt = qemu_opt_get(opts, "restrict");
|
||||
if (restrict_opt) {
|
||||
if (!strcmp(restrict_opt, "on") ||
|
||||
!strcmp(restrict_opt, "yes") || !strcmp(restrict_opt, "y")) {
|
||||
restricted = 1;
|
||||
} else if (strcmp(restrict_opt, "off") &&
|
||||
strcmp(restrict_opt, "no") && strcmp(restrict_opt, "n")) {
|
||||
error_report("invalid option: 'restrict=%s'", restrict_opt);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
vnet = user->has_net ? g_strdup(user->net) :
|
||||
user->has_ip ? g_strdup_printf("%s/24", user->ip) :
|
||||
NULL;
|
||||
|
||||
if (qemu_opt_get(opts, "ip")) {
|
||||
const char *ip = qemu_opt_get(opts, "ip");
|
||||
int l = strlen(ip) + strlen("/24") + 1;
|
||||
/* all optional fields are initialized to "all bits zero" */
|
||||
|
||||
vnet = g_malloc(l);
|
||||
net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD);
|
||||
net_init_slirp_configs(user->guestfwd, 0);
|
||||
|
||||
/* emulate legacy ip= parameter */
|
||||
pstrcpy(vnet, l, ip);
|
||||
pstrcat(vnet, l, "/24");
|
||||
}
|
||||
|
||||
if (qemu_opt_get(opts, "net")) {
|
||||
if (vnet) {
|
||||
g_free(vnet);
|
||||
}
|
||||
vnet = g_strdup(qemu_opt_get(opts, "net"));
|
||||
}
|
||||
|
||||
qemu_opt_foreach(opts, net_init_slirp_configs, NULL, 0);
|
||||
|
||||
ret = net_slirp_init(vlan, "user", name, restricted, vnet, vhost,
|
||||
vhostname, tftp_export, bootfile, vdhcp_start,
|
||||
vnamesrv, smb_export, vsmbsrv);
|
||||
ret = net_slirp_init(vlan, "user", name, user->restrict, vnet, user->host,
|
||||
user->hostname, user->tftp, user->bootfile,
|
||||
user->dhcpstart, user->dns, user->smb,
|
||||
user->smbserver);
|
||||
|
||||
while (slirp_configs) {
|
||||
config = slirp_configs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user