Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwM5I-0006ji-0o for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwM5H-0006jD-2g for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:47 -0400 Received: from [199.232.76.173] (port=39684 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwM5G-0006j6-Ro for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:46 -0400 Received: from savannah.gnu.org ([199.232.41.3]:35692 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LwM5G-00029X-AV for qemu-devel@nongnu.org; Tue, 21 Apr 2009 15:56:46 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LwM5F-0007xL-KD for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:56:45 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LwM5F-0007xG-AO for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:56:45 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 21 Apr 2009 19:56:45 +0000 Subject: [Qemu-devel] [7204] slirp: Enhance host-guest redirection setup (Jan Kiszka) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7204 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7204 Author: aliguori Date: 2009-04-21 19:56:44 +0000 (Tue, 21 Apr 2009) Log Message: ----------- slirp: Enhance host-guest redirection setup (Jan Kiszka) Allow to establish a TCP/UDP connection redirection also via a monitor command 'host_net_redir'. Moreover, assume TCP as connection type if that parameter is omitted. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/monitor.c trunk/net.c trunk/net.h trunk/qemu-options.hx trunk/vl.c Modified: trunk/monitor.c =================================================================== --- trunk/monitor.c 2009-04-21 19:56:41 UTC (rev 7203) +++ trunk/monitor.c 2009-04-21 19:56:44 UTC (rev 7204) @@ -1735,6 +1735,10 @@ "tap|user|socket|vde|dump [options]", "add host VLAN client" }, { "host_net_remove", "is", net_host_device_remove, "vlan_id name", "remove host VLAN client" }, +#ifdef CONFIG_SLIRP + { "host_net_redir", "s", net_slirp_redir, + "[tcp|udp]:host-port:[guest-host]:guest-port", "redirect TCP or UDP connections from host to guest (requires -net user)" }, +#endif { "balloon", "i", do_balloon, "target", "request VM to change it's memory allocation (in MB)" }, { "set_link", "ss", do_set_link, Modified: trunk/net.c =================================================================== --- trunk/net.c 2009-04-21 19:56:41 UTC (rev 7203) +++ trunk/net.c 2009-04-21 19:56:44 UTC (rev 7204) @@ -556,11 +556,11 @@ return 0; } -void net_slirp_redir(const char *redir_str) +void net_slirp_redir(Monitor *mon, const char *redir_str) { int is_udp; char buf[256], *r; - const char *p; + const char *p, *errmsg; struct in_addr guest_addr; int host_port, guest_port; @@ -571,41 +571,48 @@ p = redir_str; if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) - goto fail; - if (!strcmp(buf, "tcp")) { + goto fail_syntax; + if (!strcmp(buf, "tcp") || buf[0] == '\0') { is_udp = 0; } else if (!strcmp(buf, "udp")) { is_udp = 1; } else { - goto fail; + goto fail_syntax; } if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) - goto fail; + goto fail_syntax; host_port = strtol(buf, &r, 0); if (r == buf) - goto fail; + goto fail_syntax; if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) - goto fail; + goto fail_syntax; if (buf[0] == '\0') { pstrcpy(buf, sizeof(buf), "10.0.2.15"); } if (!inet_aton(buf, &guest_addr)) - goto fail; + goto fail_syntax; guest_port = strtol(p, &r, 0); if (r == p) - goto fail; + goto fail_syntax; if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) { - fprintf(stderr, "qemu: could not set up redirection\n"); - exit(1); + errmsg = "could not set up redirection\n"; + goto fail; } return; + + fail_syntax: + errmsg = "invalid redirection format\n"; fail: - fprintf(stderr, "qemu: syntax: -redir [tcp|udp]:host-port:[guest-host]:guest-port\n"); - exit(1); + if (mon) { + monitor_printf(mon, errmsg); + } else { + fprintf(stderr, "qemu: %s", errmsg); + exit(1); + } } #ifndef _WIN32 Modified: trunk/net.h =================================================================== --- trunk/net.h 2009-04-21 19:56:41 UTC (rev 7203) +++ trunk/net.h 2009-04-21 19:56:44 UTC (rev 7204) @@ -112,7 +112,7 @@ 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(const char *redir_str); +void net_slirp_redir(Monitor *mon, const char *redir_str); void net_cleanup(void); int slirp_is_inited(void); void net_client_check(void); Modified: trunk/qemu-options.hx =================================================================== --- trunk/qemu-options.hx 2009-04-21 19:56:41 UTC (rev 7203) +++ trunk/qemu-options.hx 2009-04-21 19:56:44 UTC (rev 7204) @@ -943,7 +943,7 @@ connections to the host port @var{host-port} to the guest @var{guest-host} on guest port @var{guest-port}. If @var{guest-host} is not specified, its value is 10.0.2.15 (default address given by the -built-in DHCP server). +built-in DHCP server). If no connection type is specified, TCP is used. For example, to redirect host X11 connection from screen 1 to guest screen 0, use the following: Modified: trunk/vl.c =================================================================== --- trunk/vl.c 2009-04-21 19:56:41 UTC (rev 7203) +++ trunk/vl.c 2009-04-21 19:56:44 UTC (rev 7204) @@ -4589,7 +4589,7 @@ break; #endif case QEMU_OPTION_redir: - net_slirp_redir(optarg); + net_slirp_redir(NULL, optarg); break; #endif case QEMU_OPTION_bt: