mirror of
https://github.com/mii443/qemu.git
synced 2025-12-12 05:18:37 +00:00
nbd/client: refactor nbd_receive_starttls
Split out nbd_request_simple_option to be reused for structured reply option. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20171027104037.8319-10-eblake@redhat.com>
This commit is contained in:
committed by
Eric Blake
parent
a57f6dea02
commit
d795299bf4
70
nbd/client.c
70
nbd/client.c
@@ -508,35 +508,61 @@ static int nbd_receive_query_exports(QIOChannel *ioc,
|
||||
}
|
||||
}
|
||||
|
||||
/* nbd_request_simple_option: Send an option request, and parse the reply
|
||||
* return 1 for successful negotiation,
|
||||
* 0 if operation is unsupported,
|
||||
* -1 with errp set for any other error
|
||||
*/
|
||||
static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
|
||||
{
|
||||
nbd_opt_reply reply;
|
||||
int error;
|
||||
|
||||
if (nbd_send_option_request(ioc, opt, 0, NULL, errp) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
|
||||
return -1;
|
||||
}
|
||||
error = nbd_handle_reply_err(ioc, &reply, errp);
|
||||
if (error <= 0) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (reply.type != NBD_REP_ACK) {
|
||||
error_setg(errp, "Server answered option %d (%s) with unexpected "
|
||||
"reply %" PRIx32 " (%s)", opt, nbd_opt_lookup(opt),
|
||||
reply.type, nbd_rep_lookup(reply.type));
|
||||
nbd_send_opt_abort(ioc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (reply.length != 0) {
|
||||
error_setg(errp, "Option %d ('%s') response length is %" PRIu32
|
||||
" (it should be zero)", opt, nbd_opt_lookup(opt),
|
||||
reply.length);
|
||||
nbd_send_opt_abort(ioc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
|
||||
QCryptoTLSCreds *tlscreds,
|
||||
const char *hostname, Error **errp)
|
||||
{
|
||||
nbd_opt_reply reply;
|
||||
int ret;
|
||||
QIOChannelTLS *tioc;
|
||||
struct NBDTLSHandshakeData data = { 0 };
|
||||
|
||||
trace_nbd_receive_starttls_request();
|
||||
if (nbd_send_option_request(ioc, NBD_OPT_STARTTLS, 0, NULL, errp) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
trace_nbd_receive_starttls_reply();
|
||||
if (nbd_receive_option_reply(ioc, NBD_OPT_STARTTLS, &reply, errp) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reply.type != NBD_REP_ACK) {
|
||||
error_setg(errp, "Server rejected request to start TLS %" PRIx32,
|
||||
reply.type);
|
||||
nbd_send_opt_abort(ioc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reply.length != 0) {
|
||||
error_setg(errp, "Start TLS response was not zero %" PRIu32,
|
||||
reply.length);
|
||||
nbd_send_opt_abort(ioc);
|
||||
ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp);
|
||||
if (ret <= 0) {
|
||||
if (ret == 0) {
|
||||
error_setg(errp, "Server don't support STARTTLS option");
|
||||
nbd_send_opt_abort(ioc);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user