mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-15 04:35:08 +02:00
Make a few struct fields that are not supposed to be changed defines instead
This commit is contained in:
parent
1b21919d54
commit
f34e51a1c3
12 changed files with 39 additions and 57 deletions
19
src/config.c
19
src/config.c
|
@ -54,16 +54,6 @@ static void default_config(void) {
|
||||||
|
|
||||||
conf.log_syslog_ident = strdup("fastd");
|
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.mtu = 1500;
|
||||||
conf.mode = MODE_TAP;
|
conf.mode = MODE_TAP;
|
||||||
|
|
||||||
|
@ -71,15 +61,6 @@ static void default_config(void) {
|
||||||
conf.drop_caps = DROP_CAPS_ON;
|
conf.drop_caps = DROP_CAPS_ON;
|
||||||
|
|
||||||
conf.protocol = &fastd_protocol_ec25519_fhmqvc;
|
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 = calloc(1, sizeof(fastd_peer_group_config_t));
|
||||||
conf.peer_group->name = strdup("default");
|
conf.peer_group->name = strdup("default");
|
||||||
|
|
|
@ -307,7 +307,7 @@ static inline void maintenance(void) {
|
||||||
fastd_socket_handle_binds();
|
fastd_socket_handle_binds();
|
||||||
fastd_peer_maintenance();
|
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();
|
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;
|
ctx.unknown_handshakes[0].timeout = ctx.now;
|
||||||
|
|
||||||
|
|
20
src/fastd.h
20
src/fastd.h
|
@ -159,27 +159,13 @@ struct fastd_handshake_timeout {
|
||||||
struct timespec timeout; /**< Timeout until handshakes from this address are ignored */
|
struct timespec timeout; /**< Timeout until handshakes from this address are ignored */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** The static configuration of \em fastd */
|
/** The static configuration of \em fastd */
|
||||||
struct fastd_config {
|
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_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) */
|
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") */
|
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;
|
char *ifname;
|
||||||
|
|
||||||
size_t n_bind_addrs;
|
size_t n_bind_addrs;
|
||||||
|
@ -217,10 +203,6 @@ struct fastd_config {
|
||||||
size_t min_decrypt_tail_space;
|
size_t min_decrypt_tail_space;
|
||||||
|
|
||||||
char *secret;
|
char *secret;
|
||||||
unsigned key_valid;
|
|
||||||
unsigned key_valid_old;
|
|
||||||
unsigned key_refresh;
|
|
||||||
unsigned key_refresh_splay;
|
|
||||||
|
|
||||||
const fastd_cipher_t **ciphers;
|
const fastd_cipher_t **ciphers;
|
||||||
const fastd_mac_t **macs;
|
const fastd_mac_t **macs;
|
||||||
|
|
|
@ -53,3 +53,22 @@
|
||||||
#cmakedefine ENABLE_SYSTEMD
|
#cmakedefine ENABLE_SYSTEMD
|
||||||
|
|
||||||
#define MAX_CONFIG_DEPTH @MAX_CONFIG_DEPTH_NUM@
|
#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 */
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
void fastd_method_common_init(fastd_method_common_t *session, bool initiator) {
|
void fastd_method_common_init(fastd_method_common_t *session, bool initiator) {
|
||||||
memset(session, 0, sizeof(*session));
|
memset(session, 0, sizeof(*session));
|
||||||
|
|
||||||
session->valid_till = fastd_in_seconds(conf.key_valid);
|
session->valid_till = fastd_in_seconds(KEY_VALID);
|
||||||
session->refresh_after = fastd_in_seconds(conf.key_refresh - fastd_rand(0, conf.key_refresh_splay));
|
session->refresh_after = fastd_in_seconds(KEY_REFRESH - fastd_rand(0, KEY_REFRESH_SPLAY));
|
||||||
|
|
||||||
if (initiator) {
|
if (initiator) {
|
||||||
session->send_nonce[COMMON_NONCEBYTES-1] = 3;
|
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));
|
session->receive_reorder_seen |= (1 << (shift-1));
|
||||||
|
|
||||||
memcpy(session->receive_nonce, nonce, COMMON_NONCEBYTES);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else if (age == 0 || session->receive_reorder_seen & (1 << (age-1))) {
|
else if (age == 0 || session->receive_reorder_seen & (1 << (age-1))) {
|
||||||
|
|
|
@ -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) {
|
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))
|
if (timespec_after(&session->valid_till, &valid_max))
|
||||||
session->valid_till = valid_max;
|
session->valid_till = valid_max;
|
||||||
|
|
|
@ -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);
|
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;
|
peer->last_handshake_address = peer->address;
|
||||||
conf.protocol->handshake_init(peer->sock, &peer->local_address, &peer->address, peer);
|
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) {
|
if (cmp == 0) {
|
||||||
VECTOR_INDEX(ctx.eth_addrs, cur).peer = peer;
|
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. */
|
return; /* We're done here. */
|
||||||
}
|
}
|
||||||
else if (cmp < 0) {
|
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);
|
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)) {
|
if (fastd_timed_out(&VECTOR_INDEX(ctx.eth_addrs, i).timeout)) {
|
||||||
deleted++;
|
deleted++;
|
||||||
pr_debug("MAC address %E not seen for more than %u seconds, removing",
|
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) {
|
else if (deleted) {
|
||||||
VECTOR_INDEX(ctx.eth_addrs, i-deleted) = VECTOR_INDEX(ctx.eth_addrs, i);
|
VECTOR_INDEX(ctx.eth_addrs, i-deleted) = VECTOR_INDEX(ctx.eth_addrs, i);
|
||||||
|
|
|
@ -182,12 +182,12 @@ static inline void fastd_peer_unschedule_handshake(fastd_peer_t *peer) {
|
||||||
|
|
||||||
#ifdef WITH_VERIFY
|
#ifdef WITH_VERIFY
|
||||||
static inline void fastd_peer_set_verifying(fastd_peer_t *peer) {
|
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) {
|
static inline void fastd_peer_set_verified(fastd_peer_t *peer, bool ok) {
|
||||||
if (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
|
else
|
||||||
peer->verify_valid_timeout = ctx.now;
|
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) {
|
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) {
|
static inline bool fastd_peer_is_socket_dynamic(const fastd_peer_t *peer) {
|
||||||
|
|
|
@ -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);
|
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) {
|
static void protocol_send(fastd_peer_t *peer, fastd_buffer_t buffer) {
|
||||||
|
|
|
@ -148,7 +148,7 @@ static bool establish(fastd_peer_t *peer, const fastd_method_info_t *method, fas
|
||||||
return false;
|
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_seen(peer);
|
||||||
fastd_peer_set_established(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;
|
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;
|
peer->last_handshake_response_address = *remote_addr;
|
||||||
respond_handshake(sock, local_addr, remote_addr, peer, &data->peer_handshake_key, method);
|
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 ?: "");
|
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;
|
peer->last_handshake_response_address = *remote_addr;
|
||||||
respond_handshake(sock, local_addr, remote_addr, peer, &peer_handshake_key, method);
|
respond_handshake(sock, local_addr, remote_addr, peer, &peer_handshake_key, method);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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];
|
fastd_handshake_timeout_t *t = &ctx.unknown_handshakes[ctx.unknown_handshake_pos];
|
||||||
|
|
||||||
t->address = *addr;
|
t->address = *addr;
|
||||||
t->timeout = fastd_in_seconds(conf.min_handshake_interval);
|
t->timeout = fastd_in_seconds(MIN_HANDSHAKE_INTERVAL);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
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));
|
resolv_arg_t *arg = malloc(sizeof(resolv_arg_t));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue