proxy: Respect the REQUEST_MASK
This commit is contained in:
@@ -11,6 +11,10 @@
|
|||||||
#define REQUEST_WRITE 1
|
#define REQUEST_WRITE 1
|
||||||
#define REQUEST_DISCONNECT 2
|
#define REQUEST_DISCONNECT 2
|
||||||
|
|
||||||
|
/* The top 2 bytes of the type field are overloaded and can contain flags */
|
||||||
|
#define REQUEST_MASK 0x0000ffff
|
||||||
|
|
||||||
|
|
||||||
/* 1MiB is the de-facto standard for maximum size of header + data */
|
/* 1MiB is the de-facto standard for maximum size of header + data */
|
||||||
#define NBD_MAX_SIZE ( 1024 * 1024 )
|
#define NBD_MAX_SIZE ( 1024 * 1024 )
|
||||||
|
|
||||||
|
10
src/proxy.c
10
src/proxy.c
@@ -393,19 +393,19 @@ int proxy_read_from_downstream( struct proxier *proxy, int state )
|
|||||||
if ( proxy->req.needle == NBD_REQUEST_SIZE ) {
|
if ( proxy->req.needle == NBD_REQUEST_SIZE ) {
|
||||||
nbd_r2h_request( request_raw, request );
|
nbd_r2h_request( request_raw, request );
|
||||||
|
|
||||||
if ( request->type == REQUEST_DISCONNECT ) {
|
if ( ( request->type & REQUEST_MASK ) == REQUEST_DISCONNECT ) {
|
||||||
info( "Received disconnect request from client" );
|
info( "Received disconnect request from client" );
|
||||||
return EXIT;
|
return EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Simple validations */
|
/* Simple validations */
|
||||||
if ( request->type == REQUEST_READ ) {
|
if ( ( request->type & REQUEST_MASK ) == REQUEST_READ ) {
|
||||||
if (request->len > ( NBD_MAX_SIZE - NBD_REPLY_SIZE ) ) {
|
if (request->len > ( NBD_MAX_SIZE - NBD_REPLY_SIZE ) ) {
|
||||||
warn( "NBD read request size %"PRIu32" too large", request->len );
|
warn( "NBD read request size %"PRIu32" too large", request->len );
|
||||||
return EXIT;
|
return EXIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( request->type == REQUEST_WRITE ) {
|
if ( (request->type & REQUEST_MASK ) == REQUEST_WRITE ) {
|
||||||
if (request->len > ( NBD_MAX_SIZE - NBD_REQUEST_SIZE ) ) {
|
if (request->len > ( NBD_MAX_SIZE - NBD_REQUEST_SIZE ) ) {
|
||||||
warn( "NBD write request size %"PRIu32" too large", request->len );
|
warn( "NBD write request size %"PRIu32" too large", request->len );
|
||||||
return EXIT;
|
return EXIT;
|
||||||
@@ -548,8 +548,8 @@ int proxy_read_from_upstream( struct proxier* proxy, int state )
|
|||||||
goto disconnect;
|
goto disconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( proxy->req_hdr.type || REQUEST_READ ) == REQUEST_READ ) {
|
if ( ( proxy->req_hdr.type & REQUEST_MASK ) == REQUEST_READ ) {
|
||||||
/* Read the read reply data too. Same optimisation as
|
/* Get the read reply data too. Same optimisation as
|
||||||
* read_from_downstream */
|
* read_from_downstream */
|
||||||
proxy->rsp.size += proxy->req_hdr.len;
|
proxy->rsp.size += proxy->req_hdr.len;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user