summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-05-29 18:54:03 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-05-29 18:54:03 +0200
commit404785fe4a7cfc1a9a6cd9d2a9885a69992ff1ce (patch)
tree0cbe87328df40615f23b72b893f3ee318f9db5cf /src
parent2fe678653b7dd9f61dbbcd5e7d862360882bd7e8 (diff)
downloadfastd-404785fe4a7cfc1a9a6cd9d2a9885a69992ff1ce.tar
fastd-404785fe4a7cfc1a9a6cd9d2a9885a69992ff1ce.zip
Ensure peer hashtable consistency on address resets
Diffstat (limited to 'src')
-rw-r--r--src/peer.c17
-rw-r--r--src/peer_hashtable.c3
2 files changed, 12 insertions, 8 deletions
diff --git a/src/peer.c b/src/peer.c
index cc27eb4..da15114 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -361,7 +361,9 @@ void fastd_peer_handle_resolve(fastd_peer_t *peer, fastd_remote_t *remote, size_
/** Initializes a peer */
static void setup_peer(fastd_peer_t *peer) {
+ fastd_peer_hashtable_remove(peer);
peer->address.sa.sa_family = AF_UNSPEC;
+
peer->local_address.sa.sa_family = AF_UNSPEC;
peer->state = STATE_INIT;
@@ -535,11 +537,13 @@ void fastd_peer_address_widen(fastd_peer_address_t *addr) {
/** Resets a peer's address to the unspecified address */
static inline void reset_peer_address(fastd_peer_t *peer) {
- if (fastd_peer_is_established(peer))
+ if (fastd_peer_is_established(peer)) {
fastd_peer_reset(peer);
-
- fastd_peer_hashtable_remove(peer);
- memset(&peer->address, 0, sizeof(fastd_peer_address_t));
+ }
+ else {
+ fastd_peer_hashtable_remove(peer);
+ peer->address.sa.sa_family = AF_UNSPEC;
+ }
}
/** Checks if an address is statically configured for a peer */
@@ -617,11 +621,8 @@ bool fastd_peer_claim_address(fastd_peer_t *new_peer, fastd_socket_t *sock, cons
}
fastd_peer_hashtable_remove(new_peer);
-
new_peer->address = *remote_addr;
-
- if (remote_addr->sa.sa_family != AF_UNSPEC)
- fastd_peer_hashtable_insert(new_peer);
+ fastd_peer_hashtable_insert(new_peer);
if (sock && sock->addr && sock != new_peer->sock) {
free_socket(new_peer);
diff --git a/src/peer_hashtable.c b/src/peer_hashtable.c
index 475d7f9..b191f63 100644
--- a/src/peer_hashtable.c
+++ b/src/peer_hashtable.c
@@ -88,6 +88,9 @@ static size_t peer_address_bucket(const fastd_peer_address_t *addr) {
The peer address must not change while the peer is part of the table.
*/
void fastd_peer_hashtable_insert(fastd_peer_t *peer) {
+ if (!peer->address.sa.sa_family)
+ return;
+
size_t b = peer_address_bucket(&peer->address);
VECTOR_ADD(ctx.peer_addr_ht[b], peer);
}