From patchwork Tue Sep 2 10:24:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 36447 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9110F2032B for ; Tue, 2 Sep 2014 10:25:24 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf37481498obc.8 for ; Tue, 02 Sep 2014 03:25:24 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=bd3aOHtPV2XY0TTzwNFsmeXJNOy6QSsJZn/qpcQlNLQ=; b=iNSDsnV9lOxp3VpUkrU9tn3euXEUw1gqISC5n23oxMgG6gkQoP51RsyD0t7fKP8Lju f+7o4XS6VXZWuh8Gr5JZsLk/mhFyZrwrprdm/Ax7Eyo0I0yEEmehcq3gQka69wgKeZ5V YKUGwmn60d3XQxlnT6L5Jq9UXr+/Uc9En0HJ7dwrJWKsd+9NmhgbCekA3QeY7YYkwtsI j4GchVVGIeg/sksZor5CN/r9a4sY/9g0O8YNBAMzX+2lqWHYWgBlwAz0zeffMSz8VTG9 b0QimqILU2iOJHic2XoWqyAmqS0JffElD0xrRt8YZeaU/mf2pLClASA6JNjBMI9NxGUJ f07A== X-Gm-Message-State: ALoCoQkL/0mB8cw7HTJ7aSAxsoB+fF19hSdErklA9AGfz41QCQZybxmABnqRSisxLZtTdQJFANCG X-Received: by 10.182.32.1 with SMTP id e1mr19482465obi.11.1409653524220; Tue, 02 Sep 2014 03:25:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.168 with SMTP id p37ls2259940qgp.12.gmail; Tue, 02 Sep 2014 03:25:24 -0700 (PDT) X-Received: by 10.52.148.2 with SMTP id to2mr720848vdb.38.1409653524137; Tue, 02 Sep 2014 03:25:24 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id f5si2042070vcz.99.2014.09.02.03.25.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 02 Sep 2014 03:25:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so6769889vcb.11 for ; Tue, 02 Sep 2014 03:25:24 -0700 (PDT) X-Received: by 10.52.30.2 with SMTP id o2mr663842vdh.12.1409653524022; Tue, 02 Sep 2014 03:25:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp504420vcb; Tue, 2 Sep 2014 03:25:23 -0700 (PDT) X-Received: by 10.194.191.165 with SMTP id gz5mr38317418wjc.16.1409653523085; Tue, 02 Sep 2014 03:25:23 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id br7si14029103wib.34.2014.09.02.03.25.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 02 Sep 2014 03:25:23 -0700 (PDT) Received-SPF: none (google.com: pm215@archaic.org.uk does not designate permitted sender hosts) client-ip=81.2.115.146; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XOlG5-0007G3-N4; Tue, 02 Sep 2014 11:24:17 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Markus Armbruster , Anthony Liguori Subject: [PATCH v2 3/5] qemu-char: Convert udp backend to QAPI Date: Tue, 2 Sep 2014 11:24:15 +0100 Message-Id: <1409653457-27863-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1409653457-27863-1-git-send-email-peter.maydell@linaro.org> References: <1409653457-27863-1-git-send-email-peter.maydell@linaro.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.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 4b99382..97a839e 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 */ @@ -3447,6 +3433,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"); + 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 = qemu_opt_get(opts, "ipv4"); + addr->inet->ipv4 = qemu_opt_get_bool(opts, "ipv4", 0); + addr->inet->has_ipv6 = qemu_opt_get(opts, "ipv6"); + addr->inet->ipv6 = qemu_opt_get_bool(opts, "ipv6", 0); + 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 */ @@ -4137,7 +4175,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,