From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smvv3-0001Dl-Ct for qemu-devel@nongnu.org; Thu, 05 Jul 2012 19:57:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Smvv1-0005lE-3V for qemu-devel@nongnu.org; Thu, 05 Jul 2012 19:57:08 -0400 Received: from mout.web.de ([212.227.17.12]:61131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smvv0-0005ky-Q5 for qemu-devel@nongnu.org; Thu, 05 Jul 2012 19:57:07 -0400 Message-ID: <4FF629C9.6030907@web.de> Date: Fri, 06 Jul 2012 01:56:57 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1338709501-7740-1-git-send-email-agraf@suse.de> In-Reply-To: <1338709501-7740-1-git-send-email-agraf@suse.de> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigF36459B23754C926FE21EAFF" Subject: Re: [Qemu-devel] [PATCH] slirp: add 'cmd:' target for guestfwd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: Mark McLoughlin , Anthony Liguori , =?ISO-8859-15?Q?Ren=E9_Rebe?= , Gleb Natapov , "qemu-devel@nongnu.org Developers" , Sascha Wilde This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigF36459B23754C926FE21EAFF Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable On 2012-06-03 09:45, Alexander Graf wrote: > When using guestfwd=3D, Qemu only connects the virtual server's TCP por= t > to a single chardev. This is useless in most cases, as we usually want > to have more than a single connection from the guest to the outside wor= ld. >=20 > This patch adds a new cmd: target to guestfwd=3D that allows for execut= ion > of a command on every TCP connection. This leverages the same code as > the -smb parameter, just that here the command is user defined. >=20 > Reported-by: Sascha Wilde > Signed-off-by: Alexander Graf >=20 > --- >=20 > v1 -> v2: >=20 > - rebase to current master > - fix documentation > --- > net/slirp.c | 44 +++++++++++++++++++++++++++----------------- > qemu-options.hx | 22 +++++++++++++++++++++- > 2 files changed, 48 insertions(+), 18 deletions(-) >=20 > diff --git a/net/slirp.c b/net/slirp.c > index 96f5032..41cd058 100644 > --- a/net/slirp.c > +++ b/net/slirp.c > @@ -616,25 +616,35 @@ static int slirp_guestfwd(SlirpState *s, const ch= ar *config_str, > =20 > fwd =3D g_malloc(sizeof(struct GuestFwd)); > snprintf(buf, sizeof(buf), "guestfwd.tcp.%d", port); > - fwd->hd =3D qemu_chr_new(buf, p, NULL); > - if (!fwd->hd) { > - error_report("could not open guest forwarding device '%s'", bu= f); > - g_free(fwd); > - return -1; > - } > =20 > - if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) { > - error_report("conflicting/invalid host:port in guest forwardin= g " > - "rule '%s'", config_str); > - g_free(fwd); > - return -1; > - } > - fwd->server =3D server; > - fwd->port =3D port; > - fwd->slirp =3D s->slirp; > + if ((strlen(p) > 4) && !strncmp(p, "cmd:", 4)) { > + if (slirp_add_exec(s->slirp, 0, &p[4], &server, port) < 0) { > + error_report("conflicting/invalid host:port in guest forwa= rding " > + "rule '%s'", config_str); > + g_free(fwd); > + return -1; > + } > + } else { > + fwd->hd =3D qemu_chr_new(buf, p, NULL); > + if (!fwd->hd) { > + error_report("could not open guest forwarding device '%s'"= , buf); > + g_free(fwd); > + return -1; > + } > + > + if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {= > + error_report("conflicting/invalid host:port in guest forwa= rding " > + "rule '%s'", config_str); > + g_free(fwd); > + return -1; > + } > + fwd->server =3D server; > + fwd->port =3D port; > + fwd->slirp =3D s->slirp; > =20 > - qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read, > - NULL, fwd); > + qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_rea= d, > + NULL, fwd); > + } > return 0; > =20 > fail_syntax: > diff --git a/qemu-options.hx b/qemu-options.hx > index 8b66264..ecf7ca1 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -1421,8 +1421,28 @@ Then when you use on the host @code{telnet local= host 5555}, you > connect to the guest telnet server. > =20 > @item guestfwd=3D[tcp]:@var{server}:@var{port}-@var{dev} > +@item guestfwd=3D[tcp]:@var{server}:@var{port}-@var{cmd:command} > Forward guest TCP connections to the IP address @var{server} on port @= var{port} > -to the character device @var{dev}. This option can be given multiple t= imes. > +to the character device @var{dev} or to a program executed by @var{cmd= :command} > +which gets spawned for each connection. This option can be given multi= ple times. > + > +You can either use a chardev directly and have that one used throughou= t Qemu's > +lifetime, like in the following example: > + > +@example > +# open 10.10.1.1:4321 on bootup, connect 10.0.2.100:1234 to it wheneve= r > +# the guest accesses it > +qemu -net user,guestfwd=3Dtcp:10.0.2.100:1234-tcp:10.10.1.1:4321 [...]= > +@end example > + > +Or you can execute a command on every TCP connection established by th= e guest, > +so that Qemu behaves similar to an inetd process for that virtual serv= er: > + > +@example > +# call "netcat 10.10.1.1 4321" on every TCP connection to 10.0.2.100:1= 234 > +# and connect the TCP stream to its stdin/stdout > +qemu -net 'user,guestfwd=3Dtcp:10.0.2.100:1234-cmd:netcat 10.10.1.1 43= 21' > +@end example > =20 > @end table > =20 >=20 Thanks, queued. Jan --------------enigF36459B23754C926FE21EAFF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk/2KckACgkQitSsb3rl5xQ+gQCgg4eu9QqqZTXwHrQ8JamtP/fq B4IAoInltyYc4IWKGZd1VQ4Tu0njaq2r =D3DM -----END PGP SIGNATURE----- --------------enigF36459B23754C926FE21EAFF--