From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:60251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RCTDr-0005Xf-Md for qemu-devel@nongnu.org; Sat, 08 Oct 2011 05:29:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RCTDp-0001Y5-JT for qemu-devel@nongnu.org; Sat, 08 Oct 2011 05:29:35 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:34651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RCTDo-0001XZ-TO for qemu-devel@nongnu.org; Sat, 08 Oct 2011 05:29:33 -0400 Message-ID: <4E9017F6.1090008@web.de> Date: Sat, 08 Oct 2011 11:29:26 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <4E8EB9B7.4000007@siemens.com> <4E9088F5.5020304@gmail.com> In-Reply-To: <4E9088F5.5020304@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig3CE9119CE7AB778F83B9AC37" Sender: jan.kiszka@web.de Subject: Re: [Qemu-devel] Integrating Dynamips and GNS3 UDP tunnels (Patches) 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) --------------enig3CE9119CE7AB778F83B9AC37 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2011-10-08 19:31, Benjamin wrote: > On 10/07/11 10:35, Jan Kiszka wrote: >> >> You should send out the changes as proper patch series, rebased on >> current git head. See http://wiki.qemu.org/Contribute/SubmitAPatch for= >> further requirements. And make sure that no patch breaks the build so >> that bisectability is preserved. >> >> Jan >> >=20 > Tested and used for several years by GNS3, it doesn't break the build. If you split the changes into multiple patches, there would have been the risk that some patch breaks the build until a succeeding one is appli= ed. >=20 > I could not access http://git.qemu.org/qemu.git/plain/CODING_STYLE and > http://git.qemu.org/qemu.git/plain/HACKING (404) so these patches may > not be 100% conform. The script didn't report any error though. You also find those files in your local qemu tree. >=20 > Signed-off-by: Benjamin MARSILI Patch title and description are missing. >=20 > diff --git a/Makefile.objs b/Makefile.objs > index 8d23fbb..6b4896b 100644 > --- a/Makefile.objs > +++ b/Makefile.objs > @@ -45,6 +45,7 @@ net-obj-y =3D net.o > net-nested-y =3D queue.o checksum.o util.o > net-nested-y +=3D socket.o > net-nested-y +=3D dump.o > +net-nested-y +=3D udp.o > net-nested-$(CONFIG_POSIX) +=3D tap.o > net-nested-$(CONFIG_LINUX) +=3D tap-linux.o > net-nested-$(CONFIG_WIN32) +=3D tap-win32.o > diff --git a/net.c b/net.c > index d05930c..6a3b2ba 100644 > --- a/net.c > +++ b/net.c > @@ -30,6 +30,7 @@ > #include "net/dump.h" > #include "net/slirp.h" > #include "net/vde.h" > +#include "net/udp.h" > #include "net/util.h" > #include "monitor.h" > #include "qemu-common.h" > @@ -1036,6 +1037,27 @@ static const struct { > }, > }, > #endif > + [NET_CLIENT_TYPE_UDP] =3D { > + .type =3D "udp", > + .init =3D net_init_udp, > + .desc =3D { > + NET_COMMON_PARAMS_DESC, > + { > + .name =3D "sport", > + .type =3D QEMU_OPT_NUMBER, > + .help =3D "source port number", > + }, { > + .name =3D "daddr", > + .type =3D QEMU_OPT_STRING, > + .help =3D "destination IP address", > + }, { > + .name =3D "dport", > + .type =3D QEMU_OPT_NUMBER, > + .help =3D "destination port number", > + }, > + { /* end of list */ } > + }, > + }, > [NET_CLIENT_TYPE_DUMP] =3D { > .type =3D "dump", > .init =3D net_init_dump, > diff --git a/net.h b/net.h > index 9f633f8..ac6118c 100644 > --- a/net.h > +++ b/net.h > @@ -35,6 +35,7 @@ typedef enum { > NET_CLIENT_TYPE_TAP, > NET_CLIENT_TYPE_SOCKET, > NET_CLIENT_TYPE_VDE, > + NET_CLIENT_TYPE_UDP, > NET_CLIENT_TYPE_DUMP, >=20 > NET_CLIENT_TYPE_MAX > diff --git a/net/udp.c b/net/udp.c > new file mode 100644 > index 0000000..7b4b702 > --- /dev/null > +++ b/net/udp.c > @@ -0,0 +1,140 @@ > +/* > + * QEMU System Emulator > + * > + * Copyright (c) 2003-2008 Fabrice Bellard > + * > + * Permission is hereby granted, free of charge, to any person > obtaining a copy > + * of this software and associated documentation files (the > "Software"), to deal > + * in the Software without restriction, including without limitation > the rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/o= r > sell > + * copies of the Software, and to permit persons to whom the Software = is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be > included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT S= HALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES O= R > OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > ARISING FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > DEALINGS IN > + * THE SOFTWARE. > + */ > +#include "net/udp.h" > + > +#include "config-host.h" > + > +#ifndef _WIN32 > +#include > +#include > +#include > +#endif > + > +#include "net.h" > +#include "qemu-char.h" > +#include "qemu-common.h" > +#include "qemu-option.h" > +#include "qemu_socket.h" > +#include "sysemu.h" > + > + > +typedef struct UDPState { > + VLANClientState nc; > + int rfd; > + struct sockaddr_in sender; > +} UDPState; > + > +static void udp_to_qemu(void *opaque) > +{ > + UDPState *s =3D opaque; > + uint8_t buf[4096]; > + int size; > + > + size =3D recvfrom(s->rfd, (char *)buf, sizeof(buf), 0, NULL, NULL)= ; > + if (size > 0) { > + qemu_send_packet(&s->nc, buf, size); > + } > +} > + > +static ssize_t udp_receive(VLANClientState *nc, const uint8_t *buf, > size_t size) > +{ > + UDPState *s =3D DO_UPCAST(UDPState, nc, nc); > + int ret; > + > + do { > + ret =3D sendto(s->rfd, (const char *)buf, size, 0, > + (struct sockaddr *)&s->sender, sizeof(s->sender)); > + } while (ret < 0 && errno =3D=3D EINTR); > + > + return ret; > +} > + > +static void udp_cleanup(VLANClientState *nc) > +{ > + UDPState *s =3D DO_UPCAST(UDPState, nc, nc); > + qemu_set_fd_handler(s->rfd, NULL, NULL, NULL); > + close(s->rfd); > +} > + > +static NetClientInfo net_udp_info =3D { > + .type =3D NET_CLIENT_TYPE_UDP, > + .size =3D sizeof(UDPState), > + .receive =3D udp_receive, > + .cleanup =3D udp_cleanup, > +}; > + > +static int net_udp_init(VLANState *vlan, const char *model, > + const char *name, int sport, > + const char *daddr, int dport) > +{ > + VLANClientState *nc; > + UDPState *s; > + struct sockaddr_in receiver; > + int ret; > + > + nc =3D qemu_new_net_client(&net_udp_info, vlan, NULL, model, name)= ; > + > + snprintf(nc->info_str, sizeof(nc->info_str), "udp: %i->%s:%i", > + sport, daddr, dport); > + > + s =3D DO_UPCAST(UDPState, nc, nc); > + > + s->rfd =3D socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); > + receiver.sin_family =3D AF_INET; > + receiver.sin_addr.s_addr =3D INADDR_ANY; > + receiver.sin_port =3D htons(sport); > + ret =3D bind(s->rfd, (struct sockaddr *)&receiver, sizeof(receiver= )); > + > + if (ret =3D=3D -1) { > + fprintf(stderr, "bind error:%s\n", strerror(errno)); > + return ret; > + } > + > + memset((char *)&s->sender, 0, sizeof(s->sender)); > + s->sender.sin_family =3D AF_INET; > + s->sender.sin_port =3D htons(dport); > + inet_aton(daddr, &s->sender.sin_addr); > + > + qemu_set_fd_handler(s->rfd, udp_to_qemu, NULL, s); > + > + return 0; > +} > + > +int net_init_udp(QemuOpts *opts, Monitor *mon, > + const char *name, VLANState *vlan) > +{ > + const char *daddr; > + int sport, dport; > + > + daddr =3D qemu_opt_get(opts, "daddr"); > + > + sport =3D qemu_opt_get_number(opts, "sport", 0); > + dport =3D qemu_opt_get_number(opts, "dport", 0); > + > + if (net_udp_init(vlan, "udp", name, sport, daddr, dport) =3D=3D -1= ) { > + return -1; > + } > + > + return 0; > +} > diff --git a/net/udp.h b/net/udp.h > new file mode 100644 > index 0000000..e614077 > --- /dev/null > +++ b/net/udp.h > @@ -0,0 +1,32 @@ > +/* > + * QEMU System Emulator > + * > + * Copyright (c) 2003-2008 Fabrice Bellard > + * > + * Permission is hereby granted, free of charge, to any person > obtaining a copy > + * of this software and associated documentation files (the > "Software"), to deal > + * in the Software without restriction, including without limitation > the rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/o= r > sell > + * copies of the Software, and to permit persons to whom the Software = is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be > included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT S= HALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES O= R > OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > ARISING FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER > DEALINGS IN > + * THE SOFTWARE. > + */ > +#ifndef QEMU_NET_UDP_H > +#define QEMU_NET_UDP_H > + > +#include "qemu-common.h" > +#include "qemu-option.h" > + > +int net_init_udp(QemuOpts*, Monitor*, const char *name, VLANState*); > + > +#endif /* QEMU_NET_UDP_H */ > diff --git a/qemu-options.hx b/qemu-options.hx > index dfbabd0..021d898 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -1145,6 +1145,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, > " connect the user mode network stack to VLAN 'n', > configure its\n" > " DHCP server and enabled optional services\n" > #endif > + "-net udp[,vlan=3Dn],sport=3Dsport,dport=3Ddport,daddr=3Dhost\n" > + " connect the vlan 'n' to a udp host (for > dynamips/pemu/GNS3)\n" > #ifdef _WIN32 > "-net tap[,vlan=3Dn][,name=3Dstr],ifname=3Dname\n" > " connect the host TAP network interface to VLAN 'n= '\n" >=20 >=20 >=20 -netdev support is missing. Can't you extend the existing socket support? It already has SOCK_DGRAM logic for multicast. Adding something like -net[dev] socket,udp=3Dhost:port[,localport=3Dport] (with localport=3Dremoteport as default) should fit well into the existin= g infrastructure. And it would give you -netdev for free. Just curious: Do you have setups that depend on vlan support to create multiple udp backends per NIC? Jan --------------enig3CE9119CE7AB778F83B9AC37 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/ iEYEARECAAYFAk6QF/kACgkQitSsb3rl5xRBWQCeJC/zoik+L6s8yN6H+sYEAtbk ZCoAn1lhfzWEbzfupFiDQ29vsSGSnyCC =Qgz9 -----END PGP SIGNATURE----- --------------enig3CE9119CE7AB778F83B9AC37--