diff --git a/net.c b/net.c index f26c3f804e..883a236638 100644 --- a/net.c +++ b/net.c @@ -871,7 +871,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, 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; char buf[256] = ""; @@ -879,8 +879,10 @@ static void net_slirp_hostfwd_remove(Monitor *mon, const char *port_str) int is_udp = 0; int n; - if (!mon) + if (!slirp_inited) { + monitor_printf(mon, "user mode network stack not in use\n"); return; + } if (!port_str || !port_str[0]) 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); } -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 (mon) { - 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); + monitor_printf(mon, "user mode network stack not in use\n"); return; } 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 static char smb_dir[1024]; diff --git a/net.h b/net.h index 01f3450208..9edfab108e 100644 --- a/net.h +++ b/net.h @@ -132,7 +132,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p); void net_client_uninit(NICInfo *nd); int net_client_parse(const char *str); 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); int slirp_is_inited(void); void net_client_check(void); diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 090255bd2e..13c98bc9ac 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -536,9 +536,11 @@ Remove host VLAN client. ETEXI #ifdef CONFIG_SLIRP - { "host_net_redir", "ss?", net_slirp_redir, - "[tcp|udp]:host-port:[guest-host]:guest-port", "redirect TCP or UDP connections from host to guest (requires -net user)\n" - "host_net_redir remove [tcp:|udp:]host-port -- remove redirection" }, + { "hostfwd_add", "s", net_slirp_hostfwd_add, + "[tcp|udp]:hostport:[guestaddr]:guestport", + "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 STEXI @item host_net_redir diff --git a/vl.c b/vl.c index 4f9c521604..23add311bc 100644 --- a/vl.c +++ b/vl.c @@ -5319,7 +5319,7 @@ int main(int argc, char **argv, char **envp) break; #endif case QEMU_OPTION_redir: - net_slirp_redir(NULL, optarg, NULL); + net_slirp_redir(optarg); break; #endif case QEMU_OPTION_bt: