diff options
-rw-r--r-- | NEWS | 59 | ||||
-rw-r--r-- | man/sd_listen_fds.xml | 2 | ||||
-rw-r--r-- | src/activate/activate.c | 5 | ||||
-rw-r--r-- | src/basic/hashmap.c | 7 | ||||
-rw-r--r-- | src/basic/siphash24.c | 257 | ||||
-rw-r--r-- | src/basic/siphash24.h | 4 | ||||
-rw-r--r-- | src/basic/strv.c | 2 | ||||
-rw-r--r-- | src/basic/util.c | 8 | ||||
-rw-r--r-- | src/journal/journald-rate-limit.c | 12 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-server.c | 6 | ||||
-rw-r--r-- | src/libsystemd-network/test-dhcp-server.c | 7 | ||||
-rw-r--r-- | src/test/test-hashmap-plain.c | 2 | ||||
-rw-r--r-- | src/test/test-siphash24.c | 24 |
13 files changed, 207 insertions, 188 deletions
@@ -13,8 +13,8 @@ CHANGES WITH 227: stopped having this file around as anything else than a symlink to /proc/self/mounts. - * Support for the "pids" cgroup controller has been added. - It allows accounting the number of tasks in a cgroup and + * Support for the "pids" cgroup controller has been added. It + allows accounting the number of tasks in a cgroup and enforcing limits on it. This adds two new setting TasksAccounting= and TasksMax= to each unit, as well as a global option DefaultTasksAccounting=. @@ -44,10 +44,10 @@ CHANGES WITH 227: 'machine-id-setup --commit'. The separate binary has been removed. - * The WorkingDirectory= directive in unit files may now be - set to the special value '~'. In this case, the working - directory is set to the home directory of the user configured - in User=. + * The WorkingDirectory= directive in unit files may now be set + to the special value '~'. In this case, the working + directory is set to the home directory of the user + configured in User=. * "machinectl shell" will now open the shell in the home directory of the selected user by default. @@ -57,11 +57,12 @@ CHANGES WITH 227: also be set through CrashReboot= in systemd.conf. * The CrashChVT= configuration file setting is renamed to - CrashChangeVT=, following our usual logic of not abbreviating - unnecessarily. The old directive is still supported for compat - reasons. Also, this directive now takes an integer value - between 1 and 63, or a boolean value. The formerly supported - '-1' value for disabling stays around for compat reasons. + CrashChangeVT=, following our usual logic of not + abbreviating unnecessarily. The old directive is still + supported for compat reasons. Also, this directive now takes + an integer value between 1 and 63, or a boolean value. The + formerly supported '-1' value for disabling stays around for + compat reasons. * The PrivateTmp=, PrivateDevices=, PrivateNetwork=, NoNewPrivileges=, TTYPath=, WorkingDirectory= and @@ -114,12 +115,15 @@ CHANGES WITH 227: * The RuntimeDirectory= setting now understands unit specifiers like %i or %f. - * networkd gained support for: - - setting the IPv6 Router Advertisment settings via + * systemd-networkd gained support for: + + - Setting the IPv6 Router Advertisment settings via IPv6AcceptRouterAdvertisements= in .network files. - - configuring the HelloTimeSec, MaxAgeSec and - ForwardDelaySec bridge parameters in .netdev files. - - configuring PreferredSource for static routes in + + - Configuring the HelloTimeSec=, MaxAgeSec= and + ForwardDelaySec= bridge parameters in .netdev files. + + - Configuring PreferredSource= for static routes in .network files. * udev will now create /dev/disk/by-path links for ATA devices @@ -142,11 +146,24 @@ CHANGES WITH 227: only intermittendly, and even restores state if the previous system shutdown was abrupt rather than clean. - * Sockets passed using socket activation are now named. A new - API sd_listen_fds_with_names() is added to access the names. - The default names can be overwritten either in the .socket - file using the FileDescriptorName= parameter, or by passing - FDNAME= when storing the filedescriptor using sd_notify(). + * File descriptors passed during socket activation may now be + named. A new API sd_listen_fds_with_names() is added to + access the names. The default names may be overriden, + either in the .socket file using the FileDescriptorName= + parameter, or by passing FDNAME= when storing the file + descriptors using sd_notify(). + + * The journal daemon gained support for vacuuming old journal + files controlled by the number of files that shall remain, + in addition to the already existing control by size and by + date. This is useful as journal interleaving performance + degrades with too many seperate journal files, and allows + putting an effective limit on them. The new setting defaults + to 100, but this may be changed by setting SystemMaxFiles= + and RuntimeMaxFiles= in journald.conf. Also, the + "journalctl" tool gained the new --vacuum-files= switch to + manually vacuum journal files to leave only the specified + number of files in place. * Galician, Serbian, Turkish and Korean translations were added. diff --git a/man/sd_listen_fds.xml b/man/sd_listen_fds.xml index ea55671e4f..ccd1266318 100644 --- a/man/sd_listen_fds.xml +++ b/man/sd_listen_fds.xml @@ -147,7 +147,7 @@ way. The returned array of strings has as many entries as file descriptors has been received, plus a final NULL pointer terminating the array. The caller needs to free the array itself - and each of its elements with libc's <varname>free()</varname> + and each of its elements with libc's <function>free()</function> call after use. If the <parameter>names</parameter> parameter is NULL the call is entirely equivalent to <function>sd_listen_fds()</function>.</para> diff --git a/src/activate/activate.c b/src/activate/activate.c index 6a8432314e..4ece1367c1 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -361,6 +361,11 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_FDNAME: + if (!fdname_is_valid(optarg)) { + log_error("File descriptor name %s is not valid, refusing.", optarg); + return -EINVAL; + } + arg_fdname = optarg; break; diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 3e17ed30df..20e7e51d9e 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -372,12 +372,15 @@ static uint8_t *hash_key(HashmapBase *h) { static unsigned base_bucket_hash(HashmapBase *h, const void *p) { struct siphash state; + uint64_t hash; - siphash_init(&state, hash_key(h)); + siphash24_init(&state, hash_key(h)); h->hash_ops->hash(p, &state); - return (unsigned) (siphash24_finalize(&state) % n_buckets(h)); + siphash24_finalize((uint8_t*)&hash, &state); + + return (unsigned) (hash % n_buckets(h)); } #define bucket_hash(h, p) base_bucket_hash(HASHMAP_BASE(h), p) diff --git a/src/basic/siphash24.c b/src/basic/siphash24.c index 308e4230c5..3b61961389 100644 --- a/src/basic/siphash24.c +++ b/src/basic/siphash24.c @@ -13,175 +13,170 @@ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. (Minimal changes made by Lennart Poettering, to make clean for inclusion in systemd) + (Refactored by Tom Gundersen to split up in several functions and follow systemd + coding style) */ -#include <stdint.h> -#include <stdio.h> -#include <string.h> + +#include "sparse-endian.h" #include "siphash24.h" +#include "util.h" + +static inline uint64_t rotate_left(uint64_t x, uint8_t b) { + assert(b < 64); + + return (x << b) | (x >> (64 - b)); +} + +static inline void sipround(struct siphash *state) { + assert(state); + + state->v0 += state->v1; + state->v1 = rotate_left(state->v1, 13); + state->v1 ^= state->v0; + state->v0 = rotate_left(state->v0, 32); + state->v2 += state->v3; + state->v3 = rotate_left(state->v3, 16); + state->v3 ^= state->v2; + state->v0 += state->v3; + state->v3 = rotate_left(state->v3, 21); + state->v3 ^= state->v0; + state->v2 += state->v1; + state->v1 = rotate_left(state->v1, 17); + state->v1 ^= state->v2; + state->v2 = rotate_left(state->v2, 32); +} + +void siphash24_init(struct siphash *state, const uint8_t k[16]) { + uint64_t k0, k1; -typedef uint64_t u64; -typedef uint32_t u32; -typedef uint8_t u8; - -#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) ) - -#define U32TO8_LE(p, v) \ - (p)[0] = (u8)((v) ); (p)[1] = (u8)((v) >> 8); \ - (p)[2] = (u8)((v) >> 16); (p)[3] = (u8)((v) >> 24); - -#define U64TO8_LE(p, v) \ - U32TO8_LE((p), (u32)((v) )); \ - U32TO8_LE((p) + 4, (u32)((v) >> 32)); - -#define U8TO64_LE(p) \ - (((u64)((p)[0]) ) | \ - ((u64)((p)[1]) << 8) | \ - ((u64)((p)[2]) << 16) | \ - ((u64)((p)[3]) << 24) | \ - ((u64)((p)[4]) << 32) | \ - ((u64)((p)[5]) << 40) | \ - ((u64)((p)[6]) << 48) | \ - ((u64)((p)[7]) << 56)) - -#define SIPROUND(state) \ - do { \ - (state)->v0 += (state)->v1; (state)->v1=ROTL((state)->v1,13); (state)->v1 ^= (state)->v0; (state)->v0=ROTL((state)->v0,32); \ - (state)->v2 += (state)->v3; (state)->v3=ROTL((state)->v3,16); (state)->v3 ^= (state)->v2; \ - (state)->v0 += (state)->v3; (state)->v3=ROTL((state)->v3,21); (state)->v3 ^= (state)->v0; \ - (state)->v2 += (state)->v1; (state)->v1=ROTL((state)->v1,17); (state)->v1 ^= (state)->v2; (state)->v2=ROTL((state)->v2,32); \ - } while(0) - -void siphash_init(struct siphash *state, const uint8_t k[16]) { - u64 k0, k1; - - k0 = U8TO64_LE( k ); - k1 = U8TO64_LE( k + 8 ); - - /* "somepseudorandomlygeneratedbytes" */ - state->v0 = 0x736f6d6570736575ULL ^ k0; - state->v1 = 0x646f72616e646f6dULL ^ k1; - state->v2 = 0x6c7967656e657261ULL ^ k0; - state->v3 = 0x7465646279746573ULL ^ k1; - state->padding = 0; - state->inlen = 0; + assert(state); + assert(k); + + k0 = le64toh(*(le64_t*) k); + k1 = le64toh(*(le64_t*) (k + 8)); + + /* "somepseudorandomlygeneratedbytes" */ + state->v0 = 0x736f6d6570736575ULL ^ k0; + state->v1 = 0x646f72616e646f6dULL ^ k1; + state->v2 = 0x6c7967656e657261ULL ^ k0; + state->v3 = 0x7465646279746573ULL ^ k1; + state->padding = 0; + state->inlen = 0; } void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) { - u64 m; - const u8 *in = _in; - const u8 *end = in + inlen; - int left = state->inlen & 7; + uint64_t m; + const uint8_t *in = _in; + const uint8_t *end = in + inlen; + unsigned left = state->inlen & 7; - /* update total length */ - state->inlen += inlen; + assert(in); + assert(state); - /* if padding exists, fill it out */ - if (left > 0) { - for ( ; in < end && left < 8; in ++, left ++ ) - state->padding |= ( ( u64 )*in ) << (left * 8); + /* update total length */ + state->inlen += inlen; - if (in == end && left < 8) - /* we did not have enough input to fill out the padding completely */ - return; + /* if padding exists, fill it out */ + if (left > 0) { + for ( ; in < end && left < 8; in ++, left ++ ) + state->padding |= ( ( uint64_t )*in ) << (left * 8); + + if (in == end && left < 8) + /* we did not have enough input to fill out the padding completely */ + return; #ifdef DEBUG - printf( "(%3d) v0 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v0 >> 32 ), ( u32 )state->v0 ); - printf( "(%3d) v1 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v1 >> 32 ), ( u32 )state->v1 ); - printf( "(%3d) v2 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v2 >> 32 ), ( u32 )state->v2 ); - printf( "(%3d) v3 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v3 >> 32 ), ( u32 )state->v3 ); - printf( "(%3d) compress padding %08x %08x\n", ( int )state->inlen, ( u32 )( state->padding >> 32 ), ( u32 )state->padding ); + printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0); + printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1); + printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2); + printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3); + printf("(%3zu) compress padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t)state->padding); #endif - state->v3 ^= state->padding; - SIPROUND(state); - SIPROUND(state); - state->v0 ^= state->padding; + state->v3 ^= state->padding; + sipround(state); + sipround(state); + state->v0 ^= state->padding; - state->padding = 0; - } + state->padding = 0; + } - end -= ( state->inlen % sizeof (u64) ); + end -= ( state->inlen % sizeof (uint64_t) ); - for ( ; in < end; in += 8 ) - { - m = U8TO64_LE( in ); + for ( ; in < end; in += 8 ) { + m = le64toh(*(le64_t*) in); #ifdef DEBUG - printf( "(%3d) v0 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v0 >> 32 ), ( u32 )state->v0 ); - printf( "(%3d) v1 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v1 >> 32 ), ( u32 )state->v1 ); - printf( "(%3d) v2 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v2 >> 32 ), ( u32 )state->v2 ); - printf( "(%3d) v3 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v3 >> 32 ), ( u32 )state->v3 ); - printf( "(%3d) compress %08x %08x\n", ( int )state->inlen, ( u32 )( m >> 32 ), ( u32 )m ); + printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0); + printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1); + printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2); + printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3); + printf("(%3zu) compress %08x %08x\n", state->inlen, (uint32_t) (m >> 32), (uint32_t) m); #endif - state->v3 ^= m; - SIPROUND(state); - SIPROUND(state); - state->v0 ^= m; - } + state->v3 ^= m; + sipround(state); + sipround(state); + state->v0 ^= m; + } - left = state->inlen & 7; + left = state->inlen & 7; - switch( left ) - { - case 7: state->padding |= ( ( u64 )in[ 6] ) << 48; + switch(left) + { + case 7: state->padding |= ((uint64_t) in[6]) << 48; - case 6: state->padding |= ( ( u64 )in[ 5] ) << 40; + case 6: state->padding |= ((uint64_t) in[5]) << 40; - case 5: state->padding |= ( ( u64 )in[ 4] ) << 32; + case 5: state->padding |= ((uint64_t) in[4]) << 32; - case 4: state->padding |= ( ( u64 )in[ 3] ) << 24; + case 4: state->padding |= ((uint64_t) in[3]) << 24; - case 3: state->padding |= ( ( u64 )in[ 2] ) << 16; + case 3: state->padding |= ((uint64_t) in[2]) << 16; - case 2: state->padding |= ( ( u64 )in[ 1] ) << 8; + case 2: state->padding |= ((uint64_t) in[1]) << 8; - case 1: state->padding |= ( ( u64 )in[ 0] ); break; + case 1: state->padding |= ((uint64_t) in[0]); break; - case 0: break; - } + case 0: break; + } } -uint64_t siphash24_finalize(struct siphash *state) { - u64 b; +void siphash24_finalize(uint8_t out[8], struct siphash *state) { + uint64_t b; - b = state->padding | (( ( u64 )state->inlen ) << 56); + b = state->padding | (( ( uint64_t )state->inlen ) << 56); #ifdef DEBUG - printf( "(%3d) v0 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v0 >> 32 ), ( u32 )state->v0 ); - printf( "(%3d) v1 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v1 >> 32 ), ( u32 )state->v1 ); - printf( "(%3d) v2 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v2 >> 32 ), ( u32 )state->v2 ); - printf( "(%3d) v3 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v3 >> 32 ), ( u32 )state->v3 ); - printf( "(%3d) padding %08x %08x\n", ( int )state->inlen, ( u32 )( state->padding >> 32 ), ( u32 )state->padding ); + printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t)state->v0); + printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t)state->v1); + printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t)state->v2); + printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t)state->v3); + printf("(%3zu) padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t) state->padding); #endif - state->v3 ^= b; - SIPROUND(state); - SIPROUND(state); - state->v0 ^= b; + state->v3 ^= b; + sipround(state); + sipround(state); + state->v0 ^= b; #ifdef DEBUG - printf( "(%3d) v0 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v0 >> 32 ), ( u32 )state->v0 ); - printf( "(%3d) v1 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v1 >> 32 ), ( u32 )state->v1 ); - printf( "(%3d) v2 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v2 >> 32 ), ( u32 )state->v2 ); - printf( "(%3d) v3 %08x %08x\n", ( int )state->inlen, ( u32 )( state->v3 >> 32 ), ( u32 )state->v3 ); + printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0); + printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1); + printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2); + printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3); #endif - state->v2 ^= 0xff; - SIPROUND(state); - SIPROUND(state); - SIPROUND(state); - SIPROUND(state); + state->v2 ^= 0xff; + + sipround(state); + sipround(state); + sipround(state); + sipround(state); - return state->v0 ^ state->v1 ^ state->v2 ^ state->v3; + *(le64_t*)out = htole64(state->v0 ^ state->v1 ^ state->v2 ^ state->v3); } /* SipHash-2-4 */ -void siphash24(uint8_t out[8], const void *_in, size_t inlen, const uint8_t k[16]) -{ - struct siphash state; - u64 b; - - siphash_init(&state, k); - - siphash24_compress(_in, inlen, &state); - - b = siphash24_finalize(&state); +void siphash24(uint8_t out[8], const void *_in, size_t inlen, const uint8_t k[16]) { + struct siphash state; - U64TO8_LE( out, b ); + siphash24_init(&state, k); + siphash24_compress(_in, inlen, &state); + siphash24_finalize(out, &state); } diff --git a/src/basic/siphash24.h b/src/basic/siphash24.h index c107bdd213..6c5cd98ee8 100644 --- a/src/basic/siphash24.h +++ b/src/basic/siphash24.h @@ -12,8 +12,8 @@ struct siphash { size_t inlen; }; -void siphash_init(struct siphash *state, const uint8_t k[16]); +void siphash24_init(struct siphash *state, const uint8_t k[16]); void siphash24_compress(const void *in, size_t inlen, struct siphash *state); -uint64_t siphash24_finalize(struct siphash *state); +void siphash24_finalize(uint8_t out[8], struct siphash *state); void siphash24(uint8_t out[8], const void *in, size_t inlen, const uint8_t k[16]); diff --git a/src/basic/strv.c b/src/basic/strv.c index 90f0b8c741..d5169467da 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -784,5 +784,5 @@ rollback: free(nl[j]); nl[k] = NULL; - return NULL; + return -ENOMEM; } diff --git a/src/basic/util.c b/src/basic/util.c index 630c7ea9ff..2855993afe 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -6849,12 +6849,14 @@ int version(void) { bool fdname_is_valid(const char *s) { const char *p; - /* Validates a name for $LISTEN_NAMES. We basically allow + /* Validates a name for $LISTEN_FDNAMES. We basically allow * everything ASCII that's not a control character. Also, as * special exception the ":" character is not allowed, as we - * use that as field separator in $LISTEN_NAMES. + * use that as field separator in $LISTEN_FDNAMES. * - * Note that the empty string is explicitly allowed here.*/ + * Note that the empty string is explicitly allowed + * here. However, we limit the length of the names to 255 + * characters. */ if (!s) return false; diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c index 7e06117b31..8afd493b50 100644 --- a/src/journal/journald-rate-limit.c +++ b/src/journal/journald-rate-limit.c @@ -57,7 +57,7 @@ struct JournalRateLimitGroup { char *id; JournalRateLimitPool pools[POOLS_MAX]; - unsigned long hash; + uint64_t hash; LIST_FIELDS(JournalRateLimitGroup, bucket); LIST_FIELDS(JournalRateLimitGroup, lru); @@ -158,9 +158,9 @@ static JournalRateLimitGroup* journal_rate_limit_group_new(JournalRateLimit *r, if (!g->id) goto fail; - siphash_init(&state, r->hash_key); + siphash24_init(&state, r->hash_key); string_hash_func(g->id, &state); - g->hash = siphash24_finalize(&state); + siphash24_finalize((uint8_t*)&g->hash, &state); journal_rate_limit_vacuum(r, ts); @@ -207,7 +207,7 @@ static unsigned burst_modulate(unsigned burst, uint64_t available) { } int journal_rate_limit_test(JournalRateLimit *r, const char *id, int priority, uint64_t available) { - unsigned long h; + uint64_t h; JournalRateLimitGroup *g; JournalRateLimitPool *p; struct siphash state; @@ -226,9 +226,9 @@ int journal_rate_limit_test(JournalRateLimit *r, const char *id, int priority, u ts = now(CLOCK_MONOTONIC); - siphash_init(&state, r->hash_key); + siphash24_init(&state, r->hash_key); string_hash_func(id, &state); - h = siphash24_finalize(&state); + siphash24_finalize((uint8_t*)&h, &state); g = r->buckets[h % BUCKETS_MAX]; LIST_FOREACH(bucket, g, g) diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index d941e6c0de..d27bb561ca 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -741,15 +741,17 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, address = existing_lease->address; else { struct siphash state; + uint64_t hash; uint32_t next_offer; /* even with no persistence of leases, we try to offer the same client the same IP address. we do this by using the hash of the client id as the offset into the pool of leases when finding the next free one */ - siphash_init(&state, HASH_KEY.bytes); + siphash24_init(&state, HASH_KEY.bytes); client_id_hash_func(&req->client_id, &state); - next_offer = siphash24_finalize(&state) % server->pool_size; + siphash24_finalize((uint8_t*)&hash, &state); + next_offer = hash % server->pool_size; for (i = 0; i < server->pool_size; i++) { if (!server->bound_leases[next_offer]) { diff --git a/src/libsystemd-network/test-dhcp-server.c b/src/libsystemd-network/test-dhcp-server.c index 01205efc18..c3bcb9cb4b 100644 --- a/src/libsystemd-network/test-dhcp-server.c +++ b/src/libsystemd-network/test-dhcp-server.c @@ -200,10 +200,13 @@ static void test_message_handler(void) { static uint64_t client_id_hash_helper(DHCPClientId *id, uint8_t key[HASH_KEY_SIZE]) { struct siphash state; + uint64_t hash; - siphash_init(&state, key); + siphash24_init(&state, key); client_id_hash_func(id, &state); - return siphash24_finalize(&state); + siphash24_finalize((uint8_t*)&hash, &state); + + return hash; } static void test_client_id_hash(void) { diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index 78f9c19f5b..c691f577c6 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -710,7 +710,7 @@ static void test_hashmap_many(void) { unsigned n_entries; } tests[] = { { .ops = NULL, .n_entries = 1 << 20 }, - { .ops = &crippled_hashmap_ops, .n_entries = 1 << 11 }, + { .ops = &crippled_hashmap_ops, .n_entries = 1 << 14 }, }; diff --git a/src/test/test-siphash24.c b/src/test/test-siphash24.c index 65eb2b6f35..2402da6a6f 100644 --- a/src/test/test-siphash24.c +++ b/src/test/test-siphash24.c @@ -32,23 +32,13 @@ int main(int argc, char *argv[]) { const uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; uint64_t out = 0; - unsigned i, j, k; - usec_t ts; + unsigned i, j; siphash24((uint8_t *)&out, in, sizeof(in), key); - assert_se(out == 0xa129ca6149be45e5); - - assert_se(out == 0xa129ca6149be45e5ULL); - - ts = now(CLOCK_MONOTONIC); - for (k = 0; k < ITERATIONS; k++) - siphash24((uint8_t *)&out, in, sizeof(in), key); - ts = now(CLOCK_MONOTONIC) - ts; - - log_info("%llu iterations per second", (ITERATIONS * USEC_PER_SEC) / ts); + assert_se(out == htole64(0xa129ca6149be45e5)); /* verify the internal state as given in the above paper */ - siphash_init(&state, key); + siphash24_init(&state, key); assert_se(state.v0 == 0x7469686173716475); assert_se(state.v1 == 0x6b617f6d656e6665); assert_se(state.v2 == 0x6b7f62616d677361); @@ -58,7 +48,8 @@ int main(int argc, char *argv[]) { assert_se(state.v1 == 0x0d52f6f62a4f59a4); assert_se(state.v2 == 0x634cb3577b01fd3d); assert_se(state.v3 == 0xa5224d6f55c7d9c8); - assert_se(siphash24_finalize(&state) == 0xa129ca6149be45e5); + siphash24_finalize((uint8_t*)&out, &state); + assert_se(out == htole64(0xa129ca6149be45e5)); assert_se(state.v0 == 0xf6bcd53893fecff1); assert_se(state.v1 == 0x54b9964c7ea0d937); assert_se(state.v2 == 0x1b38329c099bb55a); @@ -68,11 +59,12 @@ int main(int argc, char *argv[]) { same result */ for (i = 0; i < sizeof(in); i++) { for (j = i; j < sizeof(in); j++) { - siphash_init(&state, key); + siphash24_init(&state, key); siphash24_compress(in, i, &state); siphash24_compress(&in[i], j - i, &state); siphash24_compress(&in[j], sizeof(in) - j, &state); - assert_se(siphash24_finalize(&state) == 0xa129ca6149be45e5); + siphash24_finalize((uint8_t*)&out, &state); + assert_se(out == htole64(0xa129ca6149be45e5)); } } } |