diff options
author | Alexander Graf <agraf@suse.de> | 2009-05-26 13:03:26 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-05-27 09:46:12 -0500 |
commit | c1261d8d1617d8cf5722039a59ebb66c310f3aea (patch) | |
tree | 8aad15c7b36255d671f3911886b9c0985ee73f28 /net.c | |
parent | 8a43b1ea7fd02a8e9a5c5ef58017b1bd059663bb (diff) | |
download | qemu-c1261d8d1617d8cf5722039a59ebb66c310f3aea.zip qemu-c1261d8d1617d8cf5722039a59ebb66c310f3aea.tar.gz qemu-c1261d8d1617d8cf5722039a59ebb66c310f3aea.tar.bz2 |
User Networking: Enable removal of redirections
Using the new host_net_redir command you can easily create redirections
on the fly while your VM is running.
While that's great, it's missing the removal of redirections, in case you
want to have a port closed again at a later point in time.
This patch adds support for removal of redirections.
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -568,7 +568,43 @@ static int net_slirp_init(VLANState *vlan, const char *model, const char *name) return 0; } -void net_slirp_redir(Monitor *mon, const char *redir_str) +static void net_slirp_redir_rm(Monitor *mon, const char *port_str) +{ + int host_port; + char buf[256] = ""; + const char *p = port_str; + int is_udp = 0; + int n; + + if (!mon) + return; + + if (!port_str || !port_str[0]) + goto fail_syntax; + + get_str_sep(buf, sizeof(buf), &p, ':'); + + if (!strcmp(buf, "tcp") || buf[0] == '\0') { + is_udp = 0; + } else if (!strcmp(buf, "udp")) { + is_udp = 1; + } else { + goto fail_syntax; + } + + host_port = atoi(p); + + n = slirp_redir_rm(is_udp, host_port); + + monitor_printf(mon, "removed %d redirections to %s port %d\n", n, + is_udp ? "udp" : "tcp", host_port); + return; + + fail_syntax: + monitor_printf(mon, "invalid format\n"); +} + +void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2) { int is_udp; char buf[256], *r; @@ -581,6 +617,11 @@ void net_slirp_redir(Monitor *mon, const char *redir_str) slirp_init(slirp_restrict, slirp_ip); } + if (!strcmp(redir_str, "remove")) { + net_slirp_redir_rm(mon, redir_opt2); + return; + } + p = redir_str; if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) goto fail_syntax; |