aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2009-06-24 14:42:28 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-29 08:52:45 -0500
commitf3546deb079fd9e069870b9fd2f22bb48d5c8254 (patch)
tree40f742ab62041f18c8c5cd42f7b282616fb8fd4b
parent2ad82cf9e2c2adad874fbecabd48e1cf699b7c84 (diff)
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>
-rw-r--r--net.c37
-rw-r--r--net.h4
-rw-r--r--qemu-monitor.hx8
-rw-r--r--vl.c2
4 files changed, 29 insertions, 22 deletions
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,29 +960,30 @@ 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;
- }
+ monitor_printf(mon, "user mode network stack not in use\n");
return;
}
- if (!strcmp(redir_str, "remove")) {
- net_slirp_hostfwd_remove(mon, redir_opt2);
+ 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(mon, redir_str);
+ slirp_hostfwd(NULL, redir_str);
}
#ifndef _WIN32
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: