From f34e51a1c3b98df2b7c8c7d7eb415a33f42f2d75 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 25 May 2014 00:20:05 +0200 Subject: Make a few struct fields that are not supposed to be changed defines instead --- src/config.c | 19 ------------------- src/fastd.c | 4 ++-- src/fastd.h | 20 +------------------- src/fastd_config.h.in | 19 +++++++++++++++++++ src/methods/common.c | 6 +++--- src/methods/common.h | 2 +- src/peer.c | 8 ++++---- src/peer.h | 6 +++--- src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c | 2 +- src/protocols/ec25519_fhmqvc/handshake.c | 6 +++--- src/receive.c | 2 +- src/resolve.c | 2 +- 12 files changed, 39 insertions(+), 57 deletions(-) diff --git a/src/config.c b/src/config.c index 82a57ba..265df62 100644 --- a/src/config.c +++ b/src/config.c @@ -54,16 +54,6 @@ static void default_config(void) { conf.log_syslog_ident = strdup("fastd"); - conf.maintenance_interval = 10; - conf.keepalive_timeout = 15; - conf.peer_stale_time = 90; - conf.eth_addr_stale_time = 300; - - conf.reorder_time = 10; - - conf.min_handshake_interval = 15; - conf.min_resolve_interval = 15; - conf.mtu = 1500; conf.mode = MODE_TAP; @@ -71,15 +61,6 @@ static void default_config(void) { conf.drop_caps = DROP_CAPS_ON; conf.protocol = &fastd_protocol_ec25519_fhmqvc; - conf.key_valid = 3600; /* 60 minutes */ - conf.key_valid_old = 60; /* 1 minute */ - conf.key_refresh = 3300; /* 55 minutes */ - conf.key_refresh_splay = 300; /* 5 minutes */ - -#ifdef WITH_VERIFY - conf.min_verify_interval = 10; - conf.verify_valid_time = 60; /* 1 minute */ -#endif conf.peer_group = calloc(1, sizeof(fastd_peer_group_config_t)); conf.peer_group->name = strdup("default"); diff --git a/src/fastd.c b/src/fastd.c index 8dbfc74..a3c6d14 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -307,7 +307,7 @@ static inline void maintenance(void) { fastd_socket_handle_binds(); fastd_peer_maintenance(); - ctx.next_maintenance.tv_sec += conf.maintenance_interval; + ctx.next_maintenance.tv_sec += MAINTENANCE_INTERVAL; } @@ -541,7 +541,7 @@ int main(int argc, char *argv[]) { fastd_update_time(); - ctx.next_maintenance = fastd_in_seconds(conf.maintenance_interval); + ctx.next_maintenance = fastd_in_seconds(MAINTENANCE_INTERVAL); ctx.unknown_handshakes[0].timeout = ctx.now; diff --git a/src/fastd.h b/src/fastd.h index 8726cd0..67174cf 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -159,27 +159,13 @@ struct fastd_handshake_timeout { struct timespec timeout; /**< Timeout until handshakes from this address are ignored */ }; + /** The static configuration of \em fastd */ struct fastd_config { fastd_loglevel_t log_stderr_level; /**< The minimum loglevel of messages to print to stderr (or -1 to not print any messages on stderr) */ fastd_loglevel_t log_syslog_level; /**< The minimum loglevel of messages to print to syslog (or -1 to not print any messages on syslog) */ char *log_syslog_ident; /**< The identification string for messages sent to syslog (default: "fastd") */ - unsigned maintenance_interval; - unsigned keepalive_timeout; - unsigned peer_stale_time; - unsigned eth_addr_stale_time; - - unsigned reorder_time; - - unsigned min_handshake_interval; - unsigned min_resolve_interval; - -#ifdef WITH_VERIFY - unsigned min_verify_interval; - unsigned verify_valid_time; -#endif - char *ifname; size_t n_bind_addrs; @@ -217,10 +203,6 @@ struct fastd_config { size_t min_decrypt_tail_space; char *secret; - unsigned key_valid; - unsigned key_valid_old; - unsigned key_refresh; - unsigned key_refresh_splay; const fastd_cipher_t **ciphers; const fastd_mac_t **macs; diff --git a/src/fastd_config.h.in b/src/fastd_config.h.in index 2aace56..196ed34 100644 --- a/src/fastd_config.h.in +++ b/src/fastd_config.h.in @@ -53,3 +53,22 @@ #cmakedefine ENABLE_SYSTEMD #define MAX_CONFIG_DEPTH @MAX_CONFIG_DEPTH_NUM@ + + +#define MAINTENANCE_INTERVAL 10 +#define KEEPALIVE_TIMEOUT 15 +#define PEER_STALE_TIME 90 +#define ETH_ADDR_STALE_TIME 300 + +#define REORDER_TIME 10 + +#define MIN_VERIFY_INTERVAL 10 +#define VERIFY_VALID_TIME 60 /* 1 minute */ + +#define MIN_HANDSHAKE_INTERVAL 15 +#define MIN_RESOLVE_INTERVAL 15 + +#define KEY_VALID 3600 /* 60 minutes */ +#define KEY_VALID_OLD 60 /* 1 minute */ +#define KEY_REFRESH 3300 /* 55 minutes */ +#define KEY_REFRESH_SPLAY 300 /* 5 minutes */ diff --git a/src/methods/common.c b/src/methods/common.c index 17722cf..3fb8561 100644 --- a/src/methods/common.c +++ b/src/methods/common.c @@ -30,8 +30,8 @@ void fastd_method_common_init(fastd_method_common_t *session, bool initiator) { memset(session, 0, sizeof(*session)); - session->valid_till = fastd_in_seconds(conf.key_valid); - session->refresh_after = fastd_in_seconds(conf.key_refresh - fastd_rand(0, conf.key_refresh_splay)); + session->valid_till = fastd_in_seconds(KEY_VALID); + session->refresh_after = fastd_in_seconds(KEY_REFRESH - fastd_rand(0, KEY_REFRESH_SPLAY)); if (initiator) { session->send_nonce[COMMON_NONCEBYTES-1] = 3; @@ -79,7 +79,7 @@ bool fastd_method_reorder_check(fastd_peer_t *peer, fastd_method_common_t *sessi session->receive_reorder_seen |= (1 << (shift-1)); memcpy(session->receive_nonce, nonce, COMMON_NONCEBYTES); - session->reorder_timeout = fastd_in_seconds(conf.reorder_time); + session->reorder_timeout = fastd_in_seconds(REORDER_TIME); return true; } else if (age == 0 || session->receive_reorder_seen & (1 << (age-1))) { diff --git a/src/methods/common.h b/src/methods/common.h index ea4a13a..7b0a4ff 100644 --- a/src/methods/common.h +++ b/src/methods/common.h @@ -73,7 +73,7 @@ static inline bool fastd_method_session_common_want_refresh(const fastd_method_c } static inline void fastd_method_session_common_superseded(fastd_method_common_t *session) { - struct timespec valid_max = fastd_in_seconds(conf.key_valid_old); + struct timespec valid_max = fastd_in_seconds(KEY_VALID_OLD); if (timespec_after(&session->valid_till, &valid_max)) session->valid_till = valid_max; diff --git a/src/peer.c b/src/peer.c index 662504d..c6eee35 100644 --- a/src/peer.c +++ b/src/peer.c @@ -736,7 +736,7 @@ static void send_handshake(fastd_peer_t *peer, fastd_remote_t *next_remote) { } pr_debug("sending handshake to %P[%I]...", peer, &peer->address); - peer->last_handshake_timeout = fastd_in_seconds(conf.min_handshake_interval); + peer->last_handshake_timeout = fastd_in_seconds(MIN_HANDSHAKE_INTERVAL); peer->last_handshake_address = peer->address; conf.protocol->handshake_init(peer->sock, &peer->local_address, &peer->address, peer); } @@ -841,7 +841,7 @@ void fastd_peer_eth_addr_add(fastd_peer_t *peer, fastd_eth_addr_t addr) { if (cmp == 0) { VECTOR_INDEX(ctx.eth_addrs, cur).peer = peer; - VECTOR_INDEX(ctx.eth_addrs, cur).timeout = fastd_in_seconds(conf.eth_addr_stale_time); + VECTOR_INDEX(ctx.eth_addrs, cur).timeout = fastd_in_seconds(ETH_ADDR_STALE_TIME); return; /* We're done here. */ } else if (cmp < 0) { @@ -852,7 +852,7 @@ void fastd_peer_eth_addr_add(fastd_peer_t *peer, fastd_eth_addr_t addr) { } } - VECTOR_INSERT(ctx.eth_addrs, ((fastd_peer_eth_addr_t) {addr, peer, fastd_in_seconds(conf.eth_addr_stale_time)}), min); + VECTOR_INSERT(ctx.eth_addrs, ((fastd_peer_eth_addr_t) {addr, peer, fastd_in_seconds(ETH_ADDR_STALE_TIME)}), min); pr_debug("learned new MAC address %E on peer %P", &addr, peer); } @@ -906,7 +906,7 @@ static void eth_addr_cleanup(void) { if (fastd_timed_out(&VECTOR_INDEX(ctx.eth_addrs, i).timeout)) { deleted++; pr_debug("MAC address %E not seen for more than %u seconds, removing", - &VECTOR_INDEX(ctx.eth_addrs, i).addr, conf.eth_addr_stale_time); + &VECTOR_INDEX(ctx.eth_addrs, i).addr, ETH_ADDR_STALE_TIME); } else if (deleted) { VECTOR_INDEX(ctx.eth_addrs, i-deleted) = VECTOR_INDEX(ctx.eth_addrs, i); diff --git a/src/peer.h b/src/peer.h index b555c85..50e8a68 100644 --- a/src/peer.h +++ b/src/peer.h @@ -182,12 +182,12 @@ static inline void fastd_peer_unschedule_handshake(fastd_peer_t *peer) { #ifdef WITH_VERIFY static inline void fastd_peer_set_verifying(fastd_peer_t *peer) { - peer->verify_timeout = fastd_in_seconds(conf.min_verify_interval); + peer->verify_timeout = fastd_in_seconds(MIN_VERIFY_INTERVAL); } static inline void fastd_peer_set_verified(fastd_peer_t *peer, bool ok) { if (ok) - peer->verify_valid_timeout = fastd_in_seconds(conf.verify_valid_time); + peer->verify_valid_timeout = fastd_in_seconds(VERIFY_VALID_TIME); else peer->verify_valid_timeout = ctx.now; } @@ -233,7 +233,7 @@ static inline bool fastd_remote_is_dynamic(const fastd_remote_t *remote) { } static inline void fastd_peer_seen(fastd_peer_t *peer) { - peer->timeout = fastd_in_seconds(conf.peer_stale_time); + peer->timeout = fastd_in_seconds(PEER_STALE_TIME); } static inline bool fastd_peer_is_socket_dynamic(const fastd_peer_t *peer) { diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c index eca1cd1..70944fe 100644 --- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c +++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c @@ -169,7 +169,7 @@ static void session_send(fastd_peer_t *peer, fastd_buffer_t buffer, protocol_ses } fastd_send(peer->sock, &peer->local_address, &peer->address, peer, send_buffer, stat_size); - peer->keepalive_timeout = fastd_in_seconds(conf.keepalive_timeout); + peer->keepalive_timeout = fastd_in_seconds(KEEPALIVE_TIMEOUT); } static void protocol_send(fastd_peer_t *peer, fastd_buffer_t buffer) { diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c index 725a827..c29b7b1 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.c +++ b/src/protocols/ec25519_fhmqvc/handshake.c @@ -148,7 +148,7 @@ static bool establish(fastd_peer_t *peer, const fastd_method_info_t *method, fas return false; } - peer->establish_handshake_timeout = fastd_in_seconds(conf.min_handshake_interval); + peer->establish_handshake_timeout = fastd_in_seconds(MIN_HANDSHAKE_INTERVAL); fastd_peer_seen(peer); fastd_peer_set_established(peer); @@ -571,7 +571,7 @@ void fastd_protocol_ec25519_fhmqvc_handle_verify_return(fastd_peer_t *peer, fast const verify_data_t *data = protocol_data; - peer->last_handshake_response_timeout = fastd_in_seconds(conf.min_handshake_interval); + peer->last_handshake_response_timeout = fastd_in_seconds(MIN_HANDSHAKE_INTERVAL); peer->last_handshake_response_address = *remote_addr; respond_handshake(sock, local_addr, remote_addr, peer, &data->peer_handshake_key, method); } @@ -655,7 +655,7 @@ void fastd_protocol_ec25519_fhmqvc_handshake_handle(fastd_socket_t *sock, const pr_verbose("received handshake from %P[%I]%s%s", peer, remote_addr, handshake->peer_version ? " using fastd " : "", handshake->peer_version ?: ""); - peer->last_handshake_response_timeout = fastd_in_seconds(conf.min_handshake_interval); + peer->last_handshake_response_timeout = fastd_in_seconds(MIN_HANDSHAKE_INTERVAL); peer->last_handshake_response_address = *remote_addr; respond_handshake(sock, local_addr, remote_addr, peer, &peer_handshake_key, method); return; diff --git a/src/receive.c b/src/receive.c index 8fd5bf8..9a528fe 100644 --- a/src/receive.c +++ b/src/receive.c @@ -99,7 +99,7 @@ static bool backoff_unknown(const fastd_peer_address_t *addr) { fastd_handshake_timeout_t *t = &ctx.unknown_handshakes[ctx.unknown_handshake_pos]; t->address = *addr; - t->timeout = fastd_in_seconds(conf.min_handshake_interval); + t->timeout = fastd_in_seconds(MIN_HANDSHAKE_INTERVAL); return false; } diff --git a/src/resolve.c b/src/resolve.c index d539e56..0415852 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -124,7 +124,7 @@ void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote) { pr_verbose("resolving host `%s' for peer %P...", remote->config->hostname, peer); - remote->last_resolve_timeout = fastd_in_seconds(conf.min_resolve_interval); + remote->last_resolve_timeout = fastd_in_seconds(MIN_RESOLVE_INTERVAL); resolv_arg_t *arg = malloc(sizeof(resolv_arg_t)); -- cgit v1.2.3