From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LWUoq-0005R8-Gj for qemu-devel@nongnu.org; Mon, 09 Feb 2009 07:00:56 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LWUop-0005Qh-7o for qemu-devel@nongnu.org; Mon, 09 Feb 2009 07:00:56 -0500 Received: from [199.232.76.173] (port=46773 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LWUoo-0005QU-Sp for qemu-devel@nongnu.org; Mon, 09 Feb 2009 07:00:54 -0500 Received: from mx2.redhat.com ([66.187.237.31]:53337) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LWUoo-0004x8-9f for qemu-devel@nongnu.org; Mon, 09 Feb 2009 07:00:54 -0500 Date: Mon, 9 Feb 2009 13:58:21 +0200 From: Gleb Natapov Message-ID: <20090209115821.GB28969@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] specify vmchannel as a net option Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com Signed-off-by: Gleb Natapov diff --git a/net.c b/net.c index e7c097e..4149615 100644 --- a/net.c +++ b/net.c @@ -657,6 +657,23 @@ void do_info_slirp(void) slirp_stats(); } +struct VMChannel { + CharDriverState *hd; + int port; +} *vmchannels; + +static int vmchannel_can_read(void *opaque) +{ + struct VMChannel *vmc = (struct VMChannel*)opaque; + return slirp_socket_can_recv(4, vmc->port); +} + +static void vmchannel_read(void *opaque, const uint8_t *buf, int size) +{ + struct VMChannel *vmc = (struct VMChannel*)opaque; + slirp_socket_recv(4, vmc->port, buf, size); +} + #endif /* CONFIG_SLIRP */ #if !defined(_WIN32) @@ -1605,6 +1622,30 @@ int net_client_init(const char *device, const char *p) } vlan->nb_host_devs++; ret = net_slirp_init(vlan, device, name); + } else if (!strcmp(device, "channel")) { + long port; + char name[20], *devname; + struct VMChannel *vmc; + + port = strtol(p, &devname, 10); + devname++; + if (port < 1 || port > 65535) { + fprintf(stderr, "vmchannel wrong port number\n"); + return -1; + } + vmc = malloc(sizeof(struct VMChannel)); + snprintf(name, 20, "vmchannel%ld", port); + vmc->hd = qemu_chr_open(name, devname, NULL); + if (!vmc->hd) { + fprintf(stderr, "qemu: could not open vmchannel device" + "'%s'\n", devname); + return -1; + } + vmc->port = port; + slirp_add_exec(3, vmc->hd, 4, port); + qemu_chr_add_handlers(vmc->hd, vmchannel_can_read, vmchannel_read, + NULL, vmc); + ret = 0; } else #endif #ifdef _WIN32 diff --git a/qemu-doc.texi b/qemu-doc.texi index efb88d2..8322a08 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -643,6 +643,9 @@ Use the user mode network stack which requires no administrator privilege to run. @option{hostname=name} can be used to specify the client hostname reported by the builtin DHCP server. +@item -net channel,@var{port}:@var{dev} +Forward @option{user} TCP connection to port @var{port} to character device @var{dev} + @item -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}] Connect the host TAP network interface @var{name} to VLAN @var{n}, use the network script @var{file} to configure it and the network script -- Gleb.