mirror of https://gitee.com/openkylin/qemu.git
slirp: Rework monitor commands for host forwarding
Improve the monitor interface for adding and removing host forwarding rules by splitting it up in two commands and rename them to hostfwd_add and hostfwd_remove. Also split up the paths taken for legacy -redir support and the monitor add command as the latter will be extended later on. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
2ad82cf9e2
commit
f3546deb07
41
net.c
41
net.c
|
@ -871,7 +871,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str)
|
void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str)
|
||||||
{
|
{
|
||||||
int host_port;
|
int host_port;
|
||||||
char buf[256] = "";
|
char buf[256] = "";
|
||||||
|
@ -879,8 +879,10 @@ static void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str)
|
||||||
int is_udp = 0;
|
int is_udp = 0;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (!mon)
|
if (!slirp_inited) {
|
||||||
|
monitor_printf(mon, "user mode network stack not in use\n");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!port_str || !port_str[0])
|
if (!port_str || !port_str[0])
|
||||||
goto fail_syntax;
|
goto fail_syntax;
|
||||||
|
@ -958,31 +960,32 @@ static void slirp_hostfwd(Monitor *mon, const char *redir_str)
|
||||||
config_error(mon, "invalid host forwarding rule '%s'\n", redir_str);
|
config_error(mon, "invalid host forwarding rule '%s'\n", redir_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2)
|
void net_slirp_hostfwd_add(Monitor *mon, const char *redir_str)
|
||||||
{
|
{
|
||||||
struct slirp_config_str *config;
|
|
||||||
|
|
||||||
if (!slirp_inited) {
|
if (!slirp_inited) {
|
||||||
if (mon) {
|
monitor_printf(mon, "user mode network stack not in use\n");
|
||||||
monitor_printf(mon, "user mode network stack not in use\n");
|
|
||||||
} else {
|
|
||||||
config = qemu_malloc(sizeof(*config));
|
|
||||||
pstrcpy(config->str, sizeof(config->str), redir_str);
|
|
||||||
config->flags = SLIRP_CFG_HOSTFWD;
|
|
||||||
config->next = slirp_configs;
|
|
||||||
slirp_configs = config;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp(redir_str, "remove")) {
|
|
||||||
net_slirp_hostfwd_remove(mon, redir_opt2);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
slirp_hostfwd(mon, redir_str);
|
slirp_hostfwd(mon, redir_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void net_slirp_redir(const char *redir_str)
|
||||||
|
{
|
||||||
|
struct slirp_config_str *config;
|
||||||
|
|
||||||
|
if (!slirp_inited) {
|
||||||
|
config = qemu_malloc(sizeof(*config));
|
||||||
|
pstrcpy(config->str, sizeof(config->str), redir_str);
|
||||||
|
config->flags = SLIRP_CFG_HOSTFWD;
|
||||||
|
config->next = slirp_configs;
|
||||||
|
slirp_configs = config;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
slirp_hostfwd(NULL, redir_str);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
||||||
static char smb_dir[1024];
|
static char smb_dir[1024];
|
||||||
|
|
4
net.h
4
net.h
|
@ -132,7 +132,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p);
|
||||||
void net_client_uninit(NICInfo *nd);
|
void net_client_uninit(NICInfo *nd);
|
||||||
int net_client_parse(const char *str);
|
int net_client_parse(const char *str);
|
||||||
void net_slirp_smb(const char *exported_dir);
|
void net_slirp_smb(const char *exported_dir);
|
||||||
void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2);
|
void net_slirp_hostfwd_add(Monitor *mon, const char *redir_str);
|
||||||
|
void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str);
|
||||||
|
void net_slirp_redir(const char *redir_str);
|
||||||
void net_cleanup(void);
|
void net_cleanup(void);
|
||||||
int slirp_is_inited(void);
|
int slirp_is_inited(void);
|
||||||
void net_client_check(void);
|
void net_client_check(void);
|
||||||
|
|
|
@ -536,9 +536,11 @@ Remove host VLAN client.
|
||||||
ETEXI
|
ETEXI
|
||||||
|
|
||||||
#ifdef CONFIG_SLIRP
|
#ifdef CONFIG_SLIRP
|
||||||
{ "host_net_redir", "ss?", net_slirp_redir,
|
{ "hostfwd_add", "s", net_slirp_hostfwd_add,
|
||||||
"[tcp|udp]:host-port:[guest-host]:guest-port", "redirect TCP or UDP connections from host to guest (requires -net user)\n"
|
"[tcp|udp]:hostport:[guestaddr]:guestport",
|
||||||
"host_net_redir remove [tcp:|udp:]host-port -- remove redirection" },
|
"redirect TCP or UDP connections from host to guest (requires -net user)" },
|
||||||
|
{ "hostfwd_remove", "s", net_slirp_hostfwd_remove,
|
||||||
|
"[tcp|udp]:hostport", "remove host-to-guest TCP or UDP redirection" },
|
||||||
#endif
|
#endif
|
||||||
STEXI
|
STEXI
|
||||||
@item host_net_redir
|
@item host_net_redir
|
||||||
|
|
Loading…
Reference in New Issue