summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/async.c4
-rw-r--r--src/fastd.c8
-rw-r--r--src/peer.c4
-rw-r--r--src/peer.h10
-rw-r--r--src/resolve.c2
5 files changed, 18 insertions, 10 deletions
diff --git a/src/async.c b/src/async.c
index 7ab78ce..4348194 100644
--- a/src/async.c
+++ b/src/async.c
@@ -66,7 +66,7 @@ static void handle_resolve_return(const fastd_async_resolve_return_t *resolve_re
if (!peer)
return;
- if (!peer->config)
+ if (fastd_peer_is_dynamic(peer))
exit_bug("resolve return for dynamic peer");
fastd_remote_t *remote = &VECTOR_INDEX(peer->remotes, resolve_return->remote);
@@ -81,7 +81,7 @@ static void handle_verify_return(const fastd_async_verify_return_t *verify_retur
if (!peer)
return;
- if (peer->config)
+ if (!fastd_peer_is_dynamic(peer))
exit_bug("verify return for permanent peer");
fastd_peer_set_verified(peer, verify_return->ok);
diff --git a/src/fastd.c b/src/fastd.c
index c67c875..e7f7621 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -222,15 +222,15 @@ static void init_peers(void) {
for (i = 0; i < VECTOR_LEN(ctx.peers);) {
fastd_peer_t *peer = VECTOR_INDEX(ctx.peers, i);
- if (peer->config) {
- if (!peer->config->enabled) {
- pr_info("previously enabled peer %P disabled, deleting.", peer);
+ if (fastd_peer_is_dynamic(peer)) {
+ if (!conf.protocol->peer_check_dynamic(peer)) {
fastd_peer_delete(peer);
continue;
}
}
else {
- if (!conf.protocol->peer_check_dynamic(peer)) {
+ if (!peer->config->enabled) {
+ pr_info("previously enabled peer %P disabled, deleting.", peer);
fastd_peer_delete(peer);
continue;
}
diff --git a/src/peer.c b/src/peer.c
index 176b39c..20058fb 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -423,7 +423,7 @@ static void delete_peer(fastd_peer_t *peer) {
conf.protocol->free_peer_state(peer);
- if (!peer->config)
+ if (fastd_peer_is_dynamic(peer))
free(peer->protocol_config);
for (i = 0; i < VECTOR_LEN(peer->remotes); i++)
@@ -742,6 +742,8 @@ fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf) {
if (!fastd_shell_command_isset(&conf.on_verify))
exit_bug("tried to add dynamic peer without on-verify command");
+ peer->dynamic = true;
+
peer->verify_timeout = ctx.now;
peer->verify_valid_timeout = ctx.now;
diff --git a/src/peer.h b/src/peer.h
index 99d84f9..3451343 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -74,6 +74,8 @@ struct fastd_peer {
struct timespec establish_handshake_timeout; /**< A timeout during which all handshakes for this peer will be ignored after a new connection has been established */
#ifdef WITH_VERIFY
+ bool dynamic; /**< Specifies if the peer has been added dynamically by a on-verify script */
+
struct timespec verify_timeout; /**< Specifies the minimum time after which on-verify may be run again */
struct timespec verify_valid_timeout; /**< Specifies how long a peer stays valid after a successful on-verify run */
#endif
@@ -228,8 +230,12 @@ static inline bool fastd_peer_is_floating(const fastd_peer_t *peer) {
}
/** Checks if a peer is not statically configured, but added after a on-verify run */
-static inline bool fastd_peer_is_dynamic(const fastd_peer_t *peer) {
- return (!peer->config);
+static inline bool fastd_peer_is_dynamic(const fastd_peer_t *peer UNUSED) {
+#ifdef WITH_VERIFY
+ return peer->dynamic;
+#else
+ return false;
+#endif
}
/** Returns the currently active remote entry */
diff --git a/src/resolve.c b/src/resolve.c
index b11ce9b..df48fec 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -113,7 +113,7 @@ static void* resolve_peer(void *varg) {
/** Starts to resolve a given dynamic remote of a peer to an IP address asynchronously */
void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote) {
- if (!peer->config)
+ if (fastd_peer_is_dynamic(peer))
exit_bug("trying to resolve dynamic peer");
if (!fastd_timed_out(&remote->last_resolve_timeout)) {