diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-20 06:02:29 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-20 06:08:07 +0200 |
commit | d9dc87d8409ddf8361b7fcb311ae97088ed1d984 (patch) | |
tree | c63be2cf2a7d978dd5b30b3a404d9442acefdff7 | |
parent | 3fd947a2d13a3f110f7c558b1d294dddfd2d25e0 (diff) | |
download | fastd-d9dc87d8409ddf8361b7fcb311ae97088ed1d984.tar fastd-d9dc87d8409ddf8361b7fcb311ae97088ed1d984.zip |
Fix lots of -Wextra warnings
Everything clang and GCC warn about, except GCC's missing-field-initializers
which are just stupid as they don't allow {} syntax to zero a field.
-rw-r--r-- | src/capabilities.c | 4 | ||||
-rw-r--r-- | src/config.c | 12 | ||||
-rw-r--r-- | src/config.y | 2 | ||||
-rw-r--r-- | src/crypto.c | 28 | ||||
-rw-r--r-- | src/crypto_linux.c | 12 | ||||
-rw-r--r-- | src/fastd.c | 16 | ||||
-rw-r--r-- | src/fastd.h | 4 | ||||
-rw-r--r-- | src/lex.c | 4 | ||||
-rw-r--r-- | src/method_aes128_gcm.c | 14 | ||||
-rw-r--r-- | src/method_null.c | 14 | ||||
-rw-r--r-- | src/method_xsalsa20_poly1305.c | 14 | ||||
-rw-r--r-- | src/options.c | 48 | ||||
-rw-r--r-- | src/peer.c | 16 | ||||
-rw-r--r-- | src/printf.c | 11 | ||||
-rw-r--r-- | src/protocol_ec25519_fhmqvc.c | 10 | ||||
-rw-r--r-- | src/queue.c | 4 | ||||
-rw-r--r-- | src/receive.c | 8 | ||||
-rw-r--r-- | src/resolve.c | 2 | ||||
-rw-r--r-- | src/types.h | 3 |
19 files changed, 119 insertions, 107 deletions
diff --git a/src/capabilities.c b/src/capabilities.c index f2410c1..dd2efc7 100644 --- a/src/capabilities.c +++ b/src/capabilities.c @@ -96,10 +96,10 @@ void fastd_cap_drop(fastd_context_t *ctx) { #else /* WITH_CAPABILITIES */ -void fastd_cap_init(fastd_context_t *ctx) { +void fastd_cap_init(fastd_context_t *ctx UNUSED) { } -void fastd_cap_drop(fastd_context_t *ctx) { +void fastd_cap_drop(fastd_context_t *ctx UNUSED) { } #endif /* WITH_CAPABILITIES */ diff --git a/src/config.c b/src/config.c index 3c58cd0..ed1c332 100644 --- a/src/config.c +++ b/src/config.c @@ -124,7 +124,7 @@ static void default_config(fastd_config_t *conf) { conf->peer_group->max_connections = -1; } -bool fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *name) { +bool fastd_config_protocol(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *name) { if (!strcmp(name, "ec25519-fhmqvc")) conf->protocol = &fastd_protocol_ec25519_fhmqvc; else @@ -170,7 +170,7 @@ bool fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char exit_bug(ctx, "MAX_METHODS too low"); } -bool fastd_config_crypto(fastd_context_t *ctx, fastd_config_t *conf, const char *alg, const char *impl) { +bool fastd_config_crypto(fastd_context_t *ctx UNUSED, fastd_config_t *conf UNUSED, const char *alg UNUSED, const char *impl UNUSED) { #ifdef USE_CRYPTO_AES128CTR if (!strcasecmp(alg, "aes128-ctr") || !strcasecmp(alg, "aes128") || !strcasecmp(alg, "aes-ctr") || !strcasecmp(alg, "aes")) { if (!strcasecmp(impl, "default")) @@ -212,7 +212,7 @@ bool fastd_config_crypto(fastd_context_t *ctx, fastd_config_t *conf, const char return false; } -bool fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6) { +bool fastd_config_bind_address(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6) { #ifndef USE_BINDTODEVICE if (bindtodev) return false; @@ -237,7 +237,7 @@ bool fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const return true; } -void fastd_config_peer_group_push(fastd_context_t *ctx, fastd_config_t *conf, const char *name) { +void fastd_config_peer_group_push(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *name) { fastd_peer_group_config_t *group = calloc(1, sizeof(fastd_peer_group_config_t)); group->name = strdup(name); group->max_connections = -1; @@ -250,7 +250,7 @@ void fastd_config_peer_group_push(fastd_context_t *ctx, fastd_config_t *conf, co conf->peer_group = group; } -void fastd_config_peer_group_pop(fastd_context_t *ctx, fastd_config_t *conf) { +void fastd_config_peer_group_pop(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->peer_group = conf->peer_group->parent; } @@ -688,7 +688,7 @@ static void peer_dirs_handle_old_peers(fastd_context_t *ctx, fastd_peer_config_t } } -static void peer_dirs_handle_new_peers(fastd_context_t *ctx, fastd_peer_config_t **peers, fastd_peer_config_t *new_peers) { +static void peer_dirs_handle_new_peers(fastd_context_t *ctx UNUSED, fastd_peer_config_t **peers, fastd_peer_config_t *new_peers) { fastd_peer_config_t *peer; for (peer = new_peers; peer; peer = peer->next) { if (peer->next) diff --git a/src/config.y b/src/config.y index 989b174..774d0db 100644 --- a/src/config.y +++ b/src/config.y @@ -576,6 +576,6 @@ port: colon_or_port TOK_UINT { ; %% -void fastd_config_error(YYLTYPE *loc, fastd_context_t *ctx, fastd_config_t *conf, const char *filename, int depth, const char *s) { +void fastd_config_error(YYLTYPE *loc, fastd_context_t *ctx, fastd_config_t *conf UNUSED, const char *filename, int depth UNUSED, const char *s) { pr_error(ctx, "config error: %s at %s:%i:%i", s, filename, loc->first_line, loc->first_column); } diff --git a/src/crypto.c b/src/crypto.c index 05e7bcd..802c5da 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -39,11 +39,11 @@ struct fastd_crypto_aes128ctr_state { }; -static fastd_crypto_aes128ctr_context_t* aes128ctr_init(fastd_context_t *ctx) { +static fastd_crypto_aes128ctr_context_t* aes128ctr_init(fastd_context_t *ctx UNUSED) { return (fastd_crypto_aes128ctr_context_t*)1; } -static fastd_crypto_aes128ctr_state_t* aes128ctr_set_key(fastd_context_t *ctx, const fastd_crypto_aes128ctr_context_t *cctx, const fastd_block128_t *key) { +static fastd_crypto_aes128ctr_state_t* aes128ctr_set_key(fastd_context_t *ctx, const fastd_crypto_aes128ctr_context_t *cctx UNUSED, const fastd_block128_t *key) { fastd_crypto_aes128ctr_state_t *cstate = malloc(sizeof(fastd_crypto_aes128ctr_state_t)); cstate->d = fastd_buffer_alloc(ctx, crypto_stream_aes128ctr_BEFORENMBYTES, 0, 0); @@ -52,22 +52,22 @@ static fastd_crypto_aes128ctr_state_t* aes128ctr_set_key(fastd_context_t *ctx, c return cstate; } -static bool aes128ctr_crypt(fastd_context_t *ctx, const fastd_crypto_aes128ctr_state_t *cstate, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const fastd_block128_t *iv) { +static bool aes128ctr_crypt(fastd_context_t *ctx UNUSED, const fastd_crypto_aes128ctr_state_t *cstate, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const fastd_block128_t *iv) { crypto_stream_aes128ctr_xor_afternm(out->b, in->b, len, iv->b, cstate->d.data); return true; } -static void aes128ctr_free_state(fastd_context_t *ctx, fastd_crypto_aes128ctr_state_t *cstate) { +static void aes128ctr_free_state(fastd_context_t *ctx UNUSED, fastd_crypto_aes128ctr_state_t *cstate) { if (cstate) { fastd_buffer_free(cstate->d); free(cstate); } } -static void aes128ctr_free(fastd_context_t *ctx, fastd_crypto_aes128ctr_context_t *cctx) { +static void aes128ctr_free(fastd_context_t *ctx UNUSED, fastd_crypto_aes128ctr_context_t *cctx UNUSED) { } -fastd_crypto_aes128ctr_t fastd_crypto_aes128ctr_nacl = { +const fastd_crypto_aes128ctr_t fastd_crypto_aes128ctr_nacl = { .name = "nacl", .init = aes128ctr_init, @@ -93,7 +93,7 @@ static const fastd_block128_t r = { .b = {0xe1} }; static inline uint8_t shr(fastd_block128_t *out, const fastd_block128_t *in, int n) { - int i; + size_t i; uint8_t c = 0; for (i = 0; i < sizeof(fastd_block128_t); i++) { @@ -118,11 +118,11 @@ static inline void mulH_a(fastd_block128_t *x, const fastd_crypto_ghash_state_t } -static fastd_crypto_ghash_context_t* ghash_init(fastd_context_t *ctx) { +static fastd_crypto_ghash_context_t* ghash_init(fastd_context_t *ctx UNUSED) { return (fastd_crypto_ghash_context_t*)1; } -static fastd_crypto_ghash_state_t* ghash_set_h(fastd_context_t *ctx, const fastd_crypto_ghash_context_t *cctx, const fastd_block128_t *h) { +static fastd_crypto_ghash_state_t* ghash_set_h(fastd_context_t *ctx UNUSED, const fastd_crypto_ghash_context_t *cctx UNUSED, const fastd_block128_t *h) { fastd_crypto_ghash_state_t *cstate = malloc(sizeof(fastd_crypto_ghash_state_t)); fastd_block128_t Hbase[4]; @@ -166,10 +166,10 @@ static fastd_crypto_ghash_state_t* ghash_set_h(fastd_context_t *ctx, const fastd return cstate; } -static bool ghash_hash(fastd_context_t *ctx, const fastd_crypto_ghash_state_t *cstate, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks) { +static bool ghash_hash(fastd_context_t *ctx UNUSED, const fastd_crypto_ghash_state_t *cstate, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks) { memset(out, 0, sizeof(fastd_block128_t)); - int i; + size_t i; for (i = 0; i < n_blocks; i++) { xor_a(out, &in[i]); mulH_a(out, cstate); @@ -178,14 +178,14 @@ static bool ghash_hash(fastd_context_t *ctx, const fastd_crypto_ghash_state_t *c return true; } -static void ghash_free_state(fastd_context_t *ctx, fastd_crypto_ghash_state_t *cstate) { +static void ghash_free_state(fastd_context_t *ctx UNUSED, fastd_crypto_ghash_state_t *cstate) { free(cstate); } -static void ghash_free(fastd_context_t *ctx, fastd_crypto_ghash_context_t *cctx) { +static void ghash_free(fastd_context_t *ctx UNUSED, fastd_crypto_ghash_context_t *cctx UNUSED) { } -fastd_crypto_ghash_t fastd_crypto_ghash_builtin = { +const fastd_crypto_ghash_t fastd_crypto_ghash_builtin = { .name = "builtin", .init = ghash_init, diff --git a/src/crypto_linux.c b/src/crypto_linux.c index 477547e..2cd7145 100644 --- a/src/crypto_linux.c +++ b/src/crypto_linux.c @@ -134,21 +134,21 @@ static bool aes128ctr_crypt(fastd_context_t *ctx, const fastd_crypto_aes128ctr_s return true; } -static void aes128ctr_free_state(fastd_context_t *ctx, fastd_crypto_aes128ctr_state_t *cstate) { +static void aes128ctr_free_state(fastd_context_t *ctx UNUSED, fastd_crypto_aes128ctr_state_t *cstate) { if (cstate) { close(cstate->fd); free(cstate); } } -static void aes128ctr_free(fastd_context_t *ctx, fastd_crypto_aes128ctr_context_t *cctx) { +static void aes128ctr_free(fastd_context_t *ctx UNUSED, fastd_crypto_aes128ctr_context_t *cctx) { if (cctx) { close(cctx->fd); free(cctx); } } -fastd_crypto_aes128ctr_t fastd_crypto_aes128ctr_linux = { +const fastd_crypto_aes128ctr_t fastd_crypto_aes128ctr_linux = { .name = "linux", .init = aes128ctr_init, @@ -233,21 +233,21 @@ static bool ghash_hash(fastd_context_t *ctx, const fastd_crypto_ghash_state_t *c return true; } -static void ghash_free_state(fastd_context_t *ctx, fastd_crypto_ghash_state_t *cstate) { +static void ghash_free_state(fastd_context_t *ctx UNUSED, fastd_crypto_ghash_state_t *cstate) { if (cstate) { close(cstate->fd); free(cstate); } } -static void ghash_free(fastd_context_t *ctx, fastd_crypto_ghash_context_t *cctx) { +static void ghash_free(fastd_context_t *ctx UNUSED, fastd_crypto_ghash_context_t *cctx) { if (cctx) { close(cctx->fd); free(cctx); } } -fastd_crypto_ghash_t fastd_crypto_ghash_linux = { +const fastd_crypto_ghash_t fastd_crypto_ghash_linux = { .name = "linux", .init = ghash_init, diff --git a/src/fastd.c b/src/fastd.c index f8a5a75..0da1c08 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -44,15 +44,15 @@ static volatile bool terminate = false; static volatile bool dump = false; -static void on_sighup(int signo) { +static void on_sighup(int signo UNUSED) { sighup = true; } -static void on_terminate(int signo) { +static void on_terminate(int signo UNUSED) { terminate = true; } -static void on_sigusr1(int signo) { +static void on_sigusr1(int signo UNUSED) { dump = true; } @@ -140,7 +140,7 @@ static void close_log(fastd_context_t *ctx) { closelog(); } -static void crypto_init(fastd_context_t *ctx) { +static void crypto_init(fastd_context_t *ctx UNUSED) { #ifdef USE_CRYPTO_AES128CTR ctx->crypto_aes128ctr = ctx->conf->crypto_aes128ctr->init(ctx); if (!ctx->crypto_aes128ctr) @@ -154,7 +154,7 @@ static void crypto_init(fastd_context_t *ctx) { #endif } -static void crypto_free(fastd_context_t *ctx) { +static void crypto_free(fastd_context_t *ctx UNUSED) { #ifdef USE_CRYPTO_AES128CTR ctx->conf->crypto_aes128ctr->free(ctx, ctx->crypto_aes128ctr); ctx->crypto_aes128ctr = NULL; @@ -173,7 +173,7 @@ static void init_sockets(fastd_context_t *ctx) { unsigned i; fastd_bind_address_t *addr = ctx->conf->bind_addrs; for (i = 0; i < ctx->conf->n_bind_addrs; i++) { - ctx->socks[i] = (fastd_socket_t){-2, addr, NULL}; + ctx->socks[i] = (fastd_socket_t){ .fd = -2, .addr = addr }; if (addr == ctx->conf->bind_addr_default_v4) ctx->sock_default_v4 = &ctx->socks[i]; @@ -413,7 +413,7 @@ static void send_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { return; } - if (timespec_diff(&ctx->now, &peer->last_handshake) < ctx->conf->min_handshake_interval*1000 + if (timespec_diff(&ctx->now, &peer->last_handshake) < (int)ctx->conf->min_handshake_interval*1000 && fastd_peer_address_equal(&peer->address, &peer->last_handshake_address)) { pr_debug(ctx, "not sending a handshake to %P as we sent one a short time ago", peer); return; @@ -607,7 +607,7 @@ static void cleanup_peers(fastd_context_t *ctx) { next = peer->next; if (fastd_peer_is_temporary(peer) || fastd_peer_is_established(peer)) { - if (timespec_diff(&ctx->now, &peer->seen) > ctx->conf->peer_stale_time*1000) { + if (timespec_diff(&ctx->now, &peer->seen) > (int)ctx->conf->peer_stale_time*1000) { if (fastd_peer_is_temporary(peer)) { fastd_peer_delete(ctx, peer); } diff --git a/src/fastd.h b/src/fastd.h index 014bb2f..723b1e7 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -493,4 +493,8 @@ static inline size_t max_size_t(size_t a, size_t b) { return (a > b) ? a : b; } +static inline size_t min_size_t(size_t a, size_t b) { + return (a < b) ? a : b; +} + #endif /* _FASTD_FASTD_H_ */ @@ -169,7 +169,7 @@ static void consume(fastd_lex_t *lex, bool needspace) { lex->needspace = needspace; } -static int io_error(YYSTYPE *yylval, fastd_lex_t *lex) { +static int io_error(YYSTYPE *yylval, fastd_lex_t *lex UNUSED) { yylval->error = "I/O error"; return -1; } @@ -354,7 +354,7 @@ static int parse_keyword(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { } char *token = get_token(lex); - const keyword_t key = {token}; + const keyword_t key = { .keyword = token }; const keyword_t *ret = bsearch(&key, keywords, sizeof(keywords)/sizeof(keyword_t), sizeof(keyword_t), compare_keywords); free(token); diff --git a/src/method_aes128_gcm.c b/src/method_aes128_gcm.c index c6dafb4..f392e2e 100644 --- a/src/method_aes128_gcm.c +++ b/src/method_aes128_gcm.c @@ -80,19 +80,19 @@ static size_t method_max_packet_size(fastd_context_t *ctx) { } -static size_t method_min_encrypt_head_space(fastd_context_t *ctx) { +static size_t method_min_encrypt_head_space(fastd_context_t *ctx UNUSED) { return sizeof(fastd_block128_t); } -static size_t method_min_decrypt_head_space(fastd_context_t *ctx) { +static size_t method_min_decrypt_head_space(fastd_context_t *ctx UNUSED) { return 0; } -static size_t method_min_encrypt_tail_space(fastd_context_t *ctx) { +static size_t method_min_encrypt_tail_space(fastd_context_t *ctx UNUSED) { return (sizeof(fastd_block128_t)-1); } -static size_t method_min_decrypt_tail_space(fastd_context_t *ctx) { +static size_t method_min_decrypt_tail_space(fastd_context_t *ctx UNUSED) { return (2*sizeof(fastd_block128_t)-1); } @@ -137,7 +137,7 @@ static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_s return (session && timespec_after(&session->valid_till, &ctx->now)); } -static bool method_session_is_initiator(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { return (session->send_nonce[0] & 1); } @@ -164,7 +164,7 @@ static inline void put_size(fastd_block128_t *out, size_t len) { out->b[sizeof(fastd_block128_t)-1] = len << 3; } -static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) { +static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) { fastd_buffer_pull_head(ctx, &in, sizeof(fastd_block128_t)); memset(in.data, 0, sizeof(fastd_block128_t)); @@ -231,7 +231,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho return false; if (age >= 0) { - if (timespec_diff(&ctx->now, &session->receive_last) > ctx->conf->reorder_time*1000) + if (timespec_diff(&ctx->now, &session->receive_last) > (int)ctx->conf->reorder_time*1000) return false; if (age > ctx->conf->reorder_count) diff --git a/src/method_null.c b/src/method_null.c index a54c443..640c341 100644 --- a/src/method_null.c +++ b/src/method_null.c @@ -31,33 +31,33 @@ static size_t method_max_packet_size(fastd_context_t *ctx) { return fastd_max_packet_size(ctx); } -static size_t method_min_head_tail_space(fastd_context_t *ctx) { +static size_t method_min_head_tail_space(fastd_context_t *ctx UNUSED) { return 0; } -static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, uint8_t *secret, size_t length, bool initiator) { +static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx UNUSED, uint8_t *secret UNUSED, size_t length UNUSED, bool initiator) { if (initiator) return (fastd_method_session_state_t*)1; else return (fastd_method_session_state_t*)2; } -static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static bool method_session_is_valid(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { return session; } -static bool method_session_is_initiator(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { return (session == (fastd_method_session_state_t*)1); } -static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static bool method_session_want_refresh(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session UNUSED) { return false; } -static void method_session_free(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session UNUSED) { } -static bool method_passthrough(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) { +static bool method_passthrough(fastd_context_t *ctx UNUSED, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session UNUSED, fastd_buffer_t *out, fastd_buffer_t in) { *out = in; return true; } diff --git a/src/method_xsalsa20_poly1305.c b/src/method_xsalsa20_poly1305.c index 2de5c2b..1e26247 100644 --- a/src/method_xsalsa20_poly1305.c +++ b/src/method_xsalsa20_poly1305.c @@ -78,15 +78,15 @@ static size_t method_max_packet_size(fastd_context_t *ctx) { return (fastd_max_packet_size(ctx) + NONCEBYTES + crypto_secretbox_xsalsa20poly1305_ZEROBYTES - crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES); } -static size_t method_min_encrypt_head_space(fastd_context_t *ctx) { +static size_t method_min_encrypt_head_space(fastd_context_t *ctx UNUSED) { return crypto_secretbox_xsalsa20poly1305_ZEROBYTES; } -static size_t method_min_decrypt_head_space(fastd_context_t *ctx) { +static size_t method_min_decrypt_head_space(fastd_context_t *ctx UNUSED) { return (crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES - NONCEBYTES); } -static size_t method_min_tail_space(fastd_context_t *ctx) { +static size_t method_min_tail_space(fastd_context_t *ctx UNUSED) { return 0; } @@ -121,7 +121,7 @@ static bool method_session_is_valid(fastd_context_t *ctx, fastd_method_session_s return (session && timespec_after(&session->valid_till, &ctx->now)); } -static bool method_session_is_initiator(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static bool method_session_is_initiator(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { return (session->send_nonce[0] & 1); } @@ -129,14 +129,14 @@ static bool method_session_want_refresh(fastd_context_t *ctx, fastd_method_sessi return timespec_after(&ctx->now, &session->refresh_after); } -static void method_session_free(fastd_context_t *ctx, fastd_method_session_state_t *session) { +static void method_session_free(fastd_context_t *ctx UNUSED, fastd_method_session_state_t *session) { if(session) { memset(session, 0, sizeof(fastd_method_session_state_t)); free(session); } } -static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) { +static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) { fastd_buffer_pull_head(ctx, &in, crypto_secretbox_xsalsa20poly1305_ZEROBYTES); memset(in.data, 0, crypto_secretbox_xsalsa20poly1305_ZEROBYTES); @@ -174,7 +174,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho return false; if (age >= 0) { - if (timespec_diff(&ctx->now, &session->receive_last) > ctx->conf->reorder_time*1000) + if (timespec_diff(&ctx->now, &session->receive_last) > (int)ctx->conf->reorder_time*1000) return false; if (age > ctx->conf->reorder_count) diff --git a/src/options.c b/src/options.c index 3cd3017..b5c1e2d 100644 --- a/src/options.c +++ b/src/options.c @@ -46,7 +46,7 @@ static void print_usage(const char *options, const char *message) { puts(message); } -static void usage(fastd_context_t *ctx, fastd_config_t *conf) { +static void usage(fastd_context_t *ctx UNUSED, fastd_config_t *conf UNUSED) { puts("fastd (Fast and Secure Tunnelling Daemon) " FASTD_VERSION " usage:\n"); #define OR ", " @@ -62,16 +62,16 @@ static void usage(fastd_context_t *ctx, fastd_config_t *conf) { exit(0); } -static void version(fastd_context_t *ctx, fastd_config_t *conf) { +static void version(fastd_context_t *ctx UNUSED, fastd_config_t *conf UNUSED) { puts("fastd " FASTD_VERSION); exit(0); } -static void option_daemon(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_daemon(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->daemon = true; } -static void option_pid_file(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_pid_file(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->pid_file); conf->pid_file = strdup(arg); } @@ -99,12 +99,12 @@ static void option_config_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, c #ifdef WITH_CMDLINE_USER -static void option_user(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_user(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->user); conf->user = strdup(arg); } -static void option_group(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_group(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->group); conf->group = strdup(arg); } @@ -138,16 +138,16 @@ static void option_syslog_level(fastd_context_t *ctx, fastd_config_t *conf, cons conf->log_syslog_level = parse_log_level(ctx, arg); } -static void option_syslog_ident(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_syslog_ident(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->log_syslog_ident); conf->log_syslog_ident = strdup(arg); } -static void option_hide_ip_addresses(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_hide_ip_addresses(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->hide_ip_addresses = true; } -static void option_hide_mac_addresses(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_hide_mac_addresses(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->hide_mac_addresses = true; } @@ -164,17 +164,19 @@ static void option_mode(fastd_context_t *ctx, fastd_config_t *conf, const char * exit_error(ctx, "invalid mode `%s'", arg); } -static void option_interface(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_interface(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->ifname); conf->ifname = strdup(arg); } static void option_mtu(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { char *endptr; + long mtu = strtol(arg, &endptr, 10); - conf->mtu = strtol(arg, &endptr, 10); - if (*endptr || conf->mtu < 576 || conf->mtu > 65535) + if (*endptr || mtu < 576 || mtu > 65535) exit_error(ctx, "invalid mtu `%s'", arg); + + conf->mtu = mtu; } static void option_bind(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { @@ -249,7 +251,7 @@ static void option_method(fastd_context_t *ctx, fastd_config_t *conf, const char exit_error(ctx, "invalid method `%s'", arg); } -static void option_forward(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_forward(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->forward = true; } @@ -257,7 +259,7 @@ static void option_forward(fastd_context_t *ctx, fastd_config_t *conf) { #ifdef WITH_CMDLINE_COMMANDS -static void option_on_pre_up(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_pre_up(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_pre_up); free(conf->on_pre_up_dir); @@ -265,7 +267,7 @@ static void option_on_pre_up(fastd_context_t *ctx, fastd_config_t *conf, const c conf->on_pre_up_dir = get_current_dir_name(); } -static void option_on_up(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_up(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_up); free(conf->on_up_dir); @@ -273,7 +275,7 @@ static void option_on_up(fastd_context_t *ctx, fastd_config_t *conf, const char conf->on_up_dir = get_current_dir_name(); } -static void option_on_down(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_down(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_down); free(conf->on_down_dir); @@ -281,7 +283,7 @@ static void option_on_down(fastd_context_t *ctx, fastd_config_t *conf, const cha conf->on_down_dir = get_current_dir_name(); } -static void option_on_post_down(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_post_down(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_post_down); free(conf->on_post_down_dir); @@ -289,7 +291,7 @@ static void option_on_post_down(fastd_context_t *ctx, fastd_config_t *conf, cons conf->on_post_down_dir = get_current_dir_name(); } -static void option_on_establish(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_establish(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_establish); free(conf->on_establish_dir); @@ -297,7 +299,7 @@ static void option_on_establish(fastd_context_t *ctx, fastd_config_t *conf, cons conf->on_establish_dir = get_current_dir_name(); } -static void option_on_disestablish(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_disestablish(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_disestablish); free(conf->on_disestablish_dir); @@ -305,7 +307,7 @@ static void option_on_disestablish(fastd_context_t *ctx, fastd_config_t *conf, c conf->on_disestablish_dir = get_current_dir_name(); } -static void option_on_verify(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { +static void option_on_verify(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { free(conf->on_verify); free(conf->on_verify_dir); @@ -315,17 +317,17 @@ static void option_on_verify(fastd_context_t *ctx, fastd_config_t *conf, const c #endif -static void option_generate_key(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_generate_key(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->generate_key = true; conf->show_key = false; } -static void option_show_key(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_show_key(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->generate_key = false; conf->show_key = true; } -static void option_machine_readable(fastd_context_t *ctx, fastd_config_t *conf) { +static void option_machine_readable(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { conf->machine_readable = true; } @@ -136,7 +136,7 @@ static void reset_peer(fastd_context_t *ctx, fastd_peer_t *peer) { ctx->conf->protocol->reset_peer_state(ctx, peer); - int i, deleted = 0; + size_t i, deleted = 0; for (i = 0; i < ctx->n_eth_addr; i++) { if (ctx->eth_addr[i].peer == peer) { deleted++; @@ -240,7 +240,7 @@ static void delete_peer(fastd_context_t *ctx, fastd_peer_t *peer) { } -fastd_peer_config_t* fastd_peer_config_new(fastd_context_t *ctx, fastd_config_t *conf) { +fastd_peer_config_t* fastd_peer_config_new(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { fastd_peer_config_t *peer = calloc(1, sizeof(fastd_peer_config_t)); peer->group = conf->peer_group; @@ -266,7 +266,7 @@ void fastd_peer_config_free(fastd_peer_config_t *peer) { free(peer); } -void fastd_peer_config_delete(fastd_context_t *ctx, fastd_config_t *conf) { +void fastd_peer_config_delete(fastd_context_t *ctx UNUSED, fastd_config_t *conf) { fastd_peer_config_t *peer = conf->peers, *next = peer->next; fastd_peer_config_free(peer); conf->peers = next; @@ -332,7 +332,7 @@ static inline void reset_peer_address(fastd_context_t *ctx, fastd_peer_t *peer) memset(&peer->address, 0, sizeof(fastd_peer_address_t)); } -bool fastd_peer_owns_address(fastd_context_t *ctx, const fastd_peer_t *peer, const fastd_peer_address_t *addr) { +bool fastd_peer_owns_address(fastd_context_t *ctx UNUSED, const fastd_peer_t *peer, const fastd_peer_address_t *addr) { if (fastd_peer_is_floating(peer)) return false; @@ -348,7 +348,7 @@ bool fastd_peer_owns_address(fastd_context_t *ctx, const fastd_peer_t *peer, con return false; } -bool fastd_peer_matches_address(fastd_context_t *ctx, const fastd_peer_t *peer, const fastd_peer_address_t *addr) { +bool fastd_peer_matches_address(fastd_context_t *ctx UNUSED, const fastd_peer_t *peer, const fastd_peer_address_t *addr) { if (fastd_peer_is_floating(peer)) return true; @@ -464,7 +464,7 @@ bool fastd_peer_may_connect(fastd_context_t *ctx, fastd_peer_t *peer) { if (group->conf->max_connections < 0) continue; - if (count_established_group_peers(ctx, group) >= group->conf->max_connections) + if (count_established_group_peers(ctx, group) >= (unsigned)group->conf->max_connections) return false; } @@ -653,10 +653,10 @@ void fastd_peer_eth_addr_add(fastd_context_t *ctx, fastd_peer_t *peer, const fas } void fastd_peer_eth_addr_cleanup(fastd_context_t *ctx) { - int i, deleted = 0; + size_t i, deleted = 0; for (i = 0; i < ctx->n_eth_addr; i++) { - if (timespec_diff(&ctx->now, &ctx->eth_addr[i].seen) > ctx->conf->eth_addr_stale_time*1000) { + if (timespec_diff(&ctx->now, &ctx->eth_addr[i].seen) > (int)ctx->conf->eth_addr_stale_time*1000) { deleted++; pr_debug(ctx, "MAC address %E not seen for more than %u seconds, removing", &ctx->eth_addr[i].addr, ctx->conf->eth_addr_stale_time); diff --git a/src/printf.c b/src/printf.c index 99c577b..db111a0 100644 --- a/src/printf.c +++ b/src/printf.c @@ -31,16 +31,19 @@ #include <net/if.h> -static inline int snprintf_safe(char *buffer, size_t size, const char *format, ...) { +static inline size_t snprintf_safe(char *buffer, size_t size, const char *format, ...) { va_list ap; va_start(ap, format); int ret = vsnprintf(buffer, size, format, ap); va_end(ap); - return ret < 0 ? 0 : ret > size ? size : ret; + if (ret < 0) + return 0; + + return min_size_t(ret, size); } -static int snprint_peer_address(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_address_t *address, bool bind_address) { +static size_t snprint_peer_address(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_address_t *address, bool bind_address) { char addr_buf[INET6_ADDRSTRLEN] = ""; switch (address->sa.sa_family) { @@ -78,7 +81,7 @@ static int snprint_peer_address(const fastd_context_t *ctx, char *buffer, size_t } } -static int snprint_peer_str(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_t *peer) { +static size_t snprint_peer_str(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_t *peer) { if (peer->config && peer->config->name) { return snprintf_safe(buffer, size, "<%s>", peer->config->name); } diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c index 3d18b8c..b3bd8a5 100644 --- a/src/protocol_ec25519_fhmqvc.c +++ b/src/protocol_ec25519_fhmqvc.c @@ -340,7 +340,7 @@ static bool update_shared_handshake_key(fastd_context_t *ctx, const fastd_peer_t return true; } -static void clear_shared_handshake_key(fastd_context_t *ctx, const fastd_peer_t *peer) { +static void clear_shared_handshake_key(fastd_context_t *ctx UNUSED, const fastd_peer_t *peer) { memset(&peer->protocol_state->sigma, 0, sizeof(peer->protocol_state->sigma)); memset(&peer->protocol_state->shared_handshake_key, 0, sizeof(peer->protocol_state->shared_handshake_key)); @@ -577,7 +577,7 @@ static inline bool has_field(const fastd_handshake_t *handshake, uint8_t type, s return (handshake->records[type].length == length); } -static inline fastd_peer_t* add_temporary(fastd_context_t *ctx, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, const unsigned char key[32]) { +static inline fastd_peer_t* add_temporary(fastd_context_t *ctx, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, const unsigned char key[32]) { if (!fastd_peer_allow_unknown(ctx)) { pr_debug(ctx, "ignoring handshake from %I (unknown key)", remote_addr); return NULL; @@ -624,7 +624,7 @@ static void protocol_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock return; case ENOENT: - peer = add_temporary(ctx, sock, local_addr, remote_addr, handshake->records[RECORD_SENDER_KEY].data); + peer = add_temporary(ctx, local_addr, remote_addr, handshake->records[RECORD_SENDER_KEY].data); if (peer) { temporary_added = true; break; @@ -670,7 +670,7 @@ static void protocol_handshake_handle(fastd_context_t *ctx, fastd_socket_t *sock memcpy(peer_handshake_key.p, handshake->records[RECORD_SENDER_HANDSHAKE_KEY].data, PUBLICKEYBYTES); if (handshake->type == 1) { - if (timespec_diff(&ctx->now, &peer->last_handshake_response) < ctx->conf->min_handshake_interval*1000 + if (timespec_diff(&ctx->now, &peer->last_handshake_response) < (int)ctx->conf->min_handshake_interval*1000 && fastd_peer_address_equal(remote_addr, &peer->last_handshake_response_address)) { pr_debug(ctx, "not responding repeated handshake from %P[%I]", peer, remote_addr); return; @@ -909,7 +909,7 @@ static void protocol_set_shell_env(fastd_context_t *ctx, const fastd_peer_t *pee } } -static bool protocol_describe_peer(const fastd_context_t *ctx, const fastd_peer_t *peer, char *buf, size_t len) { +static bool protocol_describe_peer(const fastd_context_t *ctx UNUSED, const fastd_peer_t *peer, char *buf, size_t len) { if (peer && peer->protocol_config) { char dumpbuf[65]; diff --git a/src/queue.c b/src/queue.c index 9229545..93dd92d 100644 --- a/src/queue.c +++ b/src/queue.c @@ -74,7 +74,7 @@ int fastd_queue_timeout(fastd_context_t *ctx, fastd_queue_t *queue) { return diff_msec; } -void fastd_queue_filter(fastd_context_t *ctx, fastd_queue_t *queue, bool (*pred)(fastd_queue_entry_t*, void*), void *extra) { +void fastd_queue_filter(fastd_context_t *ctx UNUSED, fastd_queue_t *queue, bool (*pred)(fastd_queue_entry_t*, void*), void *extra) { fastd_queue_entry_t **entry, *next; for (entry = &queue->head; *entry;) { next = (*entry)->next; @@ -86,7 +86,7 @@ void fastd_queue_filter(fastd_context_t *ctx, fastd_queue_t *queue, bool (*pred) } } -bool fastd_queue_has_entry(fastd_context_t *ctx, fastd_queue_t *queue, bool (*pred)(fastd_queue_entry_t*, void*), void *extra) { +bool fastd_queue_has_entry(fastd_context_t *ctx UNUSED, fastd_queue_t *queue, bool (*pred)(fastd_queue_entry_t*, void*), void *extra) { fastd_queue_entry_t *entry; for (entry = queue->head; entry; entry = entry->next) { if (pred(entry, extra)) diff --git a/src/receive.c b/src/receive.c index bf4b93e..d91a5cd 100644 --- a/src/receive.c +++ b/src/receive.c @@ -30,7 +30,7 @@ #include "peer.h" -static inline void handle_socket_control(fastd_context_t *ctx, struct msghdr *message, const fastd_socket_t *sock, fastd_peer_address_t *local_addr) { +static inline void handle_socket_control(struct msghdr *message, const fastd_socket_t *sock, fastd_peer_address_t *local_addr) { memset(local_addr, 0, sizeof(fastd_peer_address_t)); const char *end = (char*)message->msg_control + message->msg_controllen; @@ -96,7 +96,7 @@ static inline void handle_socket_receive_known(fastd_context_t *ctx, fastd_socke } } -static inline bool is_unknown_peer_valid(fastd_context_t *ctx, const fastd_peer_address_t *remote_addr) { +static inline bool allow_unknown_peers(fastd_context_t *ctx) { return ctx->conf->has_floating || ctx->conf->on_verify; } @@ -136,7 +136,7 @@ static inline void handle_socket_receive(fastd_context_t *ctx, fastd_socket_t *s if (peer) { handle_socket_receive_known(ctx, sock, local_addr, remote_addr, peer, buffer); } - else if(is_unknown_peer_valid(ctx, remote_addr)) { + else if (allow_unknown_peers(ctx)) { handle_socket_receive_unknown(ctx, sock, local_addr, remote_addr, buffer); } else { @@ -173,7 +173,7 @@ void fastd_receive(fastd_context_t *ctx, fastd_socket_t *sock) { buffer.len = len; - handle_socket_control(ctx, &message, sock, &local_addr); + handle_socket_control(&message, sock, &local_addr); #ifdef USE_PKTINFO if (!local_addr.sa.sa_family) { diff --git a/src/resolve.c b/src/resolve.c index 541006d..9631c48 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -99,7 +99,7 @@ void fastd_resolve_peer(fastd_context_t *ctx, fastd_peer_t *peer, fastd_remote_t return; } - if (timespec_diff(&ctx->now, &remote->last_resolve) < ctx->conf->min_resolve_interval*1000) { + if (timespec_diff(&ctx->now, &remote->last_resolve) < (int)ctx->conf->min_resolve_interval*1000) { /* last resolve was just a few seconds ago */ return; } diff --git a/src/types.h b/src/types.h index 8eaa55d..bb7663e 100644 --- a/src/types.h +++ b/src/types.h @@ -39,6 +39,9 @@ #include <stdbool.h> +#define UNUSED __attribute__((unused)) + + typedef struct fastd_tristate { bool set : 1; bool state : 1; |