summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/fastd.c6
-rw-r--r--src/peer.c3
-rw-r--r--src/peer.h16
3 files changed, 16 insertions, 9 deletions
diff --git a/src/fastd.c b/src/fastd.c
index e39a1bc..0be82c4 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -212,10 +212,10 @@ static void init_peers(void) {
for (peer_conf = ctx.peer_configs; peer_conf; peer_conf = peer_conf->next) {
bool enable = conf.protocol->peer_check(peer_conf);
- if (enable && !peer_conf->enabled)
+ if (enable && peer_conf->config_state == CONFIG_DISABLED)
fastd_peer_add(peer_conf);
- peer_conf->enabled = enable;
+ peer_conf->config_state = enable ? CONFIG_STATIC : CONFIG_DISABLED;
}
size_t i;
@@ -229,7 +229,7 @@ static void init_peers(void) {
}
}
else {
- if (!peer->config->enabled) {
+ if (peer->config->config_state == CONFIG_DISABLED) {
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 9c3186e..8609894 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -742,8 +742,7 @@ fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf) {
exit_bug("tried to add dynamic peer without on-verify command");
peer->config = fastd_peer_config_new(conf.peer_group);
-
- peer->dynamic = true;
+ peer->config->config_state = CONFIG_DYNAMIC;
peer->verify_timeout = ctx.now;
peer->verify_valid_timeout = ctx.now;
diff --git a/src/peer.h b/src/peer.h
index 9638808..eec7bb0 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -43,6 +43,15 @@ typedef enum fastd_peer_state {
STATE_ESTABLISHED, /**< The peer has established a connection */
} fastd_peer_state_t;
+/** The config state of a peer */
+typedef enum fastd_peer_config_state {
+ CONFIG_DISABLED = 0, /**< The peer is configured statically, but has been not yet been enabled or disabled because of a configuration error */
+ CONFIG_STATIC, /**< The peer is configured statically */
+#ifdef WITH_DYNAMIC_PEERS
+ CONFIG_DYNAMIC, /**< The peer is configured dynamically (using a on-verify handler) */
+#endif
+} fastd_peer_config_state_t;
+
/** Dynamic state of a peer */
struct fastd_peer {
uint64_t id; /**< A unique ID assigned to each peer */
@@ -74,8 +83,6 @@ 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_DYNAMIC_PEERS
- 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
@@ -91,9 +98,10 @@ struct fastd_peer {
struct fastd_peer_config {
fastd_peer_config_t *next; /**< The next peer configuration */
+ fastd_peer_config_state_t config_state; /**< Specifies the way this peer was configured and if it is enabled */
+
const char *config_source_dir; /**< The directory this peer's configuration was loaded from */
- bool enabled; /**< Specifies if this peer was disabled because of a configuration error */
char *name; /**< The peer's name */
fastd_remote_config_t *remotes; /**< A linked list of the peer's remote entries */
@@ -231,7 +239,7 @@ 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 UNUSED) {
#ifdef WITH_DYNAMIC_PEERS
- return peer->dynamic;
+ return peer->config->config_state == CONFIG_DYNAMIC;
#else
return false;
#endif