From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:43111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNOEG-0003u1-Dq for qemu-devel@nongnu.org; Mon, 07 Nov 2011 07:23:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RNOEE-0001Ql-M7 for qemu-devel@nongnu.org; Mon, 07 Nov 2011 07:23:08 -0500 Received: from fmmailgate07.web.de ([217.72.192.248]:53006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNOE9-0001Q7-Pq for qemu-devel@nongnu.org; Mon, 07 Nov 2011 07:23:06 -0500 Received: from moweb001.kundenserver.de (moweb001.kundenserver.de [172.19.20.114]) by fmmailgate07.web.de (Postfix) with ESMTP id 0B0CCB6A88F for ; Mon, 7 Nov 2011 12:23:38 +0100 (CET) Message-ID: <4EB7BFB8.8060204@web.de> Date: Mon, 07 Nov 2011 12:23:36 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <4E8EB9B7.4000007@siemens.com> <4E9088F5.5020304@gmail.com> <4E9017F6.1090008@web.de> <4EB6F42D.5040904@gmail.com> <4EB6918E.5030104@web.de> <4EB7E4C3.2090605@gmail.com> In-Reply-To: <4EB7E4C3.2090605@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigEE2970C90D59DE6500066047" Subject: Re: [Qemu-devel] [PATCH] Support for UDP unicast network backend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Cc: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigEE2970C90D59DE6500066047 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2011-11-07 15:01, Benjamin wrote: > Here is the updated patch, using only localaddr. mcast expects it to be= > addr whereas udp expects addr:port. It's documented in the help output.= >=20 > I also corrected the error message when checking udp parameters. Sorry, missed that: please never forget to run your patches through checkpatch.pl. Once fixed, consider this Acked-by: Jan Kiszka >=20 > Signed-off-by: Benjamin MARSILI > --- > net.c | 9 +++++- > net/socket.c | 66 > +++++++++++++++++++++++++++++++++++++++++++++++++++++- > qemu-options.hx | 2 + > 3 files changed, 73 insertions(+), 4 deletions(-) >=20 > diff --git a/net.c b/net.c > index cb52050..c75be08 100644 > --- a/net.c > +++ b/net.c > @@ -999,7 +999,11 @@ static const struct { > }, { > .name =3D "localaddr", > .type =3D QEMU_OPT_STRING, > - .help =3D "source address for multicast packets", > + .help =3D "source address and port for multicast and u= dp > packets", > + }, { > + .name =3D "udp", > + .type =3D QEMU_OPT_STRING, > + .help =3D "UDP unicast address and port number", > }, > { /* end of list */ } > }, > @@ -1070,7 +1074,8 @@ int net_client_init(Monitor *mon, QemuOpts *opts,= > int is_netdev) > #ifdef CONFIG_VDE > strcmp(type, "vde") !=3D 0 && > #endif > - strcmp(type, "socket") !=3D 0) { > + strcmp(type, "socket") !=3D 0 && > + strcmp(type, "udp") !=3D 0) { > qerror_report(QERR_INVALID_PARAMETER_VALUE, "type", > "a netdev backend type"); > return -1; > diff --git a/net/socket.c b/net/socket.c > index e9ef128..3601228 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -524,6 +524,52 @@ static int net_socket_mcast_init(VLANState *vlan, >=20 > } >=20 > +static int net_socket_udp_init(VLANState *vlan, > + const char *model, > + const char *name, > + const char *rhost, > + const char *lhost) > +{ > + NetSocketState *s; > + int fd, val, ret; > + struct sockaddr_in laddr, raddr; > + > + if (parse_host_port(&laddr, lhost) < 0) > + return -1; > + > + if (parse_host_port(&raddr, rhost) < 0) > + return -1; > + > + fd =3D qemu_socket(PF_INET, SOCK_DGRAM, 0); > + if (fd < 0) { > + perror("socket(PF_INET, SOCK_DGRAM)"); > + return -1; > + } > + val =3D 1; > + ret =3D setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, > + (const char *)&val, sizeof(val)); > + if (ret < 0) { > + perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); > + return -1; > + } > + ret =3D bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)); > + if (ret < 0) { > + perror("bind"); > + return -1; > + } > + > + s =3D net_socket_fd_init(vlan, model, name, fd, 0); > + if (!s) > + return -1; > + > + s->dgram_dst =3D raddr; > + > + snprintf(s->nc.info_str, sizeof(s->nc.info_str), > + "socket: udp=3D%s:%d", > + inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); > + return 0; > +} > + > int net_init_socket(QemuOpts *opts, > Monitor *mon, > const char *name, > @@ -597,10 +643,26 @@ int net_init_socket(QemuOpts *opts, > if (net_socket_mcast_init(vlan, "socket", name, mcast, > localaddr) =3D=3D -1) { > return -1; > } > + } else if (qemu_opt_get(opts, "udp")) { > + const char *udp, *localaddr; > + > + if (qemu_opt_get(opts, "fd") || > + qemu_opt_get(opts, "connect") || > + qemu_opt_get(opts, "listen") || > + qemu_opt_get(opts, "mcast")) { > + error_report("fd=3D, connect=3D, listen=3D and mcast=3D is= invalid > with udp=3D"); > + return -1; > + } > + > + udp =3D qemu_opt_get(opts, "udp"); > + localaddr =3D qemu_opt_get(opts, "localaddr"); > + > + if (net_socket_udp_init(vlan, "udp", name, udp, localaddr) =3D= =3D > -1) { > + return -1; > + } > } else { > - error_report("-socket requires fd=3D, listen=3D, connect=3D or= mcast=3D"); > + error_report("-socket requires fd=3D, listen=3D, connect=3D, m= cast=3D > or udp=3D"); > return -1; > } > - > return 0; > } > diff --git a/qemu-options.hx b/qemu-options.hx > index 681eaf1..5495368 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -1217,6 +1217,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, > "-net > socket[,vlan=3Dn][,name=3Dstr][,fd=3Dh][,mcast=3Dmaddr:port[,localaddr=3D= addr]]\n" > " connect the vlan 'n' to multicast maddr and port\= n" > " use 'localaddr=3Daddr' to specify the host addres= s > to send packets from\n" > + "-net > socket[,vlan=3Dn][,name=3Dstr][,fd=3Dh][,udp=3Dhost:port][,localaddr=3D= host:port]\n" > + " connect the vlan 'n' to another VLAN using an UDP= > tunnel\n" > #ifdef CONFIG_VDE > "-net > vde[,vlan=3Dn][,name=3Dstr][,sock=3Dsocketpath][,port=3Dn][,group=3Dgro= upname][,mode=3Doctalmode]\n" >=20 > " connect the vlan 'n' to port 'n' of a vde switch > running\n" > --=20 > 1.7.3.5 >=20 --------------enigEE2970C90D59DE6500066047 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/ iEYEARECAAYFAk63v7gACgkQitSsb3rl5xRh0gCff8RyCk6aiQfp0Qly9/r3QRXF m+sAnRMFzsWqArdkH16vWE4CFVURtWYy =oFvc -----END PGP SIGNATURE----- --------------enigEE2970C90D59DE6500066047--