summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-28 02:32:18 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-28 02:32:18 +0200
commit1653c57e8167c69c11bf9aade23bdbc5207c196d (patch)
tree166ac829c50fad8ae283e4098cf0d1589458c0b4 /src
parent22a6b5706593d222bfc602859dbccd7beb5231ed (diff)
downloadfastd-1653c57e8167c69c11bf9aade23bdbc5207c196d.tar
fastd-1653c57e8167c69c11bf9aade23bdbc5207c196d.zip
Make peer takeover work
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c2
-rw-r--r--src/peer.c38
-rw-r--r--src/peer.h1
-rw-r--r--src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c2
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)
diff --git a/src/peer.c b/src/peer.c
index 9eeb9f4..a15efb1 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -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:
diff --git a/src/peer.h b/src/peer.h
index d68d830..8754d2f 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -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) {