From ad2014ac9de7dc756f5de61d0b57745046926980 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Mon, 5 Feb 2018 16:16:17 +0000 Subject: [PATCH] Fixed long-standing bug with h2r functions being back to front h2r seemd to be using beXXtoh functions instead of htobeXX. Foruntately ROT13 works symmetrically on our systems..! --- src/common/nbdtypes.c | 28 ++++++++++++++-------------- src/proxy/proxy.c | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/nbdtypes.c b/src/common/nbdtypes.c index f45bf0f..20020b4 100644 --- a/src/common/nbdtypes.c +++ b/src/common/nbdtypes.c @@ -26,16 +26,6 @@ void nbd_h2r_init( struct nbd_init * from, struct nbd_init_raw * to) void nbd_r2h_request( struct nbd_request_raw *from, struct nbd_request * to ) -{ - to->magic = htobe32( from->magic ); - to->flags = htobe16( from->flags ); - to->type = htobe16( from->type ); - to->handle.w = from->handle.w; - to->from = htobe64( from->from ); - to->len = htobe32( from->len ); -} - -void nbd_h2r_request( struct nbd_request * from, struct nbd_request_raw * to ) { to->magic = be32toh( from->magic ); to->flags = be16toh( from->flags ); @@ -45,18 +35,28 @@ void nbd_h2r_request( struct nbd_request * from, struct nbd_request_raw * to ) to->len = be32toh( from->len ); } - -void nbd_r2h_reply( struct nbd_reply_raw * from, struct nbd_reply * to ) +void nbd_h2r_request( struct nbd_request * from, struct nbd_request_raw * to ) { to->magic = htobe32( from->magic ); - to->error = htobe32( from->error ); + to->flags = htobe16( from->flags ); + to->type = htobe16( from->type ); to->handle.w = from->handle.w; + to->from = htobe64( from->from ); + to->len = htobe32( from->len ); } -void nbd_h2r_reply( struct nbd_reply * from, struct nbd_reply_raw * to ) + +void nbd_r2h_reply( struct nbd_reply_raw * from, struct nbd_reply * to ) { to->magic = be32toh( from->magic ); to->error = be32toh( from->error ); to->handle.w = from->handle.w; } +void nbd_h2r_reply( struct nbd_reply * from, struct nbd_reply_raw * to ) +{ + to->magic = htobe32( from->magic ); + to->error = htobe32( from->error ); + to->handle.w = from->handle.w; +} + diff --git a/src/proxy/proxy.c b/src/proxy/proxy.c index bacffee..39c1081 100644 --- a/src/proxy/proxy.c +++ b/src/proxy/proxy.c @@ -471,8 +471,8 @@ int proxy_read_from_downstream( struct proxier *proxy, int state ) if ( proxy->req.needle == proxy->req.size ) { debug( - "Received NBD request from downstream. type=%"PRIu32" from=%"PRIu64" len=%"PRIu32, - request->type, request->from, request->len + "Received NBD request from downstream. type=%"PRIu16" flags=%"PRIu16" from=%"PRIu64" len=%"PRIu32, + request->type, request->flags, request->from, request->len ); /* Finished reading, so advance state. Leave size untouched so the next