From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JFXeD-0007JJ-Ii for qemu-devel@nongnu.org; Thu, 17 Jan 2008 11:31:21 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JFXeA-0007G3-Lc for qemu-devel@nongnu.org; Thu, 17 Jan 2008 11:31:21 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JFXeA-0007Fm-Fs for qemu-devel@nongnu.org; Thu, 17 Jan 2008 11:31:18 -0500 Received: from smtp-15.smtp.ucla.edu ([169.232.46.251]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JFXe9-0000x7-RO for qemu-devel@nongnu.org; Thu, 17 Jan 2008 11:31:18 -0500 Message-ID: <478F8252.7000607@cs.ucla.edu> Date: Thu, 17 Jan 2008 08:29:06 -0800 From: Eddie Kohler MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] add VNC reverse connections References: <478DB1D3.60905@cs.ucla.edu> <20080116124231.GB16624@redhat.com> <478E1E0F.1040303@cs.ucla.edu> <20080116163539.GA27604@redhat.com> <478E9BA5.8090704@codemonkey.ws> In-Reply-To: <478E9BA5.8090704@codemonkey.ws> Content-Type: multipart/mixed; boundary="------------080208040209000909050204" Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------080208040209000909050204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Well, attached is a patch with ",reverse" syntax, anyway; hopefully one of these syntaxes is OK! Eddie Anthony Liguori wrote: > Daniel P. Berrange wrote: >> On Wed, Jan 16, 2008 at 07:09:03AM -0800, Eddie Kohler wrote: >> >>> Daniel P. Berrange wrote: >>> >>>> We already have the ability to pass multiple flags / options to the VNC >>>> driver as a post-fix to the host:port pair, so I'm not a fan of >>>> introducing >>>> a new option as a prefix. If using existing options syntax, it could >>>> look >>>> like: >>>> >>>> -vnc :5500,rev >>>> -vnc read.cs.ucla.edu:5500,rev --------------080208040209000909050204 Content-Type: text/x-patch; name="qemu-cvs-vnc-reverse.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-cvs-vnc-reverse.patch" Index: qemu-doc.texi =================================================================== RCS file: /sources/qemu/qemu/qemu-doc.texi,v retrieving revision 1.179 diff -u -r1.179 qemu-doc.texi --- qemu-doc.texi 14 Jan 2008 22:09:11 -0000 1.179 +++ qemu-doc.texi 17 Jan 2008 16:28:44 -0000 @@ -418,21 +418,21 @@ @table @code -@item @var{interface}:@var{d} +@item @var{host}:@var{d} -TCP connections will only be allowed from @var{interface} on display @var{d}. -By convention the TCP port is 5900+@var{d}. Optionally, @var{interface} can -be omitted in which case the server will bind to all interfaces. +TCP connections will only be allowed from @var{host} on display @var{d}. +By convention the TCP port is 5900+@var{d}. Optionally, @var{host} can +be omitted in which case the server will accept connections from any host. -@item @var{unix}:@var{path} +@item @code{unix}:@var{path} Connections will be allowed over UNIX domain sockets where @var{path} is the location of a unix socket to listen for connections on. @item none -VNC is initialized by not started. The monitor @code{change} command can be used -to later start the VNC server. +VNC is initialized but not started. The monitor @code{change} command +can be used to later start the VNC server. @end table @@ -441,6 +441,13 @@ @table @code +@item reverse + +Connect to a listening VNC client via a ``reverse'' connection. The +client is specified by the @var{display}. For reverse network +connections (@var{host}:@var{d},@code{reverse}), the @var{d} argument +is a TCP port number, not a display number. + @item password Require that password based authentication is used for client connections. Index: vnc.c =================================================================== RCS file: /sources/qemu/qemu/vnc.c,v retrieving revision 1.33 diff -u -r1.33 vnc.c --- vnc.c 14 Jan 2008 21:45:55 -0000 1.33 +++ vnc.c 17 Jan 2008 16:28:44 -0000 @@ -1898,6 +1898,22 @@ return 0; } +static void vnc_connect(VncState *vs) +{ + VNC_DEBUG("New client on socket %d\n", vs->csock); + socket_set_nonblock(vs->csock); + qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs); + vnc_write(vs, "RFB 003.008\n", 12); + vnc_flush(vs); + vnc_read_when(vs, protocol_version, 12); + memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height); + memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); + vs->has_resize = 0; + vs->has_hextile = 0; + vs->ds->dpy_copy = NULL; + vnc_update_client(vs); +} + static void vnc_listen_read(void *opaque) { VncState *vs = opaque; @@ -1909,18 +1925,7 @@ vs->csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen); if (vs->csock != -1) { - VNC_DEBUG("New client on socket %d\n", vs->csock); - socket_set_nonblock(vs->csock); - qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, opaque); - vnc_write(vs, "RFB 003.008\n", 12); - vnc_flush(vs); - vnc_read_when(vs, protocol_version, 12); - memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height); - memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); - vs->has_resize = 0; - vs->has_hextile = 0; - vs->ds->dpy_copy = NULL; - vnc_update_client(vs); + vnc_connect(vs); } } @@ -2087,6 +2092,7 @@ VncState *vs = ds ? (VncState *)ds->opaque : vnc_state; const char *options; int password = 0; + int reverse = 0; #if CONFIG_VNC_TLS int tls = 0, x509 = 0; #endif @@ -2103,6 +2109,8 @@ options++; if (strncmp(options, "password", 8) == 0) { password = 1; /* Require password auth */ + } else if (strncmp(options, "reverse", 7) == 0) { + reverse = 1; #if CONFIG_VNC_TLS } else if (strncmp(options, "tls", 3) == 0) { tls = 1; /* Require TLS */ @@ -2196,7 +2204,9 @@ memset(uaddr.sun_path, 0, 108); snprintf(uaddr.sun_path, 108, "%s", p); - unlink(uaddr.sun_path); + if (!reverse) { + unlink(uaddr.sun_path); + } } else #endif { @@ -2210,7 +2220,7 @@ return -1; } - iaddr.sin_port = htons(ntohs(iaddr.sin_port) + 5900); + iaddr.sin_port = htons(ntohs(iaddr.sin_port) + (reverse ? 0 : 5900)); vs->lsock = socket(PF_INET, SOCK_STREAM, 0); if (vs->lsock == -1) { @@ -2233,6 +2243,22 @@ } } + if (reverse) { + if (connect(vs->lsock, addr, addrlen) == -1) { + fprintf(stderr, "Connection to VNC client failed\n"); + close(vs->lsock); + vs->lsock = -1; + free(vs->display); + vs->display = NULL; + return -1; + } else { + vs->csock = vs->lsock; + vs->lsock = -1; + vnc_connect(vs); + return 0; + } + } + if (bind(vs->lsock, addr, addrlen) == -1) { fprintf(stderr, "bind() failed\n"); close(vs->lsock); --------------080208040209000909050204--