summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-04-05 05:21:58 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-04-05 05:21:58 +0200
commit329d15d50c54a69ce8e2be0865124744c0bf3428 (patch)
tree34734e0ed120a83069738a0a51df9bdd1a664640 /src/peer.c
parentcbf0166a7f12f71747c495b5ea68ff676c1a7868 (diff)
downloadfastd-329d15d50c54a69ce8e2be0865124744c0bf3428.tar
fastd-329d15d50c54a69ce8e2be0865124744c0bf3428.zip
Implement reconfiguration on SIGHUP
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/src/peer.c b/src/peer.c
index 1a418e8..9bb900b 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -95,16 +95,69 @@ fastd_peer_config* fastd_peer_config_new(fastd_context *ctx, fastd_config *conf)
return peer;
}
-void fastd_peer_config_delete(fastd_context *ctx, fastd_config *conf) {
- fastd_peer_config *peer = conf->peers, *next = peer->next;
-
+void fastd_peer_config_free(fastd_peer_config *peer) {
free(peer->name);
free(peer->key);
+ free(peer->protocol_config);
free(peer);
+}
+void fastd_peer_config_delete(fastd_context *ctx, fastd_config *conf) {
+ fastd_peer_config *peer = conf->peers, *next = peer->next;
+ fastd_peer_config_free(peer);
conf->peers = next;
}
+void fastd_peer_config_purge(fastd_context *ctx, fastd_peer_config *conf) {
+ fastd_peer *peer, *next;
+ for (peer = ctx->peers; peer; peer = next) {
+ next = peer->next;
+
+ if (peer->config == conf) {
+ reset_peer(ctx, peer);
+ delete_peer(ctx, peer);
+ continue;
+ }
+ }
+
+ ctx->conf->protocol->peer_config_purged(ctx, conf);
+ fastd_peer_config_free(conf);
+}
+
+static bool fastd_peer_addr_equal(const fastd_peer_address *addr1, const fastd_peer_address *addr2) {
+ if (addr1->sa.sa_family != addr2->sa.sa_family)
+ return false;
+
+ switch (addr1->sa.sa_family) {
+ case AF_UNSPEC:
+ break;
+
+ case AF_INET:
+ if (addr1->in.sin_addr.s_addr != addr2->in.sin_addr.s_addr)
+ return false;
+ break;
+
+ case AF_INET6:
+ if (!IN6_ARE_ADDR_EQUAL(&addr1->in6.sin6_addr, &addr2->in6.sin6_addr))
+ return false;
+ }
+
+ return true;
+}
+
+bool fastd_peer_config_equal(const fastd_peer_config *peer1, const fastd_peer_config *peer2) {
+ if (peer1->enabled != peer2->enabled)
+ return false;
+
+ if (!fastd_peer_addr_equal(&peer1->address, &peer2->address))
+ return false;
+
+ if (!strequal(peer1->key, peer2->key))
+ return false;
+
+ return true;
+}
+
void fastd_peer_reset(fastd_context *ctx, fastd_peer *peer) {
pr_debug(ctx, "resetting peer %P", peer);
@@ -116,7 +169,6 @@ void fastd_peer_reset(fastd_context *ctx, fastd_peer *peer) {
setup_peer(ctx, peer);
}
-
static fastd_peer* add_peer(fastd_context *ctx) {
fastd_peer *peer = malloc(sizeof(fastd_peer));