From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:37935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlNtv-0008Nk-UH for qemu-devel@nongnu.org; Thu, 12 Jan 2012 11:53:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlNtr-00053B-DW for qemu-devel@nongnu.org; Thu, 12 Jan 2012 11:53:19 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:40666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlNtr-00052Y-0s for qemu-devel@nongnu.org; Thu, 12 Jan 2012 11:53:15 -0500 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jan 2012 09:53:12 -0700 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q0CGr55e136486 for ; Thu, 12 Jan 2012 09:53:07 -0700 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q0CGr4p0008653 for ; Thu, 12 Jan 2012 09:53:04 -0700 Message-ID: <4F0F0FD5.9010903@us.ibm.com> Date: Thu, 12 Jan 2012 10:52:37 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1326241254-32565-1-git-send-email-mlspirat42@gmail.com> In-Reply-To: <1326241254-32565-1-git-send-email-mlspirat42@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4] Support for UDP unicast network backend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Benjamin Cc: stefanha@gmail.com, andreas.faerber@web.de, jan.kiszka@web.de, qemu-devel@nongnu.org On 01/10/2012 06:20 PM, Benjamin wrote: > Signed-off-by: Benjamin MARSILI Applied. Thanks. Regards, Anthony Liguori > --- > Added my last name. Check that localaddr= is supplied with udp=, > it crashed when misused... > > net.c | 6 +++- > net/socket.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- > qemu-options.hx | 2 + > 3 files changed, 82 insertions(+), 3 deletions(-) > > diff --git a/net.c b/net.c > index f7bebf8..2b0f766 100644 > --- a/net.c > +++ b/net.c > @@ -1000,7 +1000,11 @@ static const struct { > }, { > .name = "localaddr", > .type = QEMU_OPT_STRING, > - .help = "source address for multicast packets", > + .help = "source address and port for multicast and udp packets", > + }, { > + .name = "udp", > + .type = QEMU_OPT_STRING, > + .help = "UDP unicast address and port number", > }, > { /* end of list */ } > }, > diff --git a/net/socket.c b/net/socket.c > index c9d70d3..d4c2002 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -534,6 +534,57 @@ static int net_socket_mcast_init(VLANState *vlan, > > } > > +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 = qemu_socket(PF_INET, SOCK_DGRAM, 0); > + if (fd< 0) { > + perror("socket(PF_INET, SOCK_DGRAM)"); > + return -1; > + } > + val = 1; > + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, > + (const char *)&val, sizeof(val)); > + if (ret< 0) { > + perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)"); > + closesocket(fd); > + return -1; > + } > + ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)); > + if (ret< 0) { > + perror("bind"); > + closesocket(fd); > + return -1; > + } > + > + s = net_socket_fd_init(vlan, model, name, fd, 0); > + if (!s) { > + return -1; > + } > + > + s->dgram_dst = raddr; > + > + snprintf(s->nc.info_str, sizeof(s->nc.info_str), > + "socket: udp=%s:%d", > + inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); > + return 0; > +} > + > int net_init_socket(QemuOpts *opts, > Monitor *mon, > const char *name, > @@ -606,10 +657,32 @@ int net_init_socket(QemuOpts *opts, > if (net_socket_mcast_init(vlan, "socket", name, mcast, localaddr) == -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=, connect=, listen=\ > + and mcast= is invalid with udp="); > + return -1; > + } > + > + udp = qemu_opt_get(opts, "udp"); > + localaddr = qemu_opt_get(opts, "localaddr"); > + if (localaddr == NULL) { > + error_report("localaddr= is mandatory with udp="); > + return -1; > + } > + > + if (net_socket_udp_init(vlan, "udp", name, udp, localaddr) == -1) { > + return -1; > + } > } else { > - error_report("-socket requires fd=, listen=, connect= or mcast="); > + error_report("-socket requires fd=, listen=, \ > + connect=, mcast= or udp="); > return -1; > } > - > return 0; > } > diff --git a/qemu-options.hx b/qemu-options.hx > index 7903e5c..6295cde 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -1239,6 +1239,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, > "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]]\n" > " connect the vlan 'n' to multicast maddr and port\n" > " use 'localaddr=addr' to specify the host address to send packets from\n" > + "-net socket[,vlan=n][,name=str][,fd=h][,udp=host:port][,localaddr=host:port]\n" > + " connect the vlan 'n' to another VLAN using an UDP tunnel\n" > #ifdef CONFIG_VDE > "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n" > " connect the vlan 'n' to port 'n' of a vde switch running\n" > -- > 1.7.6 > > >