diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-28 02:32:18 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-28 02:32:18 +0200 |
commit | 1653c57e8167c69c11bf9aade23bdbc5207c196d (patch) | |
tree | 166ac829c50fad8ae283e4098cf0d1589458c0b4 /src/peer.c | |
parent | 22a6b5706593d222bfc602859dbccd7beb5231ed (diff) | |
download | fastd-1653c57e8167c69c11bf9aade23bdbc5207c196d.tar fastd-1653c57e8167c69c11bf9aade23bdbc5207c196d.zip |
Make peer takeover work
Diffstat (limited to 'src/peer.c')
-rw-r--r-- | src/peer.c | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -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: |