From patchwork Wed Nov 9 14:26:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin X-Patchwork-Id: 124474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D88741007D7 for ; Wed, 9 Nov 2011 16:26:36 +1100 (EST) Received: from localhost ([::1]:41467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RO0gA-00021L-6G for incoming@patchwork.ozlabs.org; Wed, 09 Nov 2011 00:26:30 -0500 Received: from eggs.gnu.org ([140.186.70.92]:60006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RO0g2-00021G-7S for qemu-devel@nongnu.org; Wed, 09 Nov 2011 00:26:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RO0g0-0006dU-Ja for qemu-devel@nongnu.org; Wed, 09 Nov 2011 00:26:22 -0500 Received: from mail-pz0-f43.google.com ([209.85.210.43]:41234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RO0g0-0006dN-88 for qemu-devel@nongnu.org; Wed, 09 Nov 2011 00:26:20 -0500 Received: by pzk37 with SMTP id 37so690099pzk.2 for ; Tue, 08 Nov 2011 21:26:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=SZQ0KxkWi5ngZkroaxxrUSH3Wx2emVg3AEkdbefrOpU=; b=dDUBquIwn9P2EDCfglgylBi9vJRE39bhb5x1gBYcY2zU443QLZ1gTXFEURbO8zGyzA noQ513LBtLX+wactnk4pser9VuKd/wD03q5R+veAzEK3LC7CN+CBhZg38RuzKnuO8QeI oS6ZbzP6gjVQ/bcQxPKiFQ2X7/qlTp7RZB+bU= Received: by 10.68.14.2 with SMTP id l2mr2730321pbc.37.1320816378154; Tue, 08 Nov 2011 21:26:18 -0800 (PST) Received: from yui.my.domain ([220.69.134.115]) by mx.google.com with ESMTPS id jm5sm10048528pbc.1.2011.11.08.21.26.12 (version=SSLv3 cipher=OTHER); Tue, 08 Nov 2011 21:26:16 -0800 (PST) Message-ID: <4EBA8D88.7000102@gmail.com> Date: Wed, 09 Nov 2011 15:26:16 +0100 From: Benjamin User-Agent: Mozilla/5.0 (X11; U; OpenBSD i386; en-US; rv:1.9.2.13) Gecko/20110216 Thunderbird/3.1.7 MIME-Version: 1.0 To: Jan Kiszka 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> <4EB7BFB8.8060204@web.de> <4EB8559F.7000306@gmail.com> <4EB90A01.4010709@web.de> In-Reply-To: <4EB90A01.4010709@web.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.43 Cc: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH] Support for UDP unicast network backend X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 11/08/11 11:52, Jan Kiszka wrote: > On 2011-11-07 23:03, Benjamin wrote: >> On 11/07/11 12:23, Jan Kiszka wrote: >>> 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. >>>> >>>> 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 >>> >> >> Oh, my bad, I happen to have copied some parts from net/socket.c >> that do no respect the coding style requirements. Well I guess I know >> what my next submission will be. >> >> Fixed, it's my first time submitting a patch here, is this enough? > > Yep. > > Jan > Oh, I forgot to remove a line from the old patch, when I wanted to introduce -netdev udp. Now it's just -net[dev] socket. Here's the updated patch, my apologies. It didn't break anything, it's just useless, use this instead. Support for UDP unicast network backend Signed-off-by: Benjamin MARSILI Acked-by: Jan Kiszka --- net.c | 9 +++++- net/socket.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 2 + 3 files changed, 78 insertions(+), 4 deletions(-) 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.3.5 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 = "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 */ } }, @@ -1070,7 +1074,8 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) #ifdef CONFIG_VDE strcmp(type, "vde") != 0 && #endif - strcmp(type, "socket") != 0) { + strcmp(type, "socket") != 0 && + strcmp(type, "udp") != 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..ca183f2 100644 --- a/net/socket.c +++ b/net/socket.c @@ -524,6 +524,55 @@ 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)"); + return -1; + } + ret = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)); + if (ret < 0) { + perror("bind"); + 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, @@ -597,10 +646,28 @@ 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 (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 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=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