diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-03-08 22:07:02 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-03-08 22:07:02 +0100 |
commit | 103133c2fc7110085bbb730a71c762f6759e84e9 (patch) | |
tree | c98267c41ebe08c1157de6fbb8f637aec78df0d2 /src/fastd.c | |
parent | 56255a15a35650098c2358107e2dc4f21df43241 (diff) | |
download | fastd-103133c2fc7110085bbb730a71c762f6759e84e9.tar fastd-103133c2fc7110085bbb730a71c762f6759e84e9.zip |
Handle duplicate keys
When two peers are configured with the same key, disable both. When a temporary
peer's key is configured, delete the temporary key.
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/fastd.c b/src/fastd.c index 59a99ab..3c3d130 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -615,23 +615,31 @@ static void delete_peer_groups(fastd_context_t *ctx) { static void init_peers(fastd_context_t *ctx) { fastd_peer_config_t *peer_conf; - for (peer_conf = ctx->conf->peers; peer_conf; peer_conf = peer_conf->next) { - bool was_enabled = peer_conf->enabled; - - peer_conf->enabled = true; + for (peer_conf = ctx->conf->peers; peer_conf; peer_conf = peer_conf->next) ctx->conf->protocol->peer_configure(ctx, peer_conf); - if (peer_conf->enabled && !was_enabled) + for (peer_conf = ctx->conf->peers; peer_conf; peer_conf = peer_conf->next) { + bool enable = ctx->conf->protocol->peer_check(ctx, peer_conf); + + if (enable && !peer_conf->enabled) fastd_peer_add(ctx, peer_conf); + + peer_conf->enabled = enable; } fastd_peer_t *peer, *next; for (peer = ctx->peers; peer; peer = next) { next = peer->next; - if (!peer->config->enabled) { - pr_info(ctx, "previously enabled peer %P disabled, deleting.", peer); - fastd_peer_delete(ctx, peer); + if (peer->config) { + if (!peer->config->enabled) { + pr_info(ctx, "previously enabled peer %P disabled, deleting.", peer); + fastd_peer_delete(ctx, peer); + } + } + else { + if (!ctx->conf->protocol->peer_check_temporary(ctx, peer)) + fastd_peer_delete(ctx, peer); } } } |