qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 11/11] slirp: Enhance host-guest redirection setu


From: Jan Kiszka
Subject: [Qemu-devel] [PATCH v2 11/11] slirp: Enhance host-guest redirection setup
Date: Sun, 19 Apr 2009 12:04:26 +0200
User-agent: StGIT/0.14.2

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 <address@hidden>
---

 monitor.c       |    4 ++++
 net.c           |   35 +++++++++++++++++++++--------------
 net.h           |    2 +-
 qemu-options.hx |    2 +-
 vl.c            |    2 +-
 5 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/monitor.c b/monitor.c
index 0accded..9f7fa70 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1735,6 +1735,10 @@ static const mon_cmd_t mon_cmds[] = {
       "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,
diff --git a/net.c b/net.c
index 8d688a0..db2f8d3 100644
--- a/net.c
+++ b/net.c
@@ -568,11 +568,11 @@ static int net_slirp_init(VLANState *vlan, const char 
*model, const char *name)
     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;
 
@@ -583,41 +583,48 @@ void net_slirp_redir(const char *redir_str)
 
     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
diff --git a/net.h b/net.h
index fe5ece7..cdf63a4 100644
--- a/net.h
+++ b/net.h
@@ -112,7 +112,7 @@ int net_client_init(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(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);
diff --git a/qemu-options.hx b/qemu-options.hx
index a29d1da..42bf714 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -943,7 +943,7 @@ When using the user mode network stack, redirect incoming 
TCP or UDP
 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:
diff --git a/vl.c b/vl.c
index 00c9759..3541781 100644
--- a/vl.c
+++ b/vl.c
@@ -4589,7 +4589,7 @@ int main(int argc, char **argv, char **envp)
                 break;
 #endif
             case QEMU_OPTION_redir:
-                net_slirp_redir(optarg);
+                net_slirp_redir(NULL, optarg);
                 break;
 #endif
             case QEMU_OPTION_bt:






reply via email to

[Prev in Thread] Current Thread [Next in Thread]