mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-15 04:35:08 +02:00
Unify enabled and dynamic flags into a config_state flag
This commit is contained in:
parent
c9c7cbb67c
commit
21ade840c9
3 changed files with 16 additions and 9 deletions
|
@ -212,10 +212,10 @@ static void init_peers(void) {
|
||||||
for (peer_conf = ctx.peer_configs; peer_conf; peer_conf = peer_conf->next) {
|
for (peer_conf = ctx.peer_configs; peer_conf; peer_conf = peer_conf->next) {
|
||||||
bool enable = conf.protocol->peer_check(peer_conf);
|
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);
|
fastd_peer_add(peer_conf);
|
||||||
|
|
||||||
peer_conf->enabled = enable;
|
peer_conf->config_state = enable ? CONFIG_STATIC : CONFIG_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -229,7 +229,7 @@ static void init_peers(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!peer->config->enabled) {
|
if (peer->config->config_state == CONFIG_DISABLED) {
|
||||||
pr_info("previously enabled peer %P disabled, deleting.", peer);
|
pr_info("previously enabled peer %P disabled, deleting.", peer);
|
||||||
fastd_peer_delete(peer);
|
fastd_peer_delete(peer);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -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");
|
exit_bug("tried to add dynamic peer without on-verify command");
|
||||||
|
|
||||||
peer->config = fastd_peer_config_new(conf.peer_group);
|
peer->config = fastd_peer_config_new(conf.peer_group);
|
||||||
|
peer->config->config_state = CONFIG_DYNAMIC;
|
||||||
peer->dynamic = true;
|
|
||||||
|
|
||||||
peer->verify_timeout = ctx.now;
|
peer->verify_timeout = ctx.now;
|
||||||
peer->verify_valid_timeout = ctx.now;
|
peer->verify_valid_timeout = ctx.now;
|
||||||
|
|
16
src/peer.h
16
src/peer.h
|
@ -43,6 +43,15 @@ typedef enum fastd_peer_state {
|
||||||
STATE_ESTABLISHED, /**< The peer has established a connection */
|
STATE_ESTABLISHED, /**< The peer has established a connection */
|
||||||
} fastd_peer_state_t;
|
} 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 */
|
/** Dynamic state of a peer */
|
||||||
struct fastd_peer {
|
struct fastd_peer {
|
||||||
uint64_t id; /**< A unique ID assigned to each 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 */
|
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
|
#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_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 */
|
struct timespec verify_valid_timeout; /**< Specifies how long a peer stays valid after a successful on-verify run */
|
||||||
#endif
|
#endif
|
||||||
|
@ -91,9 +98,10 @@ struct fastd_peer {
|
||||||
struct fastd_peer_config {
|
struct fastd_peer_config {
|
||||||
fastd_peer_config_t *next; /**< The next peer configuration */
|
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 */
|
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 */
|
char *name; /**< The peer's name */
|
||||||
|
|
||||||
fastd_remote_config_t *remotes; /**< A linked list of the peer's remote entries */
|
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 */
|
/** 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) {
|
static inline bool fastd_peer_is_dynamic(const fastd_peer_t *peer UNUSED) {
|
||||||
#ifdef WITH_DYNAMIC_PEERS
|
#ifdef WITH_DYNAMIC_PEERS
|
||||||
return peer->dynamic;
|
return peer->config->config_state == CONFIG_DYNAMIC;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue