From c2209762259426a8e5a25a6789711f76b4dca569 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 9 Sep 2019 17:43:20 +0200 Subject: Fix compilation on older gcc --- src/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/types.h') diff --git a/src/types.h b/src/types.h index ec37d9b..695d81d 100644 --- a/src/types.h +++ b/src/types.h @@ -77,7 +77,7 @@ #define IOCTL_REM_SRV _IO(0xab, 5) #if defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -static const uint16_t dnbd3_packet_magic = (0x73 << 8) | (0x72); +#define dnbd3_packet_magic ((uint16_t)( (0x73 << 8) | (0x72) )) // Flip bytes around on big endian when putting stuff on the net #define net_order_64(a) ((uint64_t)((((a) & 0xFFull) << 56) | (((a) & 0xFF00ull) << 40) | (((a) & 0xFF0000ull) << 24) | (((a) & 0xFF000000ull) << 8) | (((a) & 0xFF00000000ull) >> 8) | (((a) & 0xFF0000000000ull) >> 24) | (((a) & 0xFF000000000000ull) >> 40) | (((a) & 0xFF00000000000000ull) >> 56))) #define net_order_32(a) ((uint32_t)((((a) & (uint32_t)0xFF) << 24) | (((a) & (uint32_t)0xFF00) << 8) | (((a) & (uint32_t)0xFF0000) >> 8) | (((a) & (uint32_t)0xFF000000) >> 24))) @@ -96,7 +96,7 @@ static const uint16_t dnbd3_packet_magic = (0x73 << 8) | (0x72); #define BIG_ENDIAN #endif #elif defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || defined(__i386__) || defined(__i386) || defined(__x86_64) -static const uint16_t dnbd3_packet_magic = (0x73) | (0x72 << 8); +#define dnbd3_packet_magic ((uint16_t)( (0x73) | (0x72 << 8) )) // Make little endian our network byte order as probably 99.999% of machines this will be used on are LE #define net_order_64(a) (a) #define net_order_32(a) (a) -- cgit v1.2.3-55-g7522 From 11411f822e5526f8fa3ce47f4315557dd0915ddf Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 11 Sep 2019 22:01:36 +0200 Subject: [*] Use __attribute__((packed)) instead of #pragma pack --- src/types.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/types.h') diff --git a/src/types.h b/src/types.h index 695d81d..cb0ccfd 100644 --- a/src/types.h +++ b/src/types.h @@ -117,17 +117,14 @@ static const dnbd3_af HOST_NONE = (dnbd3_af)0; static const dnbd3_af HOST_IP4 = (dnbd3_af)2; static const dnbd3_af HOST_IP6 = (dnbd3_af)10; -#pragma pack(1) -typedef struct dnbd3_host_t +typedef struct __attribute__((packed)) dnbd3_host_t { uint8_t addr[16]; // 16byte (network representation, so it can be directly passed to socket functions) uint16_t port; // 2byte (network representation, so it can be directly passed to socket functions) dnbd3_af type; // 1byte (ip version. HOST_IP4 or HOST_IP6. 0 means this struct is empty and should be ignored) } dnbd3_host_t; -#pragma pack(0) -#pragma pack(1) -typedef struct +typedef struct __attribute__((packed)) { uint16_t len; dnbd3_host_t host; @@ -137,7 +134,6 @@ typedef struct int read_ahead_kb; uint8_t use_server_provided_alts; } dnbd3_ioctl_t; -#pragma pack(0) // network #define CMD_GET_BLOCK 1 @@ -150,8 +146,7 @@ typedef struct #define CMD_GET_CRC32 8 #define DNBD3_REQUEST_SIZE 24 -#pragma pack(1) -typedef struct +typedef struct __attribute__((packed)) { uint16_t magic; // 2byte uint16_t cmd; // 2byte @@ -170,27 +165,22 @@ typedef struct }; uint64_t handle; // 8byte } dnbd3_request_t; -#pragma pack(0) _Static_assert( sizeof(dnbd3_request_t) == DNBD3_REQUEST_SIZE, "dnbd3_request_t is messed up" ); #define DNBD3_REPLY_SIZE 16 -#pragma pack(1) -typedef struct +typedef struct __attribute__((packed)) { uint16_t magic; // 2byte uint16_t cmd; // 2byte uint32_t size; // 4byte uint64_t handle; // 8byte } dnbd3_reply_t; -#pragma pack(0) _Static_assert( sizeof(dnbd3_reply_t) == DNBD3_REPLY_SIZE, "dnbd3_reply_t is messed up" ); -#pragma pack(1) -typedef struct +typedef struct __attribute__((packed)) { dnbd3_host_t host; uint8_t failures; // 1byte (number of times server has been consecutively unreachable) } dnbd3_server_entry_t; -#pragma pack(0) #endif /* TYPES_H_ */ -- cgit v1.2.3-55-g7522 From 2e70a0836173c9502ff5cddd849165d432a883cb Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 17 Mar 2020 13:01:37 +0100 Subject: [SERVER] Include build type and version in RPC Added new query type q=version, which uses the STATS access rights. --- CMakeLists.txt | 7 +++---- get-version.sh | 2 +- src/server/rpc.c | 10 ++++++++-- src/server/server.c | 7 +++++-- src/types.h | 3 +++ src/version.h | 4 ---- 6 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/types.h') diff --git a/CMakeLists.txt b/CMakeLists.txt index cc8bfb7..b263f77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) ADD_DEFINITIONS(-DWITH_IPV6) +ADD_DEFINITIONS(-DBUILD_TYPE=${CMAKE_BUILD_TYPE}) FIND_PACKAGE(Threads) @@ -133,14 +134,12 @@ ADD_CUSTOM_TARGET( -P ${CMAKE_BINARY_DIR}/version.cmake ) -INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/generated ) - ################################################################################ # CLIENT # ################################################################################ if(BUILD_KERNEL_MODULE) - FILE(GLOB_RECURSE CLIENT_SRCS src/client/*.c) + FILE(GLOB_RECURSE CLIENT_SRCS ${CMAKE_BINARY_DIR}/generated/version.c src/client/*.c) ADD_EXECUTABLE(dnbd3-client ${CLIENT_SRCS}) TARGET_LINK_LIBRARIES(dnbd3-client) ADD_DEPENDENCIES(dnbd3-client version) @@ -157,7 +156,7 @@ if(BUILD_SERVER) message(" ######################## Building server for AFL mode - will be useless otherwise!") ADD_DEFINITIONS(-DAFL_MODE) ENDIF() - FILE(GLOB SERVER_SRCS src/server/*.c src/shared/*.c src/server/picohttpparser/*.c) + FILE(GLOB SERVER_SRCS ${CMAKE_BINARY_DIR}/generated/version.c src/server/*.c src/shared/*.c src/server/picohttpparser/*.c) ADD_EXECUTABLE(dnbd3-server ${SERVER_SRCS}) TARGET_INCLUDE_DIRECTORIES(dnbd3-server PRIVATE ${JANSSON_INCLUDE_DIR}) TARGET_LINK_LIBRARIES(dnbd3-server ${CMAKE_THREAD_LIBS_INIT} ${JANSSON_LIBRARIES}) diff --git a/get-version.sh b/get-version.sh index 1d4a8cb..5e5b3e1 100755 --- a/get-version.sh +++ b/get-version.sh @@ -8,7 +8,7 @@ ROOT_DIR="$(dirname "${SELF}")" cd "$ROOT_DIR" if [ -d .git ]; then - [ -n "$(git diff)" ] && MODDED='+MOD' + [ -n "$(git diff HEAD)" ] && MODDED='+MOD' echo $(git describe)$MODDED, branch $(git rev-parse --abbrev-ref HEAD), built "$(date +%Y-%m-%d)" exit 0 fi diff --git a/src/server/rpc.c b/src/server/rpc.c index b66b8fe..12ad0dd 100644 --- a/src/server/rpc.c +++ b/src/server/rpc.c @@ -6,6 +6,7 @@ #include "image.h" #include "altservers.h" #include "../shared/sockhelper.h" +#include "../version.h" #include "fileutil.h" #include "picohttpparser/picohttpparser.h" #include "urldecode.h" @@ -259,7 +260,7 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t { bool ok; bool stats = false, images = false, clients = false, space = false; - bool logfile = false, config = false, altservers = false; + bool logfile = false, config = false, altservers = false, version = false; #define SETVAR(var) if ( !var && STRCMP(fields[i].value, #var) ) var = true for (size_t i = 0; i < fields_num; ++i) { if ( !equals( &fields[i].name, &STR_Q ) ) continue; @@ -270,9 +271,10 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t else SETVAR(logfile); else SETVAR(config); else SETVAR(altservers); + else SETVAR(version); } #undef SETVAR - if ( ( stats || space ) && !(permissions & ACL_STATS) ) { + if ( ( stats || space || version ) && !(permissions & ACL_STATS) ) { return sendReply( sock, "403 Forbidden", "text/plain", "No permission to access statistics", -1, keepAlive ); } if ( images && !(permissions & ACL_IMAGE_LIST) ) { @@ -308,6 +310,10 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t statisticsJson = json_pack( "{sI}", "runId", randomRunId ); } + if ( version ) { + json_object_set_new( statisticsJson, "version", json_string( VERSION_STRING ) ); + json_object_set_new( statisticsJson, "build", json_string( TOSTRING( BUILD_TYPE ) ) ); + } if ( space ) { uint64_t spaceTotal = 0, spaceAvail = 0; file_freeDiskSpace( _basePath, &spaceTotal, &spaceAvail ); diff --git a/src/server/server.c b/src/server/server.c index c9edc05..71a49b9 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -342,7 +342,10 @@ int main(int argc, char *argv[]) net_init(); uplink_globalsInit(); rpc_init(); - logadd( LOG_INFO, "DNBD3 server starting.... Machine type: " ENDIAN_MODE ); + logadd( LOG_INFO, "DNBD3 server starting...." ); + logadd( LOG_INFO, "Machine type: " ENDIAN_MODE ); + logadd( LOG_INFO, "Build Type: " TOSTRING( BUILD_TYPE ) ); + logadd( LOG_INFO, "Version: %s", VERSION_STRING ); if ( altservers_load() < 0 ) { logadd( LOG_WARNING, "Could not load alt-servers. Does the file exist in %s?", _configDir ); @@ -385,7 +388,7 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } - logadd( LOG_INFO, "Server is ready. (%s)", VERSION_STRING ); + logadd( LOG_INFO, "Server is ready." ); if ( thread_create( &timerThread, NULL, &timerMainloop, NULL ) == 0 ) { hasTimerThread = true; diff --git a/src/types.h b/src/types.h index cb0ccfd..dc8e501 100644 --- a/src/types.h +++ b/src/types.h @@ -34,6 +34,9 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) + #ifdef __GNUC__ #define UNUSED __attribute__ ((unused)) #else diff --git a/src/version.h b/src/version.h index 0c4a66b..1c17442 100644 --- a/src/version.h +++ b/src/version.h @@ -23,8 +23,4 @@ extern const char *VERSION_STRING; -// This is done in a little weird way but otherwise eclipse complains about -// unresolvable symbols etc... -#include "version.c" - #endif /* VERSION_H_ */ -- cgit v1.2.3-55-g7522 From 3d2f1f605e07b511c4ebf79c936c7061dd918957 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 19 Mar 2020 20:43:15 +0100 Subject: [SERVER] Use PCLMUL for crc32 on AMD64 if available This is about 16x as fast as before with the lookup table for processing 4 bytes at a time and should work on any AMD64 CPU made in the last decade. We still need an AltiVec implementation for G5 though. --- src/shared/crc32.c | 221 +++++++++++++++++++++++++++++++++++++++++------------ src/types.h | 12 +-- 2 files changed, 178 insertions(+), 55 deletions(-) (limited to 'src/types.h') diff --git a/src/shared/crc32.c b/src/shared/crc32.c index db941d3..50f476a 100644 --- a/src/shared/crc32.c +++ b/src/shared/crc32.c @@ -41,21 +41,20 @@ #include "../types.h" #include -#define FAR +#if defined(__x86_64__) || defined(__amd64__) +#include +#include +#include +#include +#define zalign(n) __attribute__((aligned(n))) +#endif + #define OF(args) args -#define local static /* Definitions for doing the crc four data bytes at a time. */ -#if !defined(NOBYFOUR) -# define BYFOUR -#endif -#ifdef BYFOUR -# define TBLS 8 -#else -# define TBLS 1 -#endif /* BYFOUR */ +#define TBLS 8 -local const uint32_t crc_table[TBLS][256] = +static const uint32_t crc_table[TBLS][256] = { { 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U, @@ -110,7 +109,6 @@ local const uint32_t crc_table[TBLS][256] = 0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U, 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU, 0x2d02ef8dU -#ifdef BYFOUR }, { 0x00000000U, 0x191b3141U, 0x32366282U, 0x2b2d53c3U, 0x646cc504U, @@ -489,38 +487,159 @@ local const uint32_t crc_table[TBLS][256] = 0x95e6b8b1U, 0x7b490da3U, 0x1e2eb11bU, 0x483ed243U, 0x2d596efbU, 0xc3f6dbe9U, 0xa6916751U, 0x1fa9b0ccU, 0x7ace0c74U, 0x9461b966U, 0xf10605deU -#endif } }; -#ifdef NO_ENDIAN -// Currently not in use, always use the BYFOUR method with known endianness -/* ========================================================================= */ -#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) -#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 +#define PCLMUL_MIN_LEN 64 +#define PCLMUL_ALIGN 16 +#define PCLMUL_ALIGN_MASK 15 -/* ========================================================================= */ -uint32_t crc32(crc, buf, len) - uint32_t crc; - const uint8_t *buf; - size_t len; +#if defined(__x86_64__) || defined(__amd64__) +/* crc32_simd.c + * + * Copyright 2017 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the Chromium source repository LICENSE file. + * + * crc32_sse42_simd_(): compute the crc32 of the buffer, where the buffer + * length must be at least 64, and a multiple of 16. Based on: + * + * "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction" + * V. Gopal, E. Ozturk, et al., 2009, http://intel.ly/2ySEwL0 + */ +static uint32_t +__attribute__((target("pclmul"))) +crc32pclmul(uint32_t crc, const uint8_t *buf, size_t len) { - if (buf == NULL) return 0; + /* + * Definitions of the bit-reflected domain constants k1,k2,k3, etc and + * the CRC32+Barrett polynomials given at the end of the paper. + */ + static const uint64_t zalign(16) k1k2[] = { 0x0154442bd4, 0x01c6e41596 }; + static const uint64_t zalign(16) k3k4[] = { 0x01751997d0, 0x00ccaa009e }; + static const uint64_t zalign(16) k5k0[] = { 0x0163cd6124, 0x0000000000 }; + static const uint64_t zalign(16) poly[] = { 0x01db710641, 0x01f7011641 }; + + __m128i x0, x1, x2, x3, x4, x5, x6, x7, x8, y5, y6, y7, y8; + + /* + * There's at least one block of 64. + */ + x1 = _mm_loadu_si128((__m128i *)(buf + 0x00)); + x2 = _mm_loadu_si128((__m128i *)(buf + 0x10)); + x3 = _mm_loadu_si128((__m128i *)(buf + 0x20)); + x4 = _mm_loadu_si128((__m128i *)(buf + 0x30)); + + x1 = _mm_xor_si128(x1, _mm_cvtsi32_si128(crc)); + + x0 = _mm_load_si128((__m128i *)k1k2); + + buf += 64; + len -= 64; + + /* + * Parallel fold blocks of 64, if any. + */ + while (len >= 64) + { + x5 = _mm_clmulepi64_si128(x1, x0, 0x00); + x6 = _mm_clmulepi64_si128(x2, x0, 0x00); + x7 = _mm_clmulepi64_si128(x3, x0, 0x00); + x8 = _mm_clmulepi64_si128(x4, x0, 0x00); + + x1 = _mm_clmulepi64_si128(x1, x0, 0x11); + x2 = _mm_clmulepi64_si128(x2, x0, 0x11); + x3 = _mm_clmulepi64_si128(x3, x0, 0x11); + x4 = _mm_clmulepi64_si128(x4, x0, 0x11); + + y5 = _mm_loadu_si128((__m128i *)(buf + 0x00)); + y6 = _mm_loadu_si128((__m128i *)(buf + 0x10)); + y7 = _mm_loadu_si128((__m128i *)(buf + 0x20)); + y8 = _mm_loadu_si128((__m128i *)(buf + 0x30)); + + x1 = _mm_xor_si128(x1, x5); + x2 = _mm_xor_si128(x2, x6); + x3 = _mm_xor_si128(x3, x7); + x4 = _mm_xor_si128(x4, x8); + + x1 = _mm_xor_si128(x1, y5); + x2 = _mm_xor_si128(x2, y6); + x3 = _mm_xor_si128(x3, y7); + x4 = _mm_xor_si128(x4, y8); - crc = crc ^ 0xffffffffU; - while (len >= 8) { - DO8; - len -= 8; + buf += 64; + len -= 64; } - if (len) do { - DO1; - } while (--len); - return crc ^ 0xffffffffU; + + /* + * Fold into 128-bits. + */ + x0 = _mm_load_si128((__m128i *)k3k4); + + x5 = _mm_clmulepi64_si128(x1, x0, 0x00); + x1 = _mm_clmulepi64_si128(x1, x0, 0x11); + x1 = _mm_xor_si128(x1, x2); + x1 = _mm_xor_si128(x1, x5); + + x5 = _mm_clmulepi64_si128(x1, x0, 0x00); + x1 = _mm_clmulepi64_si128(x1, x0, 0x11); + x1 = _mm_xor_si128(x1, x3); + x1 = _mm_xor_si128(x1, x5); + + x5 = _mm_clmulepi64_si128(x1, x0, 0x00); + x1 = _mm_clmulepi64_si128(x1, x0, 0x11); + x1 = _mm_xor_si128(x1, x4); + x1 = _mm_xor_si128(x1, x5); + + /* + * Single fold blocks of 16, if any. + */ + while (len >= 16) + { + x2 = _mm_loadu_si128((__m128i *)buf); + + x5 = _mm_clmulepi64_si128(x1, x0, 0x00); + x1 = _mm_clmulepi64_si128(x1, x0, 0x11); + x1 = _mm_xor_si128(x1, x2); + x1 = _mm_xor_si128(x1, x5); + + buf += 16; + len -= 16; + } + + /* + * Fold 128-bits to 64-bits. + */ + x2 = _mm_clmulepi64_si128(x1, x0, 0x10); + x3 = _mm_setr_epi32(~0, 0, ~0, 0); + x1 = _mm_srli_si128(x1, 8); + x1 = _mm_xor_si128(x1, x2); + + x0 = _mm_loadl_epi64((__m128i*)k5k0); + + x2 = _mm_srli_si128(x1, 4); + x1 = _mm_and_si128(x1, x3); + x1 = _mm_clmulepi64_si128(x1, x0, 0x00); + x1 = _mm_xor_si128(x1, x2); + + /* + * Barret reduce to 32-bits. + */ + x0 = _mm_load_si128((__m128i*)poly); + + x2 = _mm_and_si128(x1, x3); + x2 = _mm_clmulepi64_si128(x2, x0, 0x10); + x2 = _mm_and_si128(x2, x3); + x2 = _mm_clmulepi64_si128(x2, x0, 0x00); + x1 = _mm_xor_si128(x1, x2); + + /* + * Return the crc32. + */ + return _mm_extract_epi32(x1, 1); } #endif -#ifdef BYFOUR - /* This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit integer pointer type. This violates the strict aliasing rule, where a @@ -533,7 +652,7 @@ uint32_t crc32(crc, buf, len) writes to the buffer that is passed to these routines. */ -#ifdef LITTLE_ENDIAN +#ifdef DNBD3_LITTLE_ENDIAN /* ========================================================================= */ #define DOLIT4 c ^= *buf4++; \ c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ @@ -547,16 +666,25 @@ uint32_t crc32(crc, buf, len) size_t len; { if (buf == NULL) return 0; - register uint32_t c; - register const uint32_t FAR *buf4; + uint32_t c; c = ~crc; - while (len && ((uintptr_t)buf & 3)) { + while (len && ((uintptr_t)buf & PCLMUL_ALIGN_MASK)) { c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); len--; } - - buf4 = (const uint32_t FAR *)(const void FAR *)buf; +#if defined(__x86_64__) || defined(__amd64__) + static atomic_int pclmul = -1; + if (pclmul == -1) { + pclmul = __builtin_cpu_supports("pclmul"); + } + if (pclmul && len >= PCLMUL_MIN_LEN) { + c = crc32pclmul(c, buf, len & ~PCLMUL_ALIGN_MASK); + buf += len & ~PCLMUL_ALIGN_MASK; + len &= PCLMUL_ALIGN_MASK; + } +#else + const uint32_t *buf4 = (const uint32_t *)(const void *)buf; while (len >= 32) { DOLIT32; len -= 32; @@ -565,7 +693,8 @@ uint32_t crc32(crc, buf, len) DOLIT4; len -= 4; } - buf = (const uint8_t FAR *)buf4; + buf = (const uint8_t *)buf4; +#endif if (len) do { c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); @@ -575,7 +704,7 @@ uint32_t crc32(crc, buf, len) } #endif -#ifdef BIG_ENDIAN +#ifdef DNBD3_BIG_ENDIAN /* ========================================================================= */ #define DOBIG4 c ^= *buf4++; \ c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ @@ -590,7 +719,7 @@ uint32_t crc32(crc, buf, len) { if (buf == NULL) return 0; register uint32_t c; - register const uint32_t FAR *buf4; + register const uint32_t *buf4; c = ~net_order_32(crc); while (len && ((uintptr_t)buf & 3)) { @@ -598,7 +727,7 @@ uint32_t crc32(crc, buf, len) len--; } - buf4 = (const uint32_t FAR *)(const void FAR *)buf; + buf4 = (const uint32_t *)(const void *)buf; while (len >= 32) { DOBIG32; len -= 32; @@ -607,7 +736,7 @@ uint32_t crc32(crc, buf, len) DOBIG4; len -= 4; } - buf = (const uint8_t FAR *)buf4; + buf = (const uint8_t *)buf4; if (len) do { c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); @@ -617,5 +746,3 @@ uint32_t crc32(crc, buf, len) } #endif -#endif /* BYFOUR */ - diff --git a/src/types.h b/src/types.h index dc8e501..83416f4 100644 --- a/src/types.h +++ b/src/types.h @@ -95,9 +95,7 @@ (a).size = net_order_32((a).size); \ } while (0) #define ENDIAN_MODE "Big Endian" -#ifndef BIG_ENDIAN -#define BIG_ENDIAN -#endif +#define DNBD3_BIG_ENDIAN #elif defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || defined(__i386__) || defined(__i386) || defined(__x86_64) #define dnbd3_packet_magic ((uint16_t)( (0x73) | (0x72 << 8) )) // Make little endian our network byte order as probably 99.999% of machines this will be used on are LE @@ -107,9 +105,7 @@ #define fixup_request(a) while(0) #define fixup_reply(a) while(0) #define ENDIAN_MODE "Little Endian" -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN -#endif +#define DNBD3_LITTLE_ENDIAN #else #error "Unknown Endianness" #endif @@ -156,10 +152,10 @@ typedef struct __attribute__((packed)) uint32_t size; // 4byte union { struct { -#ifdef LITTLE_ENDIAN +#ifdef DNBD3_LITTLE_ENDIAN uint64_t offset_small:56; // 7byte uint8_t hops; // 1byte -#elif defined(BIG_ENDIAN) +#elif defined(DNBD3_BIG_ENDIAN) uint8_t hops; // 1byte uint64_t offset_small:56; // 7byte #endif -- cgit v1.2.3-55-g7522