diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fastd.c | 2 | ||||
-rw-r--r-- | src/peer.c | 38 | ||||
-rw-r--r-- | src/peer.h | 1 | ||||
-rw-r--r-- | src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c | 2 |
4 files changed, 22 insertions, 21 deletions
diff --git a/src/fastd.c b/src/fastd.c index 70f4248..af17c24 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -370,7 +370,7 @@ static void cleanup_peers(fastd_context *ctx) { if (fastd_peer_is_temporary(peer)) { if (timespec_diff(&ctx->now, &peer->seen) > ctx->conf->peer_stale_time_temp*1000) - fastd_peer_delete(ctx, peer); + fastd_peer_reset(ctx, peer); } else if (fastd_peer_is_established(peer)) { if (timespec_diff(&ctx->now, &peer->seen) > ctx->conf->peer_stale_time*1000) @@ -63,6 +63,20 @@ static inline void setup_peer(fastd_context *ctx, fastd_peer *peer) { fastd_task_schedule_handshake(ctx, peer, 0, false); } +static void delete_peer(fastd_context *ctx, fastd_peer *peer) { + pr_debug(ctx, "deleting peer %P", peer); + + fastd_peer **cur_peer; + for (cur_peer = &ctx->peers; *cur_peer; cur_peer = &(*cur_peer)->next) { + if ((*cur_peer) == peer) { + *cur_peer = peer->next; + break; + } + } + + free(peer); +} + fastd_peer_config* fastd_peer_config_new(fastd_context *ctx, fastd_config *conf) { fastd_peer_config *peer = malloc(sizeof(fastd_peer_config)); @@ -85,7 +99,11 @@ void fastd_peer_reset(fastd_context *ctx, fastd_peer *peer) { pr_debug(ctx, "resetting peer %P", peer); reset_peer(ctx, peer); - setup_peer(ctx, peer); + + if (fastd_peer_is_temporary(peer)) + delete_peer(ctx, peer); + else + setup_peer(ctx, peer); } @@ -150,27 +168,11 @@ fastd_peer* fastd_peer_merge(fastd_context *ctx, fastd_peer *perm_peer, fastd_pe } } - fastd_peer_delete(ctx, temp_peer); + fastd_peer_reset(ctx, temp_peer); return perm_peer; } -void fastd_peer_delete(fastd_context *ctx, fastd_peer *peer) { - pr_debug(ctx, "deleting peer %P", peer); - - reset_peer(ctx, peer); - - fastd_peer **cur_peer; - for (cur_peer = &ctx->peers; *cur_peer; cur_peer = &(*cur_peer)->next) { - if ((*cur_peer) == peer) { - *cur_peer = peer->next; - break; - } - } - - free(peer); -} - const fastd_eth_addr* fastd_get_source_address(const fastd_context *ctx, fastd_buffer buffer) { switch (ctx->conf->mode) { case MODE_TAP: @@ -77,7 +77,6 @@ void fastd_peer_reset(fastd_context *ctx, fastd_peer *peer); fastd_peer* fastd_peer_add(fastd_context *ctx, fastd_peer_config *conf); fastd_peer* fastd_peer_add_temp(fastd_context *ctx, const fastd_peer_address *address); fastd_peer* fastd_peer_merge(fastd_context *ctx, fastd_peer *perm_peer, fastd_peer *temp_peer); -void fastd_peer_delete(fastd_context *ctx, fastd_peer *peer); const fastd_eth_addr* fastd_get_source_address(const fastd_context *ctx, fastd_buffer buffer); const fastd_eth_addr* fastd_get_dest_address(const fastd_context *ctx, fastd_buffer buffer); diff --git a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c index 9610d7b..93f0432 100644 --- a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c +++ b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c @@ -377,7 +377,7 @@ static void establish(fastd_context *ctx, fastd_peer *peer, const fastd_peer_con pr_info(ctx, "Connection with %P established.", peer); - if (fastd_peer_is_temporary(peer)) { + if (peer_config != peer->config) { fastd_peer *perm_peer; for (perm_peer = ctx->peers; perm_peer; perm_peer = perm_peer->next) { if (perm_peer->config == peer_config) { |