From patchwork Fri Aug 8 17:07:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 35147 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5647B2118A for ; Fri, 8 Aug 2014 17:08:14 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wn1sf23072654obc.2 for ; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=4j8xPR3F1aYYvReu0uNYabZYQDbMuiRuyA4IJ9hke3k=; b=P+akWD3WchApNntNrA0SPSRXkKOd6BqOy7bmTe9U2KSX+8mop0tPgF8cIW96cm4Nru MrlEtbNUAmAI4jU80dbPpFP8wRpH6pMCskgHqKCFJHTBP+f1NBC5arZJBzjVjCml8dT3 v+WeWkiiVFcQVecl8FQavMyhHY0sR4k9LukOl6vYGjMm6rhaqSbgp6IfGrRodP3YywM8 MyaqSZ4i08zmFRCp1Pp7FrChEd9V6+2zbDM90GwmVQg/NlnLxE4m3hnUdxjLi9Aw8q6w zOxVJZNolJkrTz12TxSVMlJG+om1hSyZ3tST2BztfrJGMz1kCkd3917RdyTGL6aG/Kyx 2y2A== X-Gm-Message-State: ALoCoQljQotFmPYh7TOnJqLBoQuYtewWKl0DJnVR3zRW8dQ772iyWN9bln3kB7hCpgGZ0OZnYbhH X-Received: by 10.182.4.73 with SMTP id i9mr13445898obi.28.1407517693912; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.91.40 with SMTP id y37ls630811qgd.2.gmail; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) X-Received: by 10.220.130.131 with SMTP id t3mr23012029vcs.30.1407517693799; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id mg6si3094838vec.35.2014.08.08.10.08.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Aug 2014 10:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so8732076vcb.37 for ; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) X-Received: by 10.220.105.201 with SMTP id u9mr22861505vco.11.1407517693738; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp139894vcb; Fri, 8 Aug 2014 10:08:13 -0700 (PDT) X-Received: by 10.140.107.131 with SMTP id h3mr25341229qgf.83.1407517693147; Fri, 08 Aug 2014 10:08:13 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l4si11014894qaf.97.2014.08.08.10.08.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 08 Aug 2014 10:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:52041 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFneG-00038p-Mz for patch@linaro.org; Fri, 08 Aug 2014 13:08:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFndd-0002Sw-7O for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:07:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFndb-0003iW-W2 for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:07:33 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFndb-0003iJ-Pg for qemu-devel@nongnu.org; Fri, 08 Aug 2014 13:07:31 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XFndZ-0002wD-Jf; Fri, 08 Aug 2014 18:07:29 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 8 Aug 2014 18:07:28 +0100 Message-Id: <1407517649-11257-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1407517649-11257-1-git-send-email-peter.maydell@linaro.org> References: <1407517649-11257-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: Paolo Bonzini , Gerd Hoffmann , Markus Armbruster Subject: [Qemu-devel] [PATCH 3/4] qemu-char: Convert udp char backend to parse/kind 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Convert the udp char backend to the new style QAPI framework. Signed-off-by: Peter Maydell --- qemu-char.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index cac7edb..a01ccdc 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2383,20 +2383,6 @@ static CharDriverState *qemu_chr_open_udp_fd(int fd) return chr; } -static CharDriverState *qemu_chr_open_udp(QemuOpts *opts) -{ - Error *local_err = NULL; - int fd = -1; - - fd = inet_dgram_opts(opts, &local_err); - if (fd < 0) { - qerror_report_err(local_err); - error_free(local_err); - return NULL; - } - return qemu_chr_open_udp_fd(fd); -} - /***********************************************************/ /* TCP Net console */ @@ -3449,6 +3435,58 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, backend->socket->addr = addr; } +static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + const char *host = qemu_opt_get(opts, "host"); + const char *port = qemu_opt_get(opts, "port"); + bool ipv4 = qemu_opt_get_bool(opts, "ipv4", 0); + bool ipv6 = qemu_opt_get_bool(opts, "ipv6", 0); + const char *localaddr = qemu_opt_get(opts, "localaddr"); + const char *localport = qemu_opt_get(opts, "localport"); + bool has_local = false; + SocketAddress *addr; + + if (host == NULL || strlen(host) == 0) { + host = "localhost"; + } + if (port == NULL || strlen(port) == 0) { + error_setg(errp, "chardev: udp: remote port not specified"); + return; + } + if (localport == NULL || strlen(localport) == 0) { + localport = "0"; + } else { + has_local = true; + } + if (localaddr == NULL || strlen(localaddr) == 0) { + localaddr = ""; + } else { + has_local = true; + } + + backend->udp = g_new0(ChardevUdp, 1); + + addr = g_new0(SocketAddress, 1); + addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->inet = g_new0(InetSocketAddress, 1); + addr->inet->host = g_strdup(host); + addr->inet->port = g_strdup(port); + addr->inet->has_ipv4 = addr->inet->ipv4 = ipv4; + addr->inet->has_ipv6 = addr->inet->ipv6 = ipv6; + backend->udp->remote = addr; + + if (has_local) { + backend->udp->has_local = true; + addr = g_new0(SocketAddress, 1); + addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->inet = g_new0(InetSocketAddress, 1); + addr->inet->host = g_strdup(localaddr); + addr->inet->port = g_strdup(localport); + backend->udp->local = addr; + } +} + typedef struct CharDriver { const char *name; /* old, pre qapi */ @@ -4139,7 +4177,8 @@ static void register_types(void) register_char_driver_qapi("null", CHARDEV_BACKEND_KIND_NULL, NULL); register_char_driver_qapi("socket", CHARDEV_BACKEND_KIND_SOCKET, qemu_chr_parse_socket); - register_char_driver("udp", qemu_chr_open_udp); + register_char_driver_qapi("udp", CHARDEV_BACKEND_KIND_UDP, + qemu_chr_parse_udp); register_char_driver_qapi("ringbuf", CHARDEV_BACKEND_KIND_RINGBUF, qemu_chr_parse_ringbuf); register_char_driver_qapi("file", CHARDEV_BACKEND_KIND_FILE,