{"id":831195,"url":"http://patchwork.ozlabs.org/api/1.2/patches/831195/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20171027104037.8319-10-eblake@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20171027104037.8319-10-eblake@redhat.com>","list_archive_url":null,"date":"2017-10-27T10:40:34","name":"[v6,09/12] nbd/client: refactor nbd_receive_starttls","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"02e050dcb56ab118e1d5220238a6265ad55408a4","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/1.2/people/6591/?format=json","name":"Eric Blake","email":"eblake@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20171027104037.8319-10-eblake@redhat.com/mbox/","series":[{"id":10552,"url":"http://patchwork.ozlabs.org/api/1.2/series/10552/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=10552","date":"2017-10-27T10:40:27","name":"nbd minimal structured read","version":6,"mbox":"http://patchwork.ozlabs.org/series/10552/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/831195/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/831195/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx03.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx03.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yNgcx591hz9t2Z\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 27 Oct 2017 21:50:09 +1100 (AEDT)","from localhost ([::1]:56583 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1e82DH-00084F-Ry\n\tfor incoming@patchwork.ozlabs.org; Fri, 27 Oct 2017 06:50:07 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:57498)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1e824c-0001Tt-DM\n\tfor qemu-devel@nongnu.org; Fri, 27 Oct 2017 06:41:13 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1e824b-0005nE-F1\n\tfor qemu-devel@nongnu.org; Fri, 27 Oct 2017 06:41:10 -0400","from mx1.redhat.com ([209.132.183.28]:60374)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>)\n\tid 1e824T-0005fW-E3; Fri, 27 Oct 2017 06:41:01 -0400","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 6C6447EBD6;\n\tFri, 27 Oct 2017 10:41:00 +0000 (UTC)","from red.redhat.com (ovpn-120-166.rdu2.redhat.com [10.10.120.166])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 93E8E5C549;\n\tFri, 27 Oct 2017 10:40:57 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 6C6447EBD6","From":"Eric Blake <eblake@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Fri, 27 Oct 2017 12:40:34 +0200","Message-Id":"<20171027104037.8319-10-eblake@redhat.com>","In-Reply-To":"<20171027104037.8319-1-eblake@redhat.com>","References":"<20171027104037.8319-1-eblake@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.27]);\n\tFri, 27 Oct 2017 10:41:00 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PATCH v6 09/12] nbd/client: refactor\n\tnbd_receive_starttls","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"pbonzini@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\n\nSplit out nbd_request_simple_option to be reused for structured reply\noption.\n\nSigned-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\nSigned-off-by: Eric Blake <eblake@redhat.com>\n\n---\nv6: error message tweak [Vladimir]\nv5: only check length for ACK responses\nv4: reduce redundant traces, typo fix in commit message\n---\n nbd/client.c     | 70 ++++++++++++++++++++++++++++++++++++++------------------\n nbd/trace-events |  4 +---\n 2 files changed, 49 insertions(+), 25 deletions(-)","diff":"diff --git a/nbd/client.c b/nbd/client.c\nindex 50f36b511e..9acf745b79 100644\n--- a/nbd/client.c\n+++ b/nbd/client.c\n@@ -508,35 +508,61 @@ static int nbd_receive_query_exports(QIOChannel *ioc,\n     }\n }\n\n+/* nbd_request_simple_option: Send an option request, and parse the reply\n+ * return 1 for successful negotiation,\n+ *        0 if operation is unsupported,\n+ *        -1 with errp set for any other error\n+ */\n+static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)\n+{\n+    nbd_opt_reply reply;\n+    int error;\n+\n+    if (nbd_send_option_request(ioc, opt, 0, NULL, errp) < 0) {\n+        return -1;\n+    }\n+\n+    if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {\n+        return -1;\n+    }\n+    error = nbd_handle_reply_err(ioc, &reply, errp);\n+    if (error <= 0) {\n+        return error;\n+    }\n+\n+    if (reply.type != NBD_REP_ACK) {\n+        error_setg(errp, \"Server answered option %d (%s) with unexpected \"\n+                   \"reply %\" PRIx32 \" (%s)\", opt, nbd_opt_lookup(opt),\n+                   reply.type, nbd_rep_lookup(reply.type));\n+        nbd_send_opt_abort(ioc);\n+        return -1;\n+    }\n+\n+    if (reply.length != 0) {\n+        error_setg(errp, \"Option %d ('%s') response length is %\" PRIu32\n+                   \" (it should be zero)\", opt, nbd_opt_lookup(opt),\n+                   reply.length);\n+        nbd_send_opt_abort(ioc);\n+        return -1;\n+    }\n+\n+    return 1;\n+}\n+\n static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,\n                                         QCryptoTLSCreds *tlscreds,\n                                         const char *hostname, Error **errp)\n {\n-    nbd_opt_reply reply;\n+    int ret;\n     QIOChannelTLS *tioc;\n     struct NBDTLSHandshakeData data = { 0 };\n\n-    trace_nbd_receive_starttls_request();\n-    if (nbd_send_option_request(ioc, NBD_OPT_STARTTLS, 0, NULL, errp) < 0) {\n-        return NULL;\n-    }\n-\n-    trace_nbd_receive_starttls_reply();\n-    if (nbd_receive_option_reply(ioc, NBD_OPT_STARTTLS, &reply, errp) < 0) {\n-        return NULL;\n-    }\n-\n-    if (reply.type != NBD_REP_ACK) {\n-        error_setg(errp, \"Server rejected request to start TLS %\" PRIx32,\n-                   reply.type);\n-        nbd_send_opt_abort(ioc);\n-        return NULL;\n-    }\n-\n-    if (reply.length != 0) {\n-        error_setg(errp, \"Start TLS response was not zero %\" PRIu32,\n-                   reply.length);\n-        nbd_send_opt_abort(ioc);\n+    ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp);\n+    if (ret <= 0) {\n+        if (ret == 0) {\n+            error_setg(errp, \"Server don't support STARTTLS option\");\n+            nbd_send_opt_abort(ioc);\n+        }\n         return NULL;\n     }\n\ndiff --git a/nbd/trace-events b/nbd/trace-events\nindex 52150bd738..596df96575 100644\n--- a/nbd/trace-events\n+++ b/nbd/trace-events\n@@ -8,9 +8,7 @@ nbd_opt_go_info_unknown(int info, const char *name) \"Ignoring unknown info %d (%\n nbd_opt_go_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t maximum) \"Block sizes are 0x%\" PRIx32 \", 0x%\" PRIx32 \", 0x%\" PRIx32\n nbd_receive_query_exports_start(const char *wantname) \"Querying export list for '%s'\"\n nbd_receive_query_exports_success(const char *wantname) \"Found desired export name '%s'\"\n-nbd_receive_starttls_request(void) \"Requesting TLS from server\"\n-nbd_receive_starttls_reply(void) \"Getting TLS reply from server\"\n-nbd_receive_starttls_new_client(void) \"TLS request approved, setting up TLS\"\n+nbd_receive_starttls_new_client(void) \"Setting up TLS\"\n nbd_receive_starttls_tls_handshake(void) \"Starting TLS handshake\"\n nbd_receive_negotiate(void *tlscreds, const char *hostname) \"Receiving negotiation tlscreds=%p hostname=%s\"\n nbd_receive_negotiate_magic(uint64_t magic) \"Magic is 0x%\" PRIx64\n","prefixes":["v6","09/12"]}