From 102705470366b871109d2c3bf182c151ab71eb01 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 17 Oct 2017 12:08:55 +0200 Subject: [*] Support hop-counting in request header, protocol version 3 We steal 8 bits from the request offset to count hops when requests get relayed by proxies. This still leaves plenty of bits for the offset (56 bits, supporting images of up to 72 petabytes). This is used to detect proxy cycles. The algorithm is not perfect but should prevent endless relays of the same request. This is backwards compatible to old clients and servers, as the server only ever sets the hopcount in relayed requests if the upstream server is using protocol version 3 or newer, and clients are automatically upwards compatible as there is practically no image larger than 74PB, so the newly introduced hop count field is always 0 even in requests from old clients. --- src/fuse/connection.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/fuse') diff --git a/src/fuse/connection.c b/src/fuse/connection.c index 3f142c7..a3007fd 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -203,7 +203,7 @@ bool connection_read(dnbd3_async_t *request) pthread_mutex_lock( &connection.sendMutex ); enqueueRequest( request ); if ( connection.sockFd != -1 ) { - if ( !dnbd3_get_block( connection.sockFd, request->offset, request->length, (uint64_t)request ) ) { + if ( !dnbd3_get_block( connection.sockFd, request->offset, request->length, (uint64_t)request, 0 ) ) { shutdown( connection.sockFd, SHUT_RDWR ); connection.sockFd = -1; pthread_mutex_unlock( &connection.sendMutex ); @@ -501,7 +501,7 @@ static void probeAltServers() srv->consecutiveFails += 10; goto fail; } - if ( !dnbd3_get_block( sock, 0, RTT_BLOCK_SIZE, 0 ) ) { + if ( !dnbd3_get_block( sock, 0, RTT_BLOCK_SIZE, 0, 0 ) ) { logadd( LOG_DEBUG1, "-> block request fail" ); goto fail; } @@ -637,7 +637,7 @@ static void switchConnection(int sockFd, alt_server_t *srv) logadd( LOG_DEBUG1, "Requeue after server change" ); next = it->next; enqueueRequest( it ); - if ( connection.sockFd != -1 && !dnbd3_get_block( connection.sockFd, it->offset, it->length, (uint64_t)it ) ) { + if ( connection.sockFd != -1 && !dnbd3_get_block( connection.sockFd, it->offset, it->length, (uint64_t)it, 0 ) ) { logadd( LOG_WARNING, "Resending pending request failed, re-entering panic mode" ); shutdown( connection.sockFd, SHUT_RDWR ); connection.sockFd = -1; -- cgit v1.2.3-55-g7522