qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH v6 08/16] nbd: make server compliant with fixed newstyle spec
Date: Wed, 10 Feb 2016 18:41:06 +0000	[thread overview]
Message-ID: <1455129674-17255-9-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1455129674-17255-1-git-send-email-berrange@redhat.com>

If the client does not request the fixed new style protocol,
then we should only accept NBD_OPT_EXPORT_NAME. All other
options are only valid when fixed new style has been activated.

The qemu-nbd client doesn't currently request fixed new style
protocol, but this change won't break qemu-nbd, because it
fortunately only ever uses NBD_OPT_EXPORT_NAME, so was never
triggering the non-compliant server behaviour.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 nbd/server.c | 69 ++++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 46 insertions(+), 23 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 15aa03d..074a1e6 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -310,6 +310,7 @@ fail:
 static int nbd_negotiate_options(NBDClient *client)
 {
     uint32_t flags;
+    bool fixedNewstyle = false;
 
     /* Client sends:
         [ 0 ..   3]   client flags
@@ -332,14 +333,19 @@ static int nbd_negotiate_options(NBDClient *client)
     }
     TRACE("Checking client flags");
     be32_to_cpus(&flags);
-    if (flags != 0 && flags != NBD_FLAG_C_FIXED_NEWSTYLE) {
-        LOG("Bad client flags received");
+    if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) {
+        TRACE("Support supports fixed newstyle handshake");
+        fixedNewstyle = true;
+        flags &= ~NBD_FLAG_C_FIXED_NEWSTYLE;
+    }
+    if (flags != 0) {
+        TRACE("Unknown client flags 0x%x received", flags);
         return -EIO;
     }
 
     while (1) {
         int ret;
-        uint32_t tmp, length;
+        uint32_t clientflags, length;
         uint64_t magic;
 
         if (nbd_negotiate_read(client->ioc, &magic, sizeof(magic)) !=
@@ -353,10 +359,12 @@ static int nbd_negotiate_options(NBDClient *client)
             return -EINVAL;
         }
 
-        if (nbd_negotiate_read(client->ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) {
+        if (nbd_negotiate_read(client->ioc, &clientflags,
+                               sizeof(clientflags)) != sizeof(clientflags)) {
             LOG("read failed");
             return -EINVAL;
         }
+        clientflags = be32_to_cpu(clientflags);
 
         if (nbd_negotiate_read(client->ioc, &length, sizeof(length)) !=
             sizeof(length)) {
@@ -365,26 +373,41 @@ static int nbd_negotiate_options(NBDClient *client)
         }
         length = be32_to_cpu(length);
 
-        TRACE("Checking option");
-        switch (be32_to_cpu(tmp)) {
-        case NBD_OPT_LIST:
-            ret = nbd_negotiate_handle_list(client, length);
-            if (ret < 0) {
-                return ret;
+        TRACE("Checking option 0x%x", clientflags);
+        if (fixedNewstyle) {
+            switch (clientflags) {
+            case NBD_OPT_LIST:
+                ret = nbd_negotiate_handle_list(client, length);
+                if (ret < 0) {
+                    return ret;
+                }
+                break;
+
+            case NBD_OPT_ABORT:
+                return -EINVAL;
+
+            case NBD_OPT_EXPORT_NAME:
+                return nbd_negotiate_handle_export_name(client, length);
+
+            default:
+                TRACE("Unsupported option 0x%x", clientflags);
+                nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_UNSUP,
+                                       clientflags);
+                return -EINVAL;
+            }
+        } else {
+            /*
+             * If broken new-style we should drop the connection
+             * for anything except NBD_OPT_EXPORT_NAME
+             */
+            switch (clientflags) {
+            case NBD_OPT_EXPORT_NAME:
+                return nbd_negotiate_handle_export_name(client, length);
+
+            default:
+                TRACE("Unsupported option 0x%x", clientflags);
+                return -EINVAL;
             }
-            break;
-
-        case NBD_OPT_ABORT:
-            return -EINVAL;
-
-        case NBD_OPT_EXPORT_NAME:
-            return nbd_negotiate_handle_export_name(client, length);
-
-        default:
-            tmp = be32_to_cpu(tmp);
-            LOG("Unsupported option 0x%x", tmp);
-            nbd_negotiate_send_rep(client->ioc, NBD_REP_ERR_UNSUP, tmp);
-            return -EINVAL;
         }
     }
 }
-- 
2.5.0

  parent reply	other threads:[~2016-02-10 18:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10 18:40 [Qemu-devel] [PATCH v6 00/16] Implement TLS support to QEMU NBD server & client Daniel P. Berrange
2016-02-10 18:40 ` [Qemu-devel] [PATCH v6 01/16] qom: add helpers for UserCreatable object types Daniel P. Berrange
2016-02-11 23:13   ` Eric Blake
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 02/16] qemu-nbd: add support for --object command line arg Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 03/16] nbd: convert block client to use I/O channels for connection setup Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 04/16] nbd: convert qemu-nbd server " Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 05/16] nbd: convert blockdev NBD " Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 06/16] nbd: convert to using I/O channels for actual socket I/O Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 07/16] nbd: invert client logic for negotiating protocol version Daniel P. Berrange
2016-02-10 18:41 ` Daniel P. Berrange [this message]
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 09/16] nbd: make client request fixed new style if advertized Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 10/16] nbd: allow setting of an export name for qemu-nbd server Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 11/16] nbd: always query export list in fixed new style protocol Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 12/16] nbd: use "" as a default export name if none provided Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 13/16] nbd: implement TLS support in the protocol negotiation Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 14/16] nbd: enable use of TLS with NBD block driver Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 15/16] nbd: enable use of TLS with qemu-nbd server Daniel P. Berrange
2016-02-10 18:41 ` [Qemu-devel] [PATCH v6 16/16] nbd: enable use of TLS with nbd-server-start command Daniel P. Berrange
2016-02-12 13:28 ` [Qemu-devel] [PATCH v6 00/16] Implement TLS support to QEMU NBD server & client Kashyap Chamarthy
2016-02-12 15:00   ` Daniel P. Berrange
2016-02-12 16:03     ` Kashyap Chamarthy
2016-02-12 18:14       ` Kashyap Chamarthy
2016-02-16 16:18 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455129674-17255-9-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).