2 * Copyright (C) 2013-2019 Red Hat Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Red Hat nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 #include "byte-swapping.h"
44 #include "nbd-protocol.h"
45 #include "protostrings.h"
47 /* Maximum number of client options we allow before giving up. */
48 #define MAX_NR_OPTIONS 32
50 /* Receive newstyle options. */
52 send_newstyle_option_reply (struct connection
*conn
,
53 uint32_t option
, uint32_t reply
)
55 struct nbd_fixed_new_option_reply fixed_new_option_reply
;
57 fixed_new_option_reply
.magic
= htobe64 (NBD_REP_MAGIC
);
58 fixed_new_option_reply
.option
= htobe32 (option
);
59 fixed_new_option_reply
.reply
= htobe32 (reply
);
60 fixed_new_option_reply
.replylen
= htobe32 (0);
63 &fixed_new_option_reply
,
64 sizeof fixed_new_option_reply
, 0) == -1) {
65 /* The protocol document says that the client is allowed to simply
66 * drop the connection after sending NBD_OPT_ABORT, or may read
69 if (option
== NBD_OPT_ABORT
)
70 debug ("write: %s: %m", name_of_nbd_opt (option
));
72 nbdkit_error ("write: %s: %m", name_of_nbd_opt (option
));
80 send_newstyle_option_reply_exportname (struct connection
*conn
,
81 uint32_t option
, uint32_t reply
)
83 struct nbd_fixed_new_option_reply fixed_new_option_reply
;
84 size_t name_len
= strlen (exportname
);
87 fixed_new_option_reply
.magic
= htobe64 (NBD_REP_MAGIC
);
88 fixed_new_option_reply
.option
= htobe32 (option
);
89 fixed_new_option_reply
.reply
= htobe32 (reply
);
90 fixed_new_option_reply
.replylen
= htobe32 (name_len
+ sizeof (len
));
93 &fixed_new_option_reply
,
94 sizeof fixed_new_option_reply
, SEND_MORE
) == -1) {
95 nbdkit_error ("write: %s: %m", name_of_nbd_opt (option
));
99 len
= htobe32 (name_len
);
100 if (conn
->send (conn
, &len
, sizeof len
, SEND_MORE
) == -1) {
101 nbdkit_error ("write: %s: %s: %m",
102 name_of_nbd_opt (option
), "sending length");
105 if (conn
->send (conn
, exportname
, name_len
, 0) == -1) {
106 nbdkit_error ("write: %s: %s: %m",
107 name_of_nbd_opt (option
), "sending export name");
115 send_newstyle_option_reply_info_export (struct connection
*conn
,
116 uint32_t option
, uint32_t reply
,
117 uint16_t info
, uint64_t exportsize
)
119 struct nbd_fixed_new_option_reply fixed_new_option_reply
;
120 struct nbd_fixed_new_option_reply_info_export export
;
122 fixed_new_option_reply
.magic
= htobe64 (NBD_REP_MAGIC
);
123 fixed_new_option_reply
.option
= htobe32 (option
);
124 fixed_new_option_reply
.reply
= htobe32 (reply
);
125 fixed_new_option_reply
.replylen
= htobe32 (sizeof export
);
126 export
.info
= htobe16 (info
);
127 export
.exportsize
= htobe64 (exportsize
);
128 export
.eflags
= htobe16 (conn
->eflags
);
130 if (conn
->send (conn
,
131 &fixed_new_option_reply
,
132 sizeof fixed_new_option_reply
, SEND_MORE
) == -1 ||
133 conn
->send (conn
, &export
, sizeof export
, 0) == -1) {
134 nbdkit_error ("write: %s: %m", name_of_nbd_opt (option
));
142 send_newstyle_option_reply_meta_context (struct connection
*conn
,
143 uint32_t option
, uint32_t reply
,
147 struct nbd_fixed_new_option_reply fixed_new_option_reply
;
148 struct nbd_fixed_new_option_reply_meta_context context
;
149 const size_t namelen
= strlen (name
);
151 debug ("newstyle negotiation: %s: replying with %s id %d",
152 name_of_nbd_opt (option
), name
, context_id
);
153 fixed_new_option_reply
.magic
= htobe64 (NBD_REP_MAGIC
);
154 fixed_new_option_reply
.option
= htobe32 (option
);
155 fixed_new_option_reply
.reply
= htobe32 (reply
);
156 fixed_new_option_reply
.replylen
= htobe32 (sizeof context
+ namelen
);
157 context
.context_id
= htobe32 (context_id
);
159 if (conn
->send (conn
,
160 &fixed_new_option_reply
,
161 sizeof fixed_new_option_reply
, SEND_MORE
) == -1 ||
162 conn
->send (conn
, &context
, sizeof context
, SEND_MORE
) == -1 ||
163 conn
->send (conn
, name
, namelen
, 0) == -1) {
164 nbdkit_error ("write: %s: %m", name_of_nbd_opt (option
));
171 /* Sub-function during negotiate_handshake_newstyle, to uniformly handle
172 * a client hanging up on a message boundary.
174 static int __attribute__ ((format (printf
, 4, 5)))
175 conn_recv_full (struct connection
*conn
, void *buf
, size_t len
,
176 const char *fmt
, ...)
178 int r
= conn
->recv (conn
, buf
, len
);
182 va_start (args
, fmt
);
183 nbdkit_verror (fmt
, args
);
188 /* During negotiation, client EOF on message boundary is less
189 * severe than failure in the middle of the buffer. */
190 debug ("client closed input socket, closing connection");
196 /* Sub-function of negotiate_handshake_newstyle_options below. It
197 * must be called on all non-error paths out of the options for-loop
198 * in that function, and must not cause any wire traffic.
201 finish_newstyle_options (struct connection
*conn
, uint64_t *exportsize
)
203 if (protocol_common_open (conn
, exportsize
, &conn
->eflags
) == -1)
206 debug ("newstyle negotiation: flags: export 0x%x", conn
->eflags
);
210 /* Check that the string sent as part of @option, beginning at @buf,
211 * and with a client-reported length of @len, fits within @maxlen
212 * bytes and is well-formed. If not, report an error mentioning
216 check_string (uint32_t option
, char *buf
, uint32_t len
, uint32_t maxlen
,
219 if (len
> NBD_MAX_STRING
|| len
> maxlen
) {
220 nbdkit_error ("%s: %s too long", name_of_nbd_opt (option
), name
);
223 if (strnlen (buf
, len
) != len
) {
224 nbdkit_error ("%s: %s may not include NUL bytes",
225 name_of_nbd_opt (option
), name
);
228 /* TODO: Check for valid UTF-8? */
232 /* Sub-function of negotiate_handshake_newstyle_options, to grab and
233 * validate an export name.
236 check_export_name (struct connection
*conn
, uint32_t option
, char *buf
,
237 uint32_t exportnamelen
, uint32_t maxlen
, bool save
)
239 if (check_string (option
, buf
, exportnamelen
, maxlen
, "export name") == -1)
242 assert (exportnamelen
< sizeof conn
->exportname
);
244 if (exportnamelen
!= conn
->exportnamelen
||
245 memcmp (conn
->exportname
, buf
, exportnamelen
) != 0)
246 conn
->meta_context_base_allocation
= false;
247 memcpy (conn
->exportname
, buf
, exportnamelen
);
248 conn
->exportname
[exportnamelen
] = '\0';
249 conn
->exportnamelen
= exportnamelen
;
251 debug ("newstyle negotiation: %s: client requested export '%.*s'",
252 name_of_nbd_opt (option
), (int) exportnamelen
, buf
);
257 negotiate_handshake_newstyle_options (struct connection
*conn
)
259 struct nbd_new_option new_option
;
264 struct nbd_export_name_option_reply handshake_finish
;
268 for (nr_options
= 0; nr_options
< MAX_NR_OPTIONS
; ++nr_options
) {
269 CLEANUP_FREE
char *data
= NULL
;
271 if (conn_recv_full (conn
, &new_option
, sizeof new_option
,
272 "reading option: conn->recv: %m") == -1)
275 version
= be64toh (new_option
.version
);
276 if (version
!= NBD_NEW_VERSION
) {
277 nbdkit_error ("unknown option version %" PRIx64
278 ", expecting %" PRIx64
,
279 version
, NBD_NEW_VERSION
);
283 /* There is a maximum option length we will accept, regardless
284 * of the option type.
286 optlen
= be32toh (new_option
.optlen
);
287 if (optlen
> MAX_REQUEST_SIZE
) {
288 nbdkit_error ("client option data too long (%" PRIu32
")", optlen
);
291 data
= malloc (optlen
+ 1); /* Allowing a trailing NUL helps some uses */
293 nbdkit_error ("malloc: %m");
297 option
= be32toh (new_option
.option
);
298 optname
= name_of_nbd_opt (option
);
300 /* If the client lacks fixed newstyle support, it should only send
301 * NBD_OPT_EXPORT_NAME.
303 if (!(conn
->cflags
& NBD_FLAG_FIXED_NEWSTYLE
) &&
304 option
!= NBD_OPT_EXPORT_NAME
) {
305 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
))
310 /* In --tls=require / FORCEDTLS mode the only options allowed
311 * before TLS negotiation are NBD_OPT_ABORT and NBD_OPT_STARTTLS.
313 if (tls
== 2 && !conn
->using_tls
&&
314 !(option
== NBD_OPT_ABORT
|| option
== NBD_OPT_STARTTLS
)) {
315 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_TLS_REQD
))
321 case NBD_OPT_EXPORT_NAME
:
322 if (conn_recv_full (conn
, data
, optlen
,
323 "read: %s: %m", name_of_nbd_opt (option
)) == -1)
325 if (check_export_name (conn
, option
, data
, optlen
, optlen
, true) == -1)
328 /* We have to finish the handshake by sending handshake_finish.
329 * On failure, we have to disconnect.
331 if (finish_newstyle_options (conn
, &exportsize
) == -1)
334 memset (&handshake_finish
, 0, sizeof handshake_finish
);
335 handshake_finish
.exportsize
= htobe64 (exportsize
);
336 handshake_finish
.eflags
= htobe16 (conn
->eflags
);
338 if (conn
->send (conn
,
340 (conn
->cflags
& NBD_FLAG_NO_ZEROES
)
341 ? offsetof (struct nbd_export_name_option_reply
, zeroes
)
342 : sizeof handshake_finish
, 0) == -1) {
343 nbdkit_error ("write: %s: %m", optname
);
349 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
351 debug ("client sent %s to abort the connection",
352 name_of_nbd_opt (option
));
357 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
360 if (conn_recv_full (conn
, data
, optlen
,
361 "read: %s: %m", name_of_nbd_opt (option
)) == -1)
366 /* Send back the exportname. */
367 debug ("newstyle negotiation: %s: advertising export '%s'",
368 name_of_nbd_opt (option
), exportname
);
369 if (send_newstyle_option_reply_exportname (conn
, option
,
370 NBD_REP_SERVER
) == -1)
373 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
377 case NBD_OPT_STARTTLS
:
379 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
382 if (conn_recv_full (conn
, data
, optlen
,
383 "read: %s: %m", name_of_nbd_opt (option
)) == -1)
388 if (tls
== 0) { /* --tls=off (NOTLS mode). */
390 #define NO_TLS_REPLY NBD_REP_ERR_POLICY
392 #define NO_TLS_REPLY NBD_REP_ERR_UNSUP
394 if (send_newstyle_option_reply (conn
, option
, NO_TLS_REPLY
) == -1)
397 else /* --tls=on or --tls=require */ {
398 /* We can't upgrade to TLS twice on the same connection. */
399 if (conn
->using_tls
) {
400 if (send_newstyle_option_reply (conn
, option
,
401 NBD_REP_ERR_INVALID
) == -1)
406 /* We have to send the (unencrypted) reply before starting
409 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
412 /* Upgrade the connection to TLS. Also performs access control. */
413 if (crypto_negotiate_tls (conn
, conn
->sockin
, conn
->sockout
) == -1)
415 conn
->using_tls
= true;
416 debug ("using TLS on this connection");
422 if (conn_recv_full (conn
, data
, optlen
,
423 "read: %s: %m", optname
) == -1)
426 if (optlen
< 6) { /* 32 bit export length + 16 bit nr info */
427 debug ("newstyle negotiation: %s option length < 6", optname
);
429 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
436 uint32_t exportnamelen
;
441 /* Validate the name length and number of INFO requests. */
442 memcpy (&exportnamelen
, &data
[0], 4);
443 exportnamelen
= be32toh (exportnamelen
);
444 if (exportnamelen
> optlen
-6 /* NB optlen >= 6, see above */) {
445 debug ("newstyle negotiation: %s: export name too long", optname
);
446 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
451 memcpy (&nrinfos
, &data
[exportnamelen
+4], 2);
452 nrinfos
= be16toh (nrinfos
);
453 if (optlen
!= 4 + exportnamelen
+ 2 + 2*nrinfos
) {
454 debug ("newstyle negotiation: %s: "
455 "number of information requests incorrect", optname
);
456 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
462 /* As with NBD_OPT_EXPORT_NAME we print the export name and
463 * save it in the connection. If an earlier
464 * NBD_OPT_SET_META_CONTEXT used an export name, it must match
465 * or else we drop the support for that context.
467 if (check_export_name (conn
, option
, &data
[4], exportnamelen
,
468 optlen
- 6, true) == -1) {
469 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
475 /* The spec is confusing, but it is required that we send back
476 * NBD_INFO_EXPORT, even if the client did not request it!
477 * qemu client in particular does not request this, but will
478 * fail if we don't send it. Note that if .open fails, but we
479 * succeed at .close, then we merely return an error to the
480 * client and let them try another NBD_OPT, rather than
483 if (finish_newstyle_options (conn
, &exportsize
) == -1) {
484 if (backend_finalize (backend
, conn
) == -1)
486 backend_close (backend
, conn
);
487 if (send_newstyle_option_reply (conn
, option
,
488 NBD_REP_ERR_UNKNOWN
) == -1)
493 if (send_newstyle_option_reply_info_export (conn
, option
,
499 /* For now we ignore all other info requests (but we must
500 * ignore NBD_INFO_EXPORT if it was requested, because we
501 * replied already above). Therefore this loop doesn't do
502 * much at the moment.
504 for (i
= 0; i
< nrinfos
; ++i
) {
505 memcpy (&info
, &data
[4 + exportnamelen
+ 2 + i
*2], 2);
506 info
= be16toh (info
);
508 case NBD_INFO_EXPORT
: /* ignore - reply sent above */ break;
510 debug ("newstyle negotiation: %s: "
511 "ignoring NBD_INFO_* request %u (%s)",
512 optname
, (unsigned) info
, name_of_nbd_info (info
));
518 /* Unlike NBD_OPT_EXPORT_NAME, NBD_OPT_GO sends back an ACK
519 * or ERROR packet. If this was NBD_OPT_LIST, call .close.
521 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
524 if (option
== NBD_OPT_INFO
) {
525 if (backend_finalize (backend
, conn
) == -1)
527 backend_close (backend
, conn
);
532 case NBD_OPT_STRUCTURED_REPLY
:
534 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
537 if (conn_recv_full (conn
, data
, optlen
,
538 "read: %s: %m", name_of_nbd_opt (option
)) == -1)
543 debug ("newstyle negotiation: %s: client requested structured replies",
544 name_of_nbd_opt (option
));
547 /* Must fail with ERR_UNSUP for qemu 4.2 to remain happy;
548 * but failing with ERR_POLICY would have been nicer.
550 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_UNSUP
) == -1)
552 debug ("newstyle negotiation: %s: structured replies are disabled",
553 name_of_nbd_opt (option
));
557 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
560 conn
->structured_replies
= true;
563 case NBD_OPT_LIST_META_CONTEXT
:
564 case NBD_OPT_SET_META_CONTEXT
:
567 uint32_t exportnamelen
;
572 if (conn_recv_full (conn
, data
, optlen
, "read: %s: %m", optname
) == -1)
575 /* Note that we support base:allocation whether or not the plugin
576 * supports can_extents.
578 if (!conn
->structured_replies
) {
579 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
585 /* Minimum length of the option payload is:
586 * 32 bit export name length followed by empty export name
587 * + 32 bit number of queries followed by no queries
592 opt_meta_invalid_option_len
:
593 debug ("newstyle negotiation: %s: invalid option length: %s",
596 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_INVALID
)
602 /* Remember the export name: the NBD spec says that if the client
603 * later uses NBD_OPT_GO on a different export, then the context
604 * returned here is not usable.
606 memcpy (&exportnamelen
, &data
[0], 4);
607 exportnamelen
= be32toh (exportnamelen
);
608 what
= "validating export name";
609 if (check_export_name (conn
, option
, &data
[4], exportnamelen
,
611 option
== NBD_OPT_SET_META_CONTEXT
) == -1)
612 goto opt_meta_invalid_option_len
;
613 opt_index
= 4 + exportnamelen
;
615 /* Read the number of queries. */
616 what
= "reading number of queries";
617 if (opt_index
+4 > optlen
)
618 goto opt_meta_invalid_option_len
;
619 memcpy (&nr_queries
, &data
[opt_index
], 4);
620 nr_queries
= be32toh (nr_queries
);
623 /* for LIST: nr_queries == 0 means return all meta contexts
624 * for SET: nr_queries == 0 means reset all contexts
626 debug ("newstyle negotiation: %s: %s count: %d", optname
,
627 option
== NBD_OPT_LIST_META_CONTEXT
? "query" : "set",
629 if (option
== NBD_OPT_SET_META_CONTEXT
)
630 conn
->meta_context_base_allocation
= false;
631 if (nr_queries
== 0) {
632 if (option
== NBD_OPT_LIST_META_CONTEXT
) {
633 if (send_newstyle_option_reply_meta_context
634 (conn
, option
, NBD_REP_META_CONTEXT
,
635 0, "base:allocation") == -1)
639 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
643 /* Read and answer each query. */
644 while (nr_queries
> 0) {
645 what
= "reading query string length";
646 if (opt_index
+4 > optlen
)
647 goto opt_meta_invalid_option_len
;
648 memcpy (&querylen
, &data
[opt_index
], 4);
649 querylen
= be32toh (querylen
);
651 what
= "reading query string";
652 if (check_string (option
, &data
[opt_index
], querylen
,
653 optlen
- opt_index
, "meta context query") == -1)
654 goto opt_meta_invalid_option_len
;
656 debug ("newstyle negotiation: %s: %s %.*s",
658 option
== NBD_OPT_LIST_META_CONTEXT
? "query" : "set",
659 (int) querylen
, &data
[opt_index
]);
661 /* For LIST, "base:" returns all supported contexts in the
662 * base namespace. We only support "base:allocation".
664 if (option
== NBD_OPT_LIST_META_CONTEXT
&&
666 strncmp (&data
[opt_index
], "base:", 5) == 0) {
667 if (send_newstyle_option_reply_meta_context
668 (conn
, option
, NBD_REP_META_CONTEXT
,
669 0, "base:allocation") == -1)
672 /* "base:allocation" requested by name. */
673 else if (querylen
== 15 &&
674 strncmp (&data
[opt_index
], "base:allocation", 15) == 0) {
675 if (send_newstyle_option_reply_meta_context
676 (conn
, option
, NBD_REP_META_CONTEXT
,
677 option
== NBD_OPT_SET_META_CONTEXT
678 ? base_allocation_id
: 0,
679 "base:allocation") == -1)
681 if (option
== NBD_OPT_SET_META_CONTEXT
)
682 conn
->meta_context_base_allocation
= true;
684 /* Every other query must be ignored. */
686 opt_index
+= querylen
;
689 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ACK
) == -1)
692 debug ("newstyle negotiation: %s: reply complete", optname
);
697 /* Unknown option. */
698 if (send_newstyle_option_reply (conn
, option
, NBD_REP_ERR_UNSUP
) == -1)
700 if (conn_recv_full (conn
, data
, optlen
,
701 "reading unknown option data: conn->recv: %m") == -1)
705 /* Note, since it's not very clear from the protocol doc, that the
706 * client must send NBD_OPT_EXPORT_NAME or NBD_OPT_GO last, and
707 * that ends option negotiation.
709 if (option
== NBD_OPT_EXPORT_NAME
|| option
== NBD_OPT_GO
)
713 if (nr_options
>= MAX_NR_OPTIONS
) {
714 nbdkit_error ("client exceeded maximum number of options (%d)",
719 /* In --tls=require / FORCEDTLS mode, we must have upgraded to TLS
720 * by the time we finish option negotiation. If not, give up.
722 if (tls
== 2 && !conn
->using_tls
) {
723 nbdkit_error ("non-TLS client tried to connect in --tls=require mode");
731 protocol_handshake_newstyle (struct connection
*conn
)
733 struct nbd_new_handshake handshake
;
736 gflags
= (NBD_FLAG_FIXED_NEWSTYLE
| NBD_FLAG_NO_ZEROES
) & mask_handshake
;
738 debug ("newstyle negotiation: flags: global 0x%x", gflags
);
740 handshake
.nbdmagic
= htobe64 (NBD_MAGIC
);
741 handshake
.version
= htobe64 (NBD_NEW_VERSION
);
742 handshake
.gflags
= htobe16 (gflags
);
744 if (conn
->send (conn
, &handshake
, sizeof handshake
, 0) == -1) {
745 nbdkit_error ("write: %s: %m", "sending newstyle handshake");
749 /* Client now sends us its 32 bit flags word ... */
750 if (conn_recv_full (conn
, &conn
->cflags
, sizeof conn
->cflags
,
751 "reading initial client flags: conn->recv: %m") == -1)
753 conn
->cflags
= be32toh (conn
->cflags
);
754 /* ... which we check for accuracy. */
755 debug ("newstyle negotiation: client flags: 0x%x", conn
->cflags
);
756 if (conn
->cflags
& ~gflags
) {
757 nbdkit_error ("client requested unexpected flags 0x%x", conn
->cflags
);
761 /* Receive newstyle options. */
762 if (negotiate_handshake_newstyle_options (conn
) == -1)