summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-04-25 00:56:07 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-04-25 00:56:07 +0200
commit482ddc46a62b9a6b8bd615fd35b2bac6d3b7d841 (patch)
treec96ed40c8c3c962fd17235809fb49b2b23e93dbc /src
parent1bb1eb5a334e919d0f57ffa2746c64394b47d1e9 (diff)
downloadfastd-482ddc46a62b9a6b8bd615fd35b2bac6d3b7d841.tar
fastd-482ddc46a62b9a6b8bd615fd35b2bac6d3b7d841.zip
fastd_peer_claim_address: add parameter to allow claiming addresses of established peers
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c2
-rw-r--r--src/peer.c7
-rw-r--r--src/peer.h2
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.c2
4 files changed, 9 insertions, 4 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 5c63ec6..3ee445a 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -412,7 +412,7 @@ static void send_handshake(fastd_peer_t *peer) {
return;
}
- fastd_peer_claim_address(peer, NULL, NULL, &peer->next_remote->addresses[peer->next_remote->current_address]);
+ fastd_peer_claim_address(peer, NULL, NULL, &peer->next_remote->addresses[peer->next_remote->current_address], false);
fastd_peer_reset_socket(peer);
}
diff --git a/src/peer.c b/src/peer.c
index feacc73..2d4b8bf 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -447,7 +447,7 @@ bool fastd_peer_matches_address(const fastd_peer_t *peer, const fastd_peer_addre
return false;
}
-bool fastd_peer_claim_address(fastd_peer_t *new_peer, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr) {
+bool fastd_peer_claim_address(fastd_peer_t *new_peer, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, bool force) {
if (remote_addr->sa.sa_family == AF_UNSPEC) {
if (fastd_peer_is_established(new_peer))
fastd_peer_reset(new_peer);
@@ -466,6 +466,11 @@ bool fastd_peer_claim_address(fastd_peer_t *new_peer, fastd_socket_t *sock, cons
}
if (fastd_peer_address_equal(&peer->address, remote_addr)) {
+ if (!force && fastd_peer_is_established(peer)) {
+ reset_peer_address(new_peer);
+ return false;
+ }
+
reset_peer_address(peer);
break;
}
diff --git a/src/peer.h b/src/peer.h
index 8496ee7..41cee20 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -139,7 +139,7 @@ bool fastd_peer_may_connect(fastd_peer_t *peer);
void fastd_peer_handle_resolve(fastd_peer_t *peer, fastd_remote_t *remote, size_t n_addresses, const fastd_peer_address_t *addresses);
bool fastd_peer_owns_address(const fastd_peer_t *peer, const fastd_peer_address_t *addr);
bool fastd_peer_matches_address(const fastd_peer_t *peer, const fastd_peer_address_t *addr);
-bool fastd_peer_claim_address(fastd_peer_t *peer, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr);
+bool fastd_peer_claim_address(fastd_peer_t *peer, fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, bool force);
void fastd_peer_reset_socket(fastd_peer_t *peer);
void fastd_peer_schedule_handshake(fastd_peer_t *peer, int delay);
fastd_peer_t* fastd_peer_find_by_id(uint64_t id);
diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c
index 444ce32..7e893c8 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.c
+++ b/src/protocols/ec25519_fhmqvc/handshake.c
@@ -135,7 +135,7 @@ static bool establish(fastd_peer_t *peer, const fastd_method_info_t *method, fas
pr_verbose("%I authorized as %P", remote_addr, peer);
- if (!fastd_peer_claim_address(peer, sock, local_addr, remote_addr)) {
+ if (!fastd_peer_claim_address(peer, sock, local_addr, remote_addr, true)) {
pr_warn("can't establish session with %P[%I] as the address is used by another peer", peer, remote_addr);
fastd_peer_reset(peer);
return false;